Beispiel #1
0
 /// <summary>
 /// Writes the description of a failed match to the specified <paramref name="description"/>.
 /// </summary>
 /// <param name="description">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(IDescription description, object actualValue, Matcher matcher)
 {
     description.AppendNewLine()
                .AppendText("Expected: ");
     matcher.DescribeOn(description);
     description.AppendNewLine()
                .AppendText("Actual:   ")
                .AppendValue(actualValue);
 }
Beispiel #2
0
        /// <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.Matches(actualValue))
            {
                var writer = new StringDescriptionWriter();
                WriteDescriptionOfFailedMatch(writer, actualValue, matcher);

                throw new ExpectationException(writer.ToString());
            }
        }
Beispiel #3
0
        /// <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.Matches(actualValue))
            {
                var writer = new StringDescriptionWriter();
                writer.AppendTextFormat(message, formatArgs);
                WriteDescriptionOfFailedMatch(writer, actualValue, matcher);

                throw new ExpectationException(writer.ToString());
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BinaryOperator"/> class.
 /// </summary>
 /// <param name="left">The left operand.</param>
 /// <param name="right">The right operand.</param>
 protected BinaryOperator(Matcher left, Matcher right)
 {
     Left = left;
     Right = right;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DescriptionOverride"/> class.
 /// </summary>
 /// <param name="description">The new description for the wrapped matcher.</param>
 /// <param name="otherMatcher">The matcher to wrap.</param>
 public DescriptionOverride(string description, Matcher otherMatcher)
 {
     this.description = description;
     this.otherMatcher = otherMatcher;
 }
 public void SetUp()
 {
     arg = new NamedObject("arg");
     stringMatcher = new MockMatcher();
     matcher = new ToStringMatcher(stringMatcher);
 }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AndMatcher"/> class.
 /// </summary>
 /// <param name="left">The left operand.</param>
 /// <param name="right">The right operand.</param>
 public AndMatcher(Matcher left, Matcher right)
     : base(left, right)
 {
 }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NotMatcher"/> class.
 /// </summary>
 /// <param name="negated">The matcher to negate.</param>
 public NotMatcher(Matcher negated)
 {
     this.negated = negated;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyMatcher"/> class.
 /// </summary>
 /// <param name="propertyName">Name of the property.</param>
 /// <param name="valueMatcher">The value matcher.</param>
 public PropertyMatcher(string propertyName, Matcher valueMatcher)
 {
     this.propertyName = propertyName;
     this.valueMatcher = valueMatcher;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ToStringMatcher"/> class.
 /// </summary>
 /// <param name="matcher">The wrapped matcher.</param>
 public ToStringMatcher(Matcher matcher)
 {
     this.matcher = matcher;
 }
Beispiel #11
0
 /// <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);
 }
Beispiel #12
0
 /// <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);
 }
Beispiel #13
0
 /// <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);
 }
Beispiel #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FieldMatcher"/> class.
 /// </summary>
 /// <param name="fieldName">Name of the field to match against the <paramref name="valueMatcher"/>.</param>
 /// <param name="valueMatcher">The value matcher.</param>
 public FieldMatcher(string fieldName, Matcher valueMatcher)
 {
     this.fieldName = fieldName;
     this.valueMatcher = valueMatcher;
 }
 private void AssertReturnsValue(IAction action, Type returnType, Matcher resultMatcher)
 {
     Verify.That(ValueReturnedForType(action, returnType), resultMatcher,
                 "result for type " + returnType);
 }