/// <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 void DisplayTypesAndSizes(MessageWriter writer, IEnumerable expected, IEnumerable actual, int indent) { string sExpected = MsgUtils.GetTypeRepresentation(expected); if (expected is ICollection && !(expected is Array)) { sExpected += string.Format(" with {0} elements", ((ICollection)expected).Count); } string sActual = MsgUtils.GetTypeRepresentation(actual); if (actual is ICollection && !(actual is Array)) { sActual += string.Format(" with {0} elements", ((ICollection)actual).Count); } if (sExpected == sActual) { writer.WriteMessageLine(indent, CollectionType_1, sExpected); } else { writer.WriteMessageLine(indent, CollectionType_2, sExpected, sActual); } }
public void FailureForEnumerablesWithDifferentSizes() { IEnumerable<int> expected = new int[] { 1, 2, 3 }.Select(i => i); IEnumerable<int> actual = expected.Take(2); var ex = Assert.Throws<AssertionException>(() => Assert.That(actual, Is.EqualTo(expected))); Assert.That(ex.Message, Is.EqualTo( $" Expected is {MsgUtils.GetTypeRepresentation(expected)}, actual is {MsgUtils.GetTypeRepresentation(actual)}" + Environment.NewLine)); #if NYI // Extra lines " Values differ at index [2]" + Environment.NewLine + " Missing: < 3, ... >")); #endif }