Example #1
0
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"
    Dictionary
        ""{0}""
    should contain key
        ""{1}""
    with value
        ""{2}""
    {3}";

            var codePart      = context.CodePart;
            var expectedValue = context.Expected.ToStringAwesomely();
            var actualValue   = context.Actual.ToStringAwesomely();
            var keyValue      = context.Key.ToStringAwesomely();

            if (context.HasRelevantKey)
            {
                var actualValueString = context.Actual == null
                    ? actualValue
                    : string.Format("\"{0}\"", actualValue.Trim('"'));
                var valueString = string.Format("but value was {0}", actualValueString);
                return(String.Format(format, codePart, keyValue.Trim('"'), expectedValue.Trim('"'), valueString));
            }
            else
            {
                return(String.Format(format, codePart, actualValue.Trim('"'), expectedValue.Trim('"'), "but the key does not exist"));
            }
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"
            {0}
            should {1}be within
            {2}
            of
            {3}
            but was
            {4}";

            var codePart = context.CodePart;
            var tolerance = context.Tolerance.ToStringAwesomely();
            var expectedValue = context.Expected.ToStringAwesomely();
            var actualValue = context.Actual.ToStringAwesomely();
            var negated = context.ShouldMethod.Contains("Not") ? "not " : string.Empty;

            var message = string.Format(format, codePart, negated, tolerance, expectedValue, actualValue);

            if (DifferenceHighlighter.CanHighlightDifferences(context))
            {
                message += string.Format(@"
            difference
            {0}",
                    DifferenceHighlighter.HighlightDifferences(context));
            }

            return message;
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"
            Dictionary
            ""{0}""
            should not contain key
            ""{1}""
            with value
            {2}
            {3}";

            var codePart = context.CodePart;
            var expectedValue = context.Expected.ToStringAwesomely();
            var actualValue = context.Actual.ToStringAwesomely();
            var keyValue = context.Key.ToStringAwesomely();

            var expectedValueString = context.Expected == null
                ? expectedValue
                : string.Format("\"{0}\"", expectedValue.Trim('"'));

            if (context.HasRelevantKey)
            {
                var valueString = "but does";
                return String.Format(format, codePart, keyValue.Trim('"'), expectedValueString, valueString);
            }
            else
            {
                return String.Format(format, codePart, actualValue.Trim('"'), expectedValueString, "but the key does not exist");
            }
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart     = context.CodePart;
            var expected     = context.Expected.ToStringAwesomely();
            var shouldMethod = context.ShouldMethod.PascalToSpaced();

            if (context.IsNegatedAssertion)
            {
                if (codePart == "null")
                {
                    codePart = expected;
                }

                return
                    ($@"{codePart}
    {shouldMethod} but was{(context.Expected == null ? " null" : "")}");
            }

            string details;

            if (context.Expected is IEnumerable enumerable and not string)
            {
                var count = enumerable?.Cast <object?>().Count() ?? 0;
                details = $@" had
{count}
    item{(count == 1 ? string.Empty : "s")} and";
            }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var    codePart    = context.CodePart;
            var    expected    = context.Expected.ToStringAwesomely();
            var    actualValue = context.Actual.ToStringAwesomely();
            string actual;

            if (context.IsNegatedAssertion)
            {
                actual = string.Empty;
            }
            else if (codePart == actualValue)
            {
                actual = " not";
            }
            else
            {
                actual = $"\r\n{actualValue}";
            }
            var message =
                $@"{codePart}
    {context.ShouldMethod.PascalToSpaced()}
{expected}
    but was{actual}";

            if (DifferenceHighlighter.CanHighlightDifferences(context))
            {
                message += $@"
    difference
{DifferenceHighlighter.HighlightDifferences(context)}";
            }
            return(message);
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            string codePart = context.CodePart;
            string caseSensitivity = context.CaseSensitivity == Case.Insensitive ? " (case insensitive comparison)" : "(case sensitive comparison)";
            string format = @"
            {0}
            {1}
            {2}{3}
            but was
            {4}";

            if (DifferenceHighlighter.CanHighlightDifferences(context))
            {
                format += string.Format(@"
            difference
            {0}",
                DifferenceHighlighter.HighlightDifferences(context));
            }

            return string.Format(format,
                    codePart,
                    context.ShouldMethod.PascalToSpaced(),
                    context.Expected.ToStringAwesomely(),
                    caseSensitivity,
                    context.Actual.ToStringAwesomely());
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart = context.CodePart;
            var tolerance = context.Tolerance.ToStringAwesomely();
            var expectedValue = context.Expected.ToStringAwesomely();
            var actualValue = context.Actual.ToStringAwesomely();
            string actual;
            if (codePart == actualValue) actual = " not";
            else actual = $@"
{actualValue}";
            var negated = context.ShouldMethod.Contains("Not") ? "not " : string.Empty;

            var message =
$@"{codePart}
    should {negated}be within
{tolerance}
    of
{expectedValue}
    but was{actual}";

            if (DifferenceHighlighter.CanHighlightDifferences(context))
            {
                message += $@"
    difference
{DifferenceHighlighter.HighlightDifferences(context)}";
            }

            return message;
        }
 public override bool CanProcess(IShouldlyAssertionContext context)
 {
     return(context.ShouldMethod.StartsWith("Should") &&
            !context.ShouldMethod.Contains("Contain") &&
            context.UnderlyingShouldMethod != null &&
            context.UnderlyingShouldMethod.GetParameters().Any(p => p.Name == "tolerance"));
 }
Example #9
0
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var expected = ((IEnumerable)context.Expected).Cast <object>().ToArray();
            var actual   = ((IEnumerable)context.Actual).Cast <object>().ToArray();
            var codePart = context.CodePart;
            var expectedFormattedValue = expected.ToStringAwesomely();

            var missingFromExpected = actual.Where(a => !expected.Any(e => Is.Equal(e, a))).ToArray();
            var missingFromActual   = expected.Where(e => !actual.Any(a => Is.Equal(e, a))).ToArray();

            var actualMissingMessage = missingFromActual.Any() ? string.Format("{0} is missing {1}", codePart,
                                                                               missingFromActual.ToStringAwesomely()) : string.Empty;
            var expectedMissingMessage = missingFromExpected.Any() ? string.Format("{0} is missing {1}", expectedFormattedValue,
                                                                                   missingFromExpected.ToStringAwesomely()) : string.Empty;

            //"first should be second (ignoring order) but first is missing [4] and second is missing [2]"

            const string format = @"
    {0}
            {1}
    {2} (ignoring order)
            but
    {3}";

            string missingMessage = !string.IsNullOrEmpty(actualMissingMessage) && !string.IsNullOrEmpty(expectedMissingMessage)
                ? string.Format("{0} and {1}", actualMissingMessage, expectedMissingMessage)
                : string.Format("{0}{1}", actualMissingMessage, expectedMissingMessage);

            return(string.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), expectedFormattedValue, missingMessage));
        }
Example #10
0
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart = context.CodePart == "null" ? context.Actual.ToStringAwesomely() : context.CodePart;

            var elementPhrase = context.MatchCount.HasValue
                ? context.MatchCount.Value + " element(s)"
                : "an element";

            var should   = context.ShouldMethod.PascalToSpaced();
            var expected = context.Expected.ToStringAwesomely();

            if (context.IsNegatedAssertion)
            {
                return
                    ($@"{codePart}
    {should} {elementPhrase} satisfying the condition
{expected}
    but does{""}");
            }

            return
                ($@"{codePart}
    {should} {elementPhrase} satisfying the condition
{expected}
    but does not");
        }
Example #11
0
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var throwContext      = (ShouldThrowAssertionContext)context;
            var isExtensionMethod = context.ShouldMethod == "ShouldNotThrow";
            var codePart          = context.CodePart;

            var expectedValue = context.Expected.ToStringAwesomely();

            string errorMessage;

            if (isExtensionMethod && !throwContext.IsAsync)
            {
                errorMessage = string.Format("`{0}()` should not throw but threw {1}", codePart, expectedValue);
            }
            else if (isExtensionMethod && throwContext.IsAsync)
            {
                errorMessage = string.Format("Task `{0}` should not throw but threw {1}", codePart, expectedValue);
            }
            else
            {
                errorMessage = string.Format("`{0}` should not throw but threw {1}", codePart, expectedValue);
            }

            var notThrowAssertionContext = context as ShouldThrowAssertionContext;

            errorMessage += (notThrowAssertionContext != null) ? string.Format(" with message \"{0}\"", notThrowAssertionContext.ExceptionMessage) : string.Empty;

            return(errorMessage);
        }
 public override bool CanProcess(IShouldlyAssertionContext context)
 {
     return context.ShouldMethod == "ShouldBeginWith" ||
            context.ShouldMethod == "ShouldNotBeginWith" ||
            context.ShouldMethod == "ShouldEndWith" ||
            context.ShouldMethod == "ShouldNotEndWith";
 }
 public override bool CanProcess(IShouldlyAssertionContext context)
 {
     return(context.ShouldMethod == "ShouldBeginWith" ||
            context.ShouldMethod == "ShouldNotBeginWith" ||
            context.ShouldMethod == "ShouldEndWith" ||
            context.ShouldMethod == "ShouldNotEndWith");
 }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"
        {0}
    should {1}be within
        {2}
    of
        {3}
    but was 
        {4}";

            var codePart      = context.CodePart;
            var tolerance     = context.Tolerance.ToStringAwesomely();
            var expectedValue = context.Expected.ToStringAwesomely();
            var actualValue   = context.Actual.ToStringAwesomely();
            var negated       = context.ShouldMethod.Contains("Not") ? "not " : string.Empty;

            var message = string.Format(format, codePart, negated, tolerance, expectedValue, actualValue);

            if (DifferenceHighlighter.CanHighlightDifferences(context))
            {
                message += string.Format(@"
        difference
    {0}",
                                         DifferenceHighlighter.HighlightDifferences(context));
            }

            return(message);
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            string codePart        = context.CodePart;
            string caseSensitivity = context.CaseSensitivity == Case.Insensitive ? " (case insensitive comparison)" : "(case sensitive comparison)";
            string format          = @"
    {0}
        {1}
    {2}{3}
        but was
    {4}";

            if (DifferenceHighlighter.CanHighlightDifferences(context))
            {
                format += string.Format(@"
        difference
    {0}",
                                        DifferenceHighlighter.HighlightDifferences(context));
            }

            return(string.Format(format,
                                 codePart,
                                 context.ShouldMethod.PascalToSpaced(),
                                 context.Expected.ToStringAwesomely(),
                                 caseSensitivity,
                                 context.Actual.ToStringAwesomely()));
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var    codePart      = context.CodePart;
            var    expectedValue = context.Expected.ToStringAwesomely();
            var    actualValue   = context.Actual.ToStringAwesomely();
            string actual;

            if (codePart == actualValue)
            {
                if (context.IsNegatedAssertion)
                {
                    actual = " did";
                }
                else
                {
                    actual = " did not";
                }
            }
            else
            {
                actual = $@" was
{actualValue}";
            }

            var message =
                $@"{codePart}
    {context.ShouldMethod.PascalToSpaced()}
{expectedValue}
    but{actual}";

            return(message);
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var expected = ((IEnumerable)context.Expected).Cast<object>().ToArray();
            var actual = ((IEnumerable)context.Actual).Cast<object>().ToArray();
            var codePart = context.CodePart;
            var expectedFormattedValue = expected.ToStringAwesomely();

            var missingFromExpected = actual.Where(a => !expected.Any(e => Is.Equal(e, a))).ToArray();
            var missingFromActual = expected.Where(e => !actual.Any(a => Is.Equal(e, a))).ToArray();

            var actualMissingMessage = missingFromActual.Any() ? string.Format("{0} is missing {1}", codePart,
                missingFromActual.ToStringAwesomely()) : string.Empty;
            var expectedMissingMessage = missingFromExpected.Any() ? string.Format("{0} is missing {1}", expectedFormattedValue,
                missingFromExpected.ToStringAwesomely()) : string.Empty;

            //"first should be second (ignoring order) but first is missing [4] and second is missing [2]"

            const string format = @"
            {0}
            {1}
            {2} (ignoring order)
            but
            {3}";

            string missingMessage = !string.IsNullOrEmpty(actualMissingMessage) && !string.IsNullOrEmpty(expectedMissingMessage)
                ? string.Format("{0} and {1}", actualMissingMessage, expectedMissingMessage)
                : string.Format("{0}{1}", actualMissingMessage, expectedMissingMessage);
            return string.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), expectedFormattedValue, missingMessage);
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format =
@"{0}
    should contain key
{1}
    with value
{2}
{3}";

            var codePart = context.CodePart;
            var dictionary = (IDictionary)context.Actual;
            var keyExists = dictionary.Contains(context.Key);
            var expectedValue = context.Expected.ToStringAwesomely();
            var keyValue = context.Key.ToStringAwesomely();

            if (keyExists)
            {
                var actualValueString = dictionary[context.Key].ToStringAwesomely();
                var valueString = 
$@"    but value was
{actualValueString}";
                return string.Format(format, codePart, keyValue, expectedValue, valueString);
            }

            return string.Format(format, codePart, keyValue, expectedValue, "    but the key does not exist");
        }
 public override bool CanProcess(IShouldlyAssertionContext context)
 {
     return context.ShouldMethod.StartsWith("Should")
            && !context.ShouldMethod.Contains("Contain")
            && context.UnderlyingShouldMethod != null
            && context.UnderlyingShouldMethod.GetParameters().Any(p => p.Name == "tolerance");
 }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart = context.CodePart;
            var expected = context.Expected.ToStringAwesomely();
            var actualValue = context.Actual.ToStringAwesomely();
            string actual;
            if (context.IsNegatedAssertion)
            {
                actual = string.Empty;
            }
            else if (codePart == actualValue)
            {
                actual = " not";
            }
            else
            {
                actual = $"\r\n{actualValue}";
            }
            var message =
$@"{codePart}
    {context.ShouldMethod.PascalToSpaced()}
{expected}
    but was{actual}";

            if (DifferenceHighlighter.CanHighlightDifferences(context))
            {
                message += $@"
    difference
{DifferenceHighlighter.HighlightDifferences(context)}";
            }
            return message;
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format =
                @"{0}
    should contain key
{1}
    with value
{2}
{3}";

            var codePart      = context.CodePart;
            var dictionary    = (IDictionary)context.Actual;
            var keyExists     = dictionary.Contains(context.Key);
            var expectedValue = context.Expected.ToStringAwesomely();
            var keyValue      = context.Key.ToStringAwesomely();

            if (keyExists)
            {
                var actualValueString = dictionary[context.Key].ToStringAwesomely();
                var valueString       =
                    $@"    but value was
{actualValueString}";
                return(string.Format(format, codePart, keyValue, expectedValue, valueString));
            }

            return(string.Format(format, codePart, keyValue, expectedValue, "    but the key does not exist"));
        }
Example #22
0
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            Debug.Assert(context.Actual is IDictionary);
            Debug.Assert(context.Key is object);

            const string format =
                @"{0}
    should not contain key
{1}
    with value
{2}
    {3}";

            var codePart   = context.CodePart;
            var dictionary = (IDictionary)context.Actual;
            var keyExists  = dictionary.Contains(context.Key);
            var expected   = context.Expected.ToStringAwesomely();
            var keyValue   = context.Key.ToStringAwesomely();

            if (keyExists)
            {
                return(string.Format(format, codePart, keyValue, expected, "but does"));
            }

            return(string.Format(format, codePart, keyValue, expected, "but the key does not exist"));
        }
     public override string GenerateErrorMessage(IShouldlyAssertionContext context)
     {
         return string.Format(@"
 {0}
     should complete in
 {1}
     but did not", context.Expected, context.Timeout);
     }
 public bool CanProcess(IShouldlyAssertionContext context)
 {
     return context.Expected != null && context.Actual != null
            && (context.Expected is IEnumerable)
            && !(context.Expected is string)
            && (context.Actual is IEnumerable)
            && !(context.Actual is string);
 }
     public override string GenerateErrorMessage(IShouldlyAssertionContext context)
     {
         return(string.Format(@"
 {0}
     should complete in
 {1}
     but did not", context.Expected, context.Timeout));
     }
 public override string GenerateErrorMessage(IShouldlyAssertionContext context)
 {
     return $@"
     {context.Expected}
     should complete in
     {context.Timeout}
     but did not";
 }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            return
                ($@"{context.CodePart}
    should be in {context.SortDirection.ToString().ToLower()} order but was not.
    The first out-of-order item was found at index {context.OutOfOrderIndex}:
{context.OutOfOrderObject}");
        }
 public bool CanProcess(IShouldlyAssertionContext context)
 {
     return context.Expected != null &&
            context.Actual != null &&
            context.Expected is string &&
            context.Actual is string &&
            context.ShouldMethod == "ShouldBe";
 }
Example #29
0
 public bool CanProcess(IShouldlyAssertionContext context)
 {
     return(context.Expected != null && context.Actual != null &&
            context.Expected is IEnumerable &&
            !(context.Expected is string) &&
            context.Actual is IEnumerable &&
            !(context.Actual is string));
 }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            return($@"
{context.Expected}
    should complete in
{context.Timeout}
    but did not");
        }
Example #31
0
 public override bool CanProcess(IShouldlyAssertionContext context)
 {
     return(context is
     {
         ShouldMethod : "ShouldBe",
         Expected : not Expression,
         Actual : IEnumerable <string>,
     });
 public bool CanProcess(IShouldlyAssertionContext context)
 {
     return(context.Expected != null &&
            context.Actual != null &&
            context.Expected is string &&
            context.Actual is string &&
            context.ShouldMethod == "ShouldBe");
 }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"{0} should be {1} but was {2}";

            var codePart      = context.CodePart;
            var expectedValue = context.Expected.ToStringAwesomely();

            return(string.Format(format, codePart, expectedValue, context.Actual.ToStringAwesomely()));
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"{0} {1} but was {2}";

            var codePart = context.CodePart;
            var expectedValue = context.Expected.ToStringAwesomely();

            return string.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), expectedValue);
        }
Example #35
0
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"{0} {1} but was {2}";

            var codePart      = context.CodePart;
            var expectedValue = context.Expected.ToStringAwesomely();

            return(string.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), expectedValue));
        }
Example #36
0
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"{0} should not match {1} but did";

            var codePart = context.CodePart;
            var expected = context.Expected.ToStringAwesomely();

            return(string.Format(format, codePart, expected));
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"{0} should not match {1} but did";

            var codePart = context.CodePart;
            var expectedValue = context.Expected.ToStringAwesomely();

            return string.Format(format, codePart, expectedValue);
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var expected = context.Expected.ToStringAwesomely();
            var codePart = context.CodePart == "null" ? expected : context.CodePart;
            var expectedValue = context.IsNegatedAssertion || expected == codePart ? string.Empty : $@"
{expected}";

            return $@"{codePart}
    {context.ShouldMethod.PascalToSpaced()} but was{expectedValue}";
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var expected      = context.Expected.ToStringAwesomely();
            var codePart      = context.CodePart == "null" ? expected : context.CodePart;
            var expectedValue = context.IsNegatedAssertion || expected == codePart ? string.Empty : $@"
{expected}";

            return($@"{codePart}
    {context.ShouldMethod.PascalToSpaced()} but was{expectedValue}");
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"{0} should be subset of {1} but {2} {3} outside subset";

            var codePart = context.CodePart;
            var expectedValue = context.Expected.ToStringAwesomely();

            var count = (context.Actual ?? Enumerable.Empty<object>()).As<IEnumerable>().Cast<object>().Count();

            return string.Format(format, codePart, expectedValue, context.Actual.ToStringAwesomely(), count > 1 ? "are" : "is");
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart = context.CodePart;
            var expectedValue = context.Expected.ToString();

            return
$@"{codePart}
    should satisfy all the conditions specified, but does not.
The following errors were found ...
{expectedValue}";
        }
Example #42
0
        /// <summary>
        /// Compares an actual value against an expected one and creates
        /// a string with the differences highlighted
        /// </summary>
        public static string HighlightDifferencesBetween(IShouldlyAssertionContext context)
        {
            var validHighlighter = GetHighlighterFor(context);

            if (validHighlighter == null)
            {
                return(context.Actual.Inspect());
            }

            return(validHighlighter.HighlightDifferences(context));
        }
Example #43
0
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            return
                ($@"Comparing object equivalence, at path:
{FormatPath(context)}

    Expected value to be
{context.Expected.ToStringAwesomely()}
    but was
{context.Actual.ToStringAwesomely()}");
        }
Example #44
0
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart      = context.CodePart;
            var expectedValue = context.Expected?.ToString();

            return
                ($@"{codePart}
    should satisfy all the conditions specified, but does not.
The following errors were found ...
{expectedValue}");
        }
        /// <summary>
        /// Compares an actual value against an expected one and creates
        /// a string with the differences highlighted
        /// </summary>
        public static string HighlightDifferences(IShouldlyAssertionContext context)
        {
            var validDifferenceHighlighter = GetDifferenceHighlighterFor(context);

            if (validDifferenceHighlighter == null)
            {
                return context.Actual.ToStringAwesomely();
            }

            return validDifferenceHighlighter.HighlightDifferences(context);
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"{0} should be subset of {1} but {2} {3} outside subset";

            var codePart      = context.CodePart;
            var expectedValue = context.Expected.ToStringAwesomely();

            var count = (context.Actual ?? Enumerable.Empty <object>()).As <IEnumerable>().Cast <object>().Count();

            return(string.Format(format, codePart, expectedValue, context.Actual.ToStringAwesomely(), count > 1 ? "are" : "is"));
        }
        /// <summary>
        /// Compares an actual value against an expected one and creates
        /// a string with the differences highlighted
        /// </summary>
        public static string?HighlightDifferences(IShouldlyAssertionContext context)
        {
            var validDifferenceHighlighter = GetDifferenceHighlighterFor(context);

            if (validDifferenceHighlighter == null)
            {
                return(context.Actual.ToStringAwesomely());
            }

            return(validDifferenceHighlighter.HighlightDifferences(context));
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"
            {0} should satisfy all the conditions specified, but does not.
            The following errors were found ...
            {1}";

            var codePart = context.CodePart;
            var expectedValue = context.Expected.ToString();

            return String.Format(format, codePart, expectedValue);
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"
            {0} was {1} and
            {2}
            but wasn't";

            var codePart = context.CodePart;
            var actual = context.Actual.ToStringAwesomely();

            return String.Format(format, codePart, actual, context.ShouldMethod.PascalToSpaced());
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart = context.CodePart;
            var actual = context.Actual.ToStringAwesomely();
            var actualValue = codePart != actual ? $@"
{actual}
    " : " ";

            return
$@"{codePart}
    {context.ShouldMethod.PascalToSpaced()} but{actualValue}is negative";
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"
        {0} should satisfy all the conditions specified, but does not.
        The following errors were found ...
{1}";

            var codePart      = context.CodePart;
            var expectedValue = context.Expected.ToString();

            return(String.Format(format, codePart, expectedValue));
        }
 public override string GenerateErrorMessage(IShouldlyAssertionContext context)
 {
     var codePart = context.CodePart;
     const string format = @"
     {0}
     {1} an element satisfying the condition
     {2}
     but does{3}";
     if (context.IsNegatedAssertion)
         return string.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), context.Expected.ToStringAwesomely(), "");
     return string.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), context.Expected.ToStringAwesomely(), " not");
 }
Example #53
0
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart    = context.CodePart;
            var actual      = context.Actual.ToStringAwesomely();
            var actualValue = codePart != actual ? $@"
{actual}
    " : " ";

            return
                ($@"{codePart}
    {context.ShouldMethod.PascalToSpaced()} but{actualValue}is negative");
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var throwContext = (ShouldThrowAssertionContext)context;
            var isExtensionMethod = context.ShouldMethod == "ShouldNotThrow";
            var codePart = context.CodePart;

            var expectedValue = context.Expected.ToStringAwesomely();

            string errorMessage;
            if (codePart == "null" && !throwContext.IsAsync)
            {
                errorMessage = 
$@"delegate
    should not throw but threw
{expectedValue}";
            }
            else if (codePart == "null" && throwContext.IsAsync)
            {
                errorMessage =
$@"Task
    should not throw but threw
{expectedValue}";
            }
            else if (isExtensionMethod && !throwContext.IsAsync)
            {
                errorMessage = 
$@"`{codePart}()`
    should not throw but threw
{expectedValue}";
            }
            else if (isExtensionMethod && throwContext.IsAsync)
            {
                errorMessage =
$@"Task `{codePart}`
    should not throw but threw
{expectedValue}";
            }
            else
            {
                errorMessage = 
$@"`{codePart}`
    should not throw but threw
{expectedValue}";
            }
            
            errorMessage += $@"
    with message
""{throwContext.ExceptionMessage}""";

            return errorMessage;
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            const string format = @"
            {0}
            {1}";

            var codePart = context.CodePart;

            var isNegatedAssertion = context.ShouldMethod.Contains("Not");
            if (isNegatedAssertion)
                return String.Format(format, codePart, context.ShouldMethod.PascalToSpaced());

            return String.Format(format, codePart, context.ShouldMethod.PascalToSpaced());
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart = context.CodePart;
            var caseSensitivity = context.CaseSensitivity == Case.Insensitive ? " (case insensitive comparison)" : string.Empty;
            var actual = context.Actual.ToStringAwesomely();
            var but = codePart == actual ? (context.IsNegatedAssertion ? "did" : "did not") : $@"was actually
{actual}";

            return
$@"{codePart}
    {context.ShouldMethod.PascalToSpaced()}{caseSensitivity}
{context.Expected.ToStringAwesomely()}
    but {but}";
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart = context.CodePart;
            var actualType = context.Actual?.GetType().FullName;

            var actualString = codePart == actualType || codePart == "null" ? " not" : $@"
{actualType ?? "null"}";

            return
$@"{codePart}
    {context.ShouldMethod.PascalToSpaced()}
{context.Expected.ToStringAwesomely()}
    but was{actualString}";
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart = context.CodePart;
            var expectedValue = context.Expected.ToStringAwesomely();

            var actual = context.Actual.ToStringAwesomely();
            var actualString = codePart == actual ? " had" : $@" it had
            {actual}";

            return $@"{codePart}
            should not have flag
            {expectedValue}
            but{actualString}";
        }
        public override string GenerateErrorMessage(IShouldlyAssertionContext context)
        {
            var codePart = context.CodePart;
            var actual = context.Actual.ToStringAwesomely();

            if (codePart == actual)
                codePart = context.Expected.ToStringAwesomely();

            return
$@"{codePart}
    {context.ShouldMethod.PascalToSpaced()} but
{actual}
    was duplicated";
        }
        public string HighlightDifferences(IShouldlyAssertionContext context)
        {
            var actual = context.Actual as IEnumerable;
            var expected = context.Expected as IEnumerable;
            if (CanProcess(context))
            {
                var actualList = actual.Cast<object>();
                var expectedList = expected.Cast<object>();

                var highestCount = actualList.Count() > expectedList.Count() ? actualList.Count() : expectedList.Count();

                return HighlightDifferencesBetweenLists(actualList, expectedList, highestCount);
            }

            return actual.ToStringAwesomely();
        }