Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
2025-05-18 Added unit tests for InternalExtensions
- Build failed: unable to restore NuGet packages offline

2025-05-19 Added tests for ServiceCollectionExtensions
- Fixed build and enabled unit tests
1 change: 1 addition & 0 deletions DevDistricts.Tests/DevDistricts.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
Expand Down
57 changes: 57 additions & 0 deletions DevDistricts.Tests/ServiceCollectionExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -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<SampleDistrict>), 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<NoMatchingDistrictException>(() =>
services.WithDevDistricts(o => o
.WithUserName("none")
.WithMachineName("none")));
}

[Fact]
public void WithDevDistricts_Throws_NotSupported_When_DITypes_NoCallback()
{
var services = new ServiceCollection();
Assert.Throws<NotSupportedException>(() =>
services.WithDevDistricts(o => o
.WithUserName("user")
.WithMachineName("machine")));
}
}
4 changes: 4 additions & 0 deletions DevDistricts.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=35e304cf_002D645f_002D44d8_002Da369_002D19333fcf2e8c/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;DevDistricts.Tests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Project Location="E:\Projects\DevDistricts\DevDistricts.Tests" Presentation="&amp;lt;DevDistricts.Tests&amp;gt;" /&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
3 changes: 3 additions & 0 deletions DevDistricts/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("DevDistricts.Tests")]
1 change: 1 addition & 0 deletions DevDistricts/DevDistricts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latestMajor</LangVersion>
<Nullable>enable</Nullable>
<PackageLicenseUrl>https://github.com/akrock/DevDistricts/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/akrock/DevDistricts</PackageProjectUrl>
Expand Down
Loading