public static void FailingMatchOfNonGenericCalls( IHaveNoGenericParameters fake, Exception exception) { "Given a fake" .x(() => fake = A.Fake <IHaveNoGenericParameters>()); "And a call with argument 1 made on this fake" .x(() => fake.Bar(1)); "And a call with argument 2 made on this fake" .x(() => fake.Bar(2)); "When I assert that a call with argument 3 has happened on this fake" .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(3)).MustHaveHappened())); "Then the assertion should fail" .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>()); "And the exception message should tell us that the call was not matched" .x(() => exception.Message.Should().Be(@" Assertion failed for the following call: FakeItEasy.Specs.CallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 3) Expected to find it at least once but found it #0 times among the calls: 1: FakeItEasy.Specs.CallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 1) 2: FakeItEasy.Specs.CallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 2) ")); }
public static void NonGenericCalls( IHaveNoGenericParameters fake, Exception exception) { "establish" .x(() => fake = A.Fake <IHaveNoGenericParameters>()); "when failing to match ordered non generic calls" .x(() => { using (var scope = Fake.CreateScope()) { fake.Bar(1); fake.Bar(2); using (scope.OrderedAssertions()) { A.CallTo(() => fake.Bar(2)).MustHaveHappened(); exception = Record.Exception(() => A.CallTo(() => fake.Bar(1)).MustHaveHappened()); } } }); "it should tell us that the call was not matched" .x(() => exception.Message.Should().Be( @" Assertion failed for the following calls: 'FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveNoGenericParameters.Bar(2)' repeated at least once 'FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveNoGenericParameters.Bar(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) ")); }
public static void FailingMatchOfNonGenericCalls( IHaveNoGenericParameters fake, Exception exception) { "establish" .x(() => fake = A.Fake <IHaveNoGenericParameters>()); "when failing to match non generic calls" .x(() => { fake.Bar(1); fake.Bar(2); exception = Record.Exception(() => A.CallTo(() => fake.Bar(3)).MustHaveHappened()); }); "it should tell us that the call was not matched" .x(() => exception.Message.Should().Be( @" Assertion failed for the following call: FakeItEasy.Specs.CallMatchingSpecs+IHaveNoGenericParameters.Bar(3) Expected to find it at least once but found it #0 times among the calls: 1: FakeItEasy.Specs.CallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 1) 2: FakeItEasy.Specs.CallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 2) ")); }
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")); }
public static void NoNonGenericCalls( IHaveNoGenericParameters fake, Exception exception) { "Given a fake" .x(() => fake = A.Fake <IHaveNoGenericParameters>()); "And no calls made on this fake" .x(() => { }); "When I assert that a call has happened on this fake" .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(A <int> .Ignored)).MustHaveHappened())); "Then the assertion should fail" .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>()); "And the exception message should tell us that the call was not matched" .x(() => exception.Message.Should().Be(@" Assertion failed for the following call: FakeItEasy.Specs.CallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: <Ignored>) Expected to find it at least once but no calls were made to the fake object. ")); }
public static void UnusedArgumentMatcherDescriptionNotUsed(IHaveNoGenericParameters fake, Action <IOutputWriter> writerAction) { "Given a fake" .x(() => fake = A.Fake <IHaveNoGenericParameters>()); "And an action that describes an argument matcher" .x(() => writerAction = A.Fake <Action <IOutputWriter> >()); "And I make a call to the fake" .x(() => fake.Bar(7)); "When I assert that the call happened" .x(() => A.CallTo(() => fake.Bar(A <int> .That.Matches(i => true, writerAction))).MustHaveHappened()); "Then the action is not triggered" .x(() => A.CallTo(writerAction).MustNotHaveHappened()); }
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) ")); }
public static void PassingIgnoredConstraintWithWrongTypeToAMethod( IHaveNoGenericParameters fake, Exception exception, bool wasCalled) { "Given a fake" .x(() => fake = A.Fake <IHaveNoGenericParameters>()); "When I try to configure a method of the fake with an Ignored constraint of the wrong type" .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(A <byte> .Ignored)).Invokes(() => wasCalled = true))); "And I call the method with any value" .x(() => fake.Bar(default(byte))); "Then the call configuration doesn't throw" .x(() => exception.Should().BeNull()); "And the configured call isn't matched" .x(() => wasCalled.Should().BeFalse()); }
public static void WithRepeatConstraintFailure( 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 on the Fake, passing argument 1" .x(() => fake.Bar(1)); "And a call-ordering context" .x(c => sequentialCallContext = A.SequentialCallContext()); "When I expect the call with argument 2 to have been made" .x(() => A.CallTo(() => fake.Bar(2)).MustHaveHappened().InOrder(sequentialCallContext)); "And I expect the call with argument 1 to have been made next exactly once" .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(1)).MustHaveHappened(Repeated.Exactly.Once).InOrder(sequentialCallContext))); "Then the assertion should fail" .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>()); "And the error should tell us that the call to Bar(1) was found too many times" .x(() => exception.Message.Should().Be(@" Assertion failed for the following call: FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveNoGenericParameters.Bar(1) Expected to find it exactly once but found it #2 times among the calls: 1: FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 1) 2: FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 2) 3: FakeItEasy.Specs.OrderedCallMatchingSpecs+IHaveNoGenericParameters.Bar(baz: 1) ")); }
public static void PassingNestedConstraintInArgumentEndingWithProperty( IHaveNoGenericParameters fake, Exception exception) { "Given a fake" .x(() => fake = A.Fake <IHaveNoGenericParameters>()); "When I try to configure a method of the fake with an Ignored constraint nested in an argument ending with a property" .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(new Z(A <int> .Ignored).Value)).DoesNothing())); "Then it throws an invalid operation exception" .x(() => exception.Should().BeAnExceptionOfType <InvalidOperationException>()); }
public static void WithRepeatConstraintSuccess( 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 1" .x(() => fake.Bar(1)); "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 at least twice" .x(() => A.CallTo(() => fake.Bar(1)).MustHaveHappened(Repeated.AtLeast.Twice).InOrder(sequentialCallContext)); "And I expect the call with argument 2 to have been made next exactly once" .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(2)).MustHaveHappened(Repeated.Exactly.Once).InOrder(sequentialCallContext))); "Then the assertion should succeed" .x(() => exception.Should().BeNull("because the assertion should have succeeded")); }
public static void ArgumentConstraintExpressionInvokedOnce(IHaveNoGenericParameters fake, ConstraintFactory constraintFactory) { "Given a fake" .x(() => fake = A.Fake <IHaveNoGenericParameters>()); "And an argument constraint factory" .x(() => constraintFactory = new ConstraintFactory()); "When I configure a method of the fake with an argument constraint from the factory" .x(() => A.CallTo(() => fake.Bar(constraintFactory.Create())).DoesNothing()); "Then the expression that invokes the constraint factory is called exactly once" .x(() => constraintFactory.InvocationCount.Should().Be(1)); }
public static void PassingIgnoredConstraintWithWrongTypeToAMethod( IHaveNoGenericParameters fake, Exception exception) { "Given a fake" .x(() => fake = A.Fake <IHaveNoGenericParameters>()); "When I try to configure a method of the fake with an Ignored constraint of the wrong type" .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(A <byte> .Ignored)))); "Then the call configuration throws a FakeConfigurationException" .x(() => exception.Should().BeAnExceptionOfType <FakeConfigurationException>()); "And the message indicates the actual and expected types" .x(() => exception.Message.Should().Be("Argument constraint is of type System.Byte, but parameter is of type System.Int32. No call can match this constraint.")); }
public static void NoNonGenericCalls( IHaveNoGenericParameters fake, Exception exception) { "establish" .x(() => fake = A.Fake <IHaveNoGenericParameters>()); "when no non generic calls" .x(() => exception = Record.Exception(() => A.CallTo(() => fake.Bar(A <int> .Ignored)).MustHaveHappened())); "it should tell us that the call was not matched" .x(() => exception.Message.Should().Be( @" Assertion failed for the following call: FakeItEasy.Specs.CallMatchingSpecs+IHaveNoGenericParameters.Bar(<Ignored>) Expected to find it at least once but no calls were made to the fake object. ")); }