Skip to content

Commit dd9919e

Browse files
add test for keyedimplementationfactory as well
1 parent 439a94a commit dd9919e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Ninject.Web.AspNetCore.Test/Unit/ServiceProviderKeyedTest.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ public void OptionalKeyedServiceCollectionExisting_CorrectServiceResolved()
2020
{
2121
var collection = new ServiceCollection();
2222
collection.Add(new ServiceDescriptor(typeof(IWarrior),"Samurai", typeof(Samurai), ServiceLifetime.Transient));
23-
collection.Add(new ServiceDescriptor(typeof(IWarrior), "Ninja", new Ninja("test")));
23+
collection.Add(new ServiceDescriptor(typeof(IWarrior), "Ninja1", new Ninja("test")));
24+
collection.Add(new ServiceDescriptor(typeof(IWarrior),"Ninja2",
25+
(provider, key) => new Ninja("test:" + key.ToString()), ServiceLifetime.Transient));
2426
var kernel = CreateTestKernel(collection);
2527
var provider = CreateServiceProvider(kernel);
2628

27-
provider.GetKeyedService(typeof(IWarrior), "Ninja").Should().NotBeNull().And.BeOfType(typeof(Ninja));
2829
provider.GetKeyedService(typeof(IWarrior), "Samurai").Should().NotBeNull().And.BeOfType(typeof(Samurai));
29-
30+
provider.GetKeyedService(typeof(IWarrior), "Ninja1").Should().NotBeNull().And.BeOfType(typeof(Ninja)).
31+
And.Match(x => ((Ninja)x).Name == "test");
32+
provider.GetKeyedService(typeof(IWarrior), "Ninja2").Should().NotBeNull().And.BeOfType(typeof(Ninja)).
33+
And.Match(x => ((Ninja)x).Name == "test:Ninja2");
3034
}
3135

3236
[Fact]

0 commit comments

Comments
 (0)