GetTypeRepresentation() public static method

Returns the representation of a type as used in NUnitLite. This is the same as Type.ToString() except for arrays, which are displayed with their declared sizes.
public static GetTypeRepresentation ( object obj ) : string
obj object
return string
示例#1
0
        /// <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 +
                            "  Values differ at index [2]" + Environment.NewLine +
                            "  Missing:  < 3, ... >"));
        }
示例#3
0
        /// <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 DisplayCollectionTypesAndSizes(MessageWriter writer, ICollection expected, ICollection actual, int indent)
        {
            string expectedType = MsgUtils.GetTypeRepresentation(expected);
            string actualType   = MsgUtils.GetTypeRepresentation(actual);

            if (expectedType == actualType)
            {
                writer.WriteMessageLine(indent, CollectionType_1, expectedType);
            }
            else
            {
                writer.WriteMessageLine(indent, CollectionType_2, expectedType, actualType);
            }
        }
示例#4
0
        /// <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 DisplayCollectionTypesAndSizes(MessageWriter writer, ICollection expected, ICollection actual, int indent)
        {
            string sExpected = MsgUtils.GetTypeRepresentation(expected);
            //if (!(expected is Array))
            //    sExpected += string.Format(" with {0} elements", expected.Count);

            string sActual = MsgUtils.GetTypeRepresentation(actual);

            //if (!(actual is Array))
            //    sActual += string.Format(" with {0} elements", actual.Count);

            if (sExpected == sActual)
            {
                writer.WriteMessageLine(indent, CollectionType_1, sExpected);
            }
            else
            {
                writer.WriteMessageLine(indent, CollectionType_2, sExpected, sActual);
            }
        }
示例#5
0
        private void DisplayTypesAndSizes(MessageWriter writer, IEnumerable expected, IEnumerable actual, int indent)
        {
            string text = MsgUtils.GetTypeRepresentation(expected);

            if (expected is ICollection && !(expected is Array))
            {
                text += $" with {((ICollection)expected).Count} elements";
            }
            string text2 = MsgUtils.GetTypeRepresentation(actual);

            if (actual is ICollection && !(actual is Array))
            {
                text2 += $" with {((ICollection)actual).Count} elements";
            }
            if (text == text2)
            {
                writer.WriteMessageLine(indent, CollectionType_1, text);
            }
            else
            {
                writer.WriteMessageLine(indent, CollectionType_2, text, text2);
            }
        }