Beispiel #1
0
        public void To_should_return_builder_from_factory()
        {
            // Arrange
            var foo  = A.Fake <IFoo>();
            var fake = Fake.GetFakeObject(foo);

            var recordedRule = A.Fake <RecordedCallRule>();

            this.StubResolve <RecordedCallRule.Factory>(() => recordedRule);

            var recordingRule        = A.Fake <RecordingCallRule <IFoo> >(() => new RecordingCallRule <IFoo>(fake, recordedRule, x => null));
            var recordingRuleFactory = A.Fake <IRecordingCallRuleFactory>();

            A.CallTo(() => recordingRuleFactory.Create <IFoo>(fake, recordedRule)).Returns(recordingRule);
            this.StubResolve <IRecordingCallRuleFactory>(recordingRuleFactory);

            var builder = new RuleBuilder(A.Fake <BuildableCallRule>(), fake, x => null);

            this.StubResolve <RuleBuilder.Factory>((r, f) =>
            {
                return(r.Equals(recordedRule) && f.Equals(fake) ? builder : null);
            });

            // Act
            var result = ThisCall.To(foo);

            // Assert
            Assert.That(result, Is.SameAs(builder));
            Assert.That(fake.Rules, Has.Some.SameAs(recordingRule));
        }
Beispiel #2
0
        public void Recorded_call_should_not_be_applied_when_arguments_does_not_match_specified_argument_predicate()
        {
            var fake = A.Fake <IFoo>();

            ThisCall.To(fake).WhenArgumentsMatch(x => false).Throws(new AssertionException("This should not happen"));
            fake.Bar(10);

            fake.Bar(10);
        }
Beispiel #3
0
        public void Recorded_call_should_not_be_applied_when_arguments_are_not_the_same_as_used_when_recording()
        {
            var fake = A.Fake <IFoo>();

            ThisCall.To(fake).Throws(new AssertionException("This should not be thrown!"));
            fake.Baz(1, 2);

            Assert.That(fake.Baz("foo", "bar"), Is.Not.EqualTo(10));
        }
Beispiel #4
0
        public void Recorded_calls_should_only_be_applicable_to_the_method_called()
        {
            var fake = A.Fake <IFoo>();

            ThisCall.To(fake).Throws(new Exception("This should not be thrown!"));
            fake.Bar();

            fake.Baz();
        }
Beispiel #5
0
        public void With_any_arguments_should_configure_call_so_that_any_arguments_matches()
        {
            var fake = A.Fake <IFoo>();

            ThisCall.To(fake).WithAnyArguments().Throws(new ApplicationException());
            fake.Baz(null, null);

            Assert.Throws <ApplicationException>(() =>
                                                 fake.Baz("foo", "bar"));
        }
Beispiel #6
0
        public void Recorded_call_should_apply_when_argument_predicate_returns_true()
        {
            var fake = A.Fake <IFoo>();

            ThisCall.To(fake).WhenArgumentsMatch(x => true).Throws(new ArgumentNullException());
            fake.Bar(10);

            Assert.Throws <ArgumentNullException>(() =>
                                                  fake.Bar(10));
        }
Beispiel #7
0
        public void Throws_should_throw_exception_when_configured_method_is_called_but_not_while_recording()
        {
            var fake = A.Fake <IFoo>();

            ThisCall.To(fake).Throws(new ApplicationException());
            fake.Bar();

            Assert.Throws <ApplicationException>(() =>
                                                 fake.Bar());
        }
Beispiel #8
0
        public void Recording_a_rule_should_work_even_when_there_are_already_call_rules_specified()
        {
            var fake = A.Fake <IFoo>();

            Configure.Fake(fake).CallsTo(x => x.Baz()).Returns(10);
            Configure.Fake(fake).CallsTo(x => x.Biz()).Returns("something");

            ThisCall.To(fake).Throws(new ApplicationException());
            fake.Bar();

            Assert.Throws <ApplicationException>(() =>
                                                 fake.Bar());
        }
Beispiel #9
0
        public void Arguments_from_the_call_should_be_sent_to_the_argument_predicate()
        {
            var fake = A.Fake <IFoo>();
            ArgumentCollection arguments = null;

            ThisCall.To(fake).WhenArgumentsMatch(x => { arguments = x; return(true); }).Throws(new ApplicationException());
            fake.Baz(null, null);

            try
            {
                fake.Baz(1, "a");
            }
            catch (ApplicationException) { }

            Assert.That(arguments.AsEnumerable().ToArray(), Has.Some.EqualTo(1).And.Some.EqualTo("a"));
        }
Beispiel #10
0
 public void To_should_be_properly_guarded()
 {
     NullGuardedConstraint.Assert(() => ThisCall.To(A.Fake <IFoo>()));
 }
 public void To_should_be_properly_guarded()
 {
     IsProperlyGuardedConstraint.IsProperlyGuarded(() => ThisCall.To(A.Fake <IFoo>()));
 }