public void ShouldCreateNewContainerInstanceOnCustomize() { var sut = new NSubContainer(); var sutFork = sut.Customize(); Assert.That(sutFork, Is.Not.SameAs(sut)); }
public void ShouldReturnFromParentContainerIfNoForkCustomizations() { var sut = new NSubContainer(); sut.Register <ITestInterface, TestImplSingleCtor>(NSubLifetime.Transient); var sutFork = sut.Customize().Customize().Customize(); var result = sutFork.Resolve <ITestInterface>(); Assert.That(result, Is.AssignableTo <TestImplSingleCtor>()); }
public void ShouldUseRegistrationFromForkContainerIfRequestComesFromParentContainerRegistration() { var sut = new NSubContainer(); sut.Register <ClassWithDependency, ClassWithDependency>(NSubLifetime.Transient); sut.Register <ITestInterface, TestImplSingleCtor>(NSubLifetime.Transient); var sutFork = sut.Customize().Register <ITestInterface, TestImplSingleCtor2>(NSubLifetime.Transient); var sutForkResult = sutFork.Resolve <ClassWithDependency>(); Assert.That(sutForkResult.Dep, Is.AssignableTo <TestImplSingleCtor2>()); }
public void ShouldNotModifyOriginalContainerOnCustomize() { var sut = new NSubContainer(); sut.Register <ITestInterface, TestImplSingleCtor>(NSubLifetime.Transient); var sutFork = sut.Customize().Register <ITestInterface, TestImplSingleCtor2>(NSubLifetime.Transient); var sutResult = sut.Resolve <ITestInterface>(); var sutForkResult = sutFork.Resolve <ITestInterface>(); Assert.That(sutResult, Is.AssignableTo <TestImplSingleCtor>()); Assert.That(sutForkResult, Is.AssignableTo <TestImplSingleCtor2>()); }
public void ShouldPinDecoratedRegistrationAtRegistrationTime() { var sut = new NSubContainer(); sut.Register <ITestInterface, TestImplSingleCtor>(NSubLifetime.Transient); var sutFork = sut.Customize().Decorate <ITestInterface>((impl, r) => new TestImplDecorator(impl)); // Override registration. Very rare case sut.Register <ITestInterface, TestImplSingleCtor2>(NSubLifetime.Transient); var result = sutFork.Resolve <ITestInterface>(); Assert.That(result, Is.TypeOf <TestImplDecorator>()); Assert.That(((TestImplDecorator)result).Inner, Is.TypeOf <TestImplSingleCtor>()); }
public void ShouldDecorateTheExistingRegistration() { var sut = new NSubContainer(); sut.Register <ITestInterface, TestImplSingleCtor>(NSubLifetime.PerScope); var sutFork = sut .Customize() .Decorate <ITestInterface>((impl, r) => new TestImplDecorator(impl)); var result = sutFork.Resolve <ITestInterface>(); Assert.That(result, Is.TypeOf <TestImplDecorator>()); Assert.That(((TestImplDecorator)result).Inner, Is.TypeOf <TestImplSingleCtor>()); }
public void ShouldBePossibleToCreateNestedDecorators() { var sut = new NSubContainer(); sut.Register <ITestInterface, TestImplSingleCtor>(NSubLifetime.PerScope); var sutFork = sut .Customize() .Decorate <ITestInterface>((impl, r) => new TestImplDecorator(impl)); var sutForkFork = sutFork .Customize() .Decorate <ITestInterface>((impl, r) => new TestImplDecorator(impl)); var result = sutForkFork.Resolve <ITestInterface>(); var mostInner = ((result as TestImplDecorator)?.Inner as TestImplDecorator)?.Inner; Assert.That(mostInner, Is.TypeOf <TestImplSingleCtor>()); }