コード例 #1
0
        public void AssertWasCalled_with_function_call_calls_WasCalled_on_assertions_from_factory()
        {
            var fake       = new Fake <IFoo>();
            var fakeObject = Fake.GetFakeObject(fake.FakedObject);

            var factoryAssertions = A.Fake <IFakeAssertions <IFoo> >();

            Expression <Func <IFoo, int> > callSpecification = x => x.Baz();

            using (Fake.CreateScope())
            {
                var factory = this.StubResolveWithFake <IFakeAssertionsFactory>();
                A.CallTo(() => factory.CreateAsserter <IFoo>(fakeObject))
                .Returns(factoryAssertions);

                fake.AssertWasCalled(callSpecification);
            }

            foreach (var call in Fake.GetCalls(factoryAssertions))
            {
                Console.WriteLine(call);
            }

            Fake.Assert(factoryAssertions)
            .WasCalled(x => x.WasCalled(callSpecification));
        }
コード例 #2
0
        public static void TheOtherWay()
        {
            var foo = new Fake <IFoo>();

            foo.CallsTo(x => x.Baz()).Returns(10);

            int value = foo.FakedObject.Baz();

            foo.AssertWasCalled(x => x.Baz());
        }
コード例 #3
0
        public void AssertWasCalled_with_void_call_calls_WasCalled_on_assertions_from_factory()
        {
            var fake       = new Fake <IFoo>();
            var fakeObject = Fake.GetFakeObject(fake.FakedObject);

            var factoryAssertions = A.Fake <IFakeAssertions <IFoo> >();

            Expression <Action <IFoo> > callSpecification = x => x.Bar();

            using (Fake.CreateScope())
            {
                var factory = this.StubResolveWithFake <IFakeAssertionsFactory>();
                A.CallTo(() => factory.CreateAsserter <IFoo>(fakeObject)).Returns(factoryAssertions);

                fake.AssertWasCalled(callSpecification);
            }

            Fake.Assert(factoryAssertions)
            .WasCalled(x => x.WasCalled(callSpecification));
        }
コード例 #4
0
        public void AssertWasCalled_with_function_call_and_repeat_calls_WasCalled_on_assertions_from_factory()
        {
            var fake       = new Fake <IFoo>();
            var fakeObject = Fake.GetFakeObject(fake.FakedObject);

            var factoryAssertions = A.Fake <IFakeAssertions <IFoo> >();

            Expression <Func <IFoo, int> > callSpecification = x => x.Baz();
            Expression <Func <int, bool> > repeat            = x => true;

            using (Fake.CreateScope())
            {
                var factory = this.StubResolveWithFake <IFakeAssertionsFactory>();
                A.CallTo(() => factory.CreateAsserter <IFoo>(fakeObject)).Returns(factoryAssertions);

                fake.AssertWasCalled(callSpecification, repeat);
            }

            Fake.Assert(factoryAssertions)
            .WasCalled(x => x.WasCalled(callSpecification, repeat));
        }
コード例 #5
0
        public void AssertWasCalled_with_function_call_calls_WasCalled_on_assertions_from_factory()
        {
            var fake       = new Fake <IFoo>();
            var fakeObject = Fake.GetFakeObject(fake.FakedObject);

            var factoryAssertions = A.Fake <IFakeAssertions <IFoo> >();

            Expression <Func <IFoo, int> > callSpecification = x => x.Baz();

            using (Fake.CreateScope())
            {
                var factory = this.StubResolveWithFake <IFakeAssertionsFactory>();
                Fake.Configure(factory)
                .CallsTo(x => x.CreateAsserter <IFoo>(fakeObject))
                .Returns(factoryAssertions);

                fake.AssertWasCalled(callSpecification);
            }

            Fake.Assert(factoryAssertions)
            .WasCalled(x => x.WasCalled(callSpecification));
        }