Skip to content

Commit 8a94e10

Browse files
dahlbykdustinsoftware
authored andcommitted
Add generic asserts
1 parent 837bd58 commit 8a94e10

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

test/StructureMap.Microsoft.DependencyInjection.Tests/StructureMapContainerTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void ConfigureAndRegisterDoNotPreventPopulate()
4343
{
4444
var services = new ServiceCollection();
4545
services.AddTransient<IFakeService, FakeService>();
46+
services.AddSingleton<IComparer<string>>(StringComparer.OrdinalIgnoreCase);
4647

4748
var container = new Container();
4849
container.Configure(config =>
@@ -67,6 +68,25 @@ public void ConfigureAndRegisterDoNotPreventPopulate()
6768

6869
Assert.False(spis.IsService(typeof(FakeService)));
6970
Assert.False(spis.IsService(typeof(IFakeServiceInstance)));
71+
72+
// Open generics never resolve
73+
Assert.False(spis.IsService(typeof(IComparer<>)));
74+
Assert.False(spis.IsService(typeof(IEnumerable<>)));
75+
76+
// Registered closed generic does resolve
77+
Assert.True(spis.IsService(typeof(IComparer<string>)));
78+
79+
// Unregistered closed generic does not resolve
80+
Assert.False(spis.IsService(typeof(IComparer<IFakeService>)));
81+
82+
// IEnumerable<> of registered types does resolve
83+
Assert.True(spis.IsService(typeof(IEnumerable<IFakeService>)));
84+
Assert.True(spis.IsService(typeof(IEnumerable<IFakeScopedService>)));
85+
Assert.True(spis.IsService(typeof(IEnumerable<IFakeSingletonService>)));
86+
87+
// IEnumerable<> of unregistered types also resolves
88+
Assert.True(spis.IsService(typeof(IEnumerable<FakeService>)));
89+
Assert.True(spis.IsService(typeof(IEnumerable<IFakeServiceInstance>)));
7090
}
7191

7292
[Fact]

0 commit comments

Comments
 (0)