/// <summary> /// Verifies that the <paramref name="actualValue"/> is matched by the <paramref name="matcher"/>. /// </summary> /// <param name="actualValue">The actual value to match.</param> /// <param name="matcher">The matcher.</param> /// <param name="message">The error message.</param> /// <param name="formatArgs">The format args for the error message.</param> /// <exception cref="ExpectationException">Thrown if value does not match.</exception> public static void That(object actualValue, Matcher matcher, string message, params object[] formatArgs) { if (matcher == null) throw new ArgumentNullException("matcher"); if (!matcher.Matches(actualValue)) { var writer = new DescriptionWriter(); writer.Write(message, formatArgs); WriteDescriptionOfFailedMatch(writer, actualValue, matcher); throw new ExpectationException(writer.ToString()); } }
/// <summary> /// Constructs a <see cref="UnexpectedInvocationException"/> with the given parameters. /// </summary> /// <param name="factory">The MockFactory that threw this exception</param> /// <param name="invocation">The unexpected invocation</param> /// <param name="expectations">The expectations collection to describe</param> /// <param name="message">A message to help the user understand what was unexpected</param> internal UnexpectedInvocationException(MockFactory factory, Invocation invocation, IExpectationList expectations, string message) { if (factory == null) throw new ArgumentNullException("factory"); if (invocation == null) throw new ArgumentNullException("invocation"); if (expectations == null) throw new ArgumentNullException("expectations"); Factory = factory; var writer = new DescriptionWriter(); writer.WriteLine(); if (invocation.IsPropertySetAccessor) writer.WriteLine(UNEXPECTED_PROPERTY_SETTER_PREFIX); else if (invocation.IsPropertyGetAccessor) writer.WriteLine(UNEXPECTED_PROPERTY_GETTER_PREFIX); else writer.WriteLine(MESSAGE_PREFIX); writer.Write(" "); ((ISelfDescribing)invocation).DescribeTo(writer); writer.Write(message); //expectations.DescribeActiveExpectationsTo(writer); //expectations.DescribeUnmetExpectationsTo(writer); expectations.DescribeTo(writer); _message = writer.ToString(); }