public override string GenerateErrorMessage(ShouldlyAssertionContext 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(); if (context.HasRelevantKey) { var valueString = "but does"; 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(ShouldlyAssertionContext context) { const string format = @" {0} should {1}be within {2} of {3} but was {4}"; var codePart = context.CodePart; var tolerance = context.Tolerance.Inspect(); var expectedValue = context.Expected.Inspect(); var actualValue = context.Actual.Inspect(); var negated = context.ShouldMethod.Contains("Not") ? "not " : string.Empty; var message = string.Format(format, codePart, negated, tolerance, expectedValue, actualValue); if (DifferenceHighlighterExtensions.CanGenerateDifferencesBetween(context)) { message += string.Format(@" difference {0}", DifferenceHighlighterExtensions.HighlightDifferencesBetween(context)); } return(message); }
public override string GenerateErrorMessage(ShouldlyAssertionContext context) { var expected = ((IEnumerable)context.Expected).Cast <object>().ToArray(); var actual = ((IEnumerable)context.Actual).Cast <object>().ToArray(); var codePart = context.CodePart; var expectedFormattedValue = expected.Inspect(); 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.Inspect()) : string.Empty; var expectedMissingMessage = missingFromExpected.Any() ? string.Format("{0} is missing {1}", expectedFormattedValue, missingFromExpected.Inspect()) : 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(ShouldlyAssertionContext context) { const string format = @"{0} should satisfy the condition {1} but {2} do not"; var codePart = context.CodePart; var expectedValue = context.Expected.ToStringAwesomely(); return(string.Format(format, codePart, expectedValue, context.Actual.ToStringAwesomely())); }
public override string GenerateErrorMessage(ShouldlyAssertionContext 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(ShouldlyAssertionContext context) { const string format = @" {0} {1} but {2} was duplicated"; var codePart = context.CodePart; var actual = context.Actual.Inspect(); return(String.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), actual)); }
public override string GenerateErrorMessage(ShouldlyAssertionContext context) { var codePart = context.CodePart; const string format = @" {0} {1} {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")); }
public override string GenerateErrorMessage(ShouldlyAssertionContext 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(ShouldlyAssertionContext context) { const string format = @" Dynamic object ""{0}"" should contain property {1} but does not."; var testFileName = context.OriginatingFrame.GetFileName(); var assertionLineNumber = context.OriginatingFrame.GetFileLineNumber(); var codeLine = string.Join("", File.ReadAllLines(testFileName).ToArray().Skip(assertionLineNumber - 1).Select(s => s.Trim())); var dynamicObjectName = DynamicObjectNameExtractor.Match(codeLine).Groups["dynamicObjectName"]; var propertyName = DynamicObjectNameExtractor.Match(codeLine).Groups["propertyName"]; return(String.Format(format, dynamicObjectName, propertyName)); }
public override string GenerateErrorMessage(ShouldlyAssertionContext context) { const string format = @" {0} should {1}contain {2} within {3} but was {4}"; var codePart = context.CodePart; var tolerance = context.Tolerance.Inspect(); var expectedValue = context.Expected.Inspect(); var actualValue = context.Actual.Inspect(); var negated = context.ShouldMethod.Contains("Not") ? "not " : string.Empty; return(string.Format(format, codePart, negated, expectedValue, tolerance, actualValue)); }
public override string GenerateErrorMessage(ShouldlyAssertionContext context) { const string format = @" Dictionary ""{0}"" {1} ""{2}"" but does {3}"; var codePart = context.CodePart; var expectedValue = context.Expected.Inspect(); if (context.IsNegatedAssertion) { return(String.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), context.Expected, "")); } return(String.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), expectedValue.Trim('"'), "not")); }
public override string GenerateErrorMessage(ShouldlyAssertionContext context) { const string format = @" {0} {1} but{2} was {3}"; var codePart = context.CodePart; var expectedValue = context.Expected.Inspect(); if (context.IsNegatedAssertion) { return(String.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), string.Empty, context.Expected == null ? "null" : "")); } var count = (context.Expected ?? Enumerable.Empty <object>()).As <IEnumerable>().Cast <object>().Count(); return(String.Format(format, codePart, context.ShouldMethod.PascalToSpaced(), !(context.Expected is string) && context.Expected is IEnumerable ? string.Format(" had {0} item{1} and", count, count == 1 ? string.Empty : "s") : string.Empty, expectedValue)); }
public override bool CanProcess(ShouldlyAssertionContext context) { return(Validator.IsMatch(context.ShouldMethod) && !context.HasActual); }
public abstract string GenerateErrorMessage(ShouldlyAssertionContext context);
public abstract bool CanProcess(ShouldlyAssertionContext context);
public override bool CanProcess(ShouldlyAssertionContext context) { return(context.ShouldMethod.StartsWith("Should") && context.ShouldMethod.Contains("Contain") && !(context.Expected is Expression)); }
public override bool CanProcess(ShouldlyAssertionContext context) { return(context.IgnoreOrder); }
public override bool CanProcess(ShouldlyAssertionContext context) { return(context.ShouldMethod.StartsWith("Should") && context.ShouldMethod.Contains("Contain") && context.UnderlyingShouldMethod.GetParameters().Last().Name == "tolerance"); }