예제 #1
0
        public void ConfigureFakeObject_should_do_nothing()
        {
            var fake = A.Fake <IFoo>();

            Any.CallTo(fake).Throws(new Exception());

            var container = new NullFakeObjectContainer();

            container.ConfigureFake(typeof(IFoo), fake);
        }
예제 #2
0
        public void DoesNothing_should_set_applicator_that_does_nothing_when_called()
        {
            this.builder.DoesNothing();

            var call = A.Fake <IWritableFakeObjectCall>();

            Any.CallTo(call).Throws(new AssertionException("Applicator should do nothing."));

            this.builder.RuleBeingBuilt.Applicator(call);
        }
예제 #3
0
        public void Should_not_throw_when_unsuccessful_and_throw_on_failure_is_false()
        {
            // Arrange
            this.StubProxyGeneratorToFail();

            // Act
            this.fakeObjectCreator.CreateFake(typeof(IFoo), FakeOptions.Empty, A.Dummy <IDummyValueCreationSession>(), throwOnFailure: false);

            // Assert
            Any.CallTo(this.thrower).MustNotHaveHappened();
        }
예제 #4
0
        public void ReturnTheValidUser()
        {
            var store      = A.Fake <IDataStore>();
            var encryption = A.Fake <IEncryption>();
            var expected   = new User();

            Any.CallTo(store).WithReturnType <User>().Returns(expected);
            Any.CallTo(encryption).WithReturnType <bool>().Returns(true);
            var user = new UserRepository(store, encryption).FindByCredentials(null, null);

            Assert.AreSame(expected, user);
        }
예제 #5
0
        public void ConfigureFakeObject_should_do_nothing()
        {
            var fake = A.Fake <IFoo>();

#pragma warning disable 618
            Any.CallTo(fake).Throws(new InvalidOperationException());
#pragma warning restore 618

            var container = new NullFakeObjectContainer();

            container.ConfigureFake(typeof(IFoo), fake);
        }
예제 #6
0
        public void DoesNothing_should_set_applicator_that_does_nothing_when_called()
        {
            this.builder.DoesNothing();

            var call = A.Fake <IInterceptedFakeObjectCall>();

#pragma warning disable 618
            Any.CallTo(call).Throws(new AssertionException("Applicator should do nothing."));
#pragma warning restore 618

            this.builder.RuleBeingBuilt.Applicator(call);
        }
    // The following does not work as of now but I'll seriously consider
    // implementing it:
    public void AnyCallToWithCallSpecificationExample()
    {
        var logger = A.Fake <ILogger>();

        logger.Log("whatever");

        // I would add a "filtering" method to the Any.CallTo-syntax:
        Any.CallTo(logger).WhereCallMatches(x => x.Method.Name.Equals("Log")).MustHaveHappened();

        // It would also enable an extension method:
        Any.CallTo(logger).ToMethodNamed("Log").MustHaveHappened();
    }
        public void Should_return_constraint_from_trapper_when_available()
        {
            // Arrange
            var constraint = A.Dummy <IArgumentConstraint>();

            Any.CallTo(this.trapper).WithReturnType <IEnumerable <IArgumentConstraint> >().Returns(new[] { constraint });

            // Act
            var result = this.factory.GetArgumentConstraint(BuilderForParsedArgumentExpression.BuildWithDefaults());

            // Assert
            Assert.That(result, Is.SameAs(constraint));
        }
예제 #9
0
        public void VerifiesTheSubmittedPasswordAgainstTheStoredOne()
        {
            var store      = A.Fake <IDataStore>();
            var encryption = A.Fake <IEncryption>();
            var user       = new User {
                Password = "******"
            };

            Any.CallTo(store).WithReturnType <User>().Returns(user);
            new UserRepository(store, encryption).FindByCredentials(null, "Duncan");

            A.CallTo(() => encryption.CheckPassword("Ghanima", "Duncan")).MustHaveHappened();
        }
예제 #10
0
        public void Strict_should_return_configuration_object()
        {
            // Arrange
            var options = A.Fake <IFakeOptionsBuilder <IFoo> >();

            Any.CallTo(options).WithReturnType <IFakeOptionsBuilder <IFoo> >().Returns(options);

            // Act
            var result = options.Strict();

            // Assert
            Assert.That(result, Is.SameAs(options));
        }
예제 #11
0
        public void Should_be_able_to_configure_any_call_with_a_specific_return_type_to_return_value()
        {
            // Arrange
            var foo = A.Fake <IFoo>();

            // Act
            Any.CallTo(foo).WithReturnType <int>().Returns(10);
            Any.CallTo(foo).WithReturnType <string>().Returns("foo");

            // Assert
            Assert.That(foo.SomeProperty, Is.EqualTo(10));
            Assert.That(foo.Baz(), Is.EqualTo(10));
        }
예제 #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();
            }
        }
예제 #13
0
        public void Call_configured_in_child_scope_should_not_affect_parent_scope()
        {
            var fake = A.Fake <IFoo>();

            using (Fake.CreateScope())
            {
                using (Fake.CreateScope())
                {
#pragma warning disable 618
                    Any.CallTo(fake).Throws(new InvalidOperationException());
#pragma warning restore 618
                }

                fake.Bar();
            }
        }
예제 #14
0
        public void A_fake_should_be_passed_to_the_container_to_be_configured_when_created()
        {
            // Arrange
            var container = A.Fake <IFakeObjectContainer>();

            Any.CallTo(container).WithReturnType <bool>().Returns(false);

            using (Fake.CreateScope(container))
            {
                // Act
                var fake = A.Fake <IFoo>();

                // Assert
                A.CallTo(() => container.ConfigureFake(typeof(IFoo), fake)).MustHaveHappened();
            }
        }
예제 #15
0
        public void CallTo_should_return_configuration_from_start_configuration()
        {
            // Arrange
            var foo = A.Fake <IFoo>();

            var anyCallConfiguration = A.Fake <IAnyCallConfiguration>();
            var startConfiguration   = A.Fake <IStartConfiguration <IFoo> >();
            var configurationFactory = A.Fake <IStartConfigurationFactory>();

            A.CallTo(() => configurationFactory.CreateConfiguration <IFoo>(A <FakeObject> .That.Fakes(foo))).Returns(startConfiguration);
            A.CallTo(() => startConfiguration.AnyCall()).Returns(anyCallConfiguration);

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

                // Act

                // Assert
                Assert.That(Any.CallTo(foo), Is.SameAs(anyCallConfiguration));
            }
        }