public bool Never_should_return_instance_that_matches_one_or_above(int expectedRepeat, int repeat) { // Arrange var times = Happened.Times(expectedRepeat); // Act // Assert return(times.Matches(repeat)); }
public void Assert_happened_times_should_pass_when_call_has_happened_specified_number_of_times() { // Arrange this.foo.Bar(); this.foo.Bar(); this.foo.Bar(); // Act // Assert A.CallTo(() => foo.Bar()).Assert(Happened.Times(3)); }
public void Assert_with_void_call_should_assert_on_assertions_produced_by_factory() { // Arrange A.CallTo(() => this.ruleProducedByFactory.ToString()).Returns("call description"); // Act this.builder.Assert(Happened.Times(99).Exactly); // Assert var repeatMatcher = A <Func <int, bool> > .That.Matches(x => x.Invoke(99) == true); Fake.Assert(this.asserter) .WasCalled(x => x.AssertWasCalled(A <Func <IFakeObjectCall, bool> > .Ignored, "call description", repeatMatcher, "exactly #99 times")); }
public void Assert_with_function_call_should_assert_on_assertions_produced_by_factory() { // Arrange A.CallTo(() => this.ruleProducedByFactory.ToString()).Returns("call description"); // Act var returnConfig = new RuleBuilder.ReturnValueConfiguration <int>() { ParentConfiguration = this.builder }; returnConfig.Assert(Happened.Times(99).Exactly); // Assert var repeatMatcher = A <Func <int, bool> > .That.Matches(x => x.Invoke(99) == true); A.CallTo(() => this.asserter.AssertWasCalled(A <Func <IFakeObjectCall, bool> > .Ignored, "call description", repeatMatcher, "exactly #99 times")).Assert(Happened.Once); }
public void Asserting_on_calls() { var factory = A.Fake <IWidgetFactory>(); // This would throw an exception since no call has been made. A.CallTo(() => factory.Create()).Assert(Happened.Once); A.CallTo(() => factory.Create()).Assert(Happened.Twice); A.CallTo(() => factory.Create()).Assert(Happened.Times(10)); // This on the other hand would not throw. A.CallTo(() => factory.Create()).Assert(Happened.Never); // The number of times the call has been made can be restricted so that it must have happened // exactly the number of times specified A.CallTo(() => factory.Create()).Assert(Happened.Once.Exactly); A.CallTo(() => factory.Create()).Assert(Happened.Times(4).Exactly); // Then number of times can be specified so that it must not have happened more // than the specified number of times. A.CallTo(() => factory.Create()).Assert(Happened.Twice.OrLess); A.CallTo(() => factory.Create()).Assert(Happened.Times(5).OrLess); }