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 void InvokesAListOfActionsToPerformAnInvocation() { BuildableExpectation e = (BuildableExpectation)BuildExpectation(true, true, receiver.MockObject, true, true, true, true); MockAction action1 = new MockAction(); MockAction action2 = new MockAction(); e.AddAction(action1); e.AddAction(action2); e.Perform(invocation); Assert.AreSame(invocation, action1.Received, "action1 received"); Assert.AreSame(invocation, action2.Received, "action1 received"); }
public void WillNotPrintAPeriodBetweenReceiverAndMethodIfToldToDescribeItselfAsAnIndexer() { BuildableExpectation expectation = (BuildableExpectation)BuildExpectation( "1 time", "required call count description is ignored", "matching call count description is ignored", receiver.MockObject, "", "[arguments]", "extra matcher 1", "extra matcher 2" ); expectation.AddAction(new MockAction("action 1")); expectation.AddAction(new MockAction("action 2")); expectation.DescribeAsIndexer(); AssertDescriptionIsEqual(expectation, "receiver[arguments] Matching[extra matcher 1, extra matcher 2] will return <System.Object>(System.Object), action 1, action 2 [EXPECTED: 1 time CALLED: 0 times]\r\n"); }
private static BuildableExpectation BuildExpectation( string description, Matcher requiredCallCountMatcher, Matcher matchingCallCountMatcher, IMockObject receiver, Matcher methodMatcher, Matcher argumentsMatcher, params Matcher[] extraMatchers) { var e = new BuildableExpectation(description, requiredCallCountMatcher, matchingCallCountMatcher); e.ArgumentsMatcher = argumentsMatcher; e.MethodMatcher = methodMatcher; e.AddAction(Return.Value(new object())); e.Receiver = receiver; foreach (Matcher extraMatcher in extraMatchers) { e.AddInvocationMatcher(extraMatcher); } return(e); }
public void MatchesIfAllMatchersMatch() { BuildableExpectation e = (BuildableExpectation)BuildExpectation(true, true, receiver.MockObject, true, true, true, true); Assert.IsTrue(e.Matches(invocation), "should match"); }