public void ShouldFailIfTypeToDecorateDoesNotExist() { var sut = new NSubContainer(); var ex = Assert.Throws <ArgumentException>( () => sut.Decorate <ITestInterface>((impl, r) => new TestImplDecorator(impl))); Assert.That(ex.Message, Contains.Substring("implementation is not registered")); }
public void ShouldDecorateWhenRegisteredOnSameContainer() { var sut = new NSubContainer(); sut.Register <ITestInterface, TestImplSingleCtor>(NSubLifetime.Transient); sut.Decorate <ITestInterface>((impl, r) => new TestImplDecorator(impl)); var result = sut.Resolve <ITestInterface>(); Assert.That(result, Is.TypeOf <TestImplDecorator>()); }
public void ShouldUseSameLifetimeForDecorator_SingletonCase() { var sut = new NSubContainer(); sut.Register <ITestInterface, TestImplSingleCtor>(NSubLifetime.Singleton); sut.Decorate <ITestInterface>((impl, r) => new TestImplDecorator(impl)); var result1 = sut.Resolve <ITestInterface>(); var result2 = sut.Resolve <ITestInterface>(); Assert.That(result1, Is.SameAs(result2)); Assert.That(((TestImplDecorator)result1).Inner, Is.SameAs(((TestImplDecorator)result2).Inner)); }