public void Assert_should_return_fake_assertion_object_from_factory()
        {
            var fake = A.Fake <IFoo>();


            using (Fake.CreateScope())
            {
                this.StubResolve <IFakeAssertionsFactory>(this.fakeAssertionsFactory);
                var assertions = ES.FullExtensionSyntax.Assert(fake);

                Assert.That(assertions, Is.SameAs(this.fakeAssertions));
            }
        }
Example #2
0
        public void Constructor_sets_fake_object_returned_from_fake_creator_to_FakedObject_property()
        {
            var foo = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                A.CallTo(() => this.fakeCreator.CreateFake(A <Action <IFakeOptions <IFoo> > > ._)).Returns(foo);

                var fake = new Fake <IFoo>();

                fake.FakedObject.Should().BeSameAs(foo);
            }
        }
        public void RecordedCalls_only_returns_calls_made_within_the_scope()
        {
            var foo = A.Fake <IFoo>();

            foo.Baz();

            using (Fake.CreateScope())
            {
                foo.Baz();

                Fake.GetCalls(foo).Count().Should().Be(1);
            }
        }
Example #4
0
        public void EntersStatesBelowCommonSuperStateToTarget()
        {
            using (var scope = Fake.CreateScope())
            {
                this.Testee.Fire(this.TransitionContext);

                using (scope.OrderedAssertions())
                {
                    A.CallTo(() => this.superStateOfTarget.Entry(this.TransitionContext)).MustHaveHappened();
                    A.CallTo(() => this.Target.Entry(this.TransitionContext)).MustHaveHappened();
                }
            }
        }
Example #5
0
        public void Generic_Fake_with_arguments_for_constructor_should_pass_arguments_to_factory()
        {
            var constructorArguments = new object[] { A.Fake <IServiceProvider>() };
            IServiceProvider p       = (IServiceProvider)constructorArguments[0];

            using (Fake.CreateScope())
            {
                A.Fake <AbstractTypeWithNoDefaultConstructor>(constructorArguments);

                Fake.Assert(this.factory)
                .WasCalled(x => x.CreateFake(typeof(AbstractTypeWithNoDefaultConstructor), A <IEnumerable <object> > .That.IsThisSequence(constructorArguments).Argument, false));
            }
        }
        public void RecordedCalls_only_returns_calls_made_within_the_scope()
        {
            var foo = A.Fake <IFoo>();

            foo.Baz();

            using (Fake.CreateScope())
            {
                foo.Baz();

                Assert.That(Fake.GetCalls(foo).Count(), Is.EqualTo(1));
            }
        }
Example #7
0
        public void ExitsStatesUpToBelowCommonSuperState()
        {
            using (var scope = Fake.CreateScope())
            {
                this.Testee.Fire(this.TransitionContext);

                using (scope.OrderedAssertions())
                {
                    A.CallTo(() => this.Source.Exit(this.TransitionContext)).MustHaveHappened();
                    A.CallTo(() => this.superStateOfSource.Exit(this.TransitionContext)).MustHaveHappened();
                }
            }
        }
Example #8
0
        public void Constructor_sets_fake_object_returned_from_factory_to_FakedObject_property()
        {
            var foo = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                A.CallTo(() => this.factory.CreateFake(typeof(IFoo), null, false)).Returns(foo);

                var fake = new Fake <IFoo>();

                Assert.That(fake.FakedObject, Is.SameAs(foo));
            }
        }
Example #9
0
        public void EntersAllStatesBelowSourceDownToTarget()
        {
            using (var scope = Fake.CreateScope())
            {
                this.Testee.Fire(this.TransitionContext);

                using (scope.OrderedAssertions())
                {
                    A.CallTo(() => this.intermediate.Entry(this.TransitionContext)).MustHaveHappened();
                    A.CallTo(() => this.Target.Entry(this.TransitionContext)).MustHaveHappened();
                }
            }
        }
Example #10
0
        public void Constructor_sets_fake_object_returned_from_fake_creator_to_FakedObject_property()
        {
            var foo = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                A.CallTo(() => this.fakeCreator.CreateFake <IFoo>(A <Action <IFakeOptionsBuilder <IFoo> > > ._)).Returns(foo);

                var fake = new Fake <IFoo>();

                Assert.That(fake.FakedObject, Is.SameAs(foo));
            }
        }
Example #11
0
        private void DoTestSetMinutia()
        {
            using (Fake.CreateScope())
            {
                // PREPARE:
                m_Monitor.Reset();
                // Create a random point to update the minutia with
                Point setPosition = new Point(
                    m_Random.Next(MAX_IMAGE_SIZE),
                    m_Random.Next(MAX_IMAGE_SIZE));
                // Copy the minutae before the operation
                IEnumerable <MinutiaRecord> minutae = m_ViewModel.Minutae.ToArray();
                // Record the input minutia type before the operation
                MinutiaType inputType = m_ViewModel.InputMinutiaType;

                // EXECUTE:
                m_ViewModel.PositionInput(setPosition);

                // ASSERT:
                Assert.AreEqual(CAPTURE_NO_TEMPLATE, m_ViewModel.Capture);
                Assert.AreEqual(inputType, m_ViewModel.InputMinutiaType);
                Assert.AreEqual(minutae.Count(), m_ViewModel.Minutae.Count);
                Assert.AreEqual((m_ViewModel.Minutae.Count() > 0), m_IViewModel.IsSaveTemplatePermitted);

                // Assert that the user is prompted to add a new minutia
                IEnumerable <UserActionRequiredEventArgs> userActionEvents = m_Monitor.GetEventResponses <UserActionRequiredEventArgs>("UserActionRequired");
                Assert.AreEqual(1, userActionEvents.Count());
                Assert.AreEqual(INPUT_MINUTIA_PROMPT, userActionEvents.ElementAt(0).PromptText);

                // Assert that no bound properties were changed
                Assert.AreEqual(0, m_Monitor.GetEventResponses <PropertyChangedEventArgs>("PropertyChanged").Count());

                // Assert previous minuae are unchanged (note Equals has been overridden)
                Assert.AreEqual(minutae.Count(), m_ViewModel.Minutae.Count());
                CollectionAssert.AreEqual(
                    minutae.Take(minutae.Count() - 1).ToArray(),
                    m_ViewModel.Minutae.Take(minutae.Count() - 1).ToArray());
                // Assert set minutia properties
                Assert.AreEqual(minutae.Last().Position, m_ViewModel.Minutae.Last().Position);
                Assert.AreEqual(minutae.Last().Type, m_ViewModel.Minutae.Last().Type);
                Assert.AreEqual(inputType, m_ViewModel.Minutae.Last().Type);

                Vector direction = (setPosition - minutae.Last().Position);
                Assert.AreEqual(
                    MathsHelper.RadianToDegree(Math.Atan2(direction.Y, direction.X)),
                    m_ViewModel.Minutae.Last().Angle);

                // Assert IDispatcherHelper interaction
                AssertNoCallsToDispatcherHelper();
            }
        }
Example #12
0
        public void Call_configured_in_child_scope_should_not_affect_parent_scope()
        {
            var fake = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                using (Fake.CreateScope())
                {
                    Any.CallTo(fake).Throws(new Exception());
                }

                fake.Bar();
            }
        }
Example #13
0
        public void Generic_Fake_with_no_arguments_should_return_fake_from_factory()
        {
            var foo = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                A.CallTo(() => this.factory.CreateFake(typeof(IFoo), null, false))
                .Returns(foo);

                var returned = A.Fake <IFoo>();

                Assert.That(returned, Is.SameAs(foo));
            }
        }
Example #14
0
        public virtual void SetUp()
        {
            var runIntent = RunIntent.Create(useSeparateAppDomains: false);

            runIntent.AddType(typeof(T));

            using (Scope = Fake.CreateScope())
            {
                RunResult = Evaluator.Run(runIntent);
            }

            SuiteResults = RunResult.SuiteResults.SelectMany(x => x.DescendantsAndSelf(y => y.SuiteResults)).ToList();
            TestResults  = SuiteResults.SelectMany(x => x.TestResults).ToList();
        }
Example #15
0
        public void ExitsAllStatesFromCurrentUpToSource()
        {
            using (var scope = Fake.CreateScope())
            {
                this.Testee.Fire(this.TransitionContext);

                using (scope.OrderedAssertions())
                {
                    A.CallTo(() => this.current.Exit(this.TransitionContext)).MustHaveHappened();
                    A.CallTo(() => this.intermediate.Exit(this.TransitionContext)).MustHaveHappened();
                    A.CallTo(() => this.Source.Exit(this.TransitionContext)).MustHaveHappened();
                }
            }
        }
Example #16
0
        public void Fake_with_wrapped_instance_and_recorder_should_return_fake_object_from_factory()
        {
            var recorder = A.Fake <ISelfInitializingFakeRecorder>();
            var wrapped  = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                this.StubResolve <FakeObject.Factory>(() => fake);

                var wrapper = A.Fake <IFoo>(wrapped, recorder);

                Assert.That(FakeItEasy.Fake.GetFakeObject(wrapper), Is.SameAs(this.fake));
            }
        }
Example #17
0
        public void Fake_with_wrapped_instance_and_recorder_should_add_SelfInitializationRule_to_fake_object()
        {
            var recorder = A.Fake <ISelfInitializingFakeRecorder>();
            var wrapped  = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                this.StubResolve <FakeObject.Factory>(() => fake);

                var wrapper = A.Fake <IFoo>(wrapped, recorder);

                Assert.That(this.fake.Rules.First(), Is.InstanceOf <SelfInitializationRule>());
            }
        }
        public void Constructor_that_takes_constructor_expression_sets_fake_object_returned_from_factory_to_FakedObject_property()
        {
            var foo = A.Fake <Foo>();
            var serviceProviderArgument = A.Fake <IServiceProvider>();

            using (Fake.CreateScope())
            {
                A.CallTo(() => this.factory.CreateFake(typeof(Foo), A <IEnumerable <object> > .That.IsThisSequence(new object[] { serviceProviderArgument }).Argument, false))
                .Returns(foo);

                var fake = new Fake <Foo>(() => new Foo(serviceProviderArgument));

                Assert.That(fake.FakedObject, Is.SameAs(foo));
            }
        }
        public void Constructor_that_takes_arguments_for_constructor_should_set_fake_returned_from_factory_to_FakedObject_property()
        {
            var argumentsForConstructor = new object[] { A.Fake <IFoo>() };
            var fakeReturnedFromFactory = A.Fake <AbstractTypeWithNoDefaultConstructor>(x => x.WithArgumentsForConstructor(argumentsForConstructor));

            using (Fake.CreateScope())
            {
                A.CallTo(() => this.factory.CreateFake(typeof(AbstractTypeWithNoDefaultConstructor), A <IEnumerable <object> > .That.IsThisSequence(argumentsForConstructor).Argument, false))
                .Returns(fakeReturnedFromFactory);

                var fake = new Fake <AbstractTypeWithNoDefaultConstructor>(argumentsForConstructor);

                Assert.That(fake.FakedObject, Is.SameAs(fakeReturnedFromFactory));
            }
        }
Example #20
0
        public void Generic_Fake_with_arguments_for_constructor_should_return_fake_from_factory()
        {
            var constructorArguments = new object[] { A.Fake <IServiceProvider>() };
            var foo = A.Fake <AbstractTypeWithNoDefaultConstructor>(constructorArguments);

            using (Fake.CreateScope())
            {
                A.CallTo(() => this.factory.CreateFake(typeof(AbstractTypeWithNoDefaultConstructor), A <IEnumerable <object> > .Ignored.Argument, false))
                .Returns(foo);

                var returned = A.Fake <AbstractTypeWithNoDefaultConstructor>(constructorArguments);

                Assert.That(returned, Is.SameAs(foo));
            }
        }
Example #21
0
        public void Should_not_be_able_to_fake_Uri_when_no_container_is_used()
        {
            // Arrange

            // Act
            Exception exception;

            using (Fake.CreateScope(new NullFakeObjectContainer()))
            {
                exception = Record.Exception(() => A.Fake <Guid>());
            }

            // Assert
            exception.Should().BeAnExceptionOfType <FakeCreationException>();
        }
Example #22
0
        public void Generic_Fake_with_no_arguments_should_return_fake_from_factory()
        {
            var foo = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                Fake.Configure(this.factory)
                .CallsTo(x => x.CreateFake(typeof(IFoo), null, true))
                .Returns(foo);

                var returned = A.Fake <IFoo>();

                Assert.That(returned, Is.SameAs(foo));
            }
        }
Example #23
0
        public void Type_registered_in_container_should_be_returned_when_a_dummy_is_requested()
        {
            var container = new DelegateFakeObjectContainer();

            container.Register(() => "dummy");

            string dummyString;

            using (Fake.CreateScope(container))
            {
                dummyString = A.Dummy <string>();
            }

            dummyString.Should().Be("dummy");
        }
Example #24
0
        public void Constructor_that_takes_constructor_expression_sets_fake_object_returned_from_factory_to_FakedObject_property()
        {
            var foo = A.Fake <Foo>();
            var serviceProviderArgument = A.Fake <IServiceProvider>();

            using (Fake.CreateScope())
            {
                Fake.Configure(this.factory)
                .CallsTo(x => x.CreateFake(typeof(Foo), Its.SameSequence(new object[] { serviceProviderArgument }), false))
                .Returns(foo);

                var fake = new Fake <Foo>(() => new Foo(serviceProviderArgument));

                Assert.That(fake.FakedObject, Is.SameAs(foo));
            }
        }
Example #25
0
        public void Constructor_that_takes_arguments_for_constructor_should_set_fake_returned_from_factory_to_FakedObject_property()
        {
            var argumentsForConstructor = new object[] { A.Fake <IFoo>() };
            var fakeReturnedFromFactory = A.Fake <AbstractTypeWithNoDefaultConstructor>(argumentsForConstructor);

            using (Fake.CreateScope())
            {
                Fake.Configure(this.factory)
                .CallsTo(x => x.CreateFake(typeof(AbstractTypeWithNoDefaultConstructor), Its.SameSequence(argumentsForConstructor), false))
                .Returns(fakeReturnedFromFactory);

                var fake = new Fake <AbstractTypeWithNoDefaultConstructor>(argumentsForConstructor);

                Assert.That(fake.FakedObject, Is.SameAs(fakeReturnedFromFactory));
            }
        }
Example #26
0
        public void Call_instercepted_in_child_scope_should_be_visible_in_parent_scope()
        {
            var fake = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                using (Fake.CreateScope())
                {
                    fake.Bar();
                }

                Fake.Assert(fake).WasCalled(x => x.Bar());
            }

            Fake.Assert(fake).WasCalled(x => x.Bar());
        }
Example #27
0
        public void AnyCall_should_return_fake_configuration_for_fake()
        {
            var fake = A.Fake <IFoo>();

            var callConfig = A.Fake <IAnyCallConfiguration>();

            A.CallTo(() => this.fakeConfiguration.AnyCall()).Returns(callConfig);

            using (Fake.CreateScope())
            {
                this.StubResolve <IStartConfigurationFactory>(this.fakeConfigurationFactory);

                var configuration = ES.FullExtensionSyntax.AnyCall(fake);
                Assert.That(configuration, Is.SameAs(callConfig));
            }
        }
Example #28
0
        public void Call_instercepted_in_child_scope_should_be_visible_in_parent_scope()
        {
            var fake = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                using (Fake.CreateScope())
                {
                    fake.Bar();
                }

                A.CallTo(() => fake.Bar()).MustHaveHappened();
            }

            A.CallTo(() => fake.Bar()).MustHaveHappened();
        }
Example #29
0
        public void Enumerating_through_non_generic_interface_should_enumerate_all_calls_that_were_made_in_the_scope()
        {
            // Arrange
            var fake      = A.Fake <IFoo>();
            var otherFake = A.Fake <IFoo>();

            // Act
            using (var scope = Fake.CreateScope())
            {
                fake.Bar();
                otherFake.Baz();

                // Assert
                Assert.That(((IEnumerable)scope).Cast <ICompletedFakeObjectCall>().ToArray().Select(x => x.Method.Name), Is.EquivalentTo(new[] { "Bar", "Baz" }));
            }
        }
Example #30
0
        public void Enumerating_should_enumerate_all_calls_that_were_made_in_the_scope()
        {
            // Arrange
            var fake      = A.Fake <IFoo>();
            var otherFake = A.Fake <IFoo>();

            // Act
            using (var scope = Fake.CreateScope())
            {
                fake.Bar();
                otherFake.Baz();

                // Assert
                Assert.That(scope.ToArray().Select(x => x.Method.Name), Is.EquivalentTo(new[] { "Bar", "Baz" }));
            }
        }