master
Simon G. 1 month ago
parent 41bae406c2
commit 6b74419932
Signed by: SimonG
GPG Key ID: 0B82B964BA536523
  1. 25
      Test.LightweightIocContainer/DisposeStrategyTest.cs
  2. 11
      Test.LightweightIocContainer/IocContainerInterfaceSegregationTest.cs

@ -13,11 +13,7 @@ namespace Test.LightweightIocContainer;
public class DisposeStrategyTest
{
[UsedImplicitly]
public interface ITest : IDisposable
{
}
public interface ITest : IDisposable;
private class Test : ITest
{
public void Dispose() => throw new Exception();
@ -33,14 +29,6 @@ public class DisposeStrategyTest
private class TestNotDisposable;
[UsedImplicitly]
public interface IInterfaceSegregation : ITest;
private class TestInterfaceSegregation : IInterfaceSegregation
{
public void Dispose() => throw new Exception();
}
[Test]
public void TestValidContainerDisposeStrategySingleton()
{
@ -123,15 +111,4 @@ public class DisposeStrategyTest
IocContainer iocContainer = new();
Assert.Throws<InvalidDisposeStrategyException>(() => iocContainer.Register(r => r.Add<TestNotDisposable>(Lifestyle.Singleton).WithDisposeStrategy(DisposeStrategy.Container)));
}
[Test]
public void TestValidDisposeStrategyForSingletonInterfaceSegregation()
{
IocContainer iocContainer = new();
iocContainer.Register(r => r.Add<ITest, IInterfaceSegregation, TestInterfaceSegregation>(Lifestyle.Singleton).WithDisposeStrategy(DisposeStrategy.Application));
iocContainer.Resolve<ITest>();
Assert.DoesNotThrow(() => iocContainer.Dispose());
}
}

@ -147,4 +147,15 @@ public class IocContainerInterfaceSegregationTest
Assert.That(anotherBar, Is.SameAs(foo));
Assert.That(anotherOne, Is.SameAs(foo));
}
[Test]
public void TestValidDisposeStrategyForSingleton()
{
IocContainer iocContainer = new();
iocContainer.Register(r => r.Add<IFoo, IBar, Foo>(Lifestyle.Singleton).WithDisposeStrategy(DisposeStrategy.Application));
iocContainer.Resolve<IFoo>();
Assert.DoesNotThrow(() => iocContainer.Dispose());
}
}
Loading…
Cancel
Save