From 8ffc93c7240c08ab79758a946f39cbf35c1c4af7 Mon Sep 17 00:00:00 2001 From: David Edmiston Date: Mon, 21 Nov 2022 22:57:39 -0500 Subject: [PATCH] Implement XUnit (#14) * correct webfinger namespace * create unit test project, add poc unit test * move solution up one folder above src and test * remove working-directory from gh actions solution moved up a directory and we want to build/test all. --- .github/workflows/pr-build.yml | 4 -- Smilodon.sln | 39 +++++++++++++++++++ src/Smilodon.sln | 25 ------------ .../Api/Webfinger/WebfingerEndpoints.cs | 2 +- src/WebApp/Program.cs | 1 + .../Api/Webfinger/WebfingerEndpointsTests.cs | 17 ++++++++ test/WebApp.Test/Usings.cs | 3 ++ test/WebApp.Test/WebApp.Test.csproj | 35 +++++++++++++++++ 8 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 Smilodon.sln delete mode 100644 src/Smilodon.sln create mode 100644 test/WebApp.Test/Api/Webfinger/WebfingerEndpointsTests.cs create mode 100644 test/WebApp.Test/Usings.cs create mode 100644 test/WebApp.Test/WebApp.Test.csproj diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 7397cad..65a87aa 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -6,10 +6,6 @@ on: pull_request: branches: [ "main" ] -defaults: - run: - working-directory: src - jobs: api-build: name: WebApp Build diff --git a/Smilodon.sln b/Smilodon.sln new file mode 100644 index 0000000..f457f9c --- /dev/null +++ b/Smilodon.sln @@ -0,0 +1,39 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33103.184 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApp", "src\WebApp\WebApp.csproj", "{EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{74FC9674-053B-480C-84AC-F6AAF8B82239}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{9EC4E573-048F-40B7-8721-E28857532DF0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApp.Test", "test\WebApp.Test\WebApp.Test.csproj", "{972B3171-DDE1-4CF8-863E-B45875440A80}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA}.Release|Any CPU.Build.0 = Release|Any CPU + {972B3171-DDE1-4CF8-863E-B45875440A80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {972B3171-DDE1-4CF8-863E-B45875440A80}.Debug|Any CPU.Build.0 = Debug|Any CPU + {972B3171-DDE1-4CF8-863E-B45875440A80}.Release|Any CPU.ActiveCfg = Release|Any CPU + {972B3171-DDE1-4CF8-863E-B45875440A80}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA} = {74FC9674-053B-480C-84AC-F6AAF8B82239} + {972B3171-DDE1-4CF8-863E-B45875440A80} = {9EC4E573-048F-40B7-8721-E28857532DF0} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B464DC23-8514-4B57-BA12-524A7C3994FA} + EndGlobalSection +EndGlobal diff --git a/src/Smilodon.sln b/src/Smilodon.sln deleted file mode 100644 index cf0fffd..0000000 --- a/src/Smilodon.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.4.33103.184 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApp", "WebApp\WebApp.csproj", "{EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EF2B2EA7-D380-46EA-A2CE-D7C9D22B18FA}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B464DC23-8514-4B57-BA12-524A7C3994FA} - EndGlobalSection -EndGlobal diff --git a/src/WebApp/Api/Webfinger/WebfingerEndpoints.cs b/src/WebApp/Api/Webfinger/WebfingerEndpoints.cs index 8ebb555..c799e40 100644 --- a/src/WebApp/Api/Webfinger/WebfingerEndpoints.cs +++ b/src/WebApp/Api/Webfinger/WebfingerEndpoints.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; -namespace Smilodon.WebApp.Api.Admin; +namespace Smilodon.WebApp.Api.Webfinger; public static class WebfingerEndpoints { diff --git a/src/WebApp/Program.cs b/src/WebApp/Program.cs index 45de879..961145f 100644 --- a/src/WebApp/Program.cs +++ b/src/WebApp/Program.cs @@ -1,4 +1,5 @@ using Smilodon.WebApp.Api.Admin; +using Smilodon.WebApp.Api.Webfinger; var builder = WebApplication.CreateBuilder(args); diff --git a/test/WebApp.Test/Api/Webfinger/WebfingerEndpointsTests.cs b/test/WebApp.Test/Api/Webfinger/WebfingerEndpointsTests.cs new file mode 100644 index 0000000..5cffb3e --- /dev/null +++ b/test/WebApp.Test/Api/Webfinger/WebfingerEndpointsTests.cs @@ -0,0 +1,17 @@ +using AutoFixture.Xunit2; +using Microsoft.AspNetCore.Http.HttpResults; +using Smilodon.WebApp.Api.Webfinger; + +namespace WebApp.Test.Api.Webfinger +{ + public class WebfingerEndpointsTests + { + [Theory, AutoData] + public async Task GetAllAccountReturnsResource(string resourceName) + { + var result = await WebfingerEndpoints.GetAllAccount(resourceName); + result.Should().BeOfType>() + .Which.Value.Should().Be(resourceName); + } + } +} diff --git a/test/WebApp.Test/Usings.cs b/test/WebApp.Test/Usings.cs new file mode 100644 index 0000000..5754103 --- /dev/null +++ b/test/WebApp.Test/Usings.cs @@ -0,0 +1,3 @@ +global using Xunit; +global using FluentAssertions; +global using AutoFixture; \ No newline at end of file diff --git a/test/WebApp.Test/WebApp.Test.csproj b/test/WebApp.Test/WebApp.Test.csproj new file mode 100644 index 0000000..b65b489 --- /dev/null +++ b/test/WebApp.Test/WebApp.Test.csproj @@ -0,0 +1,35 @@ + + + + net7.0 + enable + enable + + false + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + +