public static void MultistepOrderedAssertionsUsingRepeatedInOrder( IFoo fake, Exception exception, IOrderableCallAssertion lastAssertion) { "Given a Fake" .x(() => fake = A.Fake <IFoo>()); "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 2" .x(() => fake.Bar(2)); "And a call on the Fake, passing argument 3" .x(() => fake.Bar(3)); "When I use Repeated to assert that a call with argument 1 was made once exactly" .x(() => lastAssertion = A.CallTo(() => fake.Bar(1)).MustHaveHappened(Repeated.Exactly.Once)); "And then a call with argument 2" .x(() => lastAssertion = lastAssertion.Then(A.CallTo(() => fake.Bar(2)).MustHaveHappened())); "And then a call with argument 3 once exactly" .x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => fake.Bar(3)).MustHaveHappened(Repeated.Exactly.Once)))); "Then the assertions should pass" .x(() => exception.Should().BeNull()); }
public static void MultistepOrderedAssertionsInOrder( IFoo fake, Exception exception, IOrderableCallAssertion lastAssertion) { "Given a Fake" .x(() => fake = A.Fake<IFoo>()); "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 2" .x(() => fake.Bar(2)); "And a call on the Fake, passing argument 3" .x(() => fake.Bar(3)); "When I assert that a call with argument 1 was made exactly once" .x(() => lastAssertion = A.CallTo(() => fake.Bar(1)).MustHaveHappened(Repeated.Exactly.Once)); "And then a call with argument 2" .x(() => lastAssertion = lastAssertion.Then(A.CallTo(() => fake.Bar(2)).MustHaveHappened())); "And then a call with argument 3 exactly once" .x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => fake.Bar(3)).MustHaveHappened(Repeated.Exactly.Once)))); "Then the assertions should pass" .x(() => exception.Should().BeNull()); }
public static void MultistepOrderedAssertionsUsingRepeatedOutOfOrder( IFoo fake, Exception exception, IOrderableCallAssertion lastAssertion) { "Given a Fake" .x(() => fake = A.Fake <IFoo>()); "And a call on the Fake, passing argument 3" .x(() => fake.Bar(3)); "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)); "When I use Repeated to assert that a call with argument 1 was made twice exactly" .x(() => lastAssertion = A.CallTo(() => fake.Bar(1)).MustHaveHappened(Repeated.Exactly.Twice)); "And then a call with argument 2" .x(() => lastAssertion = lastAssertion.Then(A.CallTo(() => fake.Bar(2)).MustHaveHappened())); "And then that a call with argument 3 was made once exactly" .x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => fake.Bar(3)).MustHaveHappened(Repeated.Exactly.Once)))); "Then the last assertion should fail" .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>().WithMessage(@" Assertion failed for the following calls: 'FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 1)' exactly twice 'FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 2)' once or more 'FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 3)' exactly once The calls were found but not in the correct order among the calls: 1: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 3) 2: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 1) 2 times ... 4: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 2)")); }
public static void OrderedAssertionWithCallCountConstraintFailureUsingRepeated( IFoo fake, IOrderableCallAssertion lastAssertion, Exception exception) { "Given a Fake" .x(() => fake = A.Fake <IFoo>()); "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)); "When I assert that a call with argument 2 was made" .x(() => lastAssertion = A.CallTo(() => fake.Bar(2)).MustHaveHappened()); "And then that a call with argument 1 was made once exactly using Repeated" .x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => fake.Bar(1)).MustHaveHappened(Repeated.Exactly.Once)))); "Then the last assertion should fail" .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>()); "And the message should say 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+IFoo.Bar(baz: 1) Expected to find it exactly once but found it twice among the calls: 1: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 1) 2: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 2) 3: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 1) ")); }
public static void OrderedAssertionOnInterfacesWithCommonParent(ISomethingBaz baz, ISomethingQux qux, IOrderableCallAssertion lastAssertion, Exception exception) { "Given a Fake baz" .x(() => baz = A.Fake <ISomethingBaz>()); "And a Fake qux implementing an interface in common with baz" .x(() => qux = A.Fake <ISomethingQux>()); "And a call on qux" .x(() => qux.QuxMethod()); "And a call on baz" .x(() => baz.BazMethod()); "When I assert that the qux call was made" .x(() => lastAssertion = A.CallTo(() => qux.QuxMethod()).MustHaveHappened()); "And I make the same assertion again" .x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => qux.QuxMethod()).MustHaveHappened()))); "Then the second assertion should fail" .x(() => exception.Should().BeAnExceptionOfType <ExpectationException>()); }
public void should_invoke_all_actions_in_order() { var iterations = 10; var functions = new List <Func <ILoggingBuilder, ILoggingBuilder> >(); for (var i = 0; i < iterations; i++) { functions.Add(A.Fake <Func <ILoggingBuilder, ILoggingBuilder> >()); sut.AddLoggingBuilderConfiguration(functions[i]); } var logger = new OSPSuiteLogger(sut); logger.AddToLog("test", new LogLevel(), "testcategory"); for (var i = 0; i < iterations; i++) { IOrderableCallAssertion check = A.CallTo(() => functions[0].Invoke(A <ILoggingBuilder> .Ignored)).MustHaveHappened(); for (var j = 1; j < iterations; j++) { check = check.Then(A.CallTo(() => functions[j].Invoke(A <ILoggingBuilder> .Ignored)).MustHaveHappened()); } } }
public static void OrderedAssertionOnCallThatCallsAnotherFakedMethod( ClassWithAMethodThatCallsASibling fake, IOrderableCallAssertion lastAssertion, Exception exception) { "Given a class with a method that calls another class method" .See <ClassWithAMethodThatCallsASibling>(); "And a Fake of that type, configured to call base methods" .x(() => fake = A.Fake <ClassWithAMethodThatCallsASibling>(options => options.CallsBaseMethods())); "And I call the outer method" .x(() => fake.OuterMethod()); "When I assert that the outer method was called" .x(() => lastAssertion = A.CallTo(() => fake.OuterMethod()).MustHaveHappened()); "And then I assert that the inner method was called afterward" .x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => fake.InnerMethod()).MustHaveHappened()))); "Then the assertions pass" .x(() => exception.Should().BeNull()); }
public static void MultistepOrderedAssertionsOutOfOrder( IFoo fake, Exception exception, IOrderableCallAssertion lastAssertion) { "Given a Fake" .x(() => fake = A.Fake<IFoo>()); "And a call on the Fake, passing argument 3" .x(() => fake.Bar(3)); "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)); "When I assert that a call with argument 1 was made exactly twice" .x(() => lastAssertion = A.CallTo(() => fake.Bar(1)).MustHaveHappened(Repeated.Exactly.Twice)); "And then a call with argument 2" .x(() => lastAssertion = lastAssertion.Then(A.CallTo(() => fake.Bar(2)).MustHaveHappened())); "And then that a call with argument 3 was made exactly once" .x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => fake.Bar(3)).MustHaveHappened(Repeated.Exactly.Once)))); "Then the last assertion should fail" .x(() => exception.Should().BeAnExceptionOfType<ExpectationException>().WithMessage(@" Assertion failed for the following calls: 'FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(1)' repeated exactly twice 'FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(2)' repeated at least once 'FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(3)' repeated exactly once The calls were found but not in the correct order among the calls: 1: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 3) 2: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 1) repeated 2 times ... 4: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 2)")); }
public static void OrderedAssertionWithRepeatConstraintFailure( IFoo fake, IOrderableCallAssertion lastAssertion, Exception exception) { "Given a Fake" .x(() => fake = A.Fake<IFoo>()); "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)); "When I assert that a call with argument 2 was made" .x(() => lastAssertion = A.CallTo(() => fake.Bar(2)).MustHaveHappened()); "And then that a call with argument 1 was made exactly once" .x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => fake.Bar(1)).MustHaveHappened(Repeated.Exactly.Once)))); "Then the last assertion should fail" .x(() => exception.Should().BeAnExceptionOfType<ExpectationException>()); "And the message should say 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+IFoo.Bar(1) Expected to find it exactly once but found it #2 times among the calls: 1: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 1) 2: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 2) 3: FakeItEasy.Specs.OrderedCallMatchingSpecs+IFoo.Bar(baz: 1) ")); }
public static void OrderedAssertionOnInterfacesWithCommonParent(ISomethingBaz baz, ISomethingQux qux, IOrderableCallAssertion lastAssertion, Exception exception) { "Given a Fake baz" .x(() => baz = A.Fake<ISomethingBaz>()); "And a Fake qux implementing an interface in common with baz" .x(() => qux = A.Fake<ISomethingQux>()); "And a call on qux" .x(() => qux.QuxMethod()); "And a call on baz" .x(() => baz.BazMethod()); "When I assert that the qux call was made" .x(() => lastAssertion = A.CallTo(() => qux.QuxMethod()).MustHaveHappened()); "And I make the same assertion again" .x(() => exception = Record.Exception(() => lastAssertion.Then(A.CallTo(() => qux.QuxMethod()).MustHaveHappened()))); "Then the second assertion should fail" .x(() => exception.Should().BeAnExceptionOfType<ExpectationException>()); }