public void ChecksCallCountToAssertThatItHasBeenMet() { var irrelevant = Is.Anything; var mock = new ReflectiveInterceptor(null, null, "name", MockStyle.Default); var expectation = BuildExpectation( "description", Is.AtLeast(2), Is.AtMost(4), mock, irrelevant, irrelevant, irrelevant, irrelevant); AssertHasNotBeenMet(expectation, "should not have been met after no invocations"); expectation.Perform(invocation); AssertHasNotBeenMet(expectation, "should not have been met after 1 invocation"); expectation.Perform(invocation); AssertHasBeenMet(expectation, "should have been met after 2 invocations"); expectation.Perform(invocation); AssertHasBeenMet(expectation, "should have been met after 3 invocations"); expectation.Perform(invocation); AssertHasBeenMet(expectation, "should have been met after 4 invocations"); }
public void MatchesCallCountWhenMatchingInvocation() { Matcher irrelevant = Is.Anything; BuildableExpectation expectation = (BuildableExpectation)BuildExpectation( "description", Is.AtLeast(0), Is.AtMost(4), receiver.MockObject, irrelevant, irrelevant, irrelevant, irrelevant); AssertIsActive(expectation, "should be active before any invocation"); Assert.IsTrue(expectation.Matches(invocation), "should match 1st invocation"); expectation.Perform(invocation); AssertIsActive(expectation, "should be active before 2nd invocation"); Assert.IsTrue(expectation.Matches(invocation), "should match 2nd invocation"); expectation.Perform(invocation); AssertIsActive(expectation, "should be active before 3rd invocation"); Assert.IsTrue(expectation.Matches(invocation), "should match 3rd invocation"); expectation.Perform(invocation); AssertIsActive(expectation, "should be active before 4th invocation"); Assert.IsTrue(expectation.Matches(invocation), "should match 4th invocation"); expectation.Perform(invocation); AssertIsNotActive(expectation, "should not be active after 4th invocation"); Assert.IsFalse(expectation.Matches(invocation), "should not match 5th invocation"); }
public IExpectMatchSyntax Arrange(Action <T> expression) { return(new ExpectationBuilder <T>("1 time", Is.AtLeast(1), Is.AtMost(1), _proxy).Parse(expression)); }
public IExpectMatchSyntax <TResult> Arrange <TResult>(Func <T, TResult> expression) { return(new ExpectationBuilder <T>("1 time", Is.AtLeast(1), Is.AtMost(1), _proxy).Parse(expression)); }
/// <summary> /// Creates an expectation for exactly <c>count</c> number of calls for the referenced member. /// </summary> /// <param name="count">The exact number of calls expect</param> /// <returns>An <see cref="IMethodSyntax{T}"/> to reference the expected call.</returns> public IMethodSyntax <T> Exactly(int count) { return(GetExpectationBuilder(count.Times(), Is.AtLeast(count), Is.AtMost(count), _proxy)); }
/// <summary> /// Creates an expectation for a range from <c>minCount</c> to <c>maxCount</c> number of calls for the referenced member. /// </summary> /// <param name="minCount">The minimum number of expected calls.</param> /// <param name="maxCount">The maximum number of expected calls.</param> /// <returns>An <see cref="IMethodSyntax{T}"/> to reference the expected call.</returns> public IMethodSyntax <T> Between(int minCount, int maxCount) { return(GetExpectationBuilder(minCount + " to " + maxCount + " times", Is.AtLeast(minCount), Is.AtMost(maxCount), _proxy)); }
/// <summary> /// Creates an expectation for at most <c>count</c> number of calls for the referenced member. /// </summary> /// <param name="count">The maximum number of calls expect</param> /// <returns>An <see cref="IMethodSyntax{T}"/> to reference the expected call.</returns> public IMethodSyntax <T> AtMost(int count) { return(GetExpectationBuilder("at most " + count.Times(), Is.Anything, Is.AtMost(count), _proxy)); }
private void WithArgumentsTest1(Mock <IParentInterface> mock) { var expectations = new Expectations(4); using (Factory.Ordered()) { expectations[0] = mock.Expects.One.Method(_ => _.MethodVoid(0, 0, 0)).With(1, 2, 3); expectations[1] = mock.Expects.One.Method(_ => _.MethodVoid(0, 0, 0)).With(Is.EqualTo(4), Is.AtLeast(5), Is.AtMost(6)); expectations[2] = mock.Expects.One.Method(_ => _.MethodVoid(0, 0, 0)).With(7, Is.AtLeast(8), 9); expectations[3] = mock.Expects.One.Method(_ => _.MethodVoid(0, 0, 0)).With( new PredicateMatcher <int>(parameter => parameter == 10), Is.Match <int>(parameter => parameter == 11), Is.Anything); } mock.MockObject.MethodVoid(1, 2, 3); mock.MockObject.MethodVoid(4, 5, 6); mock.MockObject.MethodVoid(7, 8, 9); mock.MockObject.MethodVoid(10, 11, 12); expectations.ForEach(_ => _.Assert()); }
private void WithArgumentsTest(IParentInterface instance) { using (Factory.Ordered()) { Expect.On(instance).One.Method(_ => _.MethodVoid(0, 0, 0)).With(1, 2, 3); Expect.On(instance).One.Method(_ => _.MethodVoid(0, 0, 0)).With(Is.EqualTo(4), Is.AtLeast(5), Is.AtMost(6)); Expect.On(instance).One.Method(_ => _.MethodVoid(0, 0, 0)).With(7, Is.AtLeast(8), 9); Expect.On(instance).One.Method(_ => _.MethodVoid(0, 0, 0)).With( new PredicateMatcher <int>(parameter => parameter == 10), Is.Match <int>(parameter => parameter == 11), Is.Anything); } instance.MethodVoid(1, 2, 3); instance.MethodVoid(4, 5, 6); instance.MethodVoid(7, 8, 9); instance.MethodVoid(10, 11, 12); }