/// <summary> /// Writes the description of a failed match to the specified <paramref name="writer"/>. /// </summary> /// <param name="writer">The <see cref="TextWriter"/> where the description is written to.</param> /// <param name="actualValue">The actual value to be written.</param> /// <param name="matcher">The matcher which is used for the expected value to be written.</param> private static void WriteDescriptionOfFailedMatch(TextWriter writer, object actualValue, Matcher matcher) { writer.WriteLine(); writer.Write("Expected: "); matcher.DescribeTo(writer); writer.WriteLine(); writer.Write("Actual: "); writer.Write(actualValue); }
/// <summary> /// Verifies that the <paramref name="actualValue"/> is matched by the <paramref name="matcher"/>. /// </summary> /// <param name="actualValue">The actual value.</param> /// <param name="matcher">The matcher.</param> /// <exception cref="ExpectationException">Thrown if value does not match.</exception> public static void That(object actualValue, Matcher matcher) { if (matcher == null) throw new ArgumentNullException("matcher"); if (!matcher.Matches(actualValue)) { var writer = new DescriptionWriter(); WriteDescriptionOfFailedMatch(writer, actualValue, matcher); throw new ExpectationException(writer.ToString()); } }
/// <summary> /// Returns a matcher for checking field values. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <param name="valueMatcher">The value matcher.</param> /// <returns>Returns a <see cref="FieldMatcher"/> for checking field values.</returns> public static Matcher Field(string fieldName, Matcher valueMatcher) { return(new FieldMatcher(fieldName, valueMatcher)); }
private IMethodSyntax <T> GetExpectationBuilder(string description, Matcher requiredCountMatcher, Matcher matchingCountMatcher, object proxy) { return(new ExpectationBuilder <T>(description, requiredCountMatcher, matchingCountMatcher, proxy)); }
/// <summary> /// Returns a matcher for checking property values. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="valueMatcher">The value matcher.</param> /// <returns>Returns a <see cref="PropertyMatcher"/> for checking property values.</returns> public static Matcher Property(string propertyName, Matcher valueMatcher) { return(new PropertyMatcher(propertyName, valueMatcher)); }
/// <summary> /// Returns a matcher for testing string representation of objects. /// </summary> /// <param name="matcher">The wrapped matcher.</param> /// <returns>Returns a <see cref="ToStringMatcher"/> for testing string representation of objects.</returns> public static Matcher ToString(Matcher matcher) { return(new ToStringMatcher(matcher)); }
/// <summary> /// Returns a matcher for checking field values. /// </summary> /// <param name="fieldName">Name of the field.</param> /// <param name="valueMatcher">The value matcher.</param> /// <returns>Returns a <see cref="FieldMatcher"/> for checking field values.</returns> public static Matcher Field(string fieldName, Matcher valueMatcher) { return new FieldMatcher(fieldName, valueMatcher); }
/// <summary> /// Returns a matcher for checking property values. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="valueMatcher">The value matcher.</param> /// <returns>Returns a <see cref="PropertyMatcher"/> for checking property values.</returns> public static Matcher Property(string propertyName, Matcher valueMatcher) { return new PropertyMatcher(propertyName, valueMatcher); }
/// <summary> /// Returns a matcher for testing string representation of objects. /// </summary> /// <param name="matcher">The wrapped matcher.</param> /// <returns>Returns a <see cref="ToStringMatcher"/> for testing string representation of objects.</returns> public static Matcher ToString(Matcher matcher) { return new ToStringMatcher(matcher); }