示例#1
0
        public void has_explicit_name()
        {
            var instance = new InstanceUnderTest();
            instance.HasExplicitName().ShouldBeFalse();

            instance.Name = "name of instance";
            instance.HasExplicitName().ShouldBeTrue();
        }
示例#2
0
        private bool nestedIsValidForLifecycle(ILifecycle lifecycle)
        {
            var instance = new InstanceUnderTest();

            instance.SetLifecycleTo(lifecycle);

            return(instance.IsValidInNestedContainer());
        }
示例#3
0
        public void has_explicit_name()
        {
            var instance = new InstanceUnderTest();

            instance.HasExplicitName().ShouldBeFalse();

            instance.Name = "name of instance";
            instance.HasExplicitName().ShouldBeTrue();
        }
示例#4
0
        public void Build_the_InstanceToken()
        {
            var instance = new InstanceUnderTest();
            instance.Name = "name of instance";

            var token = instance.CreateToken();

            Assert.AreEqual(instance.Name, token.Name);
            Assert.AreEqual("InstanceUnderTest", token.Description);
        }
示例#5
0
        public void Build_the_InstanceToken()
        {
            var instance = new InstanceUnderTest();
            instance.Name = "name of instance";

            var token = instance.CreateToken();

            token.Name.ShouldBe(instance.Name);
            token.Description.ShouldBe("InstanceUnderTest");
        }
示例#6
0
        public void Build_the_InstanceToken()
        {
            var instance = new InstanceUnderTest();

            instance.Name = "name of instance";

            var token = instance.CreateToken();

            Assert.AreEqual(instance.Name, token.Name);
            Assert.AreEqual("InstanceUnderTest", token.Description);
        }
示例#7
0
        public void Build_the_InstanceToken()
        {
            var instance = new InstanceUnderTest();

            instance.Name = "name of instance";

            var token = instance.CreateToken();

            token.Name.ShouldBe(instance.Name);
            token.Description.ShouldBe("InstanceUnderTest");
        }
示例#8
0
        public void add_interceptor_that_cannot_accept_the_returned_type()
        {
            var instance = new InstanceUnderTest
            {
                Type = typeof(ColorRule)
            };

            var interceptor = new ActivatorInterceptor<IGateway>(g => g.DoSomething());

            instance.ReturnedType.CanBeCastTo(interceptor.Accepts)
                .ShouldBeFalse();

            Exception<ArgumentOutOfRangeException>.ShouldBeThrownBy(() => { instance.AddInterceptor(interceptor); });
        }
示例#9
0
        public void add_interceptor_that_cannot_accept_the_returned_type()
        {
            var instance = new InstanceUnderTest
            {
                Type = typeof(ColorRule)
            };

            var interceptor = new ActivatorInterceptor <IGateway>(g => g.DoSomething());

            instance.ReturnedType.CanBeCastTo(interceptor.Accepts)
            .ShouldBeFalse();

            Exception <ArgumentOutOfRangeException> .ShouldBeThrownBy(() => { instance.AddInterceptor(interceptor); });
        }
示例#10
0
        public void add_interceptor_when_the_accept_type_is_possible_on_the_return_type()
        {
            var instance = new InstanceUnderTest
            {
                Type = typeof (StubbedGateway)
            };

            var interceptor = new ActivatorInterceptor<IGateway>(g => g.DoSomething());

            instance.ReturnedType.CanBeCastTo(interceptor.Accepts)
                .ShouldBeTrue();

            instance.AddInterceptor(interceptor);

            instance.Interceptors.Single()
                .ShouldBeTheSameAs(interceptor);
        }
示例#11
0
        public void add_interceptor_when_the_accept_type_is_possible_on_the_return_type()
        {
            var instance = new InstanceUnderTest
            {
                Type = typeof(StubbedGateway)
            };

            var interceptor = new ActivatorInterceptor <IGateway>(g => g.DoSomething());

            instance.ReturnedType.CanBeCastTo(interceptor.Accepts)
            .ShouldBeTrue();

            instance.AddInterceptor(interceptor);

            instance.Interceptors.Single()
            .ShouldBeTheSameAs(interceptor);
        }
示例#12
0
        public void Instance_Build_Calls_into_its_Interceptor()
        {
            var mocks = new MockRepository();
            var interceptor = mocks.StrictMock<InstanceInterceptor>();
            var buildSession = mocks.StrictMock<BuildSession>();

            var instanceUnderTest = new InstanceUnderTest();
            instanceUnderTest.Interceptor = interceptor;

            var objectReturnedByInterceptor = new object();

            using (mocks.Record())
            {
                Expect.Call(interceptor.Process(instanceUnderTest.TheInstanceThatWasBuilt, buildSession)).Return(
                    objectReturnedByInterceptor);
            }

            using (mocks.Playback())
            {
                Assert.AreEqual(objectReturnedByInterceptor, instanceUnderTest.Build(typeof (object), buildSession));
            }
        }
示例#13
0
        public void Instance_Build_Calls_into_its_Interceptor()
        {
            var mocks        = new MockRepository();
            var interceptor  = mocks.StrictMock <InstanceInterceptor>();
            var buildSession = mocks.StrictMock <BuildSession>();


            var instanceUnderTest = new InstanceUnderTest();

            instanceUnderTest.Interceptor = interceptor;

            var objectReturnedByInterceptor = new object();

            using (mocks.Record())
            {
                Expect.Call(interceptor.Process(instanceUnderTest.TheInstanceThatWasBuilt, buildSession)).Return(
                    objectReturnedByInterceptor);
            }

            using (mocks.Playback())
            {
                Assert.AreEqual(objectReturnedByInterceptor, instanceUnderTest.Build(typeof(object), buildSession));
            }
        }
示例#14
0
        private bool nestedIsValidForLifecycle(ILifecycle lifecycle)
        {
            var instance = new InstanceUnderTest();
            instance.SetLifecycleTo(lifecycle);

            return instance.IsValidInNestedContainer();
        }