コード例 #1
0
        public void To_should_return_builder_from_factory()
        {
            // Arrange
            var foo  = A.Fake <IFoo>();
            var fake = Fake.GetFakeManager(foo);

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

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

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

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

            var builder = this.CreateFakeVisualBasicRuleBuilder();

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

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

            // Assert
            Assert.That(result, Is.SameAs(builder));
            Assert.That(fake.Rules, Has.Some.SameAs(recordingRule));
        }
コード例 #2
0
        public static void NextCallToSuccess(
            IHaveNoGenericParameters fake,
            ISequentialCallContext sequentialCallContext,
            Exception exception)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IHaveNoGenericParameters>());

            "And a call on the Fake, passing argument 1"
            .x(() => fake.Bar(1));

            "And a call on the Fake, passing argument 2"
            .x(() => fake.Bar(2));

            "And a call-ordering context"
            .x(c => sequentialCallContext = A.SequentialCallContext());

            "When I expect the call with argument 1 to have been made using NextCall.To"
            .x(() =>
            {
                NextCall.To(fake).MustHaveHappened().InOrder(sequentialCallContext);
                fake.Bar(1);
            });

            "And I expect the call with argument 2 to have been made next using NextCall.To"
            .x(() => exception = Record.Exception(() =>
            {
                NextCall.To(fake).MustHaveHappened().InOrder(sequentialCallContext);
                fake.Bar(2);
            }));

            "Then the assertion should succeed"
            .x(() => exception.Should().BeNull("because the assertion should have succeeded"));
        }
コード例 #3
0
        public void With_any_arguments_should_configure_call_so_that_any_arguments_matches()
        {
            var fake = A.Fake <IFoo>();

            NextCall.To(fake).WithAnyArguments().Throws(new InvalidOperationException());
            fake.Baz(null, null);

            Assert.Throws <InvalidOperationException>(() => fake.Baz("foo", "bar"));
        }
コード例 #4
0
        public static void NextCallToFailure(
            IHaveNoGenericParameters fake,
            ISequentialCallContext sequentialCallContext,
            Exception exception)
        {
            "Given a fake"
            .x(() => fake = A.Fake <IHaveNoGenericParameters>());

            "And a call on the Fake, passing argument 1"
            .x(() => fake.Bar(1));

            "And a call on the Fake, passing argument 2"
            .x(() => fake.Bar(2));

            "And a call-ordering context"
            .x(c => sequentialCallContext = A.SequentialCallContext());

            "When I expect the call with argument 2 to have been made using NextCall.To"
            .x(() =>
            {
                NextCall.To(fake).MustHaveHappened().InOrder(sequentialCallContext);
                fake.Bar(2);
            });

            "And I expect the call with argument 1 to have been made next using NextCall.To"
            .x(() => exception = Record.Exception(() =>
            {
                NextCall.To(fake).MustHaveHappened().InOrder(sequentialCallContext);
                fake.Bar(1);
            }));

            "Then the assertion should fail"
            .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>());

            "And the error should tell us that the calls were not matched in order"
            .x(() => exception.Message.Should().Be(@"

  Assertion failed for the following calls:
    'FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 2)' repeated at least once
    'FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 1)' repeated at least once
  The calls where found but not in the correct order among the calls:
    1: FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 1)
    2: FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 2)
"));
        }
コード例 #5
0
 public void To_should_be_properly_guarded()
 {
     NullGuardedConstraint.Assert(() =>
                                  NextCall.To(A.Fake <IFoo>()));
 }