/// <summary> /// Write the constraint description to a MessageWriter /// </summary> /// <param name="writer">The writer on which the description is displayed</param> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.Write( Resources.Empty ); }
/// <summary> /// Write the actual value for a failing constraint test to a /// MessageWriter. TypeCOnstraints override this method to write the /// name of the type. /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer">The writer on which the actual value is displayed</param> public override void WriteActualValueTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WriteActualValue( Actual == null ? null : Actual.GetType() ); }
/// <summary> /// Write the constraint description to a MessageWriter /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer">The writer on which the description is displayed</param> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WritePredicate( Resources.SameAs ); writer.WriteExpectedValue( _expected ); }
/// <summary> /// Write the constraint description to a MessageWriter /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer">The writer on which the description is displayed</param> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WritePredicate( Resources.StringContaining ); writer.WriteExpectedValue( _expected ); if ( CaseInsensitive ) { writer.WriteModifier( Resources.IgnoringCase ); } }
/// <summary> /// Write description of this constraint /// </summary> /// <param name="writer">The MessageWriter to write to</param> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WriteExpectedValue( _expected ); if ( Tolerance != null ) { writer.WriteConnector( "+/-" ); writer.WriteExpectedValue( Tolerance ); } if ( CaseInsensitive ) { writer.WriteModifier( Resources.IgnoringCase ); } }
/// <summary> /// Write a failure message. Overridden to provide custom failure /// messages for EqualConstraint. /// </summary> /// <param name="writer">The MessageWriter to write to</param> public override void WriteMessageTo( MessageWriter writer ) { DisplayDifferences( writer, _expected, Actual, 0 ); }
/// <summary> /// Write a description of this constraint to a MessageWriter /// </summary> /// <param name="writer">The writer on which the description is displayed</param> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WritePredicate( Resources.NoItem ); BaseConstraint.WriteDescriptionTo( writer ); }
/// <summary> /// Write the description of this constraint to a MessageWriter /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer"></param> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WriteExpectedValue( ExpectedType ); }
/// <summary> /// Displays the differences. /// </summary> /// <param name="writer">The writer.</param> /// <param name="expected">The expected.</param> /// <param name="actual">The actual.</param> /// <param name="depth">The depth.</param> private void DisplayDifferences( MessageWriter writer, object expected, object actual, int depth ) { if ( expected is string && actual is string ) { DisplayStringDifferences( writer, (string) expected, (string) actual ); } else if ( expected is ICollection && actual is ICollection ) { DisplayCollectionDifferences( writer, expected as ICollection, actual as ICollection, depth ); } else if ( expected is Stream && actual is Stream ) { DisplayStreamDifferences( writer, expected as Stream, actual as Stream, depth ); } else if ( Tolerance != null ) { writer.DisplayDifferences( expected, actual, Tolerance ); } else { writer.DisplayDifferences( expected, actual ); } }
/// <summary> /// Write the constraint description to a MessageWriter /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer">The writer on which the description is displayed</param> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WritePredicate( string.Format( Resources.PropertyName_1, _name ) ); BaseConstraint.WriteDescriptionTo( writer ); }
/// <summary> /// Write the actual value for a failing constraint test to a /// MessageWriter. The default implementation simply writes the raw /// value of actual, leaving it to the writer to perform any formatting. /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer">The writer on which the actual value is displayed</param> public override void WriteActualValueTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } if ( _propertyExists ) { writer.WriteActualValue( _propValue ); } else { writer.WriteActualValue( Actual.GetType() ); } }
/// <summary> /// Write the constraint description to a MessageWriter /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer">The writer on which the description is displayed</param> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WritePredicate( Resources.Between ); writer.WriteExpectedValue( _low ); writer.WriteConnector( Resources.And ); writer.WriteExpectedValue( _high ); }
/// <summary> /// Write the actual value for a failing constraint test to a /// MessageWriter. The default implementation simply writes the raw /// value of actual, leaving it to the writer to perform any formatting. /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer">The writer on which the actual value is displayed</param> public virtual void WriteActualValueTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WriteActualValue( _actual ); }
/// <summary> /// Write the constraint description to a MessageWriter /// </summary> /// <param name="writer">The writer on which the description is displayed</param> public abstract void WriteDescriptionTo( MessageWriter writer );
/// <summary> /// Write the failure message to the MessageWriter provided as an /// argument. The default implementation simply passes the constraint /// and the actual value to the writer, which then displays the /// constraint description and the value. /// /// Constraints that need to provide additional details, such as where /// the error occured can override this. /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer">The MessageWriter on which to display the message</param> public virtual void WriteMessageTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.DisplayDifferences( this ); }
/// <summary> /// Write the constraint description to a MessageWriter /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer">The writer on which the description is displayed</param> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WritePredicate( Resources.StringStartingWith ); writer.WriteExpectedValue( MsgUtils.ClipString( _expected, writer.MaxLineLength - 40, 0 ) ); if ( CaseInsensitive ) { writer.WriteModifier( Resources.IgnoringCase ); } }
/// <summary> /// Displays the string differences. /// </summary> /// <param name="writer">The writer.</param> /// <param name="expected">The expected.</param> /// <param name="actual">The actual.</param> private void DisplayStringDifferences( MessageWriter writer, string expected, string actual ) { int mismatch = MsgUtils.FindMismatchPosition( expected, actual, 0, CaseInsensitive ); if ( expected.Length == actual.Length ) { writer.WriteMessageLine( Resources.StringsDiffer_1, expected.Length, mismatch ); } else { writer.WriteMessageLine( Resources.StringsDiffer_2, expected.Length, actual.Length, mismatch ); } writer.DisplayStringDifferences( expected, actual, mismatch, CaseInsensitive ); }
/// <summary> /// Displays the stream differences. /// </summary> /// <param name="writer">The writer.</param> /// <param name="expected">The expected.</param> /// <param name="actual">The actual.</param> /// <param name="depth">The depth.</param> private void DisplayStreamDifferences( MessageWriter writer, Stream expected, Stream actual, int depth ) { if ( expected.Length == actual.Length ) { long offset = _failurePoints[depth]; writer.WriteMessageLine( Resources.StreamsDiffer_1, expected.Length, offset ); } else { writer.WriteMessageLine( Resources.StreamsDiffer_2, expected.Length, actual.Length ); } }
/// <summary> /// Write a description for this contraint to a MessageWriter /// </summary> /// <param name="writer">The MessageWriter to receive the description</param> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } Left.WriteDescriptionTo( writer ); writer.WriteConnector( Resources.Or ); Right.WriteDescriptionTo( writer ); }
/// <summary> /// Display the failure information for two collections that did not /// match. /// </summary> /// <param name="writer">The MessageWriter on which to display</param> /// <param name="expected">The expected collection.</param> /// <param name="actual">The actual collection</param> /// <param name="depth">The depth of this failure in a set of nested collections</param> private void DisplayCollectionDifferences( MessageWriter writer, ICollection expected, ICollection actual, int depth ) { int failurePoint = _failurePoints.Count > depth ? (int) _failurePoints[depth] : -1; DisplayCollectionTypesAndSizes( writer, expected, actual, depth ); if ( failurePoint >= 0 ) { DisplayFailurePoint( writer, expected, actual, failurePoint, depth ); if ( failurePoint < expected.Count && failurePoint < actual.Count ) { DisplayDifferences( writer, GetValueFromCollection( expected, failurePoint ), GetValueFromCollection( actual, failurePoint ), ++depth ); } else if ( expected.Count < actual.Count ) { writer.Write( string.Format( " {0}: ", Resources.Extra ) ); writer.WriteCollectionElements( actual, failurePoint, 3 ); } else { writer.Write(string.Format( " {0}: ", Resources.Missing )); writer.WriteCollectionElements( expected, failurePoint, 3 ); } } }
public override void WriteDescriptionTo( MessageWriter writer ) { writer.WriteExpectedValue( "same color as " + expectedColor.ToString() ); }
/// <summary> /// Displays a single line showing the types and sizes of the expected /// and actual collections or arrays. If both are identical, the value /// is only shown once. /// </summary> /// <param name="writer">The MessageWriter on which to display</param> /// <param name="expected">The expected collection or array</param> /// <param name="actual">The actual collection or array</param> /// <param name="indent">The indentation level for the message line</param> private static void DisplayCollectionTypesAndSizes( MessageWriter writer, ICollection expected, ICollection actual, int indent ) { string sExpected = MsgUtils.GetTypeRepresentation( expected ); if ( !( expected is Array ) ) { sExpected += string.Format( CultureInfo.CurrentCulture, Resources.WithElements_1, expected.Count ); } string sActual = MsgUtils.GetTypeRepresentation( actual ); if ( !( actual is Array ) ) { sActual += string.Format( CultureInfo.CurrentCulture, Resources.WithElements_1, expected.Count ); } if ( sExpected == sActual ) { writer.WriteMessageLine( indent, Resources.CollectionType_1, sExpected ); } else { writer.WriteMessageLine( indent, Resources.CollectionType_2, sExpected, sActual ); } }
/// <summary> /// Write a description of this constraint to a MessageWriter /// </summary> /// <exception cref="ArgumentNullException">if the message writer is null.</exception> /// <param name="writer"></param> public override void WriteDescriptionTo( MessageWriter writer ) { if ( writer == null ) { throw new ArgumentNullException( "writer" ); } writer.WritePredicate( Resources.TypeAssignableFrom ); writer.WriteExpectedValue( ExpectedType ); }
/// <summary> /// Displays a single line showing the point in the expected and actual /// arrays at which the comparison failed. If the arrays have different /// structures or dimensions, both values are shown. /// </summary> /// <param name="writer">The MessageWriter on which to display</param> /// <param name="expected">The expected array</param> /// <param name="actual">The actual array</param> /// <param name="failurePoint">Index of the failure point in the underlying collections</param> /// <param name="indent">The indentation level for the message line</param> private static void DisplayFailurePoint( MessageWriter writer, ICollection expected, ICollection actual, int failurePoint, int indent ) { Array expectedArray = expected as Array; Array actualArray = actual as Array; int expectedRank = expectedArray != null ? expectedArray.Rank : 1; int actualRank = actualArray != null ? actualArray.Rank : 1; bool useOneIndex = expectedRank == actualRank; if ( expectedArray != null && actualArray != null ) { for (int r = 1; r < expectedRank && useOneIndex; r++) { if ( expectedArray.GetLength( r ) != actualArray.GetLength( r ) ) { useOneIndex = false; } } } int[] expectedIndices = MsgUtils.GetArrayIndicesFromCollectionIndex( expected, failurePoint ); if ( useOneIndex ) { writer.WriteMessageLine( indent, Resources.ValuesDiffer_1, MsgUtils.GetArrayIndicesAsString( expectedIndices ) ); } else { int[] actualIndices = MsgUtils.GetArrayIndicesFromCollectionIndex( actual, failurePoint ); writer.WriteMessageLine( indent, Resources.ValuesDiffer_2, MsgUtils.GetArrayIndicesAsString( expectedIndices ), MsgUtils.GetArrayIndicesAsString( actualIndices ) ); } }
/// <summary> /// Write the constraint description to a MessageWriter /// </summary> /// <param name="writer">The writer on which the description is displayed</param> public override void WriteDescriptionTo( MessageWriter writer ) { RealConstraint.WriteDescriptionTo( writer ); }
/// <summary> /// Write the actual value for a failing constraint test to a /// MessageWriter. /// </summary> /// <param name="writer">The writer on which the actual value is displayed</param> public override void WriteActualValueTo( MessageWriter writer ) { BaseConstraint.WriteActualValueTo( writer ); }