示例#1
0
        public static string CreateMessage(object input, object expected)
        {
            string displayInput    = ExpectedMessageBuilder.ToDisplayableString(input);
            string displayExpected = ExpectedMessageBuilder.ToDisplayableString(expected);

            string message = "  Expected: not " + displayExpected + Environment.NewLine
                             + "  But was:  " + displayInput + Environment.NewLine;

            return(message);
        }
示例#2
0
        public static string CreateMessage <T>(T input, T expected)
        {
            var displayInput          = ExpectedMessageBuilder.ToDisplayableString(input);
            var displayExpected       = ExpectedMessageBuilder.ToDisplayableString(expected);
            var prefix                = "";
            var showStringDifferences = !Equals(expected, default(T)) && !Equals(input, default(T)) && input is string;
            var differenceIndex       = 0;

            if (showStringDifferences)
            {
                var stringInput    = input as string;
                var stringExpected = expected as string;
                differenceIndex = GetDifferenceIndex(stringInput, stringExpected);
                displayInput    = ExpectedMessageBuilder.ToDisplayableString(stringInput, differenceIndex);
                displayExpected = ExpectedMessageBuilder.ToDisplayableString(stringExpected, differenceIndex);
                var inputLength = stringInput.Length;
// ReSharper disable once PossibleNullReferenceException
                var expectedLength = stringExpected.Length;
                if (inputLength == expectedLength)
                {
                    prefix = "  String lengths are both " + expectedLength + ".";
                }
                else
                {
                    prefix = "  Expected string length " + expectedLength + " but was " + inputLength + ".";
                }
                prefix += " Strings differ at index " + differenceIndex + "." + Environment.NewLine;
            }

            var message = ExpectedMessageBuilder.BuildFor(displayExpected, displayInput);
            var suffix  = "";

            if (showStringDifferences)
            {
                if (differenceIndex > displayExpected.Length)
                {
                    differenceIndex = ExpectedMessageBuilder.Ellipsis.Length + ExpectedMessageBuilder.StringLeftStart;
                }
                suffix += "  " + "^".PadLeft(12 + differenceIndex, '-') + Environment.NewLine;
            }
            return(prefix + message + suffix);
        }
示例#3
0
        public static string CreateMessage(object input, object expected)
        {
            string displayInput          = ExpectedMessageBuilder.ToDisplayableString(input);
            string displayExpected       = ExpectedMessageBuilder.ToDisplayableString(expected);
            string prefix                = "";
            bool   showStringDifferences = expected != null && input != null && input.GetType() == typeof(string);
            int    differenceIndex       = 0;

            if (showStringDifferences)
            {
                string stringInput    = input as string;
                string stringExpected = expected as string;
                differenceIndex = GetDifferenceIndex(stringInput, stringExpected);
                displayInput    = ExpectedMessageBuilder.ToDisplayableString(stringInput, differenceIndex);
                displayExpected = ExpectedMessageBuilder.ToDisplayableString(stringExpected, differenceIndex);
                int inputLength    = stringInput.Length;
                int expectedLength = stringExpected.Length;
                if (inputLength == expectedLength)
                {
                    prefix = "  String lengths are both " + expectedLength + ".";
                }
                else
                {
                    prefix = "  Expected string length " + expectedLength + " but was " + inputLength + ".";
                }
                prefix += " Strings differ at index " + differenceIndex + "." + Environment.NewLine;
            }

            string message = ExpectedMessageBuilder.BuildFor(displayExpected, displayInput);
            string suffix  = "";

            if (showStringDifferences)
            {
                if (differenceIndex > displayExpected.Length)
                {
                    differenceIndex = ExpectedMessageBuilder.Ellipsis.Length + ExpectedMessageBuilder.StringLeftStart;
                }
                suffix += "  " + "^".PadLeft(12 + differenceIndex, '-') + Environment.NewLine;
            }
            return(prefix + message + suffix);
        }
        public static string CreateMessage(string other, string actual)
        {
            var message = ExpectedMessageBuilder.BuildFor("greater than " + other, actual);

            return(message);
        }
示例#5
0
        public static string CreateMessage()
        {
            string message = ExpectedMessageBuilder.BuildFor("True", "False");

            return(message);
        }
示例#6
0
        public static string CreateMessage()
        {
            var message = ExpectedMessageBuilder.BuildFor("not null", "null");

            return(message);
        }
示例#7
0
        public static string CreateMessage(string actual)
        {
            var message = ExpectedMessageBuilder.BuildFor("null", actual);

            return(message);
        }
		public static string CreateMessage()
		{
			var message = ExpectedMessageBuilder.BuildFor("False", "True");
			return message;
		}
示例#9
0
        public static string CreateMessage(string other, string actual)
        {
            string message = ExpectedMessageBuilder.BuildFor("less than or equal to " + other, actual);

            return(message);
        }