#60: add failing unit test

master
Simon G. 1 year ago
parent 9e2531b7fd
commit c4d67e0ba3
Signed by: SimonG
GPG Key ID: 0B82B964BA536523
  1. 24
      Test.LightweightIocContainer/SingleTypeRegistrationTest.cs

@ -15,7 +15,13 @@ namespace Test.LightweightIocContainer;
// ReSharper disable MemberHidesStaticFromOuterClass // ReSharper disable MemberHidesStaticFromOuterClass
public class SingleTypeRegistrationTest public class SingleTypeRegistrationTest
{ {
private interface IFoo [UsedImplicitly]
public interface IFooFactory
{
IFoo Create(IBar bar);
}
public interface IFoo
{ {
IBar Bar { get; } IBar Bar { get; }
} }
@ -68,4 +74,20 @@ public class SingleTypeRegistrationTest
Assert.IsInstanceOf<Foo>(foo); Assert.IsInstanceOf<Foo>(foo);
Assert.AreEqual(bar, foo.Bar); Assert.AreEqual(bar, foo.Bar);
} }
[Test]
public void TestSingleTypeRegistrationSingletonFactoryMethodOnlyCalledOnce()
{
IocContainer container = new();
IBar bar = new Bar();
IFooFactory fooFactory = Substitute.For<IFooFactory>();
container.Register(r => r.Add<IFoo>(Lifestyle.Singleton).WithFactoryMethod(_ => fooFactory.Create(bar)));
container.Resolve<IFoo>();
container.Resolve<IFoo>();
fooFactory.Received(1).Create(Arg.Any<IBar>());
}
} }
Loading…
Cancel
Save