summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-10-19 23:41:23 +0200
committerivar <i@oiee.no>2025-10-19 23:41:23 +0200
commit3f4c0720e1e3421431e7baa20882a4a4512a7fab (patch)
tree734ca81d7d0841d8863e3f523ebba14c282dc681 /tests
downloadfagprove-3f4c0720e1e3421431e7baa20882a4a4512a7fab.tar.xz
fagprove-3f4c0720e1e3421431e7baa20882a4a4512a7fab.zip
InitialHEADmaster
Diffstat (limited to 'tests')
-rw-r--r--tests/IOL.Fagprove.Tests/CryptographyTests.cs24
-rw-r--r--tests/IOL.Fagprove.Tests/EmailTests.cs32
-rw-r--r--tests/IOL.Fagprove.Tests/HelpersTests.cs43
-rw-r--r--tests/IOL.Fagprove.Tests/IOL.Fagprove.Tests.csproj20
-rw-r--r--tests/IOL.Fagprove.Tests/PasswordHasherTests.cs22
-rw-r--r--tests/IOL.Fagprove.Tests/ReservationServiceTests.cs9
-rw-r--r--tests/IOL.Fagprove.Tests/UserServiceTests.cs7
7 files changed, 157 insertions, 0 deletions
diff --git a/tests/IOL.Fagprove.Tests/CryptographyTests.cs b/tests/IOL.Fagprove.Tests/CryptographyTests.cs
new file mode 100644
index 0000000..9bd3f66
--- /dev/null
+++ b/tests/IOL.Fagprove.Tests/CryptographyTests.cs
@@ -0,0 +1,24 @@
+using System.Text.RegularExpressions;
+using IOL.Fagprove.Utilities;
+using Xunit;
+
+namespace PIT.ReservationService.Tests
+{
+ public class CryptographyTests
+ {
+ [Fact]
+ public void ReturnsDefaultLength()
+ {
+ var randomString = Cryptography.RandomString();
+ Assert.True(randomString.Length == 12);
+ }
+
+ [Fact]
+ public void ReturnsSpecifiedLength()
+ {
+ var length = 365;
+ var randomString = Cryptography.RandomString(length);
+ Assert.True(randomString.Length == length);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/IOL.Fagprove.Tests/EmailTests.cs b/tests/IOL.Fagprove.Tests/EmailTests.cs
new file mode 100644
index 0000000..01e6bbd
--- /dev/null
+++ b/tests/IOL.Fagprove.Tests/EmailTests.cs
@@ -0,0 +1,32 @@
+using IOL.Fagprove.Utilities;
+using Xunit;
+
+namespace PIT.ReservationService.Tests
+{
+ public class EmailTests
+ {
+ [Fact]
+ public void SendsMailGivenValidPayload()
+ {
+ var email = new Email
+ {
+ Message = "Hello",
+ Recepient = "ivar@protektit.no",
+ Title = "Test mail"
+ };
+ Assert.True(email.Send());
+ }
+
+ [Fact]
+ public void DoesNotSendMailGivenInValidPayload()
+ {
+ var email = new Email
+ {
+ Message = "",
+ Recepient = "xxx@*a12.o",
+ Title = "Test mail"
+ };
+ Assert.False(email.Send());
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/IOL.Fagprove.Tests/HelpersTests.cs b/tests/IOL.Fagprove.Tests/HelpersTests.cs
new file mode 100644
index 0000000..cbc991b
--- /dev/null
+++ b/tests/IOL.Fagprove.Tests/HelpersTests.cs
@@ -0,0 +1,43 @@
+using System;
+using IOL.Fagprove.Data.Enums;
+using IOL.Fagprove.Utilities;
+using Xunit;
+
+namespace PIT.ReservationService.Tests
+{
+ public class HelpersTests
+ {
+ private const string InvalidGuid = "asdf";
+ private const string ValidGuid = "c3c67267-60c5-4ed7-a754-61d189430da1";
+ private const string ValidUserRole = "1";
+ private const string InvalidUserRole = "12312as";
+
+ [Fact]
+ public void ToGuidReturnsDefaultGivenInvalidGuid()
+ {
+ var guid = InvalidGuid.ToGuid();
+ Assert.StrictEqual(default, guid);
+ }
+
+ [Fact]
+ public void ToGuidReturnsGuidGivenValidGuid()
+ {
+ var guid = ValidGuid.ToGuid();
+ Assert.StrictEqual(new Guid(ValidGuid), guid);
+ }
+
+ [Fact]
+ public void ToUserRoleReturnsDefaultOnInvalidString()
+ {
+ var userRole = InvalidUserRole.ToUserRole();
+ Assert.StrictEqual(default, userRole);
+ }
+
+ [Fact]
+ public void ToUserRoleReturnsUserRoleOnValidString()
+ {
+ var userRole = ValidUserRole.ToUserRole();
+ Assert.StrictEqual(UserRole.Administrator, userRole);
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/IOL.Fagprove.Tests/IOL.Fagprove.Tests.csproj b/tests/IOL.Fagprove.Tests/IOL.Fagprove.Tests.csproj
new file mode 100644
index 0000000..458cc60
--- /dev/null
+++ b/tests/IOL.Fagprove.Tests/IOL.Fagprove.Tests.csproj
@@ -0,0 +1,20 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netcoreapp3.1</TargetFramework>
+
+ <IsPackable>false</IsPackable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
+ <PackageReference Include="xunit" Version="2.4.0" />
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
+ <PackageReference Include="coverlet.collector" Version="1.0.1" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\src\IOL.Fagprove\IOL.Fagprove.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/tests/IOL.Fagprove.Tests/PasswordHasherTests.cs b/tests/IOL.Fagprove.Tests/PasswordHasherTests.cs
new file mode 100644
index 0000000..90b7847
--- /dev/null
+++ b/tests/IOL.Fagprove.Tests/PasswordHasherTests.cs
@@ -0,0 +1,22 @@
+using System;
+using IOL.Fagprove.Utilities;
+using Xunit;
+
+namespace PIT.ReservationService.Tests
+{
+ public class PasswordHasherTests
+ {
+ [Fact]
+ public void ThrowsGivenEmptyString()
+ {
+ Assert.Throws<ArgumentException>(() => PasswordHasher.HashPassword(""));
+ }
+
+ [Fact]
+ public void WorksGivenNonEmptyString()
+ {
+ var passwordHash = PasswordHasher.HashPassword("alksjhfoiuq");
+ Assert.False(string.IsNullOrWhiteSpace(passwordHash));
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/IOL.Fagprove.Tests/ReservationServiceTests.cs b/tests/IOL.Fagprove.Tests/ReservationServiceTests.cs
new file mode 100644
index 0000000..448e45d
--- /dev/null
+++ b/tests/IOL.Fagprove.Tests/ReservationServiceTests.cs
@@ -0,0 +1,9 @@
+using IOL.Fagprove.Data.Models;
+using Xunit;
+
+namespace PIT.ReservationService.Tests
+{
+ public class ReservationServiceTests
+ {
+ }
+} \ No newline at end of file
diff --git a/tests/IOL.Fagprove.Tests/UserServiceTests.cs b/tests/IOL.Fagprove.Tests/UserServiceTests.cs
new file mode 100644
index 0000000..f6ae97a
--- /dev/null
+++ b/tests/IOL.Fagprove.Tests/UserServiceTests.cs
@@ -0,0 +1,7 @@
+namespace PIT.ReservationService.Tests
+{
+ public class UserServiceTests
+ {
+
+ }
+} \ No newline at end of file