public void DoesNotMatchInvocationWithDifferentNumberOfArguments() { Matcher matcher = new ArgumentsMatcher(Is.Anything, Is.Anything); Assert.IsFalse(matcher.Matches(InvocationWithArguments(1)), "fewer arguments"); Assert.IsFalse(matcher.Matches(InvocationWithArguments(1, 2, 3)), "more arguments"); }
public void FormatsDescriptionToLookSimilarToAnArgumentList() { Matcher matcher = new ArgumentsMatcher( new AlwaysMatcher(true, "arg1-description"), new AlwaysMatcher(true, "arg2-description")); AssertDescription.IsEqual(matcher, "(arg1-description, arg2-description)"); }
public void DoesNotMatchIfValueMatchersDoNotMatchArgumentValues() { Matcher matcher = new ArgumentsMatcher(Is.EqualTo(arg1Value), Is.EqualTo(arg2Value)); Assert.IsFalse(matcher.Matches(InvocationWithArguments("other object", arg2Value)), "different first arg"); Assert.IsFalse(matcher.Matches(InvocationWithArguments(arg1Value, "other object")), "different second arg"); }
/// <summary> /// Initializes a new instance of the <see cref="BuildableExpectation"/> class. /// </summary> /// <param name="expectationDescription">The expectation description.</param> /// <param name="requiredCountMatcher">The required count matcher.</param> /// <param name="matchingCountMatcher">The matching count matcher.</param> public BuildableExpectation(string expectationDescription, Matcher requiredCountMatcher, Matcher matchingCountMatcher) { _expectationDescription = expectationDescription; _requiredCountMatcher = requiredCountMatcher; _matchingCountMatcher = matchingCountMatcher; ArgumentsMatcher = new ArgumentsMatcher(); IsValid = false; }
public void DoesNotMatchAndDoesNotThrowExceptionIfValueSpecifiedForOutputParameter() { Matcher matcher = new ArgumentsMatcher(Is.EqualTo(arg1Value), Is.EqualTo(arg2Value)); Invocation invocation = new Invocation( new NamedObject("receiver"), new MethodInfoStub("method", new ParameterInfoStub("in", ParameterAttributes.In), new ParameterInfoStub("out", ParameterAttributes.Out)), new[] { arg1Value, null }); Assert.IsFalse(matcher.Matches(invocation)); }
public void MatchesOutputParametersWithSpecialMatcherClass() { Matcher matcher = new ArgumentsMatcher(Is.EqualTo(arg1Value), Is.Out); Invocation invocation = new Invocation( new NamedObject("receiver"), new MethodInfoStub("method", new ParameterInfoStub("in", ParameterAttributes.In), new ParameterInfoStub("out", ParameterAttributes.Out)), new[] { arg1Value, null }); Assert.IsTrue(matcher.Matches(invocation)); }
public bool MatchesIgnoringIsActive(Invocation invocation) { if (Receiver != invocation.Receiver) { return(false); } if (!MethodMatcher.Matches(invocation.Method)) { return(false); } if (!ArgumentsMatcher.Matches(invocation)) { return(false); } if (!ExtraMatchersMatch(invocation)) { return(false); } return(true); }
public void DoesNotMatchAnObjectThatIsNotAnInvocation() { Matcher matcher = new ArgumentsMatcher(); Assert.IsFalse(matcher.Matches("not an invocation")); }
public void ShowsOutputParametersInDescription() { Matcher matcher = new ArgumentsMatcher(new AlwaysMatcher(true, "arg1"), Is.Out); AssertDescription.IsEqual(matcher, "(arg1, out)"); }
public void MatchesInvocationWithSameNumberOfArgumentsAsMatcherHasValueMatchersAndValueMatchersMatch() { Matcher matcher = new ArgumentsMatcher(Is.EqualTo(arg1Value), Is.EqualTo(arg2Value)); Assert.IsTrue(matcher.Matches(InvocationWithArguments(arg1Value, arg2Value))); }
public void DescribeTo(TextWriter writer) { if (MethodMatcher is MethodMatcher) { writer.Write(((MethodMatcher)MethodMatcher).ReturnType); writer.Write(" "); } writer.Write(Receiver.MockName); writer.Write(_methodSeparator); if (MethodMatcher != null) { MethodMatcher.DescribeTo(writer); } ArgumentsMatcher.DescribeTo(writer); if (_extraMatchers.Count > 0) { writer.Write(" Matching["); for (int i = 0; i < _extraMatchers.Count; i++) { if (i != 0) { writer.Write(", "); } _extraMatchers[i].DescribeTo(writer); } writer.Write("]"); } if (_actions.Count > 0) { writer.Write(" will "); (_actions[0]).DescribeTo(writer); for (int i = 1; i < _actions.Count; i++) { if (i != 0) { writer.Write(", "); } _actions[i].DescribeTo(writer); } } if (IsValid) { writer.Write(" [EXPECTED: "); writer.Write(_expectationDescription); writer.Write(" CALLED: "); writer.Write(_callCount); writer.Write(" time"); if (_callCount != 1) { writer.Write("s"); } writer.Write("]"); } else { writer.Write(" [EXPECTATION NOT VALID because of runtime error or incomplete setup]"); } if (!string.IsNullOrEmpty(_expectationComment)) { writer.Write(" Comment: "); writer.Write(_expectationComment); } writer.WriteLine(); }