/// <summary> /// Create an exception for an unexpected method call. /// </summary> public override ExpectationViolationException UnexpectedMethodCall(IInvocation invocation, object proxy, MethodInfo method, object[] args) { // We have move to the parent recorder, we need to pass the call to it. if (parentRecorderRedirection != null) { return(parentRecorderRedirection.UnexpectedMethodCall(invocation, proxy, method, args)); } StringBuilder sb = new StringBuilder(); CalcExpectedAndActual calc = new CalcExpectedAndActual(this, proxy, method, args); string methodAsString = MethodCallUtil.StringPresentation(invocation, method, args); sb.Append(methodAsString); sb.Append(" Expected #"); if (calc.ExpectedMax == calc.ExpectedMin) { sb.Append(calc.ExpectedMin); } else { sb.Append(calc.ExpectedMin).Append(" - ").Append(calc.ExpectedMax); } sb.Append(", Actual #").Append(calc.Actual).Append('.'); ExpectationsList list = GetAllExpectationsForProxyAndMethod(proxy, method); if (list.Count > 0) { string message = list[0].Message; if (message != null) { sb.Append(System.Environment.NewLine) .Append("Message: ") .Append(message); } } AppendNextExpected(proxy, method, sb); return(new ExpectationViolationException(sb.ToString())); }
/// <summary> /// Create an exception for an unexpected method call. /// </summary> public override ExpectationViolationException UnexpectedMethodCall(IInvocation invocation, object proxy, MethodInfo method, object[] args) { // We have move to the parent recorder, we need to pass the call to it. if (parentRecorderRedirection != null) return parentRecorderRedirection.UnexpectedMethodCall(invocation, proxy, method, args); StringBuilder sb = new StringBuilder(); CalcExpectedAndActual calc = new CalcExpectedAndActual(this, proxy, method, args); string methodAsString = MethodCallUtil.StringPresentation(invocation, method, args); sb.Append(methodAsString); sb.Append(" Expected #"); if (calc.ExpectedMax == calc.ExpectedMin) sb.Append(calc.ExpectedMin); else sb.Append(calc.ExpectedMin).Append(" - ").Append(calc.ExpectedMax); sb.Append(", Actual #").Append(calc.Actual).Append('.'); ExpectationsList list = GetAllExpectationsForProxyAndMethod(proxy, method); if (list.Count > 0) { string message = list[0].Message; if (message != null) { sb.Append(System.Environment.NewLine) .Append("Message: ") .Append(message); } } AppendNextExpected(proxy, method, sb); return new ExpectationViolationException(sb.ToString()); }