From 3f4c0720e1e3421431e7baa20882a4a4512a7fab Mon Sep 17 00:00:00 2001 From: ivar Date: Sun, 19 Oct 2025 23:41:23 +0200 Subject: Initial --- tests/IOL.Fagprove.Tests/CryptographyTests.cs | 24 ++++++++++++ tests/IOL.Fagprove.Tests/EmailTests.cs | 32 ++++++++++++++++ tests/IOL.Fagprove.Tests/HelpersTests.cs | 43 ++++++++++++++++++++++ tests/IOL.Fagprove.Tests/IOL.Fagprove.Tests.csproj | 20 ++++++++++ tests/IOL.Fagprove.Tests/PasswordHasherTests.cs | 22 +++++++++++ .../IOL.Fagprove.Tests/ReservationServiceTests.cs | 9 +++++ tests/IOL.Fagprove.Tests/UserServiceTests.cs | 7 ++++ 7 files changed, 157 insertions(+) create mode 100644 tests/IOL.Fagprove.Tests/CryptographyTests.cs create mode 100644 tests/IOL.Fagprove.Tests/EmailTests.cs create mode 100644 tests/IOL.Fagprove.Tests/HelpersTests.cs create mode 100644 tests/IOL.Fagprove.Tests/IOL.Fagprove.Tests.csproj create mode 100644 tests/IOL.Fagprove.Tests/PasswordHasherTests.cs create mode 100644 tests/IOL.Fagprove.Tests/ReservationServiceTests.cs create mode 100644 tests/IOL.Fagprove.Tests/UserServiceTests.cs (limited to 'tests/IOL.Fagprove.Tests') 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 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + 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(() => 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 -- cgit v1.3