Пример #1
0
        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"));
        }
Пример #2
0
        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>());
        }
Пример #3
0
        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));
        }