public void CreateFake_should_return_fake_from_proxy_generator_when_container_does_not_contain_type()
        {
            var factory = this.CreateFactory();

            var returned = new TestableProxyResult(typeof(IFoo), (IFakedProxy)A.Fake <IFoo>());

            A.CallTo(() => this.proxyGenerator.GenerateProxy(typeof(IFoo), A <FakeObject> .Ignored, this.container)).Returns(returned);

            Assert.That(factory.CreateFake(typeof(IFoo), null, true), Is.SameAs(returned.Proxy));
        }
        public void CreateFake_should_return_fake_from_proxy_generator_when_container_contains_type_but_non_proxied_objects_are_not_allowed()
        {
            var factory = this.CreateFactory();

            var returned = new TestableProxyResult(typeof(IFoo), (IFakedProxy)A.Fake <IFoo>());

            A.CallTo(() => this.container.TryCreateFakeObject(typeof(IFoo), out Null <object> .Out)).Returns(true).AssignsOutAndRefParameters(A.Fake <IFoo>());
            A.CallTo(() => this.proxyGenerator.GenerateProxy(typeof(IFoo), A <FakeObject> .Ignored, this.container)).Returns(returned);

            Assert.That(factory.CreateFake(typeof(IFoo), null, false), Is.SameAs(returned.Proxy));
        }
        public void CreateFake_should_set_generated_proxy_to_fake_object()
        {
            var factory = this.CreateFactory();

            var returned = new TestableProxyResult(typeof(IFoo), (IFakedProxy)A.Fake <IFoo>());

            A.CallTo(() => this.proxyGenerator.GenerateProxy(typeof(IFoo), A <FakeObject> .Ignored, A <IEnumerable <object> > .That.IsThisSequence("foo").Argument)).Returns(returned);

            factory.CreateFake(typeof(IFoo), new object[] { "foo" }, false);

            A.CallTo(() => this.fakeObject.SetProxy(returned)).MustHaveHappened(Repeated.Once);
        }
        public void CreateFake_should_return_fake_from_proxy_generator_when_arguments_for_constructor_is_specified_even_though_non_proxied_fakes_are_accepted()
        {
            var factory = this.CreateFactory();

            var returned = new TestableProxyResult(typeof(IFoo), (IFakedProxy)A.Fake <IFoo>());

            A.CallTo(() => this.proxyGenerator.GenerateProxy(typeof(IFoo), A <FakeObject> .Ignored, A <IEnumerable <object> > .That.IsThisSequence("argument for constructor").Argument)).Returns(returned);

            factory.CreateFake(typeof(IFoo), new object[] { "argument for constructor" }, true);

            A.CallTo(() => this.container.TryCreateFakeObject(typeof(IFoo), out Null <object> .Out)).MustHaveHappened(Repeated.Never);
        }
        public void CreateFake_should_pass_created_proxy_to_ConfigureFake_on_container()
        {
            var factory = this.CreateFactory();

            var returned = new TestableProxyResult(typeof(IFoo), (IFakedProxy)A.Fake <IFoo>());

            A.CallTo(() => this.proxyGenerator.GenerateProxy(typeof(IFoo), A <FakeObject> .Ignored, this.container)).Returns(returned);

            factory.CreateFake(typeof(IFoo), null, true);

            A.CallTo(() => this.container.ConfigureFake(typeof(IFoo), returned.Proxy)).MustHaveHappened(Repeated.Once);
        }
        public void CreateFake_should_return_fake_from_proxy_generator_when_container_does_not_contain_type()
        {
            var factory = this.CreateFactory();

            var returned = new TestableProxyResult(typeof(IFoo), (IFakedProxy)A.Fake <IFoo>());

            Fake.Configure(this.proxyGenerator)
            .CallsTo(x => x.TryGenerateProxy(typeof(IFoo), Argument.Is.Any <FakeObject>(), this.container, out Null <ProxyResult> .Out))
            .Returns(true)
            .AssignsOutAndRefParameters(returned);


            Assert.That(factory.CreateFake(typeof(IFoo), null, true), Is.SameAs(returned.Proxy));
        }
        public void CreateFake_should_set_generated_proxy_to_fake_object()
        {
            var factory = this.CreateFactory();

            var returned = new TestableProxyResult(typeof(IFoo), (IFakedProxy)A.Fake <IFoo>());

            Fake.Configure(this.proxyGenerator)
            .CallsTo(x => x.TryGenerateProxy(typeof(IFoo), Argument.Is.Any <FakeObject>(), Argument.Is.SameSequence <object>("foo"), out Null <ProxyResult> .Out))
            .Returns(true)
            .AssignsOutAndRefParameters(returned);

            factory.CreateFake(typeof(IFoo), new object[] { "foo" }, false);

            Fake.Assert(this.fakeObject)
            .WasCalled(x => x.SetProxy(returned));
        }
        public void CreateFake_should_return_fake_from_proxy_generator_when_arguments_for_constructor_is_specified_even_though_non_proxied_fakes_are_accepted()
        {
            var factory = this.CreateFactory();

            var returned = new TestableProxyResult(typeof(IFoo), (IFakedProxy)A.Fake <IFoo>());

            Configure.Fake(this.proxyGenerator)
            .CallsTo(x => x.TryGenerateProxy(typeof(IFoo), A <FakeObject> .Ignored, A <IEnumerable <object> > .That.IsThisSequence("argument for constructor").Argument, out Null <ProxyResult> .Out))
            .Returns(true)
            .AssignsOutAndRefParameters(returned);

            factory.CreateFake(typeof(IFoo), new object[] { "argument for constructor" }, true);

            Fake.Assert(this.container)
            .WasNotCalled(x => x.TryCreateFakeObject(typeof(IFoo), out Null <object> .Out));
        }
        public void CreateFake_should_pass_created_proxy_to_ConfigureFake_on_container()
        {
            var factory = this.CreateFactory();

            var returned = new TestableProxyResult(typeof(IFoo), (IFakedProxy)A.Fake <IFoo>());

            Configure.Fake(this.proxyGenerator)
            .CallsTo(x => x.TryGenerateProxy(typeof(IFoo), A <FakeObject> .Ignored, this.container, out Null <ProxyResult> .Out))
            .Returns(true)
            .AssignsOutAndRefParameters(returned);

            factory.CreateFake(typeof(IFoo), null, true);

            Fake.Assert(this.container)
            .WasCalled(x => x.ConfigureFake(typeof(IFoo), returned.Proxy));
        }