From 919ab053bc840e5f45900e2e464fe86fb531f868 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Thu, 9 Mar 2023 20:31:17 +0200 Subject: [PATCH] Added unit testing witn xunit --- Directory.Build.props | 2 +- ReleaseNotes.xml | 7 ++++ Tuitio.sln | 12 ++++++ .../Properties/AssemblyInfo.cs | 5 +++ .../TokenStoreTests.cs | 42 +++++++++++++++++++ .../Tuitio.Application.Tests.csproj | 22 ++++++++++ 6 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/Tuitio.Application/Properties/AssemblyInfo.cs create mode 100644 test/UnitTests/Tuitio.Application.Tests/TokenStoreTests.cs create mode 100644 test/UnitTests/Tuitio.Application.Tests/Tuitio.Application.Tests.csproj diff --git a/Directory.Build.props b/Directory.Build.props index 1c60279..2fc3dd9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 2.1.0 + 2.2.0 Tudor Stanciu STA Tuitio diff --git a/ReleaseNotes.xml b/ReleaseNotes.xml index c0c61ed..0c32df4 100644 --- a/ReleaseNotes.xml +++ b/ReleaseNotes.xml @@ -68,4 +68,11 @@ ◾ Tuitio performance optimizations + + 2.2.0 + + ◾ Added unit testing witn xunit + ◾ Added some tests + + \ No newline at end of file diff --git a/Tuitio.sln b/Tuitio.sln index ce10e3a..ecb6fe1 100644 --- a/Tuitio.sln +++ b/Tuitio.sln @@ -30,6 +30,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tuitio.PublishedLanguage", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tuitio.Wrapper", "src\Tuitio.Wrapper\Tuitio.Wrapper.csproj", "{F6FEC33B-C79E-4484-B356-9C7F1A5E5D95}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{063D24C5-0823-48D6-A5DD-974CE38F8E71}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{ECDF52C7-A2AA-4070-8FCF-A79A58CFA5F6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tuitio.Application.Tests", "test\UnitTests\Tuitio.Application.Tests\Tuitio.Application.Tests.csproj", "{11F38E16-13BA-43FB-89FD-CD863FF06BA8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -60,6 +66,10 @@ Global {F6FEC33B-C79E-4484-B356-9C7F1A5E5D95}.Debug|Any CPU.Build.0 = Debug|Any CPU {F6FEC33B-C79E-4484-B356-9C7F1A5E5D95}.Release|Any CPU.ActiveCfg = Release|Any CPU {F6FEC33B-C79E-4484-B356-9C7F1A5E5D95}.Release|Any CPU.Build.0 = Release|Any CPU + {11F38E16-13BA-43FB-89FD-CD863FF06BA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {11F38E16-13BA-43FB-89FD-CD863FF06BA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {11F38E16-13BA-43FB-89FD-CD863FF06BA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11F38E16-13BA-43FB-89FD-CD863FF06BA8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -71,6 +81,8 @@ Global {CE81A435-49AC-4544-A381-FAC91BEB3C49} = {5A8FF505-3E4D-4258-BC3E-CACD74A7B98C} {67B4D1FF-D02E-4DA6-9FB8-F71667360448} = {5A8FF505-3E4D-4258-BC3E-CACD74A7B98C} {F6FEC33B-C79E-4484-B356-9C7F1A5E5D95} = {5A8FF505-3E4D-4258-BC3E-CACD74A7B98C} + {ECDF52C7-A2AA-4070-8FCF-A79A58CFA5F6} = {063D24C5-0823-48D6-A5DD-974CE38F8E71} + {11F38E16-13BA-43FB-89FD-CD863FF06BA8} = {ECDF52C7-A2AA-4070-8FCF-A79A58CFA5F6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E93DC46D-9C55-4A05-B299-497CDD90747E} diff --git a/src/Tuitio.Application/Properties/AssemblyInfo.cs b/src/Tuitio.Application/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8fbe71c --- /dev/null +++ b/src/Tuitio.Application/Properties/AssemblyInfo.cs @@ -0,0 +1,5 @@ +// Copyright (c) 2020 Tudor Stanciu + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Tuitio.Application.Tests")] diff --git a/test/UnitTests/Tuitio.Application.Tests/TokenStoreTests.cs b/test/UnitTests/Tuitio.Application.Tests/TokenStoreTests.cs new file mode 100644 index 0000000..2353592 --- /dev/null +++ b/test/UnitTests/Tuitio.Application.Tests/TokenStoreTests.cs @@ -0,0 +1,42 @@ +using Tuitio.Application.Stores; +using Tuitio.Domain.Models; +using Xunit; + +namespace Tuitio.Application.Tests +{ + public class TokenStoreTests + { + [Fact] + public void Set_ShouldSetTokenInStore() + { + // Arrange + var key = "user001"; + var expected = new Token() { TokenId = Guid.NewGuid(), UserId = 0, UserName = "test.tuitio", CreatedAt = DateTime.Now }; + var store = new TokenStore(); + + // Act + store.Set(key, expected); + var actual = store.Get(key); + + // Assert + Assert.Equal(expected, actual); + } + + [Fact] + public void Remove_ShouldRemoveTokenFromStore() + { + // Arrange + var key = "user001"; + var mock = new Token() { TokenId = Guid.NewGuid(), UserId = 0, UserName = "test.tuitio", CreatedAt = DateTime.Now }; + var store = new TokenStore(); + + // Act + store.Set(key, mock); + store.Remove(key); + var actual = store.Get(key); + + // Assert + Assert.True(actual == null); + } + } +} \ No newline at end of file diff --git a/test/UnitTests/Tuitio.Application.Tests/Tuitio.Application.Tests.csproj b/test/UnitTests/Tuitio.Application.Tests/Tuitio.Application.Tests.csproj new file mode 100644 index 0000000..427a0d7 --- /dev/null +++ b/test/UnitTests/Tuitio.Application.Tests/Tuitio.Application.Tests.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + +