From ad0de3e1f49968d4d51414c2723b506e19cd031d Mon Sep 17 00:00:00 2001 From: Andrew Krock Date: Mon, 19 May 2025 10:25:53 -0400 Subject: [PATCH 1/2] Fix tests --- CHANGELOG.md | 5 ++ DevDistricts.Tests/DevDistricts.Tests.csproj | 4 ++ .../ServiceCollectionExtensionsTests.cs | 57 +++++++++++++++++++ DevDistricts/AssemblyInfo.cs | 3 + DevDistricts/DevDistricts.csproj | 1 + 5 files changed, 70 insertions(+) create mode 100644 DevDistricts.Tests/ServiceCollectionExtensionsTests.cs create mode 100644 DevDistricts/AssemblyInfo.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 603269a..eca6cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,7 @@ 2025-05-18 Added unit tests for InternalExtensions - Build failed: unable to restore NuGet packages offline + +2025-05-18 Added tests for ServiceCollectionExtensions + - Build failed: dotnet not found + +2025-05-19 Fixed build and enabled unit tests diff --git a/DevDistricts.Tests/DevDistricts.Tests.csproj b/DevDistricts.Tests/DevDistricts.Tests.csproj index a7eec33..bd67e0a 100644 --- a/DevDistricts.Tests/DevDistricts.Tests.csproj +++ b/DevDistricts.Tests/DevDistricts.Tests.csproj @@ -7,6 +7,10 @@ false + + + + diff --git a/DevDistricts.Tests/ServiceCollectionExtensionsTests.cs b/DevDistricts.Tests/ServiceCollectionExtensionsTests.cs new file mode 100644 index 0000000..e2e9d3c --- /dev/null +++ b/DevDistricts.Tests/ServiceCollectionExtensionsTests.cs @@ -0,0 +1,57 @@ +using System; +using System.Linq; +using DevDistricts; +using DevDistricts.Internal; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Xunit; + +[District(DependencyInjectionTypes = new[] { typeof(SampleService) })] +[Occupant(UserName = "user", MachineName = "machine")] +internal class SampleDistrict +{ +} + +internal class SampleService +{ +} + +public class ServiceCollectionExtensionsTests +{ + [Fact] + public void WithDevDistricts_RegistersHostedService_AndInvokesCallback() + { + var services = new ServiceCollection(); + Type[]? callbackTypes = null; + + services.WithDevDistricts(o => o + .WithUserName("user") + .WithMachineName("machine") + .WithDependencyInjectionCallback(types => callbackTypes = types.ToArray())); + + var descriptor = services.Single(d => d.ServiceType == typeof(IHostedService)); + Assert.Equal(typeof(DistrictRunner), descriptor.ImplementationType); + Assert.NotNull(callbackTypes); + Assert.Contains(typeof(SampleService), callbackTypes); + } + + [Fact] + public void WithDevDistricts_Throws_NoMatchingDistrictException_When_No_District() + { + var services = new ServiceCollection(); + Assert.Throws(() => + services.WithDevDistricts(o => o + .WithUserName("none") + .WithMachineName("none"))); + } + + [Fact] + public void WithDevDistricts_Throws_NotSupported_When_DITypes_NoCallback() + { + var services = new ServiceCollection(); + Assert.Throws(() => + services.WithDevDistricts(o => o + .WithUserName("user") + .WithMachineName("machine"))); + } +} diff --git a/DevDistricts/AssemblyInfo.cs b/DevDistricts/AssemblyInfo.cs new file mode 100644 index 0000000..e10192a --- /dev/null +++ b/DevDistricts/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("DevDistricts.Tests")] diff --git a/DevDistricts/DevDistricts.csproj b/DevDistricts/DevDistricts.csproj index dea3c0a..c82264f 100644 --- a/DevDistricts/DevDistricts.csproj +++ b/DevDistricts/DevDistricts.csproj @@ -2,6 +2,7 @@ netstandard2.0 + 8.0 enable https://github.com/akrock/DevDistricts/blob/master/LICENSE https://github.com/akrock/DevDistricts From b7aa695521459a33d1cb0893dd450fa1206a8966 Mon Sep 17 00:00:00 2001 From: Andrew Krock Date: Mon, 19 May 2025 10:47:44 -0400 Subject: [PATCH 2/2] tweak codex output. --- CHANGELOG.md | 6 ++---- DevDistricts.Tests/DevDistricts.Tests.csproj | 5 +---- DevDistricts.sln.DotSettings.user | 4 ++++ DevDistricts/DevDistricts.csproj | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 DevDistricts.sln.DotSettings.user diff --git a/CHANGELOG.md b/CHANGELOG.md index eca6cc1..e7ae2a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,5 @@ 2025-05-18 Added unit tests for InternalExtensions - Build failed: unable to restore NuGet packages offline -2025-05-18 Added tests for ServiceCollectionExtensions - - Build failed: dotnet not found - -2025-05-19 Fixed build and enabled unit tests +2025-05-19 Added tests for ServiceCollectionExtensions + - Fixed build and enabled unit tests \ No newline at end of file diff --git a/DevDistricts.Tests/DevDistricts.Tests.csproj b/DevDistricts.Tests/DevDistricts.Tests.csproj index bd67e0a..8c30adf 100644 --- a/DevDistricts.Tests/DevDistricts.Tests.csproj +++ b/DevDistricts.Tests/DevDistricts.Tests.csproj @@ -7,12 +7,9 @@ false - - - - + diff --git a/DevDistricts.sln.DotSettings.user b/DevDistricts.sln.DotSettings.user new file mode 100644 index 0000000..7930c35 --- /dev/null +++ b/DevDistricts.sln.DotSettings.user @@ -0,0 +1,4 @@ + + <SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &lt;DevDistricts.Tests&gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> + <Project Location="E:\Projects\DevDistricts\DevDistricts.Tests" Presentation="&lt;DevDistricts.Tests&gt;" /> +</SessionState> \ No newline at end of file diff --git a/DevDistricts/DevDistricts.csproj b/DevDistricts/DevDistricts.csproj index c82264f..8ca62f4 100644 --- a/DevDistricts/DevDistricts.csproj +++ b/DevDistricts/DevDistricts.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 8.0 + latestMajor enable https://github.com/akrock/DevDistricts/blob/master/LICENSE https://github.com/akrock/DevDistricts