From 8014b3c1ec1d42195db1c0f05a6bc33bc282eea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:52:03 +0100 Subject: [PATCH 01/58] Add assertion formatting helpers and localized resource strings --- .../TestFramework/Assertions/Assert.cs | 350 ++++++++++++++---- .../Resources/FrameworkMessages.resx | 228 ++++++------ .../Resources/xlf/FrameworkMessages.cs.xlf | 316 ++++++++-------- .../Resources/xlf/FrameworkMessages.de.xlf | 316 ++++++++-------- .../Resources/xlf/FrameworkMessages.es.xlf | 316 ++++++++-------- .../Resources/xlf/FrameworkMessages.fr.xlf | 316 ++++++++-------- .../Resources/xlf/FrameworkMessages.it.xlf | 316 ++++++++-------- .../Resources/xlf/FrameworkMessages.ja.xlf | 316 ++++++++-------- .../Resources/xlf/FrameworkMessages.ko.xlf | 316 ++++++++-------- .../Resources/xlf/FrameworkMessages.pl.xlf | 316 ++++++++-------- .../Resources/xlf/FrameworkMessages.pt-BR.xlf | 316 ++++++++-------- .../Resources/xlf/FrameworkMessages.ru.xlf | 316 ++++++++-------- .../Resources/xlf/FrameworkMessages.tr.xlf | 316 ++++++++-------- .../xlf/FrameworkMessages.zh-Hans.xlf | 316 ++++++++-------- .../xlf/FrameworkMessages.zh-Hant.xlf | 316 ++++++++-------- 15 files changed, 2600 insertions(+), 2086 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 4a832186af..61c9230df4 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -50,8 +50,17 @@ internal static void ThrowAssertFailed(string assertionName, string? message) } } - throw new AssertFailedException( - string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AssertionFailed, assertionName, message)); + string formattedMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AssertionFailed, assertionName, message); + + // When there's no user message (message starts with newline for parameter details), + // the format produces a trailing space before the newline ("failed. \\r\\n"). + // Remove it to avoid trailing whitespace on the first line. + if (message is not null && message.StartsWith(Environment.NewLine, StringComparison.Ordinal)) + { + formattedMessage = $"{assertionName} failed.{message}"; + } + + throw new AssertFailedException(formattedMessage); } private static bool ShouldLaunchDebugger() @@ -74,125 +83,306 @@ private static bool ShouldLaunchDebugger() internal static string BuildUserMessage(string? format) => format ?? string.Empty; - private static string BuildUserMessageForSingleExpression(string? format, string callerArgExpression, string parameterName) + /// + /// Checks the parameter for valid conditions. + /// + /// + /// The parameter. + /// + /// + /// The assertion Name. + /// + /// + /// parameter name. + /// + internal static void CheckParameterNotNull([NotNull] object? param, string assertionName, string parameterName) { - string userMessage = BuildUserMessage(format); - if (string.IsNullOrEmpty(callerArgExpression)) + if (param == null) { - return userMessage; + string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.NullParameterToAssert, parameterName); + ThrowAssertFailed(assertionName, finalMessage); } - - string callerArgMessagePart = string.Format(CultureInfo.InvariantCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, parameterName, callerArgExpression); - return string.IsNullOrEmpty(userMessage) - ? callerArgMessagePart - : $"{callerArgMessagePart} {userMessage}"; } - private static string BuildUserMessageForTwoExpressions(string? format, string callerArgExpression1, string parameterName1, string callerArgExpression2, string parameterName2) + internal static string ReplaceNulls(object? input) + => input?.ToString() ?? string.Empty; + + internal static string FormatValue(T? value, int maxLength = 256) { - string userMessage = BuildUserMessage(format); - if (string.IsNullOrEmpty(callerArgExpression1) || string.IsNullOrEmpty(callerArgExpression2)) + if (value is null) { - return userMessage; + return "(null)"; } - string callerArgMessagePart = string.Format(CultureInfo.InvariantCulture, FrameworkMessages.CallerArgumentExpressionTwoParametersMessage, parameterName1, callerArgExpression1, parameterName2, callerArgExpression2); - return string.IsNullOrEmpty(userMessage) - ? callerArgMessagePart - : $"{callerArgMessagePart} {userMessage}"; + if (value is string s) + { + return EscapeNewlines(Truncate($"\"{s}\"", maxLength)); + } + + // For collections, show a preview with element values + if (value is IEnumerable enumerable) + { + return FormatCollectionPreview(enumerable); + } + + Type type = typeof(T); + if (type == typeof(object)) + { + // If the static type is object, use the runtime type + type = value.GetType(); + } + + if (type.IsPrimitive || value is decimal or DateTime or DateTimeOffset + or TimeSpan or Guid or Enum) + { + return EscapeNewlines(Truncate(value.ToString() ?? string.Empty, maxLength)); + } + + MethodInfo? toStringMethod = type.GetMethod(nameof(ToString), BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null); + if (toStringMethod is not null + && toStringMethod.DeclaringType != typeof(object) + && toStringMethod.DeclaringType != typeof(ValueType)) + { + try + { + return EscapeNewlines(Truncate(value.ToString() ?? string.Empty, maxLength)); + } + catch (Exception) + { + // Fall through to type name display if ToString throws + } + } + + // No useful ToString - just return the type name + string typeName = type.FullName ?? type.Name; + return $"<{typeName}>"; } - private static string BuildUserMessageForThreeExpressions(string? format, string callerArgExpression1, string parameterName1, string callerArgExpression2, string parameterName2, string callerArgExpression3, string parameterName3) + internal static string TruncateExpression(string expression, int maxLength = 100) + => expression.Length <= maxLength + ? expression +#if NETCOREAPP3_1_OR_GREATER + : string.Concat(expression.AsSpan(0, maxLength), "..."); +#else + : expression.Substring(0, maxLength) + "..."; +#endif + + private static string Truncate(string value, int maxLength) + => value.Length <= maxLength + ? value +#if NETCOREAPP3_1_OR_GREATER + : string.Concat(value.AsSpan(0, maxLength), "... (", value.Length.ToString(CultureInfo.InvariantCulture), " chars)"); +#else + : value.Substring(0, maxLength) + $"... ({value.Length} chars)"; +#endif + + private static string EscapeNewlines(string value) + => value.Contains('\n') || value.Contains('\r') + ? value.Replace("\r\n", "\\r\\n").Replace("\n", "\\n").Replace("\r", "\\r") + : value; + + private static bool IsExpressionRedundant(string expression, string formattedValue) { - string userMessage = BuildUserMessage(format); - if (string.IsNullOrEmpty(callerArgExpression1) || string.IsNullOrEmpty(callerArgExpression2) || string.IsNullOrEmpty(callerArgExpression3)) + if (string.IsNullOrEmpty(expression)) { - return userMessage; + return true; } - string callerArgMessagePart = string.Format(CultureInfo.InvariantCulture, FrameworkMessages.CallerArgumentExpressionThreeParametersMessage, parameterName1, callerArgExpression1, parameterName2, callerArgExpression2, parameterName3, callerArgExpression3); - return string.IsNullOrEmpty(userMessage) - ? callerArgMessagePart - : $"{callerArgMessagePart} {userMessage}"; - } + // Exact match: expression "5" == formattedValue "5" + if (expression == formattedValue) + { + return true; + } - private static string BuildUserMessageForConditionExpression(string? format, string conditionExpression) - => BuildUserMessageForSingleExpression(format, conditionExpression, "condition"); + // Null literal: expression "null" vs formattedValue "(null)" + if (expression is "null" && formattedValue is "(null)") + { + return true; + } - private static string BuildUserMessageForValueExpression(string? format, string valueExpression) - => BuildUserMessageForSingleExpression(format, valueExpression, "value"); + // Boolean/true/false: expression "true" vs formattedValue "True" + if (string.Equals(expression, formattedValue, StringComparison.OrdinalIgnoreCase)) + { + return true; + } - private static string BuildUserMessageForActionExpression(string? format, string actionExpression) - => BuildUserMessageForSingleExpression(format, actionExpression, "action"); + // Numeric literal in different notation (e.g., "100E-2" vs "1") + if (double.TryParse(expression, NumberStyles.Any, CultureInfo.InvariantCulture, out double exprNum) + && double.TryParse(formattedValue, NumberStyles.Any, CultureInfo.InvariantCulture, out double fmtNum) + && exprNum == fmtNum) + { + return true; + } - private static string BuildUserMessageForCollectionExpression(string? format, string collectionExpression) - => BuildUserMessageForSingleExpression(format, collectionExpression, "collection"); + // C# string literal expression: @"\d+" or "\d+" vs formattedValue \d+ + // Strip the string literal syntax and compare the inner content + string? innerContent = TryExtractStringLiteralContent(expression); + return innerContent is not null && innerContent == formattedValue; + } - private static string BuildUserMessageForSubstringExpressionAndValueExpression(string? format, string substringExpression, string valueExpression) - => BuildUserMessageForTwoExpressions(format, substringExpression, "substring", valueExpression, "value"); + /// + /// Tries to extract the string content from a C# string literal expression. + /// Returns the inner string value for @"..." and "..." literals, or null if not a string literal. + /// + private static string? TryExtractStringLiteralContent(string expression) + { + // Verbatim string: @"content" + if (expression.Length >= 3 && expression[0] == '@' && expression[1] == '"' && expression[expression.Length - 1] == '"') + { + return expression.Substring(2, expression.Length - 3).Replace("\"\"", "\""); + } - private static string BuildUserMessageForExpectedSuffixExpressionAndValueExpression(string? format, string expectedSuffixExpression, string valueExpression) - => BuildUserMessageForTwoExpressions(format, expectedSuffixExpression, "expectedSuffix", valueExpression, "value"); + // Regular string: "content" + if (expression.Length >= 2 && expression[0] == '"' && expression[expression.Length - 1] == '"') + { + return expression.Substring(1, expression.Length - 2); + } - private static string BuildUserMessageForNotExpectedSuffixExpressionAndValueExpression(string? format, string notExpectedSuffixExpression, string valueExpression) - => BuildUserMessageForTwoExpressions(format, notExpectedSuffixExpression, "notExpectedSuffix", valueExpression, "value"); + // Not a string literal + return null; + } - private static string BuildUserMessageForExpectedPrefixExpressionAndValueExpression(string? format, string expectedPrefixExpression, string valueExpression) - => BuildUserMessageForTwoExpressions(format, expectedPrefixExpression, "expectedPrefix", valueExpression, "value"); + /// + /// Checks if the expression is a typed numeric literal (e.g., 1.0f, 1.1d, 0.001m, 2L) + /// or a well-known numeric constant (float.NaN, double.NaN) that is a more informative + /// representation than the plain ToString() value. + /// + private static bool IsExpressionMoreSpecificNumericLiteral(string expression, string formattedValue) + { + if (string.IsNullOrEmpty(expression) || expression.Length < 2) + { + return false; + } - private static string BuildUserMessageForNotExpectedPrefixExpressionAndValueExpression(string? format, string notExpectedPrefixExpression, string valueExpression) - => BuildUserMessageForTwoExpressions(format, notExpectedPrefixExpression, "notExpectedPrefix", valueExpression, "value"); + // Well-known numeric constants: float.NaN, double.NaN, float.PositiveInfinity, etc. + if (expression.StartsWith("float.", StringComparison.Ordinal) || expression.StartsWith("double.", StringComparison.Ordinal)) + { + return true; + } - private static string BuildUserMessageForPatternExpressionAndValueExpression(string? format, string patternExpression, string valueExpression) - => BuildUserMessageForTwoExpressions(format, patternExpression, "pattern", valueExpression, "value"); + // Check if expression ends with a numeric type suffix + char lastChar = expression[expression.Length - 1]; + if (lastChar is not ('f' or 'F' or 'd' or 'D' or 'm' or 'M' or 'L' or 'l' or 'u' or 'U')) + { + return false; + } - private static string BuildUserMessageForLowerBoundExpressionAndValueExpression(string? format, string lowerBoundExpression, string valueExpression) - => BuildUserMessageForTwoExpressions(format, lowerBoundExpression, "lowerBound", valueExpression, "value"); + // The formatted value should be the numeric part without the suffix + // e.g., expression "1.0d" -> formattedValue "1" or "1.0" + string numericPart = expression.Substring(0, expression.Length - 1); - private static string BuildUserMessageForUpperBoundExpressionAndValueExpression(string? format, string upperBoundExpression, string valueExpression) - => BuildUserMessageForTwoExpressions(format, upperBoundExpression, "upperBound", valueExpression, "value"); + // Handle UL/ul suffix (two chars) + if (numericPart.Length > 0 && numericPart[numericPart.Length - 1] is 'u' or 'U' or 'l' or 'L') + { + numericPart = numericPart.Substring(0, numericPart.Length - 1); + } - private static string BuildUserMessageForExpectedExpressionAndCollectionExpression(string? format, string expectedExpression, string collectionExpression) - => BuildUserMessageForTwoExpressions(format, expectedExpression, "expected", collectionExpression, "collection"); + // Check if removing the suffix gives the formatted value, or if they represent the same number + return numericPart == formattedValue + || (double.TryParse(numericPart, NumberStyles.Any, CultureInfo.InvariantCulture, out double exprNum) + && double.TryParse(formattedValue, NumberStyles.Any, CultureInfo.InvariantCulture, out double valNum) + && exprNum == valNum); + } - private static string BuildUserMessageForNotExpectedExpressionAndCollectionExpression(string? format, string notExpectedExpression, string collectionExpression) - => BuildUserMessageForTwoExpressions(format, notExpectedExpression, "notExpected", collectionExpression, "collection"); + internal static string FormatParameter(string paramName, string expression, T? value) + { + string formattedValue = FormatValue(value); - private static string BuildUserMessageForPredicateExpressionAndCollectionExpression(string? format, string predicateExpression, string collectionExpression) - => BuildUserMessageForTwoExpressions(format, predicateExpression, "predicate", collectionExpression, "collection"); + // If expression is a typed numeric literal more specific than the value, use it as the display + if (IsExpressionMoreSpecificNumericLiteral(expression, formattedValue)) + { + return $" {paramName}: {expression}"; + } - private static string BuildUserMessageForExpectedExpressionAndActualExpression(string? format, string expectedExpression, string actualExpression) - => BuildUserMessageForTwoExpressions(format, expectedExpression, "expected", actualExpression, "actual"); + // Skip expression when it matches the parameter name (e.g., "minValue (minValue): 5" → "minValue: 5") + if (expression == paramName || IsExpressionRedundant(expression, formattedValue)) + { + return $" {paramName}: {formattedValue}"; + } - private static string BuildUserMessageForNotExpectedExpressionAndActualExpression(string? format, string notExpectedExpression, string actualExpression) - => BuildUserMessageForTwoExpressions(format, notExpectedExpression, "notExpected", actualExpression, "actual"); + // Default case: show both expression and value + return $" {paramName} ({TruncateExpression(expression)}): {formattedValue}"; + } - private static string BuildUserMessageForMinValueExpressionAndMaxValueExpressionAndValueExpression(string? format, string minValueExpression, string maxValueExpression, string valueExpression) - => BuildUserMessageForThreeExpressions(format, minValueExpression, "minValue", maxValueExpression, "maxValue", valueExpression, "value"); + /// + /// Formats a parameter line showing only the expression (no value). + /// Used for parameters like collections, predicates, and actions where the + /// runtime value's ToString() is not useful. + /// Returns empty string if the expression is empty or matches the parameter name (nothing useful to show). + /// + internal static string FormatExpressionParameter(string paramName, string expression) + => string.IsNullOrEmpty(expression) || expression == paramName + ? string.Empty + : Environment.NewLine + $" {paramName}: {TruncateExpression(expression)}"; /// - /// Checks the parameter for valid conditions. + /// Formats a collection parameter line showing a preview of the collection elements. /// - /// - /// The parameter. - /// - /// - /// The assertion Name. - /// - /// - /// parameter name. - /// - internal static void CheckParameterNotNull([NotNull] object? param, string assertionName, string parameterName) + internal static string FormatCollectionParameter(string paramName, string expression, IEnumerable collection) { - if (param == null) + string preview = FormatCollectionPreview(collection); + return string.IsNullOrEmpty(expression) || expression == paramName + ? $"{Environment.NewLine} {paramName}: {preview}" + : $"{Environment.NewLine} {paramName} ({TruncateExpression(expression)}): {preview}"; + } + + private static string FormatCollectionPreview(IEnumerable collection, int maxLength = 256) + { + var elements = new List(); + int totalCount = 0; + int currentLength = 0; + bool truncated = false; + + foreach (object? item in collection) { - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.NullParameterToAssert, parameterName); - ThrowAssertFailed(assertionName, finalMessage); + totalCount++; + if (truncated) + { + continue; + } + + string formatted = item is IEnumerable innerCollection and not string + ? FormatCollectionPreview(innerCollection, maxLength: 50) + : FormatValue(item, maxLength: 50); + + // Account for ", " separator between elements + int addedLength = elements.Count > 0 + ? formatted.Length + 2 + : formatted.Length; + + if (currentLength + addedLength > maxLength && elements.Count > 0) + { + truncated = true; + } + else + { + elements.Add(formatted); + currentLength += addedLength; + } } + + string elementList = string.Join(", ", elements); + if (truncated) + { + elementList += ", ..."; + } + + return $"[{elementList}] ({totalCount} {(totalCount == 1 ? "element" : "elements")})"; } - internal static string ReplaceNulls(object? input) - => input?.ToString() ?? string.Empty; + internal static string FormatParameterWithValue(string paramName, string expression, string formattedValue) + => (expression == paramName || IsExpressionRedundant(expression, formattedValue)) + ? $" {paramName}: {formattedValue}" + : $" {paramName} ({TruncateExpression(expression)}): {formattedValue}"; + + /// + /// Formats a parameter line, checking expression redundancy against a base value + /// while displaying a different (enriched) display value. + /// + internal static string FormatParameterWithExpressionCheck(string paramName, string expression, string baseValue, string displayValue) + => (expression == paramName || IsExpressionRedundant(expression, baseValue)) + ? $" {paramName}: {displayValue}" + : $" {paramName} ({TruncateExpression(expression)}): {displayValue}"; private static int CompareInternal(string? expected, string? actual, bool ignoreCase, CultureInfo culture) #pragma warning disable CA1309 // Use ordinal string comparison diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index 537b9331a7..a2308fb26d 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -126,42 +126,12 @@ Duplicate item found:<{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - - - {0}{1} -{2} -{3} -{4} - - - Expected: - - - But was: - String lengths are both {0} but differ at index {1}. Expected string length {0} but was {1}. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -183,9 +153,6 @@ String '{0}' does not contain string '{1}'. {2}. - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} @@ -203,21 +170,9 @@ Actual: {2} {0} failed. {1} - - {0} Expected type:<{1}>. Actual type:<{2}>. - String '{0}' does not match pattern '{1}'. {2} - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - String '{0}' matches pattern '{1}'. {2} @@ -256,12 +211,6 @@ Actual: {2} (Failed to get the message for an exception of type {0} due to an exception.) - - Expected exception type:<{1}> but no exception was thrown. {0} - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - {0} ({1}) @@ -289,54 +238,9 @@ Actual: {2} The dynamic data source '{0}' in type '{1}' should exist and be a property, a method, or a field. - - Expected collection of size {1}. Actual: {2}. {0} - - - Expected exactly one item to match the predicate but found {1} item(s). {0} - - - Expected collection to contain exactly one element but found {1} element(s). {0} - - - Expected collection to contain the specified item. {0} - - - Expected at least one item to match the predicate. {0} - - - Expected collection to not contain the specified item. {0} - - - Expected no items to match the predicate. {0} - - - Expected collection to contain any item but it is empty. {0} - Invalid GitHub ticket URL - - String '{0}' does contain string '{1}'. {2}. - - - Actual value <{2}> is not greater than expected value <{1}>. {0} - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - - - Actual value <{2}> is not less than expected value <{1}>. {0} - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - - - Expected value <{1}> to be positive. {0} - - - Expected value <{1}> to be negative. {0} - String '{0}' ends with string '{1}'. {2} @@ -364,10 +268,6 @@ Actual: {2} The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. - - '{0}' expression: '{1}'. - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - Assert.That({0}) failed. {0} is the user code expression @@ -379,18 +279,130 @@ Actual: {2} Details: - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - Element(s) <{0}> is/are not present in the collection. The maximum value must be greater than or equal to the minimum value. + + Expected a difference no greater than <{0}>. + + + Expected a difference greater than <{0}>. + + + Case differs. + + + String does not start with expected prefix. + + + String starts with unexpected prefix. + + + String does not end with expected suffix. + + + String ends with unexpected suffix. + + + String does not match expected pattern. + + + String matches pattern but should not. + + + Expected collection to contain the specified item. + + + Expected at least one item to match the predicate. + + + Expected collection to not contain the specified item. + + + Expected no items to match the predicate. + + + String does not contain the expected substring. + + + String contains the unexpected substring. + + + Expected exactly one item to match the predicate but found {0} item(s). + + + Expected collection to contain exactly one element but found {0} element(s). + + + Expected collection to have the specified number of elements. + + + Expected collection to contain any item but it is empty. + + + Value is not within the expected range. + + + Wrong exception type was thrown. + + + No exception was thrown. + + + Expected values to be equal. + + + Expected values to differ. + + + Expected references to be the same. + + + Expected references to be different. + + + Expected condition to be true. + + + Expected condition to be false. + + + Expected value to be null. + + + Expected a non-null value. + + + Expected value to be of the specified type. + + + Value should not be of the specified type. + + + Expected value to be exactly of the specified type. + + + Value should not be exactly of the specified type. + + + Expected value to be greater than the specified bound. + + + Expected value to be greater than or equal to the specified bound. + + + Expected value to be less than the specified bound. + + + Expected value to be less than or equal to the specified bound. + + + Expected a positive value. + + + Expected a negative value. + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index 02a8e5a3bc..6a9f1e9e76 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -17,46 +17,20 @@ Byla nalezena duplicitní položka:<{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - Očekáváno:<{1}>. Aktuálně:<{2}>. {0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Očekáván rozdíl, který není větší jak <{3}> mezi očekávanou hodnotou <{1}> a aktuální hodnotou <{2}>. {0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - Očekáváno:<{1}>. Případ je rozdílný pro aktuální hodnotu:<{2}>. {0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - Očekáváno:<{1} ({2})>. Aktuálně:<{3} ({4})>. {0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - Očekáváno: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - Ale bylo: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ Očekávaná délka řetězce je {0}, ale byla {1}. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - Nebyla očekávána žádná hodnota kromě:<{1}>. Aktuálně:<{2}>. {0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Očekáván rozdíl, který je větší jak <{3}> mezi očekávanou hodnotou <{1}> a aktuální hodnotou <{2}>. {0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ Obě kolekce obsahují stejné elementy. {0} - - '{0}' expression: '{1}'. - Výraz „{0}“: {1}. - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - Výraz „{0}“: {1}, výraz „{2}“: {3}, výraz „{4}“: {5}. - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - Výraz „{0}“: {1}, výraz „{2}“: {3}. - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}. {1} @@ -143,39 +112,44 @@ Řetězec '{0}' neobsahuje řetězec '{1}'. {2}. - - Expected collection to contain the specified item. {0} - Očekávala se kolekce, která bude obsahovat zadanou položku. {0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - Očekávala se alespoň jedna položka odpovídající predikátu. {0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - Očekávalo se, že kolekce bude obsahovat přesně jeden prvek, ale našlo se tolik elementů: {1}. {0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - Očekávala se přesně jedna položka odpovídající predikátu, ale našlo se tolik položek: {1}. {0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - Řetězec {0} obsahuje řetězec {1}. {2}. + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - Očekávalo se, že kolekce nebude obsahovat zadanou položku. {0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - Očekávaly se žádné položky, které by odpovídaly predikátu. {0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ Řetězec „{0}“ končí řetězcem „{1}“. {2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} Řetězec „{0}“ začíná řetězcem „{1}“. {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. Dynamické datové pole {0} by mělo být statické. @@ -237,9 +226,14 @@ Skutečnost: {2} {0} selhalo. {1} - - Expected collection of size {1}. Actual: {2}. {0} - Očekávala se kolekce {1} velikosti. Skutečnost: {2} {0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Skutečnost: {2} Neplatná adresa URL lístku GitHubu - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - Hodnota {0} není v očekávaném rozsahu [{1}..{2}]. {3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Skutečnost: {2} Maximální hodnota musí být větší nebo rovna minimální hodnotě. - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0} Očekávaný typ:<{1}>. Aktuální typ:<{2}>. - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} Řetězec „{0}“ neodpovídá vzoru „{1}“. {2} - - Expected collection to contain any item but it is empty. {0} - Očekávalo se, že kolekce bude obsahovat libovolnou položku, ale je prázdná. {0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - Špatný typ:<{1}>. Aktuální typ:<{2}>. {0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} Očekávaný přesný typ:<{1}>. Skutečný typ:<{2}>. - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - Nesprávný přesný typ:<{1}>. Skutečný typ:<{2}>. {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} Řetězec „{0}“ odpovídá vzoru „{1}“. {2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Skutečnost: {2} (objekt) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (Z důvodu výjimky se nepodařilo získat zprávu o výjimce typu {0}.) - - Expected exception type:<{1}> but no exception was thrown. {0} - Byl očekáván typ výjimky: <{1}>, ale nebyla vyvolána žádná výjimka. {0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - Očekávaný typ výjimky: <{1}> Skutečný typ výjimky: <{2}>. {0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Skutečnost: {2} Vlastnost nebo metoda {0} ve třídě {1} vrací prázdné IEnumerable<object[]>. - - Actual value <{2}> is not greater than expected value <{1}>. {0} - Skutečná hodnota <{2}> není větší než očekávaná hodnota <{1}>. {0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - Skutečná hodnota <{2}> není větší nebo rovna očekávané hodnotě <{1}>. {0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - Skutečná hodnota <{2}> není menší než očekávaná hodnota <{1}>. {0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - Skutečná hodnota <{2}> není menší nebo rovna očekávané hodnotě <{1}>. {0} - - - - Expected value <{1}> to be positive. {0} - Očekávaná hodnota <{1}> má být kladná. {0} - - - - Expected value <{1}> to be negative. {0} - Očekávaná hodnota <{1}> má být záporná. {0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. Assert.Equals by neměla být pro kontrolní výrazy používána. Použijte prosím místo toho Assert.AreEqual a její přetížení. @@ -458,6 +477,11 @@ Skutečnost: {2} CollectionAssert.ReferenceEquals se nemá používat pro kontrolní výrazy. Místo toho použijte metody CollectionAssert nebo Assert.AreSame & overloads. + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index b240c09df6..d3abf80bd0 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -17,46 +17,20 @@ Doppeltes Element gefunden: <{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - Erwartet:<{1}>. Tatsächlich:<{2}>. {0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Es wurde eine Differenz nicht größer als <{3}> zwischen dem erwarteten Wert <{1}> und dem tatsächlichen Wert <{2}> erwartet. {0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - Erwartet:<{1}>. Die Großschreibung des tatsächlichen Werts weicht davon ab:<{2}>. {0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - Erwartet:<{1} ({2})>. Tatsächlich:<{3} ({4})>. {0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - Erwartet: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - War aber: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ Die erwartete Länge der Zeichenfolge ist {0}, war aber {1}. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - Es wurde ein beliebiger Wert erwartet außer:<{1}>. Tatsächlich:<{2}>. {0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Es wurde eine Differenz größer als <{3}> zwischen dem erwarteten Wert <{1}> und dem tatsächlichen Wert <{2}> erwartet. {0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ Beide Sammlungen enthalten dieselben Elemente. {0} - - '{0}' expression: '{1}'. - „{0}“ Ausdruck: „{1}“. - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - „{0}“ Ausdruck: „{1}“, „{2}“ Ausdruck: „{3}“, „{4}“ Ausdruck: „{5}“. - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - „{0}“ Ausdruck: „{1}“, „{2}“ Ausdruck: „{3}“. - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}. {1} @@ -143,39 +112,44 @@ Die Zeichenfolge "{0}" enthält nicht die Zeichenfolge "{1}". {2}. - - Expected collection to contain the specified item. {0} - Es wurde erwartet, dass die Sammlung das angegebene Element enthält. {0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - Es wurde erwartet, dass mindestens ein Element mit dem Prädikat übereinstimmt. {0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - Es wurde erwartet, dass die Sammlung genau ein Element enthält, es wurden jedoch {1} gefunden. {0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - Es wurde erwartet, dass genau ein Element mit dem Prädikat übereinstimmt, es wurden jedoch {1} Element(e) gefunden. {0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - Die Zeichenfolge „{0}“ enthält die Zeichenfolge „{1}“. {2}. + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - Es wurde erwartet, dass die Sammlung das angegebene Element nicht enthält. {0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - Es wurden erwartet, dass keine Elemente mit dem Prädikat übereinstimmen. {0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ Die Zeichenfolge „{0}“ endet mit der Zeichenfolge „{1}“. {2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} Die Zeichenfolge „{0}“ beginnt mit der Zeichenfolge „{1}“. {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. Das dynamische Datenfeld „{0}“ sollte statisch sein. @@ -237,9 +226,14 @@ Tatsächlich: {2} Fehler bei "{0}". {1} - - Expected collection of size {1}. Actual: {2}. {0} - Es wurde eine Sammlung mit einer Größe {1} erwartet. Tatsächlich: {2}. {0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Tatsächlich: {2} Ungültige GitHub-Ticket-URL. - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - Der Wert „{0}“ liegt nicht im erwarteten Bereich [{1}..{2}]. {3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Tatsächlich: {2} Der Höchstwert muss größer oder gleich dem Mindestwert sein. - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0}Erwarteter Typ:<{1}>. Tatsächlicher Typ:<{2}>. - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} Die Zeichenfolge „{0}“ stimmt nicht mit dem Muster „{1}“ überein. {2} - - Expected collection to contain any item but it is empty. {0} - Es wurde erwartet, dass die Sammlung ein beliebiges Element enthält, aber leer ist. {0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - Falscher Typ:<{1}>. Tatsächlicher Typ:<{2}>. {0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} Erwarteter genauer Typ:<{1}>. Tatsächlicher Typ:<{2}>. - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - Falscher genauer Typ:<{1}>. Tatsächlicher Typ:<{2}>. {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} Die Zeichenfolge „{0}“ stimmt mit dem Muster „{1}“ überein. {2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Tatsächlich: {2} (Objekt) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (Fehler beim Abrufen der Meldung für eine Ausnahme vom Typ "{0}" aufgrund einer Ausnahme.) - - Expected exception type:<{1}> but no exception was thrown. {0} - Erwarteter Ausnahmetyp:<{1}>, aber es wurde keine Ausnahme ausgelöst. {0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - Erwarteter Ausnahmetyp:<{1}>. Tatsächlicher Ausnahmetyp:<{2}>. {0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Tatsächlich: {2} Eigenschaft oder Methode "{0}" in "{1}" gibt leeres IEnumerable<object[]> zurück. - - Actual value <{2}> is not greater than expected value <{1}>. {0} - Der tatsächliche Wert <{2}> ist nicht größer als der erwartete Wert <{1}>. {0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - Der tatsächliche Wert <{2}> ist nicht größer oder gleich dem erwarteten Wert <{1}>. {0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - Der tatsächliche Wert <{2}> ist nicht kleiner als der erwartete Wert <{1}>. {0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - Der tatsächliche Wert <{2}> ist nicht kleiner oder gleich dem erwarteten Wert <{1}>. {0} - - - - Expected value <{1}> to be positive. {0} - Es wurde erwartet, dass der Wert <{1}> positiv ist. {0} - - - - Expected value <{1}> to be negative. {0} - Es wurde erwartet, dass der Wert <{1}> negativ ist. {0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. Assert.Equals sollte nicht für Assertions verwendet werden. Verwenden Sie stattdessen Assert.AreEqual und Überladungen. @@ -458,6 +477,11 @@ Tatsächlich: {2} CollectionAssert.ReferenceEquals darf nicht für Assertions verwendet werden. Verwenden Sie stattdessen CollectionAssert-Methoden oder Assert.AreSame und Überladungen. + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index 427b030537..c7a82dba08 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -17,46 +17,20 @@ Se encontró un elemento duplicado:<{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - Se esperaba <{1}>, pero es <{2}>. {0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Se esperaba una diferencia no superior a <{3}> entre el valor esperado <{1}> y el valor actual <{2}>. {0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - Se esperaba:<{1}>. La caja es diferente para el valor actual:<{2}>. {0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - Se esperaba:<{1} ({2})>, pero es:<{3} ({4})>. {0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - Se esperaba: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - Pero fue: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ Se esperaba una longitud de cadena {0} pero fue {1}. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - Se esperaba cualquier valor excepto <{1}>, pero es <{2}>. {0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Se esperaba una diferencia mayor que <{3}> entre el valor esperado <{1}> y el valor actual <{2}>. {0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ Ambas colecciones tienen los mismos elementos. {0} - - '{0}' expression: '{1}'. - Expresión "{0}": "{1}". - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - Expresión "{0}": "{1}", expresión "{2}": "{3}", expresión "{4}": "{5}". - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - Expresión "{0}": "{1}", expresión "{2}": "{3}". - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}. {1} @@ -143,39 +112,44 @@ La cadena '{0}' no contiene la cadena '{1}'. {2}. - - Expected collection to contain the specified item. {0} - Se esperaba que la colección contuviera el elemento especificado. {0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - Se esperaba al menos un elemento para que coincida con el predicado. {0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - Se esperaba que la colección contuviera exactamente un elemento, pero se encontraron {1} elementos. {0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - Se esperaba exactamente un elemento para que coincida con el predicado, pero se encontraron {1} elementos. {0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - La cadena '{0}' contiene la cadena '{1}'. {2}. + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - Se esperaba que la colección no contenga el elemento especificado. {0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - No se esperaba que ningún elemento coincidía con el predicado. {0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ La cadena "{0}" termina con la cadena "{1}". {2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} La cadena "{0}" comienza con la cadena "{1}". {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. El campo de datos dinámico '{0}' debe ser estático. @@ -237,9 +226,14 @@ Real: {2} Error de {0}. {1} - - Expected collection of size {1}. Actual: {2}. {0} - Se esperaba una colección de tamaño {1}. Real: {2}. {0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Real: {2} Dirección URL de vale de GitHub no válida - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - El valor "{0}" no está dentro del rango esperado [{1}..{2}]. {3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Real: {2} El valor máximo debe ser igual o mayor que el valor mínimo. - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0} Tipo esperado:<{1}>. Tipo real:<{2}>. - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} La cadena "{0}" no coincide con el patrón "{1}". {2} - - Expected collection to contain any item but it is empty. {0} - Se esperaba que la colección contenga cualquier elemento, pero está vacía. {0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - Tipo incorrecto:<{1}>. Tipo actual:<{2}>. {0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} Tipo exacto esperado: <{1}>. Tipo real:<{2}>. - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - Tipo exacto incorrecto: <{1}>. Tipo actual:<{2}>. {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} La cadena "{0}" coincide con el patrón "{1}". {2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Real: {2} (objeto) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (No se pudo obtener el mensaje para una excepción del tipo {0} debido a una excepción.) - - Expected exception type:<{1}> but no exception was thrown. {0} - Tipo de excepción esperada:<{1}> pero no se lanzó ninguna excepción. {0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - Tipo de excepción esperada:<{1}>. Tipo de excepción actual: <{2}>. {0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Real: {2} La propiedad o el método {0} en {1} devuelve un elemento IEnumerable<object[]> vacío. - - Actual value <{2}> is not greater than expected value <{1}>. {0} - El valor real <{2}> no es mayor que el valor esperado <{1}>. {0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - El valor real <{2}> no es mayor o igual que el valor esperado <{1}>. {0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - El valor real <{2}> no es menor que el valor esperado <{1}>. {0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - El valor real <{2}> no es menor o igual que el valor esperado <{1}>. {0} - - - - Expected value <{1}> to be positive. {0} - Se esperaba que el valor <{1}> ser positivo. {0} - - - - Expected value <{1}> to be negative. {0} - Se esperaba que el valor <{1}> ser negativo. {0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. No se debe usar Assert.Equals para aserciones. Use Assert.AreEqual y Overloads en su lugar. @@ -458,6 +477,11 @@ Real: {2} CollectionAssert.ReferenceEquals no se debe usar para las aserciones. Use los métodos CollectionAssert o las sobrecargas Assert.AreSame & en su lugar. + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index 0e46d1985a..ad48f54900 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -17,46 +17,20 @@ Un élément dupliqué a été trouvé : <{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - Attendu : <{1}>, Réel : <{2}>. {0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Différence attendue non supérieure à <{3}> comprise entre la valeur attendue <{1}> et la valeur réelle <{2}>. {0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - Attendu :<{1}>. La casse est différente pour la valeur réelle :<{2}>. {0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - Attendu : <{1} ({2})>, Réel : <{3} ({4})>. {0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - Attendu : - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - Mais c'était : - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ La longueur de chaîne attendue {0} mais était {1}. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - Toute valeur attendue sauf :<{1}>. Réel :<{2}>. {0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Différence attendue supérieure à <{3}> comprise entre la valeur attendue <{1}> et la valeur réelle <{2}>. {0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ Les deux collections contiennent les mêmes éléments. {0} - - '{0}' expression: '{1}'. - « {0} » expression : « {1} ». - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - expression « {0} », « {1} », expression « {2} », « {3} », expression « {4} », « {5} ». - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - expression « {0} » : « {1} », expression « {2} » : « {3} ». - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}. {1} @@ -143,39 +112,44 @@ La chaîne '{0}' ne contient pas la chaîne '{1}'. {2}. - - Expected collection to contain the specified item. {0} - Collection attendue pour contenir l’élément spécifié. {0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - Au moins un élément doit correspondre au prédicat. {0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - Collection attendue pour contenir exactement un élément mais {1} élément(s) trouvé(s). {0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - Un seul élément était attendu pour correspondre au prédicat, mais {1} élément(s) trouvé(s). {0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - La chaîne « {0} » contient la chaîne « {1} ». {2}. + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - Collection attendue pour ne pas contenir l’élément spécifié. {0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - Aucun élément ne doit correspondre au prédicat. {0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ La chaîne '{0}' se termine par la chaîne '{1}'. {2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} La chaîne '{0}' commence par la chaîne '{1}'. {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. Le champ de données dynamiques « {0} » doit être statique. @@ -237,9 +226,14 @@ Réel : {2} Échec de {0}. {1} - - Expected collection of size {1}. Actual: {2}. {0} - Collection de tailles attendue {1}. Réel : {2}. {0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Réel : {2} URL de ticket GitHub non valide - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - La valeur « {0} » n'est pas dans la plage attendue [{1}..{2}]. {3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Réel : {2} La valeur maximale doit être supérieure ou égale à la valeur minimale. - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0}Type attendu :<{1}>. Type réel :<{2}>. - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} La chaîne '{0}' ne correspond pas au modèle '{1}'. {2} - - Expected collection to contain any item but it is empty. {0} - La collection doit contenir n’importe quel élément, mais elle est vide. {0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - Type incorrect : <{1}>, Type réel : <{2}>. {0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} Type exact attendu :<{1}>. Type réel :<{2}>. - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - Type exact incorrect :<{1}>. Type réel :<{2}>. {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} La chaîne '{0}' correspond au modèle '{1}'. {2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Réel : {2} (objet) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (Échec de la réception du message pour une exception de type {0} en raison d'une exception.) - - Expected exception type:<{1}> but no exception was thrown. {0} - Type d’exception attendu :<{1}> mais aucune exception n’a été levée. {0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - Type d’exception attendu :<{1}>. Type d’exception réel :<{2}>. {0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Réel : {2} La propriété ou la méthode {0} sur {1} retourne un IEnumerable<object[]> vide. - - Actual value <{2}> is not greater than expected value <{1}>. {0} - La valeur réelle <{2}> n’est pas supérieure à la valeur attendue <{1}>. {0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - La valeur réelle <{2}> n’est pas supérieure ou égale à la valeur attendue <{1}>. {0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - La valeur réelle <{2}> n’est pas inférieure à la valeur attendue <{1}>. {0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - La valeur réelle <{2}> n’est pas inférieure ou égale à la valeur attendue <{1}>. {0} - - - - Expected value <{1}> to be positive. {0} - La valeur attendue <{1}> doit être positive. {0} - - - - Expected value <{1}> to be negative. {0} - La valeur attendue <{1}> doit être négative. {0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. Assert.Equals ne doit pas être utilisé pour les assertions. Utilisez Assert.AreEqual & overloads à la place. @@ -458,6 +477,11 @@ Réel : {2} CollectionAssert.ReferenceEquals ne doit pas être utilisé pour les assertions. Utilisez plutôt les méthodes CollectionAssert ou Assert.AreSame & overloads. + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index bfdc4c7ee6..9dfcbe6442 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -17,46 +17,20 @@ Rilevato elemento duplicato:<{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - Previsto:<{1}>. Effettivo:<{2}>. {0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Prevista una differenza non maggiore di <{3}> tra il valore previsto <{1}> e il valore effettivo <{2}>. {0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - Previsto:<{1}>. La combinazione di maiuscole e minuscole è diversa per il valore effettivo:<{2}>. {0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - Previsto:<{1} ({2})>. Effettivo:<{3} ({4})>. {0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - Previsto: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - Ma era: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ La lunghezza della stringa prevista è {0} ma era {1}. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - Previsto qualsiasi valore tranne:<{1}>. Effettivo:<{2}>. {0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Prevista una differenza maggiore di <{3}> tra il valore previsto <{1}> e il valore effettivo <{2}>. {0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ Le raccolte contengono entrambe gli stessi elementi. {0} - - '{0}' expression: '{1}'. - Espressione '{0}': '{1}'. - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - Espressione '{0}': '{1}', espressione '{2}': '{3}', espressione '{4}': '{5}'. - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - Espressione '{0}': '{1}', espressione '{2}': '{3}'. - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}. {1} @@ -143,39 +112,44 @@ La stringa '{0}' non contiene la stringa '{1}'. {2}. - - Expected collection to contain the specified item. {0} - La raccolta dovrebbe contenere l'elemento specificato. {0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - Almeno un elemento dovrebbe corrispondere al predicato. {0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - La raccolta dovrebbe contenere un unico elemento, ma ne sono stati trovati {1}. {0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - Un unico elemento dovrebbe corrispondere al predicato, ma ne sono stati trovati {1}. {0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - La stringa '{0}' contiene la stringa '{1}'. {2}. + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - La raccolta non dovrebbe contenere l'elemento specificato. {0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - Nessun elemento dovrebbe corrispondere al predicato. {0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ La stringa '{0}' termina con la stringa '{1}'. {2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} La stringa '{0}' inizia con la stringa '{1}'. {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. Il campo dati dinamico '{0}' deve essere statico. @@ -237,9 +226,14 @@ Effettivo: {2} {0} non riuscita. {1} - - Expected collection of size {1}. Actual: {2}. {0} - Prevista raccolta di dimensioni {1}. Effettivo: {2}. {0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Effettivo: {2} L'URL del ticket GitHub non è valido - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - Il valore '{0}' non è compreso nell'intervallo previsto [{1}, {2}]. {3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Effettivo: {2} Il valore massimo deve essere maggiore o uguale al valore minimo. - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0} Tipo previsto:<{1}>. Tipo effettivo:<{2}>. - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} La stringa '{0}' non corrisponde al criterio '{1}'. {2} - - Expected collection to contain any item but it is empty. {0} - È previsto che la raccolta contenga qualsiasi elemento, ma è vuota. {0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - Tipo errato:<{1}>. Tipo effettivo:<{2}>. {0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} Tipo esatto previsto:<{1}>. Tipo effettivo:<{2}>. - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - Tipo esatto errato:<{1}>. Tipo effettivo:<{2}>. {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} La stringa '{0}' corrisponde al criterio '{1}'. {2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Effettivo: {2} (oggetto) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) Non è stato possibile ottenere il messaggio per un'eccezione di tipo {0} a causa di un'eccezione. - - Expected exception type:<{1}> but no exception was thrown. {0} - È previsto il tipo di eccezione: <{1}> ma non è stata generata alcuna eccezione. {0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - Tipo di eccezione previsto:<{1}>. Tipo di eccezione effettivo: <{2}>. {0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Effettivo: {2} La proprietà o il metodo {0} nella classe {1} restituisce un elemento IEnumerable<object[]> vuoto. - - Actual value <{2}> is not greater than expected value <{1}>. {0} - Il valore effettivo <{2}> non è maggiore del valore previsto <{1}>. {0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - Il valore effettivo <{2}> non è maggiore o uguale al valore previsto <{1}>. {0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - Il valore effettivo <{2}> non è minore del valore previsto <{1}>. {0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - Il valore effettivo <{2}> non è minore o uguale al valore previsto <{1}>. {0} - - - - Expected value <{1}> to be positive. {0} - Il valore <{1}{0}> dovrebbe essere positivo. - - - - Expected value <{1}> to be negative. {0} - Il valore <{1}{0}> dovrebbe essere negativo. - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. Non è possibile usare Assert.Equals per le asserzioni. Usare Assert.AreEqual e gli overload. @@ -458,6 +477,11 @@ Effettivo: {2} Non è possibile usare CollectionAssert.ReferenceEquals per le asserzioni. In alternativa, usare i metodi CollectionAssert o Assert.AreSame e gli overload. + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index bdced96434..cd8d26e44b 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -17,46 +17,20 @@ 重複する項目が見つかりました:<{1}>。{0} - - Expected:<{1}>. Actual:<{2}>. {0} - <{1}> が必要ですが、<{2}> が指定されました。{0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - 指定する値 <{1}> と実際の値 <{2}> との間には <{3}> 以内の差が必要です。{0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - <{1}> が必要です。実際の値: <{2}> では大文字と小文字が異なります。{0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - <{1} ({2})> が必要ですが、<{3} ({4})> が指定されました。{0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - 期待値: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - しかし、次でした: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ 期待される文字列の長さは {0} ですが、実際は {1} でした。 - - Expected any value except:<{1}>. Actual:<{2}>. {0} - <{1}> 以外の任意の値が必要ですが、<{2}> が指定されています。{0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - 指定する値 <{1}> と実際の値 <{2}> との間には、<{3}> を超える差が必要です。{0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ 両方のコレクションが同じ要素を含んでいます。{0} - - '{0}' expression: '{1}'. - '{0}' 式: '{1}'。 - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - '{0}' 式: '{1}'、'{2}' 式: '{3}'、'{4}' 式: '{5}'。 - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - '{0}' 式: '{1}'、'{2}' 式: '{3}'。 - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}。{1} @@ -143,39 +112,44 @@ 文字列 '{0}' は文字列 '{1}' を含んでいません。{2}。 - - Expected collection to contain the specified item. {0} - 指定された項目を含むコレクションが必要です。{0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - 述語と一致する項目が少なくとも 1 つ必要です。{0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - コレクションには 1 つの要素だけを含める必要がありますが、{1} 要素が見つかりました。{0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - 述語と一致する項目が 1 つだけ必要ですが、{1} 項目が見つかりました。{0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - 文字列 '{0}' は文字列 '{1}' を含んでいます。{2}。 + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - 指定された項目を含まないコレクションが必要です。{0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - 述語に一致する項目が必要ありません。{0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ 文字列 '{0}' の末尾は文字列 '{1}' です。{2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} 文字列 '{0}' は文字列 '{1}' で始まります。 {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. 動的データ フィールド '{0}' は静的である必要があります。 @@ -237,9 +226,14 @@ Actual: {2} {0} に失敗しました。{1} - - Expected collection of size {1}. Actual: {2}. {0} - サイズ {1} のコレクションが必要です。実際: {2}。{0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Actual: {2} GitHub チケット URL が無効です - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - 値 '{0}' は予期される範囲 [{1}..{2}] 内にありません。{3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Actual: {2} 最大値は、最小値以上である必要があります。 - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0} には型 <{1}> が必要ですが、型 <{2}> が指定されました。 - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} 文字列 '{0}' はパターン '{1}' と一致しません。{2} - - Expected collection to contain any item but it is empty. {0} - コレクションには項目が含まれている必要がありますが、空です。{0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - 正しくない型は <{1}> であり、実際の型は <{2}> です。{0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} 正確な型が必要です: <{1}>。実際の型: <{2}>。 - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - 間違った正確な型: <{1}>。実際の型: {2}。{0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} 文字列 '{0}' はパターン '{1}' と一致します。{2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Actual: {2} (オブジェクト) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (例外が発生したため、型 {0} の例外のメッセージを取得できませんでした。) - - Expected exception type:<{1}> but no exception was thrown. {0} - 例外の種類: <{1}> が予期されますが、例外はスローされませんでした。{0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - 予期される例外の種類: <{1}>。実際の例外の種類: <{2}>。{0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Actual: {2} {1} 上のプロパティまたはメソッド {0} は空の IEnumerable<object[]> を返します。 - - Actual value <{2}> is not greater than expected value <{1}>. {0} - 実際の値 <{2}> は、予期された値 <{1}> より大きくありません。{0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - 実際の値 <{2}> は、予期された値 <{1}> 以上ではありません。{0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - 実際の値 <{2}> は、予期された値 <{1}> より小さくありません。{0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - 実際の値 <{2}> は、予期された値 <{1}> 以下ではありません。{0} - - - - Expected value <{1}> to be positive. {0} - 正の値 <{1}> が必要です。{0} - - - - Expected value <{1}> to be negative. {0} - 負の値 <{1}> が必要です。{0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. アサーションには Assert.Equals を使用せずに、Assert.AreEqual とオーバーロードを使用してください。(& ) @@ -458,6 +477,11 @@ Actual: {2} アサーションには CollectionAssert.ReferenceEquals を使用しないでください。代わりに CollectionAssert メソッドまたは Assert.AreSame およびオーバーロードを使用してください。 + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index 6d9292a56e..88fb07d606 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -17,46 +17,20 @@ 중복된 항목이 있습니다. <{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - 예상 값: <{1}>. 실제 값: <{2}>. {0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - 예상 값 <{1}>과(와) 실제 값 <{2}>의 차이가 <{3}>보다 크지 않아야 합니다. {0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - 예상 값: <{1}>. 대/소문자가 다른 실제 값: <{2}>. {0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - 예상 값: <{1} ({2})>. 실제 값: <{3} ({4})>. {0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - 예상: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - 그러나 다음과 같습니다. - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ 문자열 길이 {0}(을)를 예상했지만 {1}입니다. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - 예상 값: <{1}>을(를) 제외한 모든 값. 실제 값: <{2}>. {0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - 예상 값 <{1}>과(와) 실제 값 <{2}>의 차이가 <{3}>보다 커야 합니다. {0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ 두 컬렉션에 같은 요소가 포함되어 있습니다. {0} - - '{0}' expression: '{1}'. - '{0}' 식: '{1}'. - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - ' {0}' 식: '{1}', '{2}' 식: '{3}', '{4}' 식: '{5}'. - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - '{0}' 식: '{1}', '{2}' 식: '{3}'. - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}. {1} @@ -143,39 +112,44 @@ '{0}' 문자열이 '{1}' 문자열을 포함하지 않습니다. {2} - - Expected collection to contain the specified item. {0} - 지정한 항목을 포함할 컬렉션이 필요합니다. {0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - 조건자와 일치하는 항목이 하나 이상 필요합니다. {0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - 정확히 하나의 요소를 포함할 컬렉션이 필요하지만 {1}개 요소가 발견되었습니다. {0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - 조건자에 일치하는 항목이 하나만 필요하지만 {1}개 항목이 발견되었습니다. {0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - '{0}' 문자열에 '{1}' 문자열이 포함되어 있습니다. {2}. + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - 지정한 항목을 포함하지 않을 컬렉션이 필요합니다. {0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - 조건자와 일치하는 항목이 필요하지 않습니다. {0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ 문자열 '{0}'은 문자열 '{1}'(으)로 끝납니다. {2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} 문자열 '{0}'은 문자열 '{1}'(으)로 시작합니다. {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. 동적 데이터 필드 '{0}'은(는) 정적이어야 합니다. @@ -237,9 +226,14 @@ Actual: {2} {0}이(가) 실패했습니다. {1} - - Expected collection of size {1}. Actual: {2}. {0} - {1} 크기 컬렉션이 필요합니다. 실제: {2}. {0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Actual: {2} 잘못된 GitHub 티켓 URL - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - '{0}' 값이 예상 범위 [{1}..{2}] 내에 있지 않습니다. {3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Actual: {2} 최댓값은 최솟값보다 크거나 같아야 합니다. - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0} 예상 형식: <{1}>, 실제 형식: <{2}>. - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} '{0}' 문자열이 '{1}' 패턴과 일치하지 않습니다. {2} - - Expected collection to contain any item but it is empty. {0} - 항목을 포함할 컬렉션이 필요한데 비어 있습니다. {0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - 잘못된 형식: <{1}>, 실제 형식: <{2}>. {0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} 예상되는 정확한 형식:<{1}>. 실제 형식: <{2}>. - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - 잘못된 정확한 형식:<{1}>. 실제 형식: <{2}>. {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} '{0}' 문자열이 '{1}' 패턴과 일치합니다. {2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Actual: {2} (개체) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (예외로 인해 {0} 형식의 예외에 대한 메시지를 가져오지 못했습니다.) - - Expected exception type:<{1}> but no exception was thrown. {0} - 예상 예외 형식:<{1}> 하지만 예외가 발생하지 않음. {0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - 예상 예외 형식:<{1}>. 실제 예상 형식:<{2}>. {0} - - {0} ({1}) {0}({1}) @@ -398,36 +447,6 @@ Actual: {2} {1}의 속성 또는 메서드 {0}이(가) 빈 IEnumerable<object[]>를 반환합니다. - - Actual value <{2}> is not greater than expected value <{1}>. {0} - 실제 값 <{2}>은(는)는 예상 값 <{1}>보다 크지 않습니다. {0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - 실제 값 <{2}>은(는)는 예상 값 <{1}>보다 크거나 같지 않습니다. {0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - 실제 값 <{2}>은(는)는 예상 값 <{1}>보다 작지 않습니다. {0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - 실제 값 <{2}>은(는)는 예상 값 <{1}>보다 작거나 같지 않습니다. {0} - - - - Expected value <{1}> to be positive. {0} - 예상 값 <{1}>은(는) 양수일 것으로 예상합니다. {0} - - - - Expected value <{1}> to be negative. {0} - 예상 값 <{1}>은(는) 음수일 것으로 예상합니다. {0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. 어설션에 Assert.Equals를 사용할 수 없습니다. 대신 Assert.AreEqual 및 오버로드를 사용하세요. @@ -458,6 +477,11 @@ Actual: {2} CollectionAssert.ReferenceEquals는 Assertions에 사용할 수 없습니다. 대신 CollectionAssert 메서드 또는 Assert.AreSame 및 오버로드를 사용하세요. + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index c50ff5897a..c184b50ba4 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -17,46 +17,20 @@ Znaleziono duplikat:<{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - Oczekiwana:<{1}>. Rzeczywista:<{2}>. {0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Oczekiwano różnicy nie większej niż <{3}> pomiędzy oczekiwaną wartością <{1}> a rzeczywistą wartością <{2}>. {0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - Oczekiwano:<{1}>. Przypadek różni się od rzeczywistej wartości:<{2}>. {0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - Oczekiwana:<{1} ({2})>. Rzeczywista:<{3} ({4})>. {0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - Oczekiwane: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - Ale było: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ Oczekiwano ciągu o długości {0}, ale miał wartość {1}. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - Oczekiwano dowolnej wartości za wyjątkiem:<{1}>. Rzeczywista:<{2}>. {0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Oczekiwano różnicy większej niż <{3}> pomiędzy oczekiwaną wartością <{1}> a rzeczywistą wartością <{2}>. {0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ Obie kolekcje zawierają te same elementy. {0} - - '{0}' expression: '{1}'. - Wyrażenie „{0}”: „{1}”. - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - Wyrażenie „{0}”: „{1}”, wyrażenie „{2}”: „{3}”, wyrażenie „{4}”: „{5}”. - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - Wyrażenie „{0}”: „{1}”, wyrażenie „{2}”: „{3}”. - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}. {1} @@ -143,39 +112,44 @@ Ciąg „{0}” nie zawiera ciągu „{1}”. {2}. - - Expected collection to contain the specified item. {0} - Oczekiwano, że kolekcja będzie zawierać określony element. {0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - Oczekiwano co najmniej jednego elementu zgodnego z predykatem. {0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - Oczekiwano, że kolekcja będzie zawierać dokładnie jeden element, ale znaleziono {1} elementów. {0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - Oczekiwano dokładnie jednego elementu zgodnego z predykatem, ale znaleziono {1} elementów. {0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - Ciąg „{0}” zawiera ciąg „{1}”. {2}. + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - Oczekiwano, że kolekcja nie będzie zawierać określonego elementu. {0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - Nie oczekiwano elementów zgodnych z predykatem. {0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ Ciąg „{0}” kończy się ciągiem „{1}”. {2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} Ciąg „{0}” rozpoczyna się od ciągu „{1}”. {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. Dynamiczne pole danych „{0}” powinno być statyczne. @@ -237,9 +226,14 @@ Rzeczywiste: {2} {0} — niepowodzenie. {1} - - Expected collection of size {1}. Actual: {2}. {0} - Oczekiwano kolekcji rozmiaru {1}. Wartość rzeczywista: {2}. {0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Rzeczywiste: {2} Nieprawidłowy adres URL biletu usługi GitHub - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - Wartość „{0}” nie mieści się w oczekiwanym zakresie [{1}..{2}]. {3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Rzeczywiste: {2} Wartość maksymalna musi być większa niż wartość minimalna lub jej równa. - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0} Oczekiwany typ:<{1}>. Rzeczywisty typ:<{2}>. - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} Ciąg „{0}” nie jest zgodny ze wzorcem „{1}”. {2} - - Expected collection to contain any item but it is empty. {0} - Oczekiwano, że kolekcja będzie zawierać dowolny element, ale jest pusta. {0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - Zły typ:<{1}>. Rzeczywisty typ:<{2}>. {0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} Oczekiwano dokładnego typu:<{1}>. Rzeczywisty typ:<{2}>. - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - Nieprawidłowy dokładny typ:<{1}>. Rzeczywisty typ:<{2}>. {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} Ciąg „{0}” jest zgodny ze wzorcem „{1}”. {2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Rzeczywiste: {2} (obiekt) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (Nie można pobrać komunikatu dotyczącego wyjątku typu {0} z powodu wyjątku). - - Expected exception type:<{1}> but no exception was thrown. {0} - Oczekiwano typu wyjątku:<{1}>, ale nie zgłoszono wyjątku. {0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - Oczekiwano typu wyjątku:<{1}>. Rzeczywisty typ wyjątku:<{2}>. {0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Rzeczywiste: {2} Właściwość lub metoda {0} w elemencie {1} zwraca pusty interfejs IEnumerable<object[]>. - - Actual value <{2}> is not greater than expected value <{1}>. {0} - Wartość rzeczywista <{2}> nie jest większa niż oczekiwana wartość <{1}>. {0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - Wartość rzeczywista <{2}> nie jest większa lub równa oczekiwanej wartości <{1}>. {0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - Wartość rzeczywista <{2}> nie jest mniejsza niż oczekiwana wartość <{1}>. {0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - Wartość rzeczywista <{2}> nie jest mniejsza lub równa oczekiwanej wartości <{1}>. {0} - - - - Expected value <{1}> to be positive. {0} - Oczekiwana wartość <{1}> powinna być dodatnia. {0} - - - - Expected value <{1}> to be negative. {0} - Oczekiwana wartość <{1}> powinna być negatywna. {0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. Assert.Equals nie powinno być używane do potwierdzania. Zamiast tego użyj Assert.AreEqual i przeciążeń. @@ -458,6 +477,11 @@ Rzeczywiste: {2} Element Assert.ReferenceEquals nie powinien być używany dla asercji. Zamiast tego użyj metod CollectionAssert lub Assert.AreSame oraz ich przeciążeń. + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index faf04cc886..369b210b24 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -17,46 +17,20 @@ Item duplicado encontrado:<{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - Esperado:<{1}>. Real:<{2}>. {0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Esperada uma diferença não maior que <{3}> entre o valor esperado <{1}> e o valor real <{2}>. {0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - Esperado:<{1}>. Capitalização é diferente para o valor real:<{2}>. {0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - Esperado:<{1} ({2})>. Real:<{3} ({4})>. {0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - Esperado: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - Mas foi: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ Comprimento esperado da cadeia de caracteres {0}, mas foi {1}. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - Esperado qualquer valor exceto:<{1}>. Real:<{2}>. {0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Esperada uma diferença maior que <{3}> entre o valor esperado <{1}> e o valor real <{2}>. {0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ Ambas as coleções contêm os mesmos elementos. {0} - - '{0}' expression: '{1}'. - Expressão "{0}": "{1}". - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - Expressão "{0}": "{1}", "{2}" expressão: "{3}", "{4}" expressão: "{5}". - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - Expressão "{0}": "{1}", "{2}" expressão: "{3}". - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}. {1} @@ -143,39 +112,44 @@ A cadeia de caracteres '{0}' não contém a cadeia de caracteres '{1}'. {2}. - - Expected collection to contain the specified item. {0} - A coleção esperada contém o item especificado. {0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - Esperava-se que pelo menos um item correspondesse ao predicado. {0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - A coleção esperada contém exatamente um elemento, mas encontrou {1} elementos. {0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - Esperava-se exatamente um item para corresponder ao predicado, mas encontrou {1} itens. {0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - A cadeia de caracteres "{0}" contém a cadeia de caracteres "{1}". {2}. + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - A coleção esperada não contém o item especificado. {0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - Não era esperado nenhum item que corresponda ao predicado. {0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ A cadeia de caracteres “{0}” termina com cadeia de caracteres “{1}”. {2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} A cadeia de caracteres “{0}” começa com a cadeia de caracteres “{1}”. {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. O campo de dados dinâmicos '{0}' deve ser estático. @@ -237,9 +226,14 @@ Real: {2} {0} falhou. {1} - - Expected collection of size {1}. Actual: {2}. {0} - Coleção esperada de tamanho {1}. Real: {2}. {0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Real: {2} URL de tíquete do GitHub inválida - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - O valor '{0}' não está dentro do intervalo esperado [{1}.. {2}]. {3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Real: {2} O valor máximo deve ser maior ou igual ao valor mínimo. - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0} Tipo esperado:<{1}>. Tipo real:<{2}>. - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} A cadeia de caracteres “{0}” não corresponde ao padrão “{1}”. {2} - - Expected collection to contain any item but it is empty. {0} - A coleção esperada conter qualquer item, mas ela está vazia. {0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - Tipo errado:<{1}>. Tipo real:<{2}>. {0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} Tipo exato esperado:<{1}>. Tipo real:<{2}>. - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - Tipo exato errado:<{1}>. Tipo real:<{2}>. {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} A cadeia de caracteres “{0}” corresponde ao padrão “{1}”. {2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Real: {2} (objeto) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (Falha ao obter a mensagem para uma exceção do tipo {0} devido a uma exceção.) - - Expected exception type:<{1}> but no exception was thrown. {0} - Tipo de exceção esperado:<{1}> mas nenhuma exceção foi lançada. {0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - Tipo de exceção esperado:<{1}>. Tipo de exceção real:<{2}>. {0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Real: {2} A propriedade ou o método {0} em {1} retorna um IEnumerable<object[]> vazio. - - Actual value <{2}> is not greater than expected value <{1}>. {0} - O valor <{2}> real não é maior que o valor esperado <{1}>. {0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - O valor <{2}> real não é maior ou igual ao valor esperado <{1}>. {0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - O valor <{2}> real não é menor que o valor esperado <{1}>. {0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - O valor <{2}> real não é menor ou igual ao valor esperado <{1}>. {0} - - - - Expected value <{1}> to be positive. {0} - O valor <{1}> esperado deve ser positivo. {0} - - - - Expected value <{1}> to be negative. {0} - O valor <{1}> esperado deve ser negativo. {0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. Assert.Equals não deveria ser usado para Declarações. Use Assert.AreEqual e sobrecargas em seu lugar. @@ -458,6 +477,11 @@ Real: {2} CollectionAssert.ReferenceEquals não deve ser usado com as Declarações. Em vez disso, use os métodos CollectionAssert ou Assert.AreSame e as sobrecargas. + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index e39af70016..9a81c2d917 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -17,46 +17,20 @@ Обнаружен совпадающий элемент: <{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - Ожидается: <{1}>. Фактически: <{2}>. {0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Между ожидаемым значением <{1}> и фактическим значением <{2}> требуется разница не более чем <{3}>. {0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - Ожидается: <{1}>. Отличается на фактическое значение: <{2}>. {0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - Ожидается: <{1} ({2})>. Фактически: <{3} ({4})>. {0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - Ожидалось: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - Было: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ Ожидалась длина строки: {0}, фактическая длина строки: {1}. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - Ожидается любое значение, кроме: <{1}>. Фактически: <{2}>. {0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Между ожидаемым значением <{1}> и фактическим значением <{2}> требуется разница более чем <{3}>. {0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ Обе коллекции содержат одинаковые элементы. {0} - - '{0}' expression: '{1}'. - Выражение "{0}": "{1}". - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - Выражение "{0}": "{1}", выражение "{2}": "{3}", выражение "{4}": "{5}". - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - Выражение "{0}": "{1}", выражение "{2}": "{3}". - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}. {1} @@ -143,39 +112,44 @@ Строка "{0}" не содержит строку "{1}". {2}. - - Expected collection to contain the specified item. {0} - Ожидалось, что коллекция будет содержать указанный элемент. {0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. - - Expected at least one item to match the predicate. {0} - Ожидался по крайней мере один элемент, соответствующий предикату. {0} + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected collection to contain exactly one element but found {1} element(s). {0} - Ожидалось, что коллекция будет содержать ровно один элемент, но найдено элементов: {1}. {0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - Ожидался ровно один элемент, соответствующий предикату, но найдено элементов: {1}. {0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - String '{0}' does contain string '{1}'. {2}. - Строка "{0}" не содержит строку "{1}". {2}. + + String does not contain the expected substring. + String does not contain the expected substring. + + + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - Ожидалось, что коллекция не будет содержать указанный элемент. {0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - Ожидалось, что ни один элемент не будет соответствовать предикату. {0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ Строка "{0}" заканчивается строкой "{1}". {2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} Строка "{0}" начинается со строки "{1}". {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. Поле динамических данных "{0}" должно быть статическим. @@ -237,9 +226,14 @@ Actual: {2} Сбой {0}. {1} - - Expected collection of size {1}. Actual: {2}. {0} - Ожидается коллекция размеров {1}. Фактически: {2}. {0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Actual: {2} Недопустимый URL-адрес билета GitHub - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - Значение "{0}" не находится в пределах ожидаемого диапазона [{1}..{2}]. {3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Actual: {2} Максимальное значение должно быть больше минимального значения или равно ему. - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0}Ожидается тип: <{1}>. Фактический тип: <{2}>. - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} Строка "{0}" не соответствует шаблону "{1}". {2} - - Expected collection to contain any item but it is empty. {0} - Ожидается, что коллекция будет содержать любой элемент, но она пуста. {0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - Неверный тип: <{1}>. Фактический тип: <{2}>. {0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} Ожидается точный тип: <{1}>. Фактический тип: <{2}>. - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - Неверный точный тип: <{1}>. Фактический тип: <{2}>. {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} Строка "{0}" соответствует шаблону "{1}". {2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Actual: {2} (объект) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (Не удалось получить сообщение для исключения с типом {0} в связи с возникновением исключения.) - - Expected exception type:<{1}> but no exception was thrown. {0} - Ожидаемый тип исключения:<{1}> но исключение не создано. {0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - Ожидаемый тип исключения:<{1}>. Фактический тип исключения:<{2}>. {0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Actual: {2} Свойство или метод {0} класса {1} возвращает пустой IEnumerable<object[]>. - - Actual value <{2}> is not greater than expected value <{1}>. {0} - Действительное значение <{2}> не больше ожидаемого значения <{1}>. {0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - Действительное значение <{2}> не больше или не равно ожидаемому значению <{1}>. {0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - Действительное значение <{2}> не меньше ожидаемого значения <{1}>. {0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - Действительное значение <{2}> не меньше или не равно ожидаемому значению <{1}>. {0} - - - - Expected value <{1}> to be positive. {0} - Ожидалось, что значение <{1}> будет положительным. {0} - - - - Expected value <{1}> to be negative. {0} - Ожидалось, что значение <{1}> будет отрицательным. {0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. Нельзя использовать Assert.Equals для Assertions. Вместо этого используйте Assert.AreEqual и перегрузки. @@ -458,6 +477,11 @@ Actual: {2} Нельзя использовать CollectionAssert.ReferenceEquals для Assertions. Вместо этого используйте методы CollectionAssert или Assert.AreSame и перегрузки. + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index 3a24012694..4659b8ad12 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -17,46 +17,20 @@ Yinelenen öğe bulundu:<{1}>. {0} - - Expected:<{1}>. Actual:<{2}>. {0} - Beklenen:<{1}>. Gerçek:<{2}>. {0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Beklenen değer <{1}> ile gerçek değer <{2}> arasında, şundan büyük olmayan fark bekleniyor: <{3}>. {0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - Beklenen:<{1}>. Durum, gerçek değer için farklı:<{2}>. {0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - Beklenen:<{1} ({2})>. Gerçek:<{3} ({4})>. {0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - Beklenen: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - Ancak: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ Beklenen dize uzunluğu {0} idi, ancak dize uzunluğu {1} oldu. - - Expected any value except:<{1}>. Actual:<{2}>. {0} - Şunun dışında bir değer bekleniyor:<{1}>. Gerçek:<{2}>. {0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - Beklenen değer <{1}> ile gerçek değer <{2}> arasında, şundan büyük olan fark bekleniyor: <{3}>. {0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ Her iki koleksiyon da aynı öğeleri içeriyor. {0} - - '{0}' expression: '{1}'. - '{0}' ifadesi: '{1}'. - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - '{0}' ifadesi: '{1}', '{2}' ifadesi: '{3}', '{4}' ifadesi: '{5}'. - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - '{0}' ifadesi: '{1}', '{2}' ifadesi: '{3}'. - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}. {1} @@ -143,39 +112,44 @@ '{0}' dizesi, '{1}' dizesini içermiyor. {2}. - - Expected collection to contain the specified item. {0} - Koleksiyonun belirtilen öğeyi içermesi bekleniyordu. {0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. - - Expected at least one item to match the predicate. {0} - En az bir öğenin koşulla eşleşmesi bekleniyordu. {0} + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected collection to contain exactly one element but found {1} element(s). {0} - Beklenen koleksiyonun tam olarak bir öğe içermesi beklenirken, {1} öğe bulundu. {0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - Özellikle bir öğenin koşulla eşleşmesi beklenirken {1} öğe bulundu. {0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - String '{0}' does contain string '{1}'. {2}. - '{0}' dizesi, '{1}' dizesini içermiyor. {2}. + + String does not contain the expected substring. + String does not contain the expected substring. + + + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - Koleksiyonun belirtilen öğeyi içermemesi bekleniyordu. {0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - Hiçbir öğenin koşulla eşleşmesi beklenmiyordu. {0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ '{0}' dizesi '{1}' dizesi ile bitiyor. {2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} '{0}' dizesi '{1}' dizesi ile başlıyor. {2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. Dinamik veri alanı ‘{0}’ statik olmalıdır. @@ -237,9 +226,14 @@ Gerçekte olan: {2} {0} başarısız. {1} - - Expected collection of size {1}. Actual: {2}. {0} - Beklenen boyut {1}. Gerçek: {2}. {0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Gerçekte olan: {2} Geçersiz GitHub anahtar URL'si - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - Değer '{0}' beklenen aralık [{1}..{2}] içinde değil. {3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Gerçekte olan: {2} En büyük değer en küçük değerden büyük veya buna eşit olmalıdır. - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0} Beklenen tür:<{1}>. Gerçek tür:<{2}>. - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} '{0}' dizesi, '{1}' deseni ile eşleşmiyor. {2} - - Expected collection to contain any item but it is empty. {0} - Koleksiyonun herhangi bir öğe içermesi bekleniyordu ancak boş. {0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - Yanlış Tür:<{1}>. Gerçek tür:<{2}>. {0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} Beklenen tam tür:<{1}>. Gerçek tür:<{2}>. - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - Yanlış tam tür:<{1}>. Gerçek tür:<{2}>. {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} '{0}' dizesi, '{1}' deseni ile eşleşiyor. {2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Gerçekte olan: {2} (nesne) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (Bir özel durum nedeniyle, {0} türündeki özel durum iletisi alınamadı.) - - Expected exception type:<{1}> but no exception was thrown. {0} - Beklenen özel durum türü:<{1}> ancak hiçbir özel durum oluşmadı. {0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - Beklenen özel durum türü:<{1}>. Gerçek özel durum türü:<{2}>. {0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Gerçekte olan: {2} {1} üzerindeki {0} özelliği veya metodu boş IEnumerable<object[]> döndürür. - - Actual value <{2}> is not greater than expected value <{1}>. {0} - Geçerli <{2}> değeri, beklenen <{1}> değerinden daha büyük değil. {0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - Geçerli <{2}> değeri, beklenen <{1}> değerinden büyük veya bu değere eşit değil. {0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - Geçerli <{2}> değeri, beklenen <{1}> değerinden daha küçük değil. {0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - Geçerli <{2}> değeri, beklenen <{1}> değerinden küçük veya bu değere eşit değil. {0} - - - - Expected value <{1}> to be positive. {0} - Beklenen <{1}> değeri pozitif olmalıdır. {0} - - - - Expected value <{1}> to be negative. {0} - Beklenen <{1}> değeri negatif olmalıdır. {0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. Assert.Equals, Onaylama için kullanılmamalı. Lütfen yerine Assert.AreEqual & aşırı yüklemeleri kullanın. @@ -458,6 +477,11 @@ Gerçekte olan: {2} CollectionAssert.ReferenceEquals, Onaylama için kullanılmamalı. Lütfen bunun yerine CollectionAssert yöntemlerini veya Assert.AreSame & aşırı yüklemelerini kullanın. + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index 94100054a3..33cb8bc4a0 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -17,46 +17,20 @@ 找到了重复项: <{1}>。{0} - - Expected:<{1}>. Actual:<{2}>. {0} - 应为: <{1}>,实际为: <{2}>。{0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - 预期值 <{1}> 和实际值 <{2}> 之间的差不应大于 <{3}>。{0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - 应为: <{1}>。实际值的大小写有所不同: <{2}>。{0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - 应为: <{1} ({2})>,实际为: <{3} ({4})>。{0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - 应为: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - 但却是: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ 字符串长度应为 {0},但为 {1}。 - - Expected any value except:<{1}>. Actual:<{2}>. {0} - 应为: <{1}> 以外的任意值,实际为: <{2}>。{0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - 预期值 <{1}> 和实际值 <{2}> 之间的差应大于 <{3}>。{0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ 这两个集合包含相同的元素。{0} - - '{0}' expression: '{1}'. - ‘{0}’表达式:‘{1}’。 - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - ‘{0}’表达式:‘{1}’,‘{2}’表达式:‘{3}’,‘{4}’表达式:‘{5}’。 - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - ‘{0}’表达式:‘{1}’,‘{2}’表达式:‘{3}’。 - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}。{1} @@ -143,39 +112,44 @@ 字符串“{0}”不包含字符串“{1}”。{2}。 - - Expected collection to contain the specified item. {0} - 预期集合包含指定项。{0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - 应至少有一项与谓词匹配。{0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - 预期集合仅包含一个元素,但找到 {1} 个元素。{0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - 应恰好只有一项与谓词匹配,但找到 {1} 项。{0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - 字符串“{0}”确实包含字符串“{1}”。{2} + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - 预期集合不包含指定项。{0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - 预期没有与谓词匹配的项。{0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ 字符串 '{0}' 以字符串 '{1}'结尾。{2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} 字符串 '{0}' 以字符串 '{1}' 开头。{2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. 动态数据字段“{0}”应该是静态的。 @@ -237,9 +226,14 @@ Actual: {2} {0} 失败。{1} - - Expected collection of size {1}. Actual: {2}. {0} - 大小 {1} 的预期集合。实际: {2}。{0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Actual: {2} GitHub 票证 URL 无效 - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - 值 "{0}" 不在预期范围 [{1}..{2}] 内。{3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Actual: {2} 最大值必须大于或等于最小值。 - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0} 类型应为: <{1}>。类型实为: <{2}>。 - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} 字符串 '{0}' 与模式 '{1}' 不匹配。{2} - - Expected collection to contain any item but it is empty. {0} - 集合应包含任何项,但它为空。{0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - 错误类型为: <{1}>,实际类型为: <{2}>。{0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} 预期的确切类型: <{1}>。实际类型: <{2}>。 - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - 错误的确切类型: <{1}>。实际类型: <{2}>。{0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} 字符串 '{0}' 与模式 '{1}' 匹配。{2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Actual: {2} (对象) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (因异常而未能获取类型为 {0} 的异常的消息。) - - Expected exception type:<{1}> but no exception was thrown. {0} - 预期异常类型:<{1}>,但未引发异常。{0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - 预期异常类型:<{1}>。实际异常类型:<{2}>。{0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Actual: {2} {1} 上的属性或方法 {0} 返回空 IEnumerable<object[]>。 - - Actual value <{2}> is not greater than expected value <{1}>. {0} - 实际值 <{2}> 不大于预期值 <{1}>。{0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - 实际值 <{2}> 不大于或等于预期值 <{1}>。{0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - 实际值 <{2}> 不小于预期值 <{1}>。{0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - 实际值 <{2}> 不小于或等于预期值 <{1}>。{0} - - - - Expected value <{1}> to be positive. {0} - 预期值 <{1}> 为正值。{0} - - - - Expected value <{1}> to be negative. {0} - 预期值 <{1}> 为负值。{0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. Assert.Equals 不应用于断言。请改用 Assert.AreEqual 和重载。 @@ -458,6 +477,11 @@ Actual: {2} CollectionAssert.ReferenceEquals 不应用于断言。请改用 CollectionAssert 方法或 Assert.AreSame 和重载。 + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index 3d758f945a..f2f38200b9 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -17,46 +17,20 @@ 找到重複的項目: <{1}>。{0} - - Expected:<{1}>. Actual:<{2}>. {0} - 預期: <{1}>。實際: <{2}>。{0} - - - - Expected a difference no greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - 預期值 <{1}> 和實際值 <{2}> 之間的預期差異沒有大於 <{3}>。{0} - - - - Expected:<{1}>. Case is different for actual value:<{2}>. {0} - 預期: <{1}>。大小寫與下列實際值不同: <{2}>。{0} - - - - Expected:<{1} ({2})>. Actual:<{3} ({4})>. {0} - 預期: <{1} ({2})>。實際: <{3} ({4})>。{0} - - - - {0}{1} -{2} -{3} -{4} - {0}{1} -{2} -{3} -{4} + + Case differs. + Case differs. - - Expected: - 預期為: - + + Expected a difference no greater than <{0}>. + Expected a difference no greater than <{0}>. + - - But was: - 但為: - + + Expected values to be equal. + Expected values to be equal. + String lengths are both {0} but differ at index {1}. @@ -68,15 +42,25 @@ 預期的字串長度為 {0},但為 {1}。 - - Expected any value except:<{1}>. Actual:<{2}>. {0} - 預期任何值 (<{1}> 除外)。實際: <{2}>。{0} - + + Expected a difference greater than <{0}>. + Expected a difference greater than <{0}>. + - - Expected a difference greater than <{3}> between expected value <{1}> and actual value <{2}>. {0} - 預期值 <{1}> 和實際值 <{2}> 之間的預期差異大於 <{3}>。{0} - + + Expected values to differ. + Expected values to differ. + + + + Expected references to be different. + Expected references to be different. + + + + Expected references to be the same. + Expected references to be the same. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} @@ -118,21 +102,6 @@ 兩個集合含有相同的項目。{0} - - '{0}' expression: '{1}'. - '{0}' 運算式: '{1}'。 - Example: "'value' expression: 'new object()'", where 'value' is the parameter name of an assertion method, and 'new object()' is the expression the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}', '{4}' expression: '{5}'. - '{0}' 運算式: '{1}','{2}' 運算式: '{3}','{4}' 運算式: '{5}'。 - Example: "'substring' expression: 'userCode1', 'value' expression: 'userCode2'", where 'substring' and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - - - '{0}' expression: '{1}', '{2}' expression: '{3}'. - '{0}' 運算式: '{1}','{2}' 運算式: '{3}'。 - Example: "'minValue' expression: 'userCode1', 'maxValue' expression: 'userCode2', 'value' expression: 'userCode3'", where 'minValue', 'maxValue', and 'value' are the parameter names of an assertion method, and 'userCode's are the expressions the user passed to the assert method. - {0}. {1} {0}。{1} @@ -143,39 +112,44 @@ 字串 '{0}' 未包含字串 '{1}'。{2}。 - - Expected collection to contain the specified item. {0} - 預期集合包含指定的項目。{0} + + Expected collection to contain the specified item. + Expected collection to contain the specified item. + + + + Expected at least one item to match the predicate. + Expected at least one item to match the predicate. - - Expected at least one item to match the predicate. {0} - 必須至少有一個項目符合述詞。{0} + + Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one element but found {0} element(s). - - Expected collection to contain exactly one element but found {1} element(s). {0} - 預期集合應僅包含一個元素,但發現 {1} 個元素。{0} + + Expected exactly one item to match the predicate but found {0} item(s). + Expected exactly one item to match the predicate but found {0} item(s). - - Expected exactly one item to match the predicate but found {1} item(s). {0} - 預期只有一個項目符合述詞,但找到 {1} 個項目。{0} + + String does not contain the expected substring. + String does not contain the expected substring. - - String '{0}' does contain string '{1}'. {2}. - 字串 '{0}' 有包含字串 '{1}'。{2}。 + + Expected collection to not contain the specified item. + Expected collection to not contain the specified item. - - Expected collection to not contain the specified item. {0} - 預期集合不包含指定的項目。{0} + + Expected no items to match the predicate. + Expected no items to match the predicate. - - Expected no items to match the predicate. {0} - 預期沒有任何項目符合述詞。{0} + + String contains the unexpected substring. + String contains the unexpected substring. @@ -183,11 +157,26 @@ 字串 '{0}' 以字串 '{1}' 結尾。{2} + + String ends with unexpected suffix. + String ends with unexpected suffix. + + + + String matches pattern but should not. + String matches pattern but should not. + + String '{0}' starts with string '{1}'. {2} 字串 '{0}' 以字串 '{1}' 開頭。{2} + + String starts with unexpected prefix. + String starts with unexpected prefix. + + Dynamic data field '{0}' should be static. 動態資料欄位 '{0}' 應該為靜態。 @@ -237,9 +226,14 @@ Actual: {2} {0} 失敗。 {1} - - Expected collection of size {1}. Actual: {2}. {0} - 預期的大小集合 {1}。實際: {2}。{0} + + String does not end with expected suffix. + String does not end with expected suffix. + + + + Expected collection to have the specified number of elements. + Expected collection to have the specified number of elements. @@ -252,9 +246,29 @@ Actual: {2} 無效的 GitHub 票證 URL - - Value '{0}' is not within the expected range [{1}..{2}]. {3} - 值 '{0}' 不在預期的範圍 [{1}, {2}] 內。{3} + + Expected value to be exactly of the specified type. + Expected value to be exactly of the specified type. + + + + Expected condition to be false. + Expected condition to be false. + + + + Expected value to be greater than the specified bound. + Expected value to be greater than the specified bound. + + + + Expected value to be greater than or equal to the specified bound. + Expected value to be greater than or equal to the specified bound. + + + + Value is not within the expected range. + Value is not within the expected range. @@ -262,41 +276,81 @@ Actual: {2} 最大值必須大於或等於最小值。 - - {0} Expected type:<{1}>. Actual type:<{2}>. - {0} 預期的類型: <{1}>,實際的類型: <{2}>。 - + + Expected value to be of the specified type. + Expected value to be of the specified type. + + + + Expected value to be less than the specified bound. + Expected value to be less than the specified bound. + + + + Expected value to be less than or equal to the specified bound. + Expected value to be less than or equal to the specified bound. + String '{0}' does not match pattern '{1}'. {2} 字串 '{0}' 與模式 '{1}' 不符。{2} - - Expected collection to contain any item but it is empty. {0} - 預期集合包含任何專案,但卻是空的。{0} + + Expected a negative value. + Expected a negative value. - - Wrong Type:<{1}>. Actual type:<{2}>. {0} - 錯誤的類型: <{1}>。實際的類型: <{2}>。{0} - + + Expected collection to contain any item but it is empty. + Expected collection to contain any item but it is empty. + - - {0} Expected exact type:<{1}>. Actual type:<{2}>. - {0} 預期的精確類型:<{1}>。實際的類型: <{2}>。 - + + Value should not be exactly of the specified type. + Value should not be exactly of the specified type. + - - Wrong exact Type:<{1}>. Actual type:<{2}>. {0} - 錯誤的精確類型:<{1}>。實際的類型: <{2}>。 {0} - + + Value should not be of the specified type. + Value should not be of the specified type. + String '{0}' matches pattern '{1}'. {2} 字串 '{0}' 與模式 '{1}' 相符。{2} + + Expected a non-null value. + Expected a non-null value. + + + + Expected value to be null. + Expected value to be null. + + + + Expected a positive value. + Expected a positive value. + + + + Expected condition to be true. + Expected condition to be true. + + + + String does not match expected pattern. + String does not match expected pattern. + + + + No exception was thrown. + No exception was thrown. + + The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -358,21 +412,16 @@ Actual: {2} (物件) + + String does not start with expected prefix. + String does not start with expected prefix. + + (Failed to get the message for an exception of type {0} due to an exception.) (因為發生例外狀況,所以無法取得類型 {0} 之例外狀況的訊息。) - - Expected exception type:<{1}> but no exception was thrown. {0} - 預期的例外狀況類型:<{1}>,但未擲回任何例外狀況。{0} - - - - Expected exception type:<{1}>. Actual exception type:<{2}>. {0} - 預期的例外狀況類型:<{1}>。實際的例外狀況類型:<{2}>。{0} - - {0} ({1}) {0} ({1}) @@ -398,36 +447,6 @@ Actual: {2} {1} 上的屬性或方法 {0} 傳回空的 IEnumerable<object[]>。 - - Actual value <{2}> is not greater than expected value <{1}>. {0} - 實際值 <{2}> 不大於預期值 <{1}>。{0} - - - - Actual value <{2}> is not greater than or equal to expected value <{1}>. {0} - 實際值 <{2}> 不大於或等於預期值 <{1}>。{0} - - - - Actual value <{2}> is not less than expected value <{1}>. {0} - 實際值 <{2}> 不小於預期值 <{1}>。{0} - - - - Actual value <{2}> is not less than or equal to expected value <{1}>. {0} - 實際值 <{2}> 不小於或等於預期值 <{1}>。{0} - - - - Expected value <{1}> to be positive. {0} - 預期值 <{1}> 為正數。{0} - - - - Expected value <{1}> to be negative. {0} - 預期值 <{1}> 為負數。{0} - - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. Assert.Equals 不應使用於判斷提示。請改用 Assert.AreEqual 及多載。 @@ -458,6 +477,11 @@ Actual: {2} CollectionAssert.ReferenceEquals 不應使用於判斷提示。請改用 CollectionAssert 方法或 Assert.AreSame 及其多載。 + + Wrong exception type was thrown. + Wrong exception type was thrown. + + \ No newline at end of file From b2127af8688c60fbd8451690e2c4759b3e627ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:52:13 +0100 Subject: [PATCH 02/58] Improve AreEqual/AreNotEqual assertion error messages --- .../Assertions/Assert.AreEqual.cs | 240 ++++------ .../Assertions/AssertTests.AreEqualTests.cs | 449 +++++++++++++++--- 2 files changed, 467 insertions(+), 222 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 5cd7fe9939..a9f8078a1f 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -48,8 +48,7 @@ internal void ComputeAssertion(string expectedExpression, string actualExpressio { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionTwoParametersMessage, "expected", expectedExpression, "actual", actualExpression) + " "); - ThrowAssertAreEqualFailed(_expected, _actual, _builder.ToString()); + ThrowAssertAreEqualFailed(_expected, _actual, _builder.ToString(), expectedExpression, actualExpression); } } @@ -115,8 +114,7 @@ internal void ComputeAssertion(string notExpectedExpression, string actualExpres { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionTwoParametersMessage, "notExpected", notExpectedExpression, "actual", actualExpression) + " "); - ThrowAssertAreNotEqualFailed(_notExpected, _actual, _builder.ToString()); + ThrowAssertAreNotEqualFailed(_notExpected, _actual, _builder.ToString(), notExpectedExpression, actualExpression); } } @@ -159,7 +157,7 @@ internal void ComputeAssertion(string notExpectedExpression, string actualExpres public readonly struct AssertNonGenericAreEqualInterpolatedStringHandler { private readonly StringBuilder? _builder; - private readonly Action? _failAction; + private readonly Action? _failAction; public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int formattedCount, float expected, float actual, float delta, out bool shouldAppend) { @@ -167,7 +165,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); + _failAction = (userMessage, expectedExpr, actualExpr) => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage, expectedExpr, actualExpr); } } @@ -177,7 +175,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); + _failAction = (userMessage, expectedExpr, actualExpr) => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage, expectedExpr, actualExpr); } } @@ -187,7 +185,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); + _failAction = (userMessage, expectedExpr, actualExpr) => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage, expectedExpr, actualExpr); } } @@ -197,7 +195,7 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); + _failAction = (userMessage, expectedExpr, actualExpr) => ThrowAssertAreEqualFailed(expected, actual, delta, userMessage, expectedExpr, actualExpr); } } @@ -213,18 +211,12 @@ public AssertNonGenericAreEqualInterpolatedStringHandler(int literalLength, int if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => ThrowAssertAreEqualFailed(expected, actual, ignoreCase, culture, userMessage); + _failAction = (userMessage, expectedExpr, actualExpr) => ThrowAssertAreEqualFailed(expected, actual, ignoreCase, culture, userMessage, expectedExpr, actualExpr); } } internal void ComputeAssertion(string expectedExpression, string actualExpression) - { - if (_failAction is not null) - { - _builder!.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionTwoParametersMessage, "expected", expectedExpression, "actual", actualExpression) + " "); - _failAction.Invoke(_builder!.ToString()); - } - } + => _failAction?.Invoke(_builder!.ToString(), expectedExpression, actualExpression); public void AppendLiteral(string value) => _builder!.Append(value); @@ -265,7 +257,7 @@ internal void ComputeAssertion(string expectedExpression, string actualExpressio public readonly struct AssertNonGenericAreNotEqualInterpolatedStringHandler { private readonly StringBuilder? _builder; - private readonly Action? _failAction; + private readonly Action? _failAction; public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, int formattedCount, float notExpected, float actual, float delta, out bool shouldAppend) { @@ -273,7 +265,7 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); + _failAction = (userMessage, notExpectedExpr, actualExpr) => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage, notExpectedExpr, actualExpr); } } @@ -283,7 +275,7 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); + _failAction = (userMessage, notExpectedExpr, actualExpr) => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage, notExpectedExpr, actualExpr); } } @@ -293,7 +285,7 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); + _failAction = (userMessage, notExpectedExpr, actualExpr) => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage, notExpectedExpr, actualExpr); } } @@ -303,7 +295,7 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); + _failAction = (userMessage, notExpectedExpr, actualExpr) => ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage, notExpectedExpr, actualExpr); } } @@ -319,18 +311,12 @@ public AssertNonGenericAreNotEqualInterpolatedStringHandler(int literalLength, i if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); - _failAction = userMessage => ThrowAssertAreNotEqualFailed(notExpected, actual, userMessage); + _failAction = (userMessage, notExpectedExpr, actualExpr) => ThrowAssertAreNotEqualFailed(notExpected, actual, userMessage, notExpectedExpr, actualExpr); } } internal void ComputeAssertion(string notExpectedExpression, string actualExpression) - { - if (_failAction is not null) - { - _builder!.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionTwoParametersMessage, "notExpected", notExpectedExpression, "actual", actualExpression) + " "); - _failAction.Invoke(_builder!.ToString()); - } - } + => _failAction?.Invoke(_builder!.ToString(), notExpectedExpression, actualExpression); public void AppendLiteral(string value) => _builder!.Append(value); @@ -488,8 +474,7 @@ public static void AreEqual(T? expected, T? actual, IEqualityComparer comp return; } - string userMessage = BuildUserMessageForExpectedExpressionAndActualExpression(message, expectedExpression, actualExpression); - ThrowAssertAreEqualFailed(expected, actual, userMessage); + ThrowAssertAreEqualFailed(expected, actual, message, expectedExpression, actualExpression); } private static bool AreEqualFailing(T? expected, T? actual, IEqualityComparer? comparer) @@ -544,27 +529,15 @@ private static bool AreEqualFailing(decimal expected, decimal actual, decimal de private static bool AreEqualFailing(long expected, long actual, long delta) => Math.Abs(expected - actual) > delta; - private static string FormatStringComparisonMessage(string? expected, string? actual, string userMessage) + private static string FormatStringComparisonMessage(string? expected, string? actual, string userMessage, string expectedExpression, string actualExpression) { // Handle null cases - if (expected is null && actual is null) - { - return string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualFailMsg, - userMessage, - ReplaceNulls(expected), - ReplaceNulls(actual)); - } - if (expected is null || actual is null) { - return string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualFailMsg, - userMessage, - ReplaceNulls(expected), - ReplaceNulls(actual)); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; + message += Environment.NewLine + FormatParameter(nameof(expected), expectedExpression, expected) + + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); + return message; } // Find the first difference @@ -577,7 +550,7 @@ private static string FormatStringComparisonMessage(string? expected, string? ac } // Format the enhanced string comparison message - return FormatStringDifferenceMessage(expected, actual, diffIndex, userMessage); + return FormatStringDifferenceMessage(expected, actual, diffIndex, userMessage, expectedExpression, actualExpression); } private static int FindFirstStringDifference(string expected, string actual) @@ -596,7 +569,7 @@ private static int FindFirstStringDifference(string expected, string actual) return expected.Length != actual.Length ? minLength : -1; } - private static string FormatStringDifferenceMessage(string expected, string actual, int diffIndex, string userMessage) + private static string FormatStringDifferenceMessage(string expected, string actual, int diffIndex, string userMessage, string expectedExpression, string actualExpression) { string lengthInfo = expected.Length == actual.Length ? string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreEqualStringDiffLengthBothMsg, expected.Length, diffIndex) @@ -609,9 +582,16 @@ private static string FormatStringDifferenceMessage(string expected, string actu string actualPreview = tuple.Item2; int caretPosition = tuple.Item3; - // Get localized prefixes - string expectedPrefix = FrameworkMessages.AreEqualStringDiffExpectedPrefix; - string actualPrefix = FrameworkMessages.AreEqualStringDiffActualPrefix; + // Build parameter line prefixes with expression info + // Skip expression when it's redundant (equals the quoted string value) + string expectedQuoted = $"\"{expected}\""; + string actualQuoted = $"\"{actual}\""; + string expectedPrefix = (expectedExpression == nameof(expected) || IsExpressionRedundant(expectedExpression, expectedQuoted)) + ? " expected: " + : $" expected ({TruncateExpression(expectedExpression)}): "; + string actualPrefix = (actualExpression == nameof(actual) || IsExpressionRedundant(actualExpression, actualQuoted)) + ? " actual: " + : $" actual ({TruncateExpression(actualExpression)}): "; // Calculate the maximum prefix length to align the caret properly int maxPrefixLength = Math.Max(expectedPrefix.Length, actualPrefix.Length); @@ -625,82 +605,70 @@ private static string FormatStringDifferenceMessage(string expected, string actu string actualLine = paddedActualPrefix + $"\"{actualPreview}\""; // The caret should align under the difference in the string content - // For localized prefixes with different lengths, we need to account for the longer prefix - // to ensure proper alignment. But the caret position is relative to the string content. int adjustedCaretPosition = maxPrefixLength + 1 + caretPosition; // +1 for the opening quote - // Format user message properly - add leading space if not empty, otherwise no extra formatting - string formattedUserMessage = string.IsNullOrEmpty(userMessage) ? string.Empty : $" {userMessage}"; - - return string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualStringDiffFailMsg, - lengthInfo, - formattedUserMessage, - expectedLine, - actualLine, - new string('-', adjustedCaretPosition) + "^"); + string formattedUserMessage = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; + + return formattedUserMessage + Environment.NewLine + lengthInfo + Environment.NewLine + expectedLine + Environment.NewLine + actualLine + Environment.NewLine + new string('-', adjustedCaretPosition) + "^"; } [DoesNotReturn] - private static void ThrowAssertAreEqualFailed(object? expected, object? actual, string userMessage) + private static void ThrowAssertAreEqualFailed(object? expected, object? actual, string? userMessage, string expectedExpression, string actualExpression) { - string finalMessage = actual != null && expected != null && !actual.GetType().Equals(expected.GetType()) - ? string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualDifferentTypesFailMsg, - userMessage, - ReplaceNulls(expected), - expected.GetType().FullName, - ReplaceNulls(actual), - actual.GetType().FullName) - : expected is string expectedString && actual is string actualString - ? FormatStringComparisonMessage(expectedString, actualString, userMessage) - : string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualFailMsg, - userMessage, - ReplaceNulls(expected), - ReplaceNulls(actual)); - ThrowAssertFailed("Assert.AreEqual", finalMessage); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + + if (actual is not null && expected is not null && !actual.GetType().Equals(expected.GetType())) + { + message += Environment.NewLine + FrameworkMessages.AreEqualFailNew; + message += $"{Environment.NewLine}{FormatParameter(nameof(expected), expectedExpression, expected)} ({expected.GetType().FullName})" + + $"{Environment.NewLine}{FormatParameter(nameof(actual), actualExpression, actual)} ({actual.GetType().FullName})"; + } + else if (expected is string expectedString && actual is string actualString) + { + message = FormatStringComparisonMessage(expectedString, actualString, message, expectedExpression, actualExpression); + ThrowAssertFailed("Assert.AreEqual", message); + return; + } + else + { + message += Environment.NewLine + FrameworkMessages.AreEqualFailNew; + message += Environment.NewLine + FormatParameter(nameof(expected), expectedExpression, expected) + + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); + } + + ThrowAssertFailed("Assert.AreEqual", message); } [DoesNotReturn] - private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, string userMessage) + private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, string? userMessage, string expectedExpression, string actualExpression) where T : struct, IConvertible { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualDeltaFailMsg, - userMessage, - expected.ToString(CultureInfo.CurrentCulture.NumberFormat), - actual.ToString(CultureInfo.CurrentCulture.NumberFormat), - delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - ThrowAssertFailed("Assert.AreEqual", finalMessage); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreEqualDeltaNoGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); + message += Environment.NewLine + FormatParameter(nameof(expected), expectedExpression, expected) + + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); + ThrowAssertFailed("Assert.AreEqual", message); } [DoesNotReturn] - private static void ThrowAssertAreEqualFailed(string? expected, string? actual, bool ignoreCase, CultureInfo culture, string userMessage) + private static void ThrowAssertAreEqualFailed(string? expected, string? actual, bool ignoreCase, CultureInfo culture, string? userMessage, string expectedExpression, string actualExpression) { - string finalMessage; + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; // If the user requested to match case, and the difference between expected/actual is casing only, then we use a different message. if (!ignoreCase && CompareInternal(expected, actual, ignoreCase: true, culture) == 0) { - finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreEqualCaseFailMsg, - userMessage, - ReplaceNulls(expected), - ReplaceNulls(actual)); + message += Environment.NewLine + FrameworkMessages.AreEqualCaseDiffersMsg; + message += Environment.NewLine + FormatParameter(nameof(expected), expectedExpression, expected) + + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); } else { // Use enhanced string comparison for string-specific failures - finalMessage = FormatStringComparisonMessage(expected, actual, userMessage); + message = FormatStringComparisonMessage(expected, actual, message, expectedExpression, actualExpression); } - ThrowAssertFailed("Assert.AreEqual", finalMessage); + ThrowAssertFailed("Assert.AreEqual", message); } /// @@ -791,8 +759,7 @@ public static void AreNotEqual(T? notExpected, T? actual, IEqualityComparer @@ -837,8 +804,7 @@ public static void AreEqual(float expected, float actual, float delta, string? m { if (AreEqualFailing(expected, actual, delta)) { - string userMessage = BuildUserMessageForExpectedExpressionAndActualExpression(message, expectedExpression, actualExpression); - ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); + ThrowAssertAreEqualFailed(expected, actual, delta, message, expectedExpression, actualExpression); } } @@ -884,8 +850,7 @@ public static void AreNotEqual(float notExpected, float actual, float delta, str { if (AreNotEqualFailing(notExpected, actual, delta)) { - string userMessage = BuildUserMessageForNotExpectedExpressionAndActualExpression(message, notExpectedExpression, actualExpression); - ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); + ThrowAssertAreNotEqualFailed(notExpected, actual, delta, message, notExpectedExpression, actualExpression); } } @@ -952,8 +917,7 @@ public static void AreEqual(decimal expected, decimal actual, decimal delta, str { if (AreEqualFailing(expected, actual, delta)) { - string userMessage = BuildUserMessageForExpectedExpressionAndActualExpression(message, expectedExpression, actualExpression); - ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); + ThrowAssertAreEqualFailed(expected, actual, delta, message, expectedExpression, actualExpression); } } @@ -999,8 +963,7 @@ public static void AreNotEqual(decimal notExpected, decimal actual, decimal delt { if (AreNotEqualFailing(notExpected, actual, delta)) { - string userMessage = BuildUserMessageForNotExpectedExpressionAndActualExpression(message, notExpectedExpression, actualExpression); - ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); + ThrowAssertAreNotEqualFailed(notExpected, actual, delta, message, notExpectedExpression, actualExpression); } } @@ -1049,8 +1012,7 @@ public static void AreEqual(long expected, long actual, long delta, string? mess { if (AreEqualFailing(expected, actual, delta)) { - string userMessage = BuildUserMessageForExpectedExpressionAndActualExpression(message, expectedExpression, actualExpression); - ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); + ThrowAssertAreEqualFailed(expected, actual, delta, message, expectedExpression, actualExpression); } } @@ -1096,8 +1058,7 @@ public static void AreNotEqual(long notExpected, long actual, long delta, string { if (AreNotEqualFailing(notExpected, actual, delta)) { - string userMessage = BuildUserMessageForNotExpectedExpressionAndActualExpression(message, notExpectedExpression, actualExpression); - ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); + ThrowAssertAreNotEqualFailed(notExpected, actual, delta, message, notExpectedExpression, actualExpression); } } @@ -1145,8 +1106,7 @@ public static void AreEqual(double expected, double actual, double delta, string { if (AreEqualFailing(expected, actual, delta)) { - string userMessage = BuildUserMessageForExpectedExpressionAndActualExpression(message, expectedExpression, actualExpression); - ThrowAssertAreEqualFailed(expected, actual, delta, userMessage); + ThrowAssertAreEqualFailed(expected, actual, delta, message, expectedExpression, actualExpression); } } @@ -1192,8 +1152,7 @@ public static void AreNotEqual(double notExpected, double actual, double delta, { if (AreNotEqualFailing(notExpected, actual, delta)) { - string userMessage = BuildUserMessageForNotExpectedExpressionAndActualExpression(message, notExpectedExpression, actualExpression); - ThrowAssertAreNotEqualFailed(notExpected, actual, delta, userMessage); + ThrowAssertAreNotEqualFailed(notExpected, actual, delta, message, notExpectedExpression, actualExpression); } } @@ -1219,17 +1178,14 @@ private static bool AreNotEqualFailing(double notExpected, double actual, double } [DoesNotReturn] - private static void ThrowAssertAreNotEqualFailed(T notExpected, T actual, T delta, string userMessage) + private static void ThrowAssertAreNotEqualFailed(T notExpected, T actual, T delta, string? userMessage, string notExpectedExpression, string actualExpression) where T : struct, IConvertible { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreNotEqualDeltaFailMsg, - userMessage, - notExpected.ToString(CultureInfo.CurrentCulture.NumberFormat), - actual.ToString(CultureInfo.CurrentCulture.NumberFormat), - delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreNotEqualDeltaGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); + message += Environment.NewLine + FormatParameter(nameof(notExpected), notExpectedExpression, notExpected) + + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); + ThrowAssertFailed("Assert.AreNotEqual", message); } /// @@ -1322,8 +1278,7 @@ public static void AreEqual(string? expected, string? actual, bool ignoreCase, C return; } - string userMessage = BuildUserMessageForExpectedExpressionAndActualExpression(message, expectedExpression, actualExpression); - ThrowAssertAreEqualFailed(expected, actual, ignoreCase, culture, userMessage); + ThrowAssertAreEqualFailed(expected, actual, ignoreCase, culture, message, expectedExpression, actualExpression); } /// @@ -1418,8 +1373,7 @@ public static void AreNotEqual(string? notExpected, string? actual, bool ignoreC return; } - string userMessage = BuildUserMessageForNotExpectedExpressionAndActualExpression(message, notExpectedExpression, actualExpression); - ThrowAssertAreNotEqualFailed(notExpected, actual, userMessage); + ThrowAssertAreNotEqualFailed(notExpected, actual, message, notExpectedExpression, actualExpression); } private static bool AreNotEqualFailing(string? notExpected, string? actual, bool ignoreCase, CultureInfo culture) @@ -1429,15 +1383,13 @@ private static bool AreNotEqualFailing(T? notExpected, T? actual, IEqualityCo => (comparer ?? EqualityComparer.Default).Equals(notExpected!, actual!); [DoesNotReturn] - private static void ThrowAssertAreNotEqualFailed(object? notExpected, object? actual, string userMessage) + private static void ThrowAssertAreNotEqualFailed(object? notExpected, object? actual, string? userMessage, string notExpectedExpression, string actualExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreNotEqualFailMsg, - userMessage, - ReplaceNulls(notExpected), - ReplaceNulls(actual)); - ThrowAssertFailed("Assert.AreNotEqual", finalMessage); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.AreNotEqualFailNew; + message += Environment.NewLine + FormatParameter(nameof(notExpected), notExpectedExpression, notExpected) + + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); + ThrowAssertFailed("Assert.AreNotEqual", message); } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index 1ba1daaad9..39ce38389d 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -19,7 +19,12 @@ public void AreNotEqualShouldFailWhenNotEqualTypeWithMessage() { Action action = () => Assert.AreNotEqual(1, 1, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreNotEqual failed. A Message + Expected values to differ. + notExpected: 1 + actual: 1 + """); } public void AreNotEqualShouldFailWhenNotEqualString() @@ -32,7 +37,12 @@ public void AreNotEqualShouldFailWhenNotEqualStringWithMessage() { Action action = () => Assert.AreNotEqual("A", "A", "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreNotEqual failed. A Message + Expected values to differ. + notExpected: "A" + actual: "A" + """); } [SuppressMessage("Globalization", "CA1304:Specify CultureInfo", Justification = "Testing the API without the culture")] @@ -52,7 +62,12 @@ public void AreNotEqualShouldFailWhenNotEqualIntWithMessage() { Action action = () => Assert.AreNotEqual(1, 1, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreNotEqual failed. A Message + Expected values to differ. + notExpected: 1 + actual: 1 + """); } public void AreNotEqualShouldFailWhenNotEqualLong() @@ -65,7 +80,12 @@ public void AreNotEqualShouldFailWhenNotEqualLongWithMessage() { Action action = () => Assert.AreNotEqual(1L, 1L, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreNotEqual failed. A Message + Expected values to differ. + notExpected: 1L + actual: 1L + """); } public void AreNotEqualShouldFailWhenNotEqualLongWithDelta() @@ -84,7 +104,12 @@ public void AreNotEqualShouldFailWhenNotEqualDecimalWithMessage() { Action action = () => Assert.AreNotEqual(0.1M, 0.1M, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreNotEqual failed. A Message + Expected values to differ. + notExpected: 0.1M + actual: 0.1M + """); } public void AreNotEqualShouldFailWhenNotEqualDecimalWithDelta() @@ -103,7 +128,12 @@ public void AreNotEqualShouldFailWhenNotEqualDoubleWithMessage() { Action action = () => Assert.AreNotEqual(0.1, 0.1, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreNotEqual failed. A Message + Expected values to differ. + notExpected: 0.1 + actual: 0.1 + """); } public void AreNotEqualShouldFailWhenNotEqualDoubleWithDelta() @@ -122,7 +152,12 @@ public void AreNotEqualShouldFailWhenFloatDoubleWithMessage() { Action action = () => Assert.AreNotEqual(100E-2, 100E-2, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreNotEqual failed. A Message + Expected values to differ. + notExpected: 1 + actual: 1 + """); } public void AreNotEqualShouldFailWhenNotEqualFloatWithDelta() @@ -141,7 +176,12 @@ public void AreEqualShouldFailWhenNotEqualTypeWithMessage() { Action action = () => Assert.AreEqual(null, "string", "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreEqual failed. A Message + Expected values to be equal. + expected: (null) + actual: "string" + """); } public void AreEqual_WithTurkishCultureAndIgnoreCase_Throws() @@ -174,7 +214,12 @@ public void AreEqual_WithEnglishCultureAndDoesNotIgnoreCase_Throws() // Won't ignore case. Action action = () => Assert.AreEqual(expected, actual, false, englishCulture); action.Should().Throw() - .WithMessage("Assert.AreEqual failed. Expected:. Case is different for actual value:. 'expected' expression: 'expected', 'actual' expression: 'actual'."); + .WithMessage("""" + Assert.AreEqual failed. + Case differs. + expected: "i" + actual: "I" + """"); } public void AreEqual_WithTurkishCultureAndDoesNotIgnoreCase_Throws() @@ -191,8 +236,7 @@ public void AreEqual_WithTurkishCultureAndDoesNotIgnoreCase_Throws() public void AreEqualShouldFailWhenNotEqualStringWithMessage() { Action action = () => Assert.AreEqual("A", "a", "A Message"); - action.Should().Throw() - .And.Message.Should().Contain("A Message"); + action.Should().Throw().And.Message.Should().Contain("A Message"); } [SuppressMessage("Globalization", "CA1304:Specify CultureInfo", Justification = "Testing the API without the culture")] @@ -212,7 +256,12 @@ public void AreEqualShouldFailWhenNotEqualIntWithMessage() { Action action = () => Assert.AreEqual(1, 2, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreEqual failed. A Message + Expected values to be equal. + expected: 1 + actual: 2 + """); } public void AreEqualShouldFailWhenNotEqualLong() @@ -225,7 +274,12 @@ public void AreEqualShouldFailWhenNotEqualLongWithMessage() { Action action = () => Assert.AreEqual(1L, 2L, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreEqual failed. A Message + Expected values to be equal. + expected: 1L + actual: 2L + """); } public void AreEqualShouldFailWhenNotEqualLongWithDelta() @@ -244,7 +298,12 @@ public void AreEqualShouldFailWhenNotEqualDoubleWithMessage() { Action action = () => Assert.AreEqual(0.1, 0.2, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreEqual failed. A Message + Expected values to be equal. + expected: 0.1 + actual: 0.2 + """); } public void AreEqualShouldFailWhenNotEqualDoubleWithDelta() @@ -264,7 +323,12 @@ public void AreEqualShouldFailWhenNotEqualDecimalWithMessage() { Action action = () => Assert.AreEqual(0.1M, 0.2M, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreEqual failed. A Message + Expected values to be equal. + expected: 0.1M + actual: 0.2M + """); } public void AreEqualShouldFailWhenNotEqualDecimalWithDelta() @@ -283,7 +347,12 @@ public void AreEqualShouldFailWhenFloatDoubleWithMessage() { Action action = () => Assert.AreEqual(100E-2, 200E-2, "A Message"); action.Should().Throw() - .And.Message.Should().Contain("A Message"); + .WithMessage(""" + Assert.AreEqual failed. A Message + Expected values to be equal. + expected: 1 + actual: 2 + """); } public void AreEqualShouldFailWhenNotEqualFloatWithDelta() @@ -302,7 +371,12 @@ public void AreEqualTwoObjectsDifferentTypeShouldFail() { Action action = () => Assert.AreEqual(new object(), 1); action.Should().Throw() - .And.Message.Should().Contain("Assert.AreEqual failed. Expected:. Actual:<1 (System.Int32)>."); + .WithMessage(""" + Assert.AreEqual failed. + Expected values to be equal. + expected (new object()): (System.Object) + actual: 1 (System.Int32) + """); } public void AreEqualWithTypeOverridingEqualsShouldWork() @@ -373,7 +447,12 @@ public async Task GenericAreEqual_InterpolatedString_DifferentValues_ShouldFail( DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreEqual(0, 1, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.AreEqual failed. Expected:<0>. Actual:<1>. 'expected' expression: '0', 'actual' expression: '1'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.AreEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected values to be equal. + expected: 0 + actual: 1 + """); o.WasToStringCalled.Should().BeTrue(); } @@ -390,7 +469,12 @@ public async Task GenericAreNotEqual_InterpolatedString_SameValues_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreNotEqual(0, 0, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.AreNotEqual failed. Expected any value except:<0>. Actual:<0>. 'notExpected' expression: '0', 'actual' expression: '0'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.AreNotEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected values to differ. + notExpected: 0 + actual: 0 + """); o.WasToStringCalled.Should().BeTrue(); } @@ -407,7 +491,12 @@ public async Task FloatAreEqual_InterpolatedString_DifferentValues_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreEqual(1.0f, 1.1f, 0.001f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.AreEqual failed. Expected a difference no greater than <0.001> between expected value <1> and actual value <1.1>. 'expected' expression: '1.0f', 'actual' expression: '1.1f'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.AreEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected a difference no greater than <0.001>. + expected: 1.0f + actual: 1.1f + """); o.WasToStringCalled.Should().BeTrue(); } @@ -424,7 +513,12 @@ public async Task FloatAreNotEqual_InterpolatedString_SameValues_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreNotEqual(1.0f, 1.1f, 0.2f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.AreNotEqual failed. Expected a difference greater than <0.2> between expected value <1> and actual value <1.1>. 'notExpected' expression: '1.0f', 'actual' expression: '1.1f'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.AreNotEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected a difference greater than <0.2>. + notExpected: 1.0f + actual: 1.1f + """); o.WasToStringCalled.Should().BeTrue(); } @@ -441,7 +535,12 @@ public async Task DecimalAreEqual_InterpolatedString_DifferentValues_ShouldFail( DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreEqual(1.0m, 1.1m, 0.001m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.AreEqual failed. Expected a difference no greater than <0.001> between expected value <1.0> and actual value <1.1>. 'expected' expression: '1.0m', 'actual' expression: '1.1m'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.AreEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected a difference no greater than <0.001>. + expected: 1.0m + actual: 1.1m + """); o.WasToStringCalled.Should().BeTrue(); } @@ -458,7 +557,12 @@ public async Task DecimalAreNotEqual_InterpolatedString_SameValues_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreNotEqual(1.0m, 1.1m, 0.2m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.AreNotEqual failed. Expected a difference greater than <0.2> between expected value <1.0> and actual value <1.1>. 'notExpected' expression: '1.0m', 'actual' expression: '1.1m'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.AreNotEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected a difference greater than <0.2>. + notExpected: 1.0m + actual: 1.1m + """); o.WasToStringCalled.Should().BeTrue(); } @@ -475,7 +579,12 @@ public async Task LongAreEqual_InterpolatedString_DifferentValues_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreEqual(1L, 2L, 0L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.AreEqual failed. Expected a difference no greater than <0> between expected value <1> and actual value <2>. 'expected' expression: '1L', 'actual' expression: '2L'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.AreEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected a difference no greater than <0>. + expected: 1L + actual: 2L + """); o.WasToStringCalled.Should().BeTrue(); } @@ -492,7 +601,12 @@ public async Task LongAreNotEqual_InterpolatedString_SameValues_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreNotEqual(1L, 2L, 1L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.AreNotEqual failed. Expected a difference greater than <1> between expected value <1> and actual value <2>. 'notExpected' expression: '1L', 'actual' expression: '2L'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.AreNotEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected a difference greater than <1>. + notExpected: 1L + actual: 2L + """); o.WasToStringCalled.Should().BeTrue(); } @@ -509,7 +623,12 @@ public async Task DoubleAreEqual_InterpolatedString_DifferentValues_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreEqual(1.0d, 1.1d, 0.001d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.AreEqual failed. Expected a difference no greater than <0.001> between expected value <1> and actual value <1.1>. 'expected' expression: '1.0d', 'actual' expression: '1.1d'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.AreEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected a difference no greater than <0.001>. + expected: 1.0d + actual: 1.1d + """); o.WasToStringCalled.Should().BeTrue(); } @@ -526,7 +645,12 @@ public async Task DoubleAreNotEqual_InterpolatedString_SameValues_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreNotEqual(1.0d, 1.1d, 0.2d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.AreNotEqual failed. Expected a difference greater than <0.2> between expected value <1> and actual value <1.1>. 'notExpected' expression: '1.0d', 'actual' expression: '1.1d'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.AreNotEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected a difference greater than <0.2>. + notExpected: 1.0d + actual: 1.1d + """); o.WasToStringCalled.Should().BeTrue(); } @@ -698,13 +822,23 @@ Specified argument was out of the range of valid values. public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDifferenceGreaterThanDeltaPositive_DeltaIsNumeric_ShouldFail() { Action action = () => Assert.AreEqual(5.0f, 2.0f, 2.0f); // difference is 3. Delta is 2 - action.Should().Throw().WithMessage("Assert.AreEqual failed. Expected a difference no greater than <2> between expected value <5> and actual value <2>. 'expected' expression: '5.0f', 'actual' expression: '2.0f'."); + action.Should().Throw().WithMessage("""" + Assert.AreEqual failed. + Expected a difference no greater than <2>. + expected: 5.0f + actual: 2.0f + """"); } public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDifferenceGreaterThanDeltaNegative_DeltaIsNumeric_ShouldFail() { Action action = () => Assert.AreEqual(2.0f, 5.0f, 2.0f); // difference is -3. Delta is 2 - action.Should().Throw().WithMessage("Assert.AreEqual failed. Expected a difference no greater than <2> between expected value <2> and actual value <5>. 'expected' expression: '2.0f', 'actual' expression: '5.0f'."); + action.Should().Throw().WithMessage("""" + Assert.AreEqual failed. + Expected a difference no greater than <2>. + expected: 2.0f + actual: 5.0f + """"); } public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDifferenceLessThanDeltaPositive_DeltaIsNumeric_ShouldPass() @@ -716,13 +850,23 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif public void FloatAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFail() { Action action = () => Assert.AreEqual(5.0f, float.NaN, 2.0f); - action.Should().Throw().WithMessage("Assert.AreEqual failed. Expected a difference no greater than <2> between expected value <5> and actual value . 'expected' expression: '5.0f', 'actual' expression: 'float.NaN'."); + action.Should().Throw().WithMessage("""" + Assert.AreEqual failed. + Expected a difference no greater than <2>. + expected: 5.0f + actual: float.NaN + """"); } public void FloatAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFail() { Action action = () => Assert.AreEqual(float.NaN, 5.0f, 2.0f); - action.Should().Throw().WithMessage("Assert.AreEqual failed. Expected a difference no greater than <2> between expected value and actual value <5>. 'expected' expression: 'float.NaN', 'actual' expression: '5.0f'."); + action.Should().Throw().WithMessage("""" + Assert.AreEqual failed. + Expected a difference no greater than <2>. + expected: float.NaN + actual: 5.0f + """"); } public void FloatAreEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldPass() @@ -910,13 +1054,23 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDifferenceLessThanDeltaPositive_DeltaIsNumeric_ShouldFail() { Action action = () => Assert.AreNotEqual(5.0f, 4.0f, 2.0f); // difference is 1. Delta is 2 - action.Should().Throw().WithMessage("Assert.AreNotEqual failed. Expected a difference greater than <2> between expected value <5> and actual value <4>. 'notExpected' expression: '5.0f', 'actual' expression: '4.0f'."); + action.Should().Throw().WithMessage("""" + Assert.AreNotEqual failed. + Expected a difference greater than <2>. + notExpected: 5.0f + actual: 4.0f + """"); } public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDifferenceLessThanDeltaNegative_DeltaIsNumeric_ShouldFail() { Action action = () => Assert.AreNotEqual(4.0f, 5.0f, 2.0f); // difference is -1. Delta is 2 - action.Should().Throw().WithMessage("Assert.AreNotEqual failed. Expected a difference greater than <2> between expected value <4> and actual value <5>. 'notExpected' expression: '4.0f', 'actual' expression: '5.0f'."); + action.Should().Throw().WithMessage("""" + Assert.AreNotEqual failed. + Expected a difference greater than <2>. + notExpected: 4.0f + actual: 5.0f + """"); } public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldPass() => Assert.AreNotEqual(5.0f, float.NaN, 2.0f); @@ -927,7 +1081,12 @@ public void FloatAreNotEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_Should public void FloatAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFail() { Action action = () => Assert.AreNotEqual(float.NaN, float.NaN, 2.0f); - action.Should().Throw().WithMessage("Assert.AreNotEqual failed. Expected a difference greater than <2> between expected value and actual value . 'notExpected' expression: 'float.NaN', 'actual' expression: 'float.NaN'."); + action.Should().Throw().WithMessage("""" + Assert.AreNotEqual failed. + Expected a difference greater than <2>. + notExpected: float.NaN + actual: float.NaN + """"); } public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualNotEquals_DeltaIsNaN_ShouldFail() @@ -1111,14 +1270,24 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi { Action action = () => Assert.AreEqual(5.0d, 2.0d, 2.0d); // difference is 3. Delta is 2 action.Should().Throw() - .WithMessage("Assert.AreEqual failed. Expected a difference no greater than <2> between expected value <5> and actual value <2>. 'expected' expression: '5.0d', 'actual' expression: '2.0d'."); + .WithMessage("""" + Assert.AreEqual failed. + Expected a difference no greater than <2>. + expected: 5.0d + actual: 2.0d + """"); } public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDifferenceGreaterThanDeltaNegative_DeltaIsNumeric_ShouldFail() { Action action = () => Assert.AreEqual(2.0d, 5.0d, 2.0d); // difference is -3. Delta is 2 action.Should().Throw() - .WithMessage("Assert.AreEqual failed. Expected a difference no greater than <2> between expected value <2> and actual value <5>. 'expected' expression: '2.0d', 'actual' expression: '5.0d'."); + .WithMessage("""" + Assert.AreEqual failed. + Expected a difference no greater than <2>. + expected: 2.0d + actual: 5.0d + """"); } public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDifferenceLessThanDeltaPositive_DeltaIsNumeric_ShouldPass() @@ -1131,14 +1300,24 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFa { Action action = () => Assert.AreEqual(5.0d, double.NaN, 2.0d); action.Should().Throw() - .WithMessage("Assert.AreEqual failed. Expected a difference no greater than <2> between expected value <5> and actual value . 'expected' expression: '5.0d', 'actual' expression: 'double.NaN'."); + .WithMessage("""" + Assert.AreEqual failed. + Expected a difference no greater than <2>. + expected: 5.0d + actual: double.NaN + """"); } public void DoubleAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFail() { Action action = () => Assert.AreEqual(double.NaN, 5.0d, 2.0d); action.Should().Throw() - .WithMessage("Assert.AreEqual failed. Expected a difference no greater than <2> between expected value and actual value <5>. 'expected' expression: 'double.NaN', 'actual' expression: '5.0d'."); + .WithMessage("""" + Assert.AreEqual failed. + Expected a difference no greater than <2>. + expected: double.NaN + actual: 5.0d + """"); } public void DoubleAreEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldPass() @@ -1334,14 +1513,24 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua { Action action = () => Assert.AreNotEqual(5.0d, 4.0d, 2.0d); // difference is 1. Delta is 2 action.Should().Throw() - .WithMessage("Assert.AreNotEqual failed. Expected a difference greater than <2> between expected value <5> and actual value <4>. 'notExpected' expression: '5.0d', 'actual' expression: '4.0d'."); + .WithMessage("""" + Assert.AreNotEqual failed. + Expected a difference greater than <2>. + notExpected: 5.0d + actual: 4.0d + """"); } public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDifferenceLessThanDeltaNegative_DeltaIsNumeric_ShouldFail() { Action action = () => Assert.AreNotEqual(4.0d, 5.0d, 2.0d); // difference is -1. Delta is 2 action.Should().Throw() - .WithMessage("Assert.AreNotEqual failed. Expected a difference greater than <2> between expected value <4> and actual value <5>. 'notExpected' expression: '4.0d', 'actual' expression: '5.0d'."); + .WithMessage("""" + Assert.AreNotEqual failed. + Expected a difference greater than <2>. + notExpected: 4.0d + actual: 5.0d + """"); } public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldPass() => Assert.AreNotEqual(5.0d, double.NaN, 2.0d); @@ -1353,7 +1542,12 @@ public void DoubleAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFai { Action action = () => Assert.AreNotEqual(double.NaN, double.NaN, 2.0d); action.Should().Throw() - .WithMessage("Assert.AreNotEqual failed. Expected a difference greater than <2> between expected value and actual value . 'notExpected' expression: 'double.NaN', 'actual' expression: 'double.NaN'."); + .WithMessage("""" + Assert.AreNotEqual failed. + Expected a difference greater than <2>. + notExpected: double.NaN + actual: double.NaN + """"); } private class TypeOverridesEquals @@ -1412,10 +1606,11 @@ public void AreEqualStringDifferenceAtBeginning() Action action = () => Assert.AreEqual("baaa", "aaaa"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. String lengths are both 4 but differ at index 0. 'expected' expression: '"baaa"', 'actual' expression: '"aaaa"'. - Expected: "baaa" - But was: "aaaa" - -----------^ + Assert.AreEqual failed. + String lengths are both 4 but differ at index 0. + expected: "baaa" + actual: "aaaa" + -------------^ """); } @@ -1424,10 +1619,11 @@ public void AreEqualStringDifferenceAtEnd() Action action = () => Assert.AreEqual("aaaa", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. String lengths are both 4 but differ at index 3. 'expected' expression: '"aaaa"', 'actual' expression: '"aaab"'. - Expected: "aaaa" - But was: "aaab" - --------------^ + Assert.AreEqual failed. + String lengths are both 4 but differ at index 3. + expected: "aaaa" + actual: "aaab" + ----------------^ """); } @@ -1436,10 +1632,11 @@ public void AreEqualStringWithSpecialCharactersShouldEscape() Action action = () => Assert.AreEqual("aa\ta", "aa a"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. String lengths are both 4 but differ at index 2. 'expected' expression: '"aa\ta"', 'actual' expression: '"aa a"'. - Expected: "aa␉a" - But was: "aa a" - -------------^ + Assert.AreEqual failed. + String lengths are both 4 but differ at index 2. + expected ("aa\ta"): "aa?a" + actual: "aa a" + -------------------------^ """); } @@ -1451,10 +1648,11 @@ public void AreEqualLongStringsShouldTruncateAndShowContext() Action action = () => Assert.AreEqual(expected, actual); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. String lengths are both 201 but differ at index 100. 'expected' expression: 'expected', 'actual' expression: 'actual'. - Expected: "...aaaaaaaaaaaaaaaaaabcccccccccccccccc..." - But was: "...aaaaaaaaaaaaaaaaaadcccccccccccccccc..." - --------------------------------^ + Assert.AreEqual failed. + String lengths are both 201 but differ at index 100. + expected: "...aaaaaaaaaaaaaaaaaabcccccccccccccccc..." + actual: "...aaaaaaaaaaaaaaaaaadcccccccccccccccc..." + ----------------------------------^ """); } @@ -1463,10 +1661,11 @@ public void AreEqualStringWithCultureShouldUseEnhancedMessage() Action action = () => Assert.AreEqual("aaaa", "aaab", false, CultureInfo.InvariantCulture); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. String lengths are both 4 but differ at index 3. 'expected' expression: '"aaaa"', 'actual' expression: '"aaab"'. - Expected: "aaaa" - But was: "aaab" - --------------^ + Assert.AreEqual failed. + String lengths are both 4 but differ at index 3. + expected: "aaaa" + actual: "aaab" + ----------------^ """); } @@ -1475,10 +1674,11 @@ public void AreEqualStringWithDifferentLength() Action action = () => Assert.AreEqual("aaaa", "aaa"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. Expected string length 4 but was 3. 'expected' expression: '"aaaa"', 'actual' expression: '"aaa"'. - Expected: "aaaa" - But was: "aaa" - --------------^ + Assert.AreEqual failed. + Expected string length 4 but was 3. + expected: "aaaa" + actual: "aaa" + ----------------^ """); } @@ -1487,10 +1687,11 @@ public void AreEqualShorterExpectedString() Action action = () => Assert.AreEqual("aaa", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. Expected string length 3 but was 4. 'expected' expression: '"aaa"', 'actual' expression: '"aaab"'. - Expected: "aaa" - But was: "aaab" - --------------^ + Assert.AreEqual failed. + Expected string length 3 but was 4. + expected: "aaa" + actual: "aaab" + ----------------^ """); } @@ -1499,22 +1700,24 @@ public void AreEqualStringWithUserMessage() Action action = () => Assert.AreEqual("aaaa", "aaab", "My custom message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. String lengths are both 4 but differ at index 3. 'expected' expression: '"aaaa"', 'actual' expression: '"aaab"'. My custom message - Expected: "aaaa" - But was: "aaab" - --------------^ + Assert.AreEqual failed. My custom message + String lengths are both 4 but differ at index 3. + expected: "aaaa" + actual: "aaab" + ----------------^ """); } public void AreEqualStringWithEmojis() { - Action action = () => Assert.AreEqual("🥰", "aaab"); + Action action = () => Assert.AreEqual("??", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. Expected string length 2 but was 4. 'expected' expression: '"🥰"', 'actual' expression: '"aaab"'. - Expected: "🥰" - But was: "aaab" - -----------^ + Assert.AreEqual failed. + Expected string length 2 but was 4. + expected: "??" + actual: "aaab" + -------------^ """); } @@ -1722,4 +1925,94 @@ private void StringPreviewsAreEqual(string expected, string actual) """); } } + + #region Truncation and newline escaping + + public void AreEqual_WithLongExpression_ShouldTruncateExpression() + { + object aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = 1; + + Action action = () => Assert.AreEqual(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 2); + action.Should().Throw() + .WithMessage(""" + Assert.AreEqual failed. + Expected values to be equal. + expected (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 1 + actual: 2 + """); + } + + public void AreEqual_WithLongToStringValue_ShouldTruncateValue() + { + var expected = new ObjectWithLongToString(); + var actual = new ObjectWithLongToString(); + + Action action = () => Assert.AreEqual(expected, actual); + action.Should().Throw() + .WithMessage($""" + Assert.AreEqual failed. + Expected values to be equal. + expected: {new string('L', 256)}... (300 chars) + actual: {new string('L', 256)}... (300 chars) + """); + } + + public void AreEqual_WithNewlineInToString_ShouldEscapeNewlines() + { + var expected = new ObjectWithNewlineToString(); + var actual = new ObjectWithNewlineToString(); + + Action action = () => Assert.AreEqual(expected, actual); + action.Should().Throw() + .WithMessage(""" + Assert.AreEqual failed. + Expected values to be equal. + expected: line1\r\nline2\nline3 + actual: line1\r\nline2\nline3 + """); + } + + public void AreNotEqual_WithLongExpression_ShouldTruncateExpression() + { + object aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = 1; + + Action action = () => Assert.AreNotEqual(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 1); + action.Should().Throw() + .WithMessage(""" + Assert.AreNotEqual failed. + Expected values to differ. + notExpected (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 1 + actual: 1 + """); + } + + public void AreNotEqual_WithLongToStringValue_ShouldTruncateValue() + { + var obj = new ObjectWithLongToString(); + + Action action = () => Assert.AreNotEqual(obj, obj); + action.Should().Throw() + .WithMessage($""" + Assert.AreNotEqual failed. + Expected values to differ. + notExpected (obj): {new string('L', 256)}... (300 chars) + actual (obj): {new string('L', 256)}... (300 chars) + """); + } + + public void AreNotEqual_WithNewlineInToString_ShouldEscapeNewlines() + { + var obj = new ObjectWithNewlineToString(); + + Action action = () => Assert.AreNotEqual(obj, obj); + action.Should().Throw() + .WithMessage(""" + Assert.AreNotEqual failed. + Expected values to differ. + notExpected (obj): line1\r\nline2\nline3 + actual (obj): line1\r\nline2\nline3 + """); + } + + #endregion } From 9ac484932e0804d5ef20f6c9829bad9541f24b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:52:23 +0100 Subject: [PATCH 03/58] Improve AreSame/AreNotSame assertion error messages --- .../Assertions/Assert.AreSame.cs | 58 +++++-- .../Assertions/AssertTests.AreSame.cs | 147 ++++++++++++++++-- 2 files changed, 180 insertions(+), 25 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 93be91c7fd..5f40000fb5 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -38,8 +38,7 @@ internal void ComputeAssertion(string expectedExpression, string actualExpressio { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionTwoParametersMessage, "expected", expectedExpression, "actual", actualExpression) + " "); - ThrowAssertAreSameFailed(_expected, _actual, _builder.ToString()); + ThrowAssertAreSameFailed(_expected, _actual, _builder.ToString(), expectedExpression, actualExpression); } } @@ -80,9 +79,13 @@ internal void ComputeAssertion(string expectedExpression, string actualExpressio public readonly struct AssertAreNotSameInterpolatedStringHandler { private readonly StringBuilder? _builder; + private readonly TArgument? _notExpected; + private readonly TArgument? _actual; public AssertAreNotSameInterpolatedStringHandler(int literalLength, int formattedCount, TArgument? notExpected, TArgument? actual, out bool shouldAppend) { + _notExpected = notExpected; + _actual = actual; shouldAppend = IsAreNotSameFailing(notExpected, actual); if (shouldAppend) { @@ -94,8 +97,7 @@ internal void ComputeAssertion(string notExpectedExpression, string actualExpres { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionTwoParametersMessage, "notExpected", notExpectedExpression, "actual", actualExpression) + " "); - ThrowAssertAreNotSameFailed(_builder.ToString()); + ThrowAssertAreNotSameFailed(_notExpected, _actual, _builder.ToString(), notExpectedExpression, actualExpression); } } @@ -177,26 +179,44 @@ public static void AreSame(T? expected, T? actual, string? message = "", [Cal return; } - string userMessage = BuildUserMessageForExpectedExpressionAndActualExpression(message, expectedExpression, actualExpression); - ThrowAssertAreSameFailed(expected, actual, userMessage); + ThrowAssertAreSameFailed(expected, actual, message, expectedExpression, actualExpression); } private static bool IsAreSameFailing(T? expected, T? actual) => !object.ReferenceEquals(expected, actual); [DoesNotReturn] - private static void ThrowAssertAreSameFailed(T? expected, T? actual, string userMessage) + private static void ThrowAssertAreSameFailed(T? expected, T? actual, string? userMessage, string expectedExpression, string actualExpression) { - string finalMessage = userMessage; + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + + // When both values have the same string representation, include hash codes + // to help the user understand they are different object instances. + string expectedFormatted = FormatValue(expected); + string actualFormatted = FormatValue(actual); + bool sameToString = expected is not null && actual is not null && expectedFormatted == actualFormatted; + string expectedValue = sameToString + ? expectedFormatted + $" (HashCode={RuntimeHelpers.GetHashCode(expected!)})" + : expectedFormatted; + string actualValue = sameToString + ? actualFormatted + $" (HashCode={RuntimeHelpers.GetHashCode(actual!)})" + : actualFormatted; + + // If value types, add diagnostic hint before parameter details if (expected is ValueType && actual is ValueType) { - finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AreSameGivenValues, - userMessage); + message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreSameGivenValues, string.Empty).TrimEnd(); + } + else + { + message += Environment.NewLine + FrameworkMessages.AreSameFailNew; } - ThrowAssertFailed("Assert.AreSame", finalMessage); + // Check expression redundancy against the base formatted value (without hashcode) + message += Environment.NewLine + FormatParameterWithExpressionCheck(nameof(expected), expectedExpression, expectedFormatted, expectedValue) + + Environment.NewLine + FormatParameterWithExpressionCheck(nameof(actual), actualExpression, actualFormatted, actualValue); + + ThrowAssertFailed("Assert.AreSame", message); } /// @@ -240,7 +260,7 @@ public static void AreNotSame(T? notExpected, T? actual, string? message = "" { if (IsAreNotSameFailing(notExpected, actual)) { - ThrowAssertAreNotSameFailed(BuildUserMessageForNotExpectedExpressionAndActualExpression(message, notExpectedExpression, actualExpression)); + ThrowAssertAreNotSameFailed(notExpected, actual, message, notExpectedExpression, actualExpression); } } @@ -248,6 +268,12 @@ private static bool IsAreNotSameFailing(T? notExpected, T? actual) => object.ReferenceEquals(notExpected, actual); [DoesNotReturn] - private static void ThrowAssertAreNotSameFailed(string userMessage) - => ThrowAssertFailed("Assert.AreNotSame", userMessage); + private static void ThrowAssertAreNotSameFailed(T? notExpected, T? actual, string? userMessage, string notExpectedExpression, string actualExpression) + { + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.AreNotSameFailNew; + message += Environment.NewLine + FormatParameter(nameof(notExpected), notExpectedExpression, notExpected) + + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); + ThrowAssertFailed("Assert.AreNotSame", message); + } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index bd97809016..b2157ff8a0 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -16,7 +16,12 @@ public void AreSame_PassSameObject_ShouldPass() public void AreSame_PassDifferentObject_ShouldFail() { Action action = () => Assert.AreSame(new object(), new object()); - action.Should().Throw().WithMessage("Assert.AreSame failed. 'expected' expression: 'new object()', 'actual' expression: 'new object()'."); + action.Should().Throw().WithMessage(""" + Assert.AreSame failed. + Expected references to be the same. + expected (new object()): (HashCode=*) + actual (new object()): (HashCode=*) + """); } public void AreSame_StringMessage_PassSameObject_ShouldPass() @@ -28,7 +33,12 @@ public void AreSame_StringMessage_PassSameObject_ShouldPass() public void AreSame_StringMessage_PassDifferentObject_ShouldFail() { Action action = () => Assert.AreSame(new object(), new object(), "User-provided message"); - action.Should().Throw().WithMessage("Assert.AreSame failed. 'expected' expression: 'new object()', 'actual' expression: 'new object()'. User-provided message"); + action.Should().Throw().WithMessage(""" + Assert.AreSame failed. User-provided message + Expected references to be the same. + expected (new object()): (HashCode=*) + actual (new object()): (HashCode=*) + """); } public void AreSame_InterpolatedString_PassSameObject_ShouldPass() @@ -43,7 +53,12 @@ public async Task AreSame_InterpolatedString_PassDifferentObject_ShouldFail() DummyClassTrackingToStringCalls o = new(); DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreSame(new object(), new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); - (await action.Should().ThrowAsync()).WithMessage($"Assert.AreSame failed. 'expected' expression: 'new object()', 'actual' expression: 'new object()'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + (await action.Should().ThrowAsync()).WithMessage(""" + Assert.AreSame failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected references to be the same. + expected (new object()): (HashCode=*) + actual (new object()): (HashCode=*) + """); o.WasToStringCalled.Should().BeTrue(); } @@ -53,26 +68,46 @@ public void AreNotSame_PassDifferentObject_ShouldPass() public void AreSame_BothAreValueTypes_ShouldFailWithSpecializedMessage() { Action action = () => Assert.AreSame(1, 1); - action.Should().Throw().WithMessage("Assert.AreSame failed. Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). 'expected' expression: '1', 'actual' expression: '1'."); + action.Should().Throw().WithMessage(""" + Assert.AreSame failed. + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). + expected: 1 (HashCode=*) + actual: 1 (HashCode=*) + """); } public void AreSame_StringMessage_BothAreValueTypes_ShouldFailWithSpecializedMessage() { Action action = () => Assert.AreSame(1, 1, "User-provided message"); - action.Should().Throw().WithMessage("Assert.AreSame failed. Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). 'expected' expression: '1', 'actual' expression: '1'. User-provided message"); + action.Should().Throw().WithMessage(""" + Assert.AreSame failed. User-provided message + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). + expected: 1 (HashCode=*) + actual: 1 (HashCode=*) + """); } public void AreSame_InterpolatedString_BothAreValueTypes_ShouldFailWithSpecializedMessage() { Action action = () => Assert.AreSame(1, 1, $"User-provided message {new object().GetType()}"); - action.Should().Throw().WithMessage("Assert.AreSame failed. Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). 'expected' expression: '1', 'actual' expression: '1'. User-provided message System.Object"); + action.Should().Throw().WithMessage(""" + Assert.AreSame failed. User-provided message System.Object + Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). + expected: 1 (HashCode=*) + actual: 1 (HashCode=*) + """); } public void AreNotSame_PassSameObject_ShouldFail() { object o = new(); Action action = () => Assert.AreNotSame(o, o); - action.Should().Throw().WithMessage("Assert.AreNotSame failed. 'notExpected' expression: 'o', 'actual' expression: 'o'."); + action.Should().Throw().WithMessage(""" + Assert.AreNotSame failed. + Expected references to be different. + notExpected (o): + actual (o): + """); } public void AreNotSame_StringMessage_PassDifferentObject_ShouldPass() @@ -82,7 +117,12 @@ public void AreNotSame_StringMessage_PassSameObject_ShouldFail() { object o = new(); Action action = () => Assert.AreNotSame(o, o, "User-provided message"); - action.Should().Throw().WithMessage("Assert.AreNotSame failed. 'notExpected' expression: 'o', 'actual' expression: 'o'. User-provided message"); + action.Should().Throw().WithMessage(""" + Assert.AreNotSame failed. User-provided message + Expected references to be different. + notExpected (o): + actual (o): + """); } public void AreNotSame_InterpolatedString_PassDifferentObject_ShouldPass() @@ -97,7 +137,96 @@ public async Task AreNotSame_InterpolatedString_PassSameObject_ShouldFail() DummyClassTrackingToStringCalls o = new(); DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreNotSame(o, o, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); - (await action.Should().ThrowAsync()).WithMessage($"Assert.AreNotSame failed. 'notExpected' expression: 'o', 'actual' expression: 'o'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + (await action.Should().ThrowAsync()).WithMessage(""" + Assert.AreNotSame failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected references to be different. + notExpected (o): DummyClassTrackingToStringCalls + actual (o): DummyClassTrackingToStringCalls + """); o.WasToStringCalled.Should().BeTrue(); } + + #region AreSame/AreNotSame truncation and newline escaping + + public void AreSame_WithLongExpression_ShouldTruncateExpression() + { + object aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = new object(); + + Action action = () => Assert.AreSame(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, new object()); + action.Should().Throw() + .WithMessage(""" + Assert.AreSame failed. + Expected references to be the same. + expected (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): (HashCode=*) + actual (new object()): (HashCode=*) + """); + } + + public void AreSame_WithLongToStringValue_ShouldTruncateValue() + { + Action action = () => Assert.AreSame(new ObjectWithLongToString(), new ObjectWithLongToString()); + action.Should().Throw() + .WithMessage($""" + Assert.AreSame failed. + Expected references to be the same. + expected (new ObjectWithLongToString()): {new string('L', 256)}... (300 chars) (HashCode=*) + actual (new ObjectWithLongToString()): {new string('L', 256)}... (300 chars) (HashCode=*) + """); + } + + public void AreSame_WithNewlineInToString_ShouldEscapeNewlines() + { + Action action = () => Assert.AreSame(new ObjectWithNewlineToString(), new ObjectWithNewlineToString()); + action.Should().Throw() + .WithMessage(""" + Assert.AreSame failed. + Expected references to be the same. + expected (new ObjectWithNewlineToString()): line1\r\nline2\nline3 (HashCode=*) + actual (new ObjectWithNewlineToString()): line1\r\nline2\nline3 (HashCode=*) + """); + } + + public void AreNotSame_WithLongExpression_ShouldTruncateExpression() + { + object aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = new object(); + + Action action = () => Assert.AreNotSame(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.AreNotSame failed. + Expected references to be different. + notExpected (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): + actual (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): + """); + } + + public void AreNotSame_WithLongToStringValue_ShouldTruncateValue() + { + var obj = new ObjectWithLongToString(); + + Action action = () => Assert.AreNotSame(obj, obj); + action.Should().Throw() + .WithMessage($""" + Assert.AreNotSame failed. + Expected references to be different. + notExpected (obj): {new string('L', 256)}... (300 chars) + actual (obj): {new string('L', 256)}... (300 chars) + """); + } + + public void AreNotSame_WithNewlineInToString_ShouldEscapeNewlines() + { + var obj = new ObjectWithNewlineToString(); + + Action action = () => Assert.AreNotSame(obj, obj); + action.Should().Throw() + .WithMessage(""" + Assert.AreNotSame failed. + Expected references to be different. + notExpected (obj): line1\r\nline2\nline3 + actual (obj): line1\r\nline2\nline3 + """); + } + + #endregion } From 375f0b52673e74b75f4a9370ee300992d44887a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:52:34 +0100 Subject: [PATCH 04/58] Improve IsTrue/IsFalse assertion error messages --- .../TestFramework/Assertions/Assert.IsTrue.cs | 33 +++-- .../Assertions/AssertTests.IsTrueTests.cs | 140 +++++++++++++++--- 2 files changed, 144 insertions(+), 29 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 1c31f3add1..a9dcae1299 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -22,9 +22,11 @@ public sealed partial class Assert public readonly struct AssertIsTrueInterpolatedStringHandler { private readonly StringBuilder? _builder; + private readonly bool? _condition; public AssertIsTrueInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) { + _condition = condition; shouldAppend = IsTrueFailing(condition); if (shouldAppend) { @@ -36,8 +38,7 @@ internal void ComputeAssertion(string conditionExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "condition", conditionExpression) + " "); - ThrowAssertIsTrueFailed(_builder.ToString()); + ThrowAssertIsTrueFailed(_condition, _builder.ToString(), conditionExpression); } } @@ -74,9 +75,11 @@ internal void ComputeAssertion(string conditionExpression) public readonly struct AssertIsFalseInterpolatedStringHandler { private readonly StringBuilder? _builder; + private readonly bool? _condition; public AssertIsFalseInterpolatedStringHandler(int literalLength, int formattedCount, bool? condition, out bool shouldAppend) { + _condition = condition; shouldAppend = IsFalseFailing(condition); if (shouldAppend) { @@ -88,8 +91,7 @@ internal void ComputeAssertion(string conditionExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "condition", conditionExpression) + " "); - ThrowAssertIsFalseFailed(_builder.ToString()); + ThrowAssertIsFalseFailed(_condition, _builder.ToString(), conditionExpression); } } @@ -150,15 +152,21 @@ public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string? mess { if (IsTrueFailing(condition)) { - ThrowAssertIsTrueFailed(BuildUserMessageForConditionExpression(message, conditionExpression)); + ThrowAssertIsTrueFailed(condition, message, conditionExpression); } } private static bool IsTrueFailing(bool? condition) => condition is false or null; - private static void ThrowAssertIsTrueFailed(string? message) - => ThrowAssertFailed("Assert.IsTrue", message); + [DoesNotReturn] + private static void ThrowAssertIsTrueFailed(bool? condition, string? userMessage, string conditionExpression) + { + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.IsTrueFailNew; + message += Environment.NewLine + FormatParameter(nameof(condition), conditionExpression, condition); + ThrowAssertFailed("Assert.IsTrue", message); + } /// #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 @@ -188,7 +196,7 @@ public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string? mess { if (IsFalseFailing(condition)) { - ThrowAssertIsFalseFailed(BuildUserMessageForConditionExpression(message, conditionExpression)); + ThrowAssertIsFalseFailed(condition, message, conditionExpression); } } @@ -196,6 +204,11 @@ private static bool IsFalseFailing(bool? condition) => condition is true or null; [DoesNotReturn] - private static void ThrowAssertIsFalseFailed(string userMessage) - => ThrowAssertFailed("Assert.IsFalse", userMessage); + private static void ThrowAssertIsFalseFailed(bool? condition, string? userMessage, string conditionExpression) + { + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.IsFalseFailNew; + message += Environment.NewLine + FormatParameter(nameof(condition), conditionExpression, condition); + ThrowAssertFailed("Assert.IsFalse", message); + } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs index a09c1416ef..f3c5796aeb 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -12,7 +12,11 @@ public void IsFalseNullableBooleanShouldFailWithNull() bool? nullBool = null; Action action = () => Assert.IsFalse(nullBool); action.Should().Throw() - .WithMessage("Assert.IsFalse failed. 'condition' expression: 'nullBool'."); + .WithMessage(""" + Assert.IsFalse failed. + Expected condition to be false. + condition (nullBool): (null) + """); } public void IsFalseNullableBooleanShouldFailWithTrue() @@ -20,7 +24,11 @@ public void IsFalseNullableBooleanShouldFailWithTrue() bool? nullBool = true; Action action = () => Assert.IsFalse(nullBool); action.Should().Throw() - .WithMessage("Assert.IsFalse failed. 'condition' expression: 'nullBool'."); + .WithMessage(""" + Assert.IsFalse failed. + Expected condition to be false. + condition (nullBool): True + """); } public void IsFalseNullableBooleanShouldNotFailWithFalse() @@ -33,7 +41,11 @@ public void IsFalseBooleanShouldFailWithTrue() { Action action = () => Assert.IsFalse(true); action.Should().Throw() - .WithMessage("Assert.IsFalse failed. 'condition' expression: 'true'."); + .WithMessage(""" + Assert.IsFalse failed. + Expected condition to be false. + condition: True + """); } public void IsFalseBooleanShouldNotFailWithFalse() @@ -44,7 +56,11 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithNull() bool? nullBool = null; Action action = () => Assert.IsFalse(nullBool, "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsFalse failed. 'condition' expression: 'nullBool'. User-provided message"); + .WithMessage(""" + Assert.IsFalse failed. User-provided message + Expected condition to be false. + condition (nullBool): (null) + """); } public void IsFalseNullableBooleanStringMessageShouldFailWithTrue() @@ -52,7 +68,11 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithTrue() bool? nullBool = true; Action action = () => Assert.IsFalse(nullBool, "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsFalse failed. 'condition' expression: 'nullBool'. User-provided message"); + .WithMessage(""" + Assert.IsFalse failed. User-provided message + Expected condition to be false. + condition (nullBool): True + """); } public void IsFalseNullableBooleanStringMessageShouldNotFailWithFalse() @@ -65,7 +85,11 @@ public void IsFalseBooleanStringMessageShouldFailWithTrue() { Action action = () => Assert.IsFalse(true, "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsFalse failed. 'condition' expression: 'true'. User-provided message"); + .WithMessage(""" + Assert.IsFalse failed. User-provided message + Expected condition to be false. + condition: True + """); } public void IsFalseBooleanStringMessageShouldNotFailWithFalse() @@ -78,7 +102,11 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithN DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsFalse(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsFalse failed. 'condition' expression: 'nullBool'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsFalse failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected condition to be false. + condition (nullBool): (null) + """); } public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithTrue() @@ -88,7 +116,11 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithT DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsFalse(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsFalse failed. 'condition' expression: 'nullBool'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsFalse failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected condition to be false. + condition (nullBool): True + """); } public void IsFalseNullableBooleanInterpolatedStringMessageShouldNotFailWithFalse() @@ -103,7 +135,11 @@ public async Task IsFalseBooleanInterpolatedStringMessageShouldFailWithTrue() DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsFalse(true, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsFalse failed. 'condition' expression: 'true'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsFalse failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected condition to be false. + condition: True + """); } public void IsFalseBooleanInterpolatedStringMessageShouldNotFailWithFalse() @@ -114,7 +150,11 @@ public void IsTrueNullableBooleanShouldFailWithNull() bool? nullBool = null; Action action = () => Assert.IsTrue(nullBool); action.Should().Throw() - .WithMessage("Assert.IsTrue failed. 'condition' expression: 'nullBool'."); + .WithMessage(""" + Assert.IsTrue failed. + Expected condition to be true. + condition (nullBool): (null) + """); } public void IsTrueNullableBooleanShouldFailWithFalse() @@ -122,7 +162,11 @@ public void IsTrueNullableBooleanShouldFailWithFalse() bool? nullBool = false; Action action = () => Assert.IsTrue(nullBool); action.Should().Throw() - .WithMessage("Assert.IsTrue failed. 'condition' expression: 'nullBool'."); + .WithMessage(""" + Assert.IsTrue failed. + Expected condition to be true. + condition (nullBool): False + """); } public void IsTrueNullableBooleanShouldNotFailWithTrue() @@ -135,7 +179,11 @@ public void IsTrueBooleanShouldFailWithFalse() { Action action = () => Assert.IsTrue(false); action.Should().Throw() - .WithMessage("Assert.IsTrue failed. 'condition' expression: 'false'."); + .WithMessage(""" + Assert.IsTrue failed. + Expected condition to be true. + condition: False + """); } public void IsTrueBooleanShouldNotFailWithTrue() @@ -146,7 +194,11 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithNull() bool? nullBool = null; Action action = () => Assert.IsTrue(nullBool, "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsTrue failed. 'condition' expression: 'nullBool'. User-provided message"); + .WithMessage(""" + Assert.IsTrue failed. User-provided message + Expected condition to be true. + condition (nullBool): (null) + """); } public void IsTrueNullableBooleanStringMessageShouldFailWithFalse() @@ -154,7 +206,11 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithFalse() bool? nullBool = false; Action action = () => Assert.IsTrue(nullBool, "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsTrue failed. 'condition' expression: 'nullBool'. User-provided message"); + .WithMessage(""" + Assert.IsTrue failed. User-provided message + Expected condition to be true. + condition (nullBool): False + """); } public void IsTrueNullableBooleanStringMessageShouldNotFailWithTrue() @@ -167,7 +223,11 @@ public void IsTrueBooleanStringMessageShouldFailWithFalse() { Action action = () => Assert.IsTrue(false, "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsTrue failed. 'condition' expression: 'false'. User-provided message"); + .WithMessage(""" + Assert.IsTrue failed. User-provided message + Expected condition to be true. + condition: False + """); } public void IsTrueBooleanStringMessageShouldNotFailWithTrue() @@ -180,7 +240,11 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithNu DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsTrue(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsTrue failed. 'condition' expression: 'nullBool'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsTrue failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected condition to be true. + condition (nullBool): (null) + """); } public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithFalse() @@ -190,7 +254,11 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithFa DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsTrue(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsTrue failed. 'condition' expression: 'nullBool'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsTrue failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected condition to be true. + condition (nullBool): False + """); } public void IsTrueNullableBooleanInterpolatedStringMessageShouldNotFailWithTrue() @@ -205,9 +273,43 @@ public async Task IsTrueBooleanInterpolatedStringMessageShouldFailWithFalse() DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsTrue(false, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsTrue failed. 'condition' expression: 'false'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsTrue failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected condition to be true. + condition: False + """); } public void IsTrueBooleanInterpolatedStringMessageShouldNotFailWithTrue() => Assert.IsTrue(true, $"User-provided message. Input: {true}"); + + #region IsTrue/IsFalse truncation + + public void IsTrue_WithLongExpression_ShouldTruncateExpression() + { + bool aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = false; + + Action action = () => Assert.IsTrue(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.IsTrue failed. + Expected condition to be true. + condition (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): False + """); + } + + public void IsFalse_WithLongExpression_ShouldTruncateExpression() + { + bool aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = true; + + Action action = () => Assert.IsFalse(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.IsFalse failed. + Expected condition to be false. + condition (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): True + """); + } + + #endregion } From bd663568996a8423dcfafdf8b4f287d6a0d4985a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:52:41 +0100 Subject: [PATCH 05/58] Improve IsNull/IsNotNull assertion error messages --- .../TestFramework/Assertions/Assert.IsNull.cs | 31 ++- .../Assertions/AssertTests.IsNull.cs | 38 ++- .../Assertions/AssertTests.cs | 230 +++++++++++++++++- 3 files changed, 281 insertions(+), 18 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index fd6db5b3d4..8de60e7629 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -22,9 +22,11 @@ public sealed partial class Assert public readonly struct AssertIsNullInterpolatedStringHandler { private readonly StringBuilder? _builder; + private readonly object? _value; public AssertIsNullInterpolatedStringHandler(int literalLength, int formattedCount, object? value, out bool shouldAppend) { + _value = value; shouldAppend = IsNullFailing(value); if (shouldAppend) { @@ -36,8 +38,7 @@ internal void ComputeAssertion(string valueExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "value", valueExpression) + " "); - ThrowAssertIsNullFailed(_builder.ToString()); + ThrowAssertIsNullFailed(_value, _builder.ToString(), valueExpression); } } @@ -90,8 +91,7 @@ internal void ComputeAssertion(string valueExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "value", valueExpression) + " "); - ThrowAssertIsNotNullFailed(_builder.ToString()); + ThrowAssertIsNotNullFailed(_builder.ToString(), valueExpression); } } @@ -152,14 +152,20 @@ public static void IsNull(object? value, string? message = "", [CallerArgumentEx { if (IsNullFailing(value)) { - ThrowAssertIsNullFailed(BuildUserMessageForValueExpression(message, valueExpression)); + ThrowAssertIsNullFailed(value, message, valueExpression); } } private static bool IsNullFailing(object? value) => value is not null; - private static void ThrowAssertIsNullFailed(string? message) - => ThrowAssertFailed("Assert.IsNull", message); + [DoesNotReturn] + private static void ThrowAssertIsNullFailed(object? value, string? userMessage, string valueExpression) + { + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.IsNullFailNew; + message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.IsNull", message); + } /// #pragma warning disable IDE0060 // Remove unused parameter - https://github.com/dotnet/roslyn/issues/76578 @@ -191,13 +197,18 @@ public static void IsNotNull([NotNull] object? value, string? message = "", [Cal { if (IsNotNullFailing(value)) { - ThrowAssertIsNotNullFailed(BuildUserMessageForValueExpression(message, valueExpression)); + ThrowAssertIsNotNullFailed(message, valueExpression); } } private static bool IsNotNullFailing([NotNullWhen(false)] object? value) => value is null; [DoesNotReturn] - private static void ThrowAssertIsNotNullFailed(string? message) - => ThrowAssertFailed("Assert.IsNotNull", message); + private static void ThrowAssertIsNotNullFailed(string? userMessage, string valueExpression) + { + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.IsNotNullFailNew; + message += Environment.NewLine + FormatParameter("value", valueExpression, null); + ThrowAssertFailed("Assert.IsNotNull", message); + } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index bd365d680a..ba0142e030 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -16,7 +16,11 @@ public void IsNull_PassNonNull_ShouldFail() { Action action = () => Assert.IsNull(new object()); action.Should().Throw() - .WithMessage("Assert.IsNull failed. 'value' expression: 'new object()'."); + .WithMessage(""" + Assert.IsNull failed. + Expected value to be null. + value (new object()): + """); } public void IsNull_StringMessage_PassNull_ShouldPass() @@ -26,7 +30,11 @@ public void IsNull_StringMessage_PassNonNull_ShouldFail() { Action action = () => Assert.IsNull(new object(), "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsNull failed. 'value' expression: 'new object()'. User-provided message"); + .WithMessage(""" + Assert.IsNull failed. User-provided message + Expected value to be null. + value (new object()): + """); } public void IsNull_InterpolatedString_PassNull_ShouldPass() @@ -42,7 +50,11 @@ public async Task IsNull_InterpolatedString_PassNonNull_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsNull(new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsNull failed. 'value' expression: 'new object()'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsNull failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected value to be null. + value (new object()): + """); o.WasToStringCalled.Should().BeTrue(); } @@ -73,14 +85,22 @@ public void IsNotNull_PassNull_ShouldFail() { Action action = () => Assert.IsNotNull(null); action.Should().Throw() - .WithMessage("Assert.IsNotNull failed. 'value' expression: 'null'."); + .WithMessage(""" + Assert.IsNotNull failed. + Expected a non-null value. + value: (null) + """); } public void IsNotNull_StringMessage_PassNonNull_ShouldFail() { Action action = () => Assert.IsNotNull(null, "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsNotNull failed. 'value' expression: 'null'. User-provided message"); + .WithMessage(""" + Assert.IsNotNull failed. User-provided message + Expected a non-null value. + value: (null) + """); } public async Task IsNotNull_InterpolatedString_PassNonNull_ShouldFail() @@ -89,7 +109,11 @@ public async Task IsNotNull_InterpolatedString_PassNonNull_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsNotNull(null, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsNotNull failed. 'value' expression: 'null'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsNotNull failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected a non-null value. + value: (null) + """); o.WasToStringCalled.Should().BeTrue(); } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index 21dbd8e1ac..f5837865e6 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -65,4 +65,232 @@ private sealed class DummyIFormattable : IFormattable public string ToString(string? format, IFormatProvider? formatProvider) => "DummyIFormattable.ToString()"; } + + #region FormatValue truncation + + public void FormatValue_WhenStringExceedsMaxLength_ShouldTruncateWithEllipsis() + { + // FormatValue truncation applies to non-string-diff contexts like IsNull + // 300 'x' chars -> quoted as "xxx..." (302 chars total) -> truncated at 256 chars with ellipsis + string longValue = new('x', 300); + // Truncate takes first 256 chars of quoted string: opening quote + 255 x's, then appends "... (302 chars)" + string expectedValue = "\"" + new string('x', 255) + "... (302 chars)"; + + Action action = () => Assert.IsNull(longValue); + action.Should().Throw() + .WithMessage($""" + Assert.IsNull failed. + Expected value to be null. + value (longValue): {expectedValue} + """); + } + + public void FormatValue_WhenStringIsWithinMaxLength_ShouldNotTruncate() + { + string value = new('x', 50); + string expectedFullValue = "\"" + new string('x', 50) + "\""; + + Action action = () => Assert.IsNull(value); + action.Should().Throw() + .WithMessage($""" + Assert.IsNull failed. + Expected value to be null. + value: {expectedFullValue} + """); + } + + public void FormatValue_WhenCustomToStringExceedsMaxLength_ShouldTruncate() + { + // Custom ToString returns 300 chars ? truncated at 256 + var obj = new ObjectWithLongToString(); + string expectedValue = new string('L', 256) + "... (300 chars)"; + + Action action = () => Assert.IsNull(obj); + action.Should().Throw() + .WithMessage($""" + Assert.IsNull failed. + Expected value to be null. + value (obj): {expectedValue} + """); + } + + public void TruncateExpression_WhenExpressionExceeds100Chars_ShouldShowEllipsis() + { + // Variable name is 113 chars ? exceeds 100 char limit ? truncated with "..." + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = null!; + + Action action = () => Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.IsNotNull failed. + Expected a non-null value. + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): (null) + """); + } + + #endregion + + #region FormatValue newline escaping + + public void FormatValue_WhenValueContainsNewlines_ShouldEscapeThem() + { + var obj = new ObjectWithNewlineToString(); + + Action action = () => Assert.IsNull(obj); + action.Should().Throw() + .WithMessage(""" + Assert.IsNull failed. + Expected value to be null. + value (obj): line1\r\nline2\nline3 + """); + } + + public void FormatValue_WhenStringContainsNewlines_ShouldEscapeThem() + { + string value = "hello\nworld"; + + Action action = () => Assert.IsNull(value); + action.Should().Throw() + .WithMessage(""" + Assert.IsNull failed. + Expected value to be null. + value: "hello\nworld" + """); + } + + #endregion + + #region FormatValue collection preview + + public void FormatValue_WhenValueIsCollection_ShouldShowPreview() + { + var collection = new List { 1, 2, 3 }; + + Action action = () => Assert.IsNull(collection); + action.Should().Throw() + .WithMessage(""" + Assert.IsNull failed. + Expected value to be null. + value (collection): [1, 2, 3] (3 elements) + """); + } + + public void FormatCollectionPreview_WhenTotalStringLengthExceeds256_ShouldTruncate() + { + // Each element is a 30-char string ? FormatValue wraps in quotes ? "aaa...aaa" = 32 chars + // With ", " separator: first = 32, subsequent = 34 each + // 32 + 634 = 236 = 256, 32 + 734 = 270 > 256 + // So 7 elements should display, then "...", with total count 20 + var collection = new List(); + for (int i = 0; i < 20; i++) + { + collection.Add(new string((char)('a' + (i % 26)), 30)); + } + + Action action = () => Assert.Contains("not-there", collection); + action.Should().Throw() + .WithMessage(""" + Assert.Contains failed. + Expected collection to contain the specified item. + expected: "not-there" + collection*[*...*] (20 elements) + """); + } + + public void FormatCollectionPreview_WhenElementToStringExceeds50_ShouldTruncateElement() + { + // Element has 80-char string ? FormatValue(maxLength:50) ? "zzz..." (82 chars quoted) ? truncated at 50 + var collection = new List { new string('z', 80), "short" }; + string expectedFirstElement = "\"" + new string('z', 49) + "... (82 chars)"; + + Action action = () => Assert.Contains("not-there", collection); + action.Should().Throw() + .WithMessage($""" + Assert.Contains failed. + Expected collection to contain the specified item. + expected: "not-there" + collection*[{expectedFirstElement}, "short"] (2 elements) + """); + } + + public void FormatCollectionPreview_WhenCollectionContainsNestedCollections_ShouldShowNestedPreview() + { + var inner1 = new List { 1, 2 }; + var inner2 = new List { 3, 4 }; + var outer = new List> { inner1, inner2 }; + + Action action = () => Assert.IsNull(outer); + action.Should().Throw() + .WithMessage(""" + Assert.IsNull failed. + Expected value to be null. + value (outer): [[1, 2] (2 elements), [3, 4] (2 elements)] (2 elements) + """); + } + + public void FormatCollectionPreview_WhenNestedCollectionIsLarge_ShouldTruncateInnerAt50() + { + // Inner collection has many elements ? inner preview string budget is 50 chars + // Elements 0-9 are 1 char each: "0" takes 1, subsequent take 3 (digit + ", ") + // 1 + 93 = 28 chars for 0-9. Then 10-99 are 2 char digits + 2 sep = 4 each + // 28 + 4n = 50 ? n = 5.5 ? 5 more (10-14). 28 + 54 = 48, next would be 52 > 50 + // So inner preview shows: 0-14 (15 elements), then "..." + var inner = new List(); + for (int i = 0; i < 50; i++) + { + inner.Add(i); + } + + var outer = new List> { inner }; + + Action action = () => Assert.IsNull(outer); + action.Should().Throw() + .WithMessage(""" + Assert.IsNull failed. + Expected value to be null. + value (outer): [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...] (50 elements)] (1 element) + """); + } + + public void FormatCollectionPreview_WhenElementContainsNewlines_ShouldEscapeThem() + { + var collection = new List { "line1\nline2", "ok" }; + + Action action = () => Assert.Contains("not-there", collection); + action.Should().Throw() + .WithMessage(""" + Assert.Contains failed. + Expected collection to contain the specified item. + expected: "not-there" + collection*["line1\nline2", "ok"] (2 elements) + """); + } + + public void FormatCollectionPreview_WhenSingleElement_ShouldShowSingularForm() + { + var collection = new List { 42 }; + + Action action = () => Assert.Contains(99, collection); + action.Should().Throw() + .WithMessage(""" + Assert.Contains failed. + Expected collection to contain the specified item. + expected: 99 + collection*[42] (1 element) + """); + } + + #endregion +} + +[TestClass] +public sealed class ObjectWithNewlineToString +{ + public override string ToString() => "line1\r\nline2\nline3"; +} + +[TestClass] +public sealed class ObjectWithLongToString +{ + public override string ToString() => new string('L', 300); } From 7e7f07e7411c7572ae722ecf08f984760c95405a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:52:47 +0100 Subject: [PATCH 06/58] Improve IsInstanceOfType/IsNotInstanceOfType assertion error messages --- .../Assertions/Assert.IsInstanceOfType.cs | 56 +++--- .../AssertTests.IsInstanceOfTypeTests.cs | 161 ++++++++++++++++-- 2 files changed, 178 insertions(+), 39 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index bdd68f1607..afb997ef4a 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -38,8 +38,7 @@ internal void ComputeAssertion(string valueExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "value", valueExpression) + " "); - ThrowAssertIsInstanceOfTypeFailed(_value, _expectedType, _builder.ToString()); + ThrowAssertIsInstanceOfTypeFailed(_value, _expectedType, _builder.ToString(), valueExpression); } } @@ -98,8 +97,7 @@ internal void ComputeAssertion(string valueExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "value", valueExpression) + " "); - ThrowAssertIsInstanceOfTypeFailed(_value, typeof(TArg), _builder.ToString()); + ThrowAssertIsInstanceOfTypeFailed(_value, typeof(TArg), _builder.ToString(), valueExpression); } } @@ -160,8 +158,7 @@ internal void ComputeAssertion(string valueExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "value", valueExpression) + " "); - ThrowAssertIsNotInstanceOfTypeFailed(_value, _wrongType, _builder.ToString()); + ThrowAssertIsNotInstanceOfTypeFailed(_value, _wrongType, _builder.ToString(), valueExpression); } } @@ -220,8 +217,7 @@ internal void ComputeAssertion(string valueExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "value", valueExpression) + " "); - ThrowAssertIsNotInstanceOfTypeFailed(_value, typeof(TArg), _builder.ToString()); + ThrowAssertIsNotInstanceOfTypeFailed(_value, typeof(TArg), _builder.ToString(), valueExpression); } } @@ -292,7 +288,7 @@ public static void IsInstanceOfType([NotNull] object? value, [NotNull] Type? exp { if (IsInstanceOfTypeFailing(value, expectedType)) { - ThrowAssertIsInstanceOfTypeFailed(value, expectedType, BuildUserMessageForValueExpression(message, valueExpression)); + ThrowAssertIsInstanceOfTypeFailed(value, expectedType, message, valueExpression); } } @@ -331,20 +327,22 @@ private static bool IsInstanceOfTypeFailing([NotNullWhen(false)] object? value, => expectedType == null || value == null || !expectedType.IsInstanceOfType(value); [DoesNotReturn] - private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expectedType, string userMessage) + private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expectedType, string? userMessage, string valueExpression) { - string finalMessage = userMessage; + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; if (expectedType is not null && value is not null) { - finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsInstanceOfFailMsg, - userMessage, - expectedType.ToString(), - value.GetType().ToString()); + message += Environment.NewLine + FrameworkMessages.IsInstanceOfTypeFailNew; } - ThrowAssertFailed("Assert.IsInstanceOfType", finalMessage); + message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + if (expectedType is not null && value is not null) + { + message += Environment.NewLine + $" expectedType: {expectedType}" + + Environment.NewLine + $" actualType: {value.GetType()}"; + } + + ThrowAssertFailed("Assert.IsInstanceOfType", message); } /// @@ -376,7 +374,7 @@ public static void IsNotInstanceOfType(object? value, [NotNull] Type? wrongType, { if (IsNotInstanceOfTypeFailing(value, wrongType)) { - ThrowAssertIsNotInstanceOfTypeFailed(value, wrongType, BuildUserMessageForValueExpression(message, valueExpression)); + ThrowAssertIsNotInstanceOfTypeFailed(value, wrongType, message, valueExpression); } } @@ -409,19 +407,21 @@ private static bool IsNotInstanceOfTypeFailing(object? value, [NotNullWhen(false (value is not null && wrongType.IsInstanceOfType(value)); [DoesNotReturn] - private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wrongType, string userMessage) + private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wrongType, string? userMessage, string valueExpression) { - string finalMessage = userMessage; + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + if (wrongType is not null) + { + message += Environment.NewLine + FrameworkMessages.IsNotInstanceOfTypeFailNew; + } + + message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (wrongType is not null) { - finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsNotInstanceOfFailMsg, - userMessage, - wrongType.ToString(), - value!.GetType().ToString()); + message += Environment.NewLine + $" wrongType: {wrongType}" + + Environment.NewLine + $" actualType: {value!.GetType()}"; } - ThrowAssertFailed("Assert.IsNotInstanceOfType", finalMessage); + ThrowAssertFailed("Assert.IsNotInstanceOfType", message); } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 6e5e917ed7..318bb61968 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -12,21 +12,33 @@ public void InstanceOfTypeShouldFailWhenValueIsNull() { Action action = () => Assert.IsInstanceOfType(null, typeof(AssertTests)); action.Should().Throw() - .WithMessage("Assert.IsInstanceOfType failed. 'value' expression: 'null'."); + .WithMessage(""" + Assert.IsInstanceOfType failed. + value: (null) + """); } public void InstanceOfTypeShouldFailWhenTypeIsNull() { Action action = () => Assert.IsInstanceOfType(5, null); action.Should().Throw() - .WithMessage("Assert.IsInstanceOfType failed. 'value' expression: '5'."); + .WithMessage(""" + Assert.IsInstanceOfType failed. + value: 5 + """); } public void InstanceOfTypeShouldFailWhenTypeIsMismatched() { Action action = () => Assert.IsInstanceOfType(5, typeof(string)); action.Should().Throw() - .WithMessage("Assert.IsInstanceOfType failed. 'value' expression: '5'. Expected type:. Actual type:."); + .WithMessage(""" + Assert.IsInstanceOfType failed. + Expected value to be of the specified type. + value: 5 + expectedType: System.String + actualType: System.Int32 + """); } public void InstanceOfTypeShouldPassOnSameInstance() => Assert.IsInstanceOfType(5, typeof(int)); @@ -37,21 +49,33 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() { Action action = () => Assert.IsInstanceOfType(null, typeof(AssertTests), "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsInstanceOfType failed. 'value' expression: 'null'. User-provided message"); + .WithMessage(""" + Assert.IsInstanceOfType failed. User-provided message + value: (null) + """); } public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() { Action action = () => Assert.IsInstanceOfType(5, null, "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsInstanceOfType failed. 'value' expression: '5'. User-provided message"); + .WithMessage(""" + Assert.IsInstanceOfType failed. User-provided message + value: 5 + """); } public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() { Action action = () => Assert.IsInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsInstanceOfType failed. 'value' expression: '5'. User-provided message Expected type:. Actual type:."); + .WithMessage(""" + Assert.IsInstanceOfType failed. User-provided message + Expected value to be of the specified type. + value: 5 + expectedType: System.String + actualType: System.Int32 + """); } public void InstanceOfType_WithStringMessage_ShouldPassWhenTypeIsCorrect() @@ -63,7 +87,10 @@ public async Task InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNul DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsInstanceOfType(null, typeof(AssertTests), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsInstanceOfType failed. 'value' expression: 'null'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsInstanceOfType failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + value: (null) + """); o.WasToStringCalled.Should().BeTrue(); } @@ -72,7 +99,10 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull() DummyClassTrackingToStringCalls o = new(); Action action = () => Assert.IsInstanceOfType(5, null, $"User-provided message {o}"); action.Should().Throw() - .WithMessage("Assert.IsInstanceOfType failed. 'value' expression: '5'. User-provided message DummyClassTrackingToStringCalls"); + .WithMessage(""" + Assert.IsInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls + value: 5 + """); o.WasToStringCalled.Should().BeTrue(); } @@ -81,7 +111,13 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMismatched DummyClassTrackingToStringCalls o = new(); Action action = () => Assert.IsInstanceOfType(5, typeof(string), $"User-provided message {o}"); action.Should().Throw() - .WithMessage("Assert.IsInstanceOfType failed. 'value' expression: '5'. User-provided message DummyClassTrackingToStringCalls Expected type:. Actual type:."); + .WithMessage(""" + Assert.IsInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls + Expected value to be of the specified type. + value: 5 + expectedType: System.String + actualType: System.Int32 + """); o.WasToStringCalled.Should().BeTrue(); } @@ -108,14 +144,23 @@ public void IsInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() { Action action = () => Assert.IsInstanceOfType(null); action.Should().Throw() - .WithMessage("Assert.IsInstanceOfType failed. 'value' expression: 'null'."); + .WithMessage(""" + Assert.IsInstanceOfType failed. + value: (null) + """); } public void IsInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() { Action action = () => Assert.IsInstanceOfType(5); action.Should().Throw() - .WithMessage("Assert.IsInstanceOfType failed. 'value' expression: '5'. Expected type:. Actual type:."); + .WithMessage(""" + Assert.IsInstanceOfType failed. + Expected value to be of the specified type. + value: 5 + expectedType: System.String + actualType: System.Int32 + """); } public void IsInstanceOfTypeUsingGenericTypeWithOutParameter_WhenValueIsNull_Fails() @@ -229,4 +274,98 @@ public void IsNotInstanceOfType_WhenNonNullNullableTypeAndMessage_LearnNonNull() private Type? GetObjType() => typeof(object); private Type? GetIntType() => typeof(int); + + #region IsInstanceOfType/IsNotInstanceOfType truncation and newline escaping + + public void IsInstanceOfType_WithLongExpression_ShouldTruncateExpression() + { + object aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello"; + + Action action = () => Assert.IsInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(int)); + action.Should().Throw() + .WithMessage(""" + Assert.IsInstanceOfType failed. + Expected value to be of the specified type. + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + expectedType: System.Int32 + actualType: System.String + """); + } + + public void IsInstanceOfType_WithLongToStringValue_ShouldTruncateValue() + { + var obj = new ObjectWithLongToString(); + + Action action = () => Assert.IsInstanceOfType(obj, typeof(int)); + action.Should().Throw() + .WithMessage($""" + Assert.IsInstanceOfType failed. + Expected value to be of the specified type. + value (obj): {new string('L', 256)}... (300 chars) + expectedType: System.Int32 + actualType: *ObjectWithLongToString + """); + } + + public void IsInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() + { + var obj = new ObjectWithNewlineToString(); + + Action action = () => Assert.IsInstanceOfType(obj, typeof(int)); + action.Should().Throw() + .WithMessage(""" + Assert.IsInstanceOfType failed. + Expected value to be of the specified type. + value (obj): line1\r\nline2\nline3 + expectedType: System.Int32 + actualType: *ObjectWithNewlineToString + """); + } + + public void IsNotInstanceOfType_WithLongExpression_ShouldTruncateExpression() + { + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello"; + + Action action = () => Assert.IsNotInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(string)); + action.Should().Throw() + .WithMessage(""" + Assert.IsNotInstanceOfType failed. + Value should not be of the specified type. + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + wrongType: System.String + actualType: System.String + """); + } + + public void IsNotInstanceOfType_WithLongToStringValue_ShouldTruncateValue() + { + var obj = new ObjectWithLongToString(); + + Action action = () => Assert.IsNotInstanceOfType(obj, typeof(ObjectWithLongToString)); + action.Should().Throw() + .WithMessage($""" + Assert.IsNotInstanceOfType failed. + Value should not be of the specified type. + value (obj): {new string('L', 256)}... (300 chars) + wrongType: *ObjectWithLongToString + actualType: *ObjectWithLongToString + """); + } + + public void IsNotInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() + { + var obj = new ObjectWithNewlineToString(); + + Action action = () => Assert.IsNotInstanceOfType(obj, typeof(ObjectWithNewlineToString)); + action.Should().Throw() + .WithMessage(""" + Assert.IsNotInstanceOfType failed. + Value should not be of the specified type. + value (obj): line1\r\nline2\nline3 + wrongType: *ObjectWithNewlineToString + actualType: *ObjectWithNewlineToString + """); + } + + #endregion } From bebe2ef7de5cb1eb324b314a7dcfab8efe3d77df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:52:56 +0100 Subject: [PATCH 07/58] Improve IsExactInstanceOfType/IsNotExactInstanceOfType assertion error messages --- .../Assert.IsExactInstanceOfType.cs | 73 +++--- .../AssertTests.IsExactInstanceOfTypeTests.cs | 211 ++++++++++++++++-- 2 files changed, 227 insertions(+), 57 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs index 144f17cdbe..5f8fa68c2c 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs @@ -38,8 +38,7 @@ internal void ComputeAssertion(string valueExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "value", valueExpression) + " "); - ThrowAssertIsExactInstanceOfTypeFailed(_value, _expectedType, _builder.ToString()); + ThrowAssertIsExactInstanceOfTypeFailed(_value, _expectedType, _builder.ToString(), valueExpression); } } @@ -50,16 +49,11 @@ internal void ComputeAssertion(string valueExpression) #if NETCOREAPP3_1_OR_GREATER public void AppendFormatted(ReadOnlySpan value) => _builder!.Append(value); -#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads +#pragma warning disable RS0027 public void AppendFormatted(ReadOnlySpan value, int alignment = 0, string? format = null) => AppendFormatted(value.ToString(), alignment, format); -#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads +#pragma warning restore RS0027 #endif - // NOTE: All the overloads involving format and/or alignment are not super efficient. - // This code path is only for when an assert is failing, so that's not the common scenario - // and should be okay if not very optimized. - // A more efficient implementation that can be used for .NET 6 and later is to delegate the work to - // the BCL's StringBuilder.AppendInterpolatedStringHandler public void AppendFormatted(T value, string? format) => _builder!.AppendFormat(null, $"{{0:{format}}}", value); public void AppendFormatted(T value, int alignment) => _builder!.AppendFormat(null, $"{{0,{alignment}}}", value); @@ -68,13 +62,13 @@ internal void ComputeAssertion(string valueExpression) public void AppendFormatted(string? value) => _builder!.Append(value); -#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters -#pragma warning disable RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads +#pragma warning disable RS0026 +#pragma warning disable RS0027 public void AppendFormatted(string? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); public void AppendFormatted(object? value, int alignment = 0, string? format = null) => _builder!.AppendFormat(null, $"{{0,{alignment}:{format}}}", value); -#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters -#pragma warning restore RS0027 // API with optional parameter(s) should have the most parameters amongst its public overloads +#pragma warning restore RS0026 +#pragma warning restore RS0027 } [InterpolatedStringHandler] @@ -98,8 +92,7 @@ internal void ComputeAssertion(string valueExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "value", valueExpression) + " "); - ThrowAssertIsExactInstanceOfTypeFailed(_value, typeof(TArg), _builder.ToString()); + ThrowAssertIsExactInstanceOfTypeFailed(_value, typeof(TArg), _builder.ToString(), valueExpression); } } @@ -160,8 +153,7 @@ internal void ComputeAssertion(string valueExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "value", valueExpression) + " "); - ThrowAssertIsNotExactInstanceOfTypeFailed(_value, _wrongType, _builder.ToString()); + ThrowAssertIsNotExactInstanceOfTypeFailed(_value, _wrongType, _builder.ToString(), valueExpression); } } @@ -220,8 +212,7 @@ internal void ComputeAssertion(string valueExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "value", valueExpression) + " "); - ThrowAssertIsNotExactInstanceOfTypeFailed(_value, typeof(TArg), _builder.ToString()); + ThrowAssertIsNotExactInstanceOfTypeFailed(_value, typeof(TArg), _builder.ToString(), valueExpression); } } @@ -291,7 +282,7 @@ public static void IsExactInstanceOfType([NotNull] object? value, [NotNull] Type { if (IsExactInstanceOfTypeFailing(value, expectedType)) { - ThrowAssertIsExactInstanceOfTypeFailed(value, expectedType, BuildUserMessageForValueExpression(message, valueExpression)); + ThrowAssertIsExactInstanceOfTypeFailed(value, expectedType, message, valueExpression); } } @@ -329,20 +320,22 @@ private static bool IsExactInstanceOfTypeFailing([NotNullWhen(false)] object? va => expectedType is null || value is null || value.GetType() != expectedType; [DoesNotReturn] - private static void ThrowAssertIsExactInstanceOfTypeFailed(object? value, Type? expectedType, string userMessage) + private static void ThrowAssertIsExactInstanceOfTypeFailed(object? value, Type? expectedType, string? userMessage, string valueExpression) { - string finalMessage = userMessage; + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + if (expectedType is not null && value is not null) + { + message += Environment.NewLine + FrameworkMessages.IsExactInstanceOfTypeFailNew; + } + + message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (expectedType is not null && value is not null) { - finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsExactInstanceOfFailMsg, - userMessage, - expectedType.ToString(), - value.GetType().ToString()); + message += Environment.NewLine + $" expectedType: {expectedType}" + + Environment.NewLine + $" actualType: {value.GetType()}"; } - ThrowAssertFailed("Assert.IsExactInstanceOfType", finalMessage); + ThrowAssertFailed("Assert.IsExactInstanceOfType", message); } /// @@ -373,7 +366,7 @@ public static void IsNotExactInstanceOfType(object? value, [NotNull] Type? wrong { if (IsNotExactInstanceOfTypeFailing(value, wrongType)) { - ThrowAssertIsNotExactInstanceOfTypeFailed(value, wrongType, BuildUserMessageForValueExpression(message, valueExpression)); + ThrowAssertIsNotExactInstanceOfTypeFailed(value, wrongType, message, valueExpression); } } @@ -405,19 +398,21 @@ private static bool IsNotExactInstanceOfTypeFailing(object? value, [NotNullWhen( (value is not null && value.GetType() == wrongType); [DoesNotReturn] - private static void ThrowAssertIsNotExactInstanceOfTypeFailed(object? value, Type? wrongType, string userMessage) + private static void ThrowAssertIsNotExactInstanceOfTypeFailed(object? value, Type? wrongType, string? userMessage, string valueExpression) { - string finalMessage = userMessage; + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + if (wrongType is not null) + { + message += Environment.NewLine + FrameworkMessages.IsNotExactInstanceOfTypeFailNew; + } + + message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (wrongType is not null) { - finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsNotExactInstanceOfFailMsg, - userMessage, - wrongType.ToString(), - value!.GetType().ToString()); + message += Environment.NewLine + $" wrongType: {wrongType}" + + Environment.NewLine + $" actualType: {value!.GetType()}"; } - ThrowAssertFailed("Assert.IsNotExactInstanceOfType", finalMessage); + ThrowAssertFailed("Assert.IsNotExactInstanceOfType", message); } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index af72c579fa..f4b24d3137 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -12,21 +12,33 @@ public void ExactInstanceOfTypeShouldFailWhenValueIsNull() { Action action = () => Assert.IsExactInstanceOfType(null, typeof(AssertTests)); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: 'null'."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. + value: (null) +"""); } public void ExactInstanceOfTypeShouldFailWhenTypeIsNull() { Action action = () => Assert.IsExactInstanceOfType(5, null); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: '5'."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. + value: 5 +"""); } public void ExactInstanceOfTypeShouldFailWhenTypeIsMismatched() { Action action = () => Assert.IsExactInstanceOfType(5, typeof(string)); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: '5'. Expected exact type:. Actual type:."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. +Expected value to be exactly of the specified type. + value: 5 + expectedType: System.String + actualType: System.Int32 +"""); } public void ExactInstanceOfTypeShouldPassOnSameInstance() => Assert.IsExactInstanceOfType(5, typeof(int)); @@ -35,7 +47,13 @@ public void ExactInstanceOfTypeShouldFailOnHigherInstance() { Action action = () => Assert.IsExactInstanceOfType(5, typeof(object)); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: '5'. Expected exact type:. Actual type:."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. +Expected value to be exactly of the specified type. + value: 5 + expectedType: System.Object + actualType: System.Int32 +"""); } public void ExactInstanceOfTypeShouldFailOnDerivedType() @@ -43,7 +61,13 @@ public void ExactInstanceOfTypeShouldFailOnDerivedType() object x = new MemoryStream(); Action action = () => Assert.IsExactInstanceOfType(x, typeof(Stream)); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: 'x'. Expected exact type:. Actual type:."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. +Expected value to be exactly of the specified type. + value (x): + expectedType: System.IO.Stream + actualType: System.IO.MemoryStream +"""); } public void ExactInstanceOfTypeShouldPassOnExactType() @@ -56,21 +80,33 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() { Action action = () => Assert.IsExactInstanceOfType(null, typeof(AssertTests), "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: 'null'. User-provided message"); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. User-provided message + value: (null) +"""); } public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() { Action action = () => Assert.IsExactInstanceOfType(5, null, "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: '5'. User-provided message"); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. User-provided message + value: 5 +"""); } public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() { Action action = () => Assert.IsExactInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: '5'. User-provided message Expected exact type:. Actual type:."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. User-provided message +Expected value to be exactly of the specified type. + value: 5 + expectedType: System.String + actualType: System.Int32 +"""); } public void ExactInstanceOfType_WithStringMessage_ShouldPassWhenTypeIsCorrect() @@ -82,7 +118,10 @@ public async Task ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenValue DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsExactInstanceOfType(null, typeof(AssertTests), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsExactInstanceOfType failed. 'value' expression: 'null'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsExactInstanceOfType failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + value: (null) + """); o.WasToStringCalled.Should().BeTrue(); } @@ -91,7 +130,10 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull( DummyClassTrackingToStringCalls o = new(); Action action = () => Assert.IsExactInstanceOfType(5, null, $"User-provided message {o}"); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: '5'. User-provided message DummyClassTrackingToStringCalls"); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls + value: 5 +"""); o.WasToStringCalled.Should().BeTrue(); } @@ -100,7 +142,13 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMisma DummyClassTrackingToStringCalls o = new(); Action action = () => Assert.IsExactInstanceOfType(5, typeof(string), $"User-provided message {o}"); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: '5'. User-provided message DummyClassTrackingToStringCalls Expected exact type:. Actual type:."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls +Expected value to be exactly of the specified type. + value: 5 + expectedType: System.String + actualType: System.Int32 +"""); o.WasToStringCalled.Should().BeTrue(); } @@ -134,21 +182,36 @@ public void ExactInstanceNotOfTypeShouldFailOnExactType() object x = new MemoryStream(); Action action = () => Assert.IsNotExactInstanceOfType(x, typeof(MemoryStream)); action.Should().Throw() - .WithMessage("Assert.IsNotExactInstanceOfType failed. Wrong exact Type:. Actual type:. 'value' expression: 'x'."); + .WithMessage(""" +Assert.IsNotExactInstanceOfType failed. +Value should not be exactly of the specified type. + value (x): + wrongType: System.IO.MemoryStream + actualType: System.IO.MemoryStream +"""); } public void IsExactInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() { Action action = () => Assert.IsExactInstanceOfType(null); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: 'null'."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. + value: (null) +"""); } public void IsExactInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() { Action action = () => Assert.IsExactInstanceOfType(5); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: '5'. Expected exact type:. Actual type:."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. +Expected value to be exactly of the specified type. + value: 5 + expectedType: System.String + actualType: System.Int32 +"""); } public void IsExactInstanceOfTypeUsingGenericType_WhenDerivedType_Fails() @@ -156,7 +219,13 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenDerivedType_Fails() object x = new MemoryStream(); Action action = () => Assert.IsExactInstanceOfType(x); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: 'x'. Expected exact type:. Actual type:."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. +Expected value to be exactly of the specified type. + value (x): + expectedType: System.IO.Stream + actualType: System.IO.MemoryStream +"""); } public void IsExactInstanceOfTypeUsingGenericType_OnSameInstance_DoesNotThrow() => Assert.IsExactInstanceOfType(5); @@ -178,7 +247,13 @@ public void IsExactInstanceOfTypeUsingGenericType_OnHigherInstance_Fails() { Action action = () => Assert.IsExactInstanceOfType(5); action.Should().Throw() - .WithMessage("Assert.IsExactInstanceOfType failed. 'value' expression: '5'. Expected exact type:. Actual type:."); + .WithMessage(""" +Assert.IsExactInstanceOfType failed. +Expected value to be exactly of the specified type. + value: 5 + expectedType: System.Object + actualType: System.Int32 +"""); } public void IsExactInstanceOfTypeUsingGenericTypeWithReturn_OnExactType_DoesNotThrow() @@ -205,7 +280,13 @@ public void IsNotExactInstanceOfTypeUsingGenericType_OnExactType_Fails() object x = new MemoryStream(); Action action = () => Assert.IsNotExactInstanceOfType(x); action.Should().Throw() - .WithMessage("Assert.IsNotExactInstanceOfType failed. Wrong exact Type:. Actual type:. 'value' expression: 'x'."); + .WithMessage(""" +Assert.IsNotExactInstanceOfType failed. +Value should not be exactly of the specified type. + value (x): + wrongType: System.IO.MemoryStream + actualType: System.IO.MemoryStream +"""); } public void IsExactInstanceOfType_WhenNonNullNullableValue_LearnNonNull() @@ -277,4 +358,98 @@ public void IsNotExactInstanceOfType_WhenNonNullNullableTypeAndMessage_LearnNonN Assert.IsNotExactInstanceOfType(new object(), intType, "my message"); _ = intType.ToString(); // no warning about possible null } + + #region IsExactInstanceOfType/IsNotExactInstanceOfType truncation and newline escaping + + public void IsExactInstanceOfType_WithLongExpression_ShouldTruncateExpression() + { + object aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello"; + + Action action = () => Assert.IsExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(int)); + action.Should().Throw() + .WithMessage(""" + Assert.IsExactInstanceOfType failed. + Expected value to be exactly of the specified type. + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + expectedType: System.Int32 + actualType: System.String + """); + } + + public void IsExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() + { + var obj = new ObjectWithLongToString(); + + Action action = () => Assert.IsExactInstanceOfType(obj, typeof(int)); + action.Should().Throw() + .WithMessage($""" + Assert.IsExactInstanceOfType failed. + Expected value to be exactly of the specified type. + value (obj): {new string('L', 256)}... (300 chars) + expectedType: System.Int32 + actualType: *ObjectWithLongToString + """); + } + + public void IsExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() + { + var obj = new ObjectWithNewlineToString(); + + Action action = () => Assert.IsExactInstanceOfType(obj, typeof(int)); + action.Should().Throw() + .WithMessage(""" + Assert.IsExactInstanceOfType failed. + Expected value to be exactly of the specified type. + value (obj): line1\r\nline2\nline3 + expectedType: System.Int32 + actualType: *ObjectWithNewlineToString + """); + } + + public void IsNotExactInstanceOfType_WithLongExpression_ShouldTruncateExpression() + { + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello"; + + Action action = () => Assert.IsNotExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(string)); + action.Should().Throw() + .WithMessage(""" + Assert.IsNotExactInstanceOfType failed. + Value should not be exactly of the specified type. + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + wrongType: System.String + actualType: System.String + """); + } + + public void IsNotExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() + { + var obj = new ObjectWithLongToString(); + + Action action = () => Assert.IsNotExactInstanceOfType(obj, typeof(ObjectWithLongToString)); + action.Should().Throw() + .WithMessage($""" + Assert.IsNotExactInstanceOfType failed. + Value should not be exactly of the specified type. + value (obj): {new string('L', 256)}... (300 chars) + wrongType: *ObjectWithLongToString + actualType: *ObjectWithLongToString + """); + } + + public void IsNotExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() + { + var obj = new ObjectWithNewlineToString(); + + Action action = () => Assert.IsNotExactInstanceOfType(obj, typeof(ObjectWithNewlineToString)); + action.Should().Throw() + .WithMessage(""" + Assert.IsNotExactInstanceOfType failed. + Value should not be exactly of the specified type. + value (obj): line1\r\nline2\nline3 + wrongType: *ObjectWithNewlineToString + actualType: *ObjectWithNewlineToString + """); + } + + #endregion } From d35c33bf73fdf9c5432caf0a53f5daf528dda4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:53:03 +0100 Subject: [PATCH 08/58] Improve IComparable assertion error messages --- .../Assertions/Assert.IComparable.cs | 110 +++---- .../AssertTests.IComparableTests.cs | 270 +++++++++++++++++- 2 files changed, 307 insertions(+), 73 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs b/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs index a953f5cd33..c4cc5c3183 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs @@ -49,8 +49,7 @@ public static void IsGreaterThan(T lowerBound, T value, string? message = "", return; } - string userMessage = BuildUserMessageForLowerBoundExpressionAndValueExpression(message, lowerBoundExpression, valueExpression); - ThrowAssertIsGreaterThanFailed(lowerBound, value, userMessage); + ThrowAssertIsGreaterThanFailed(lowerBound, value, message, lowerBoundExpression, valueExpression); } #endregion // IsGreaterThan @@ -94,8 +93,7 @@ public static void IsGreaterThanOrEqualTo(T lowerBound, T value, string? mess return; } - string userMessage = BuildUserMessageForLowerBoundExpressionAndValueExpression(message, lowerBoundExpression, valueExpression); - ThrowAssertIsGreaterThanOrEqualToFailed(lowerBound, value, userMessage); + ThrowAssertIsGreaterThanOrEqualToFailed(lowerBound, value, message, lowerBoundExpression, valueExpression); } #endregion // IsGreaterThanOrEqualTo @@ -139,8 +137,7 @@ public static void IsLessThan(T upperBound, T value, string? message = "", [C return; } - string userMessage = BuildUserMessageForUpperBoundExpressionAndValueExpression(message, upperBoundExpression, valueExpression); - ThrowAssertIsLessThanFailed(upperBound, value, userMessage); + ThrowAssertIsLessThanFailed(upperBound, value, message, upperBoundExpression, valueExpression); } #endregion // IsLessThan @@ -184,8 +181,7 @@ public static void IsLessThanOrEqualTo(T upperBound, T value, string? message return; } - string userMessage = BuildUserMessageForUpperBoundExpressionAndValueExpression(message, upperBoundExpression, valueExpression); - ThrowAssertIsLessThanOrEqualToFailed(upperBound, value, userMessage); + ThrowAssertIsLessThanOrEqualToFailed(upperBound, value, message, upperBoundExpression, valueExpression); } #endregion // IsLessThanOrEqualTo @@ -221,15 +217,13 @@ public static void IsPositive(T value, string? message = "", [CallerArgumentE // Handle special case for floating point NaN values if (value is float.NaN) { - string userMessage = BuildUserMessageForValueExpression(message, valueExpression); - ThrowAssertIsPositiveFailed(value, userMessage); + ThrowAssertIsPositiveFailed(value, message, valueExpression); return; } if (value is double.NaN) { - string userMessage = BuildUserMessageForValueExpression(message, valueExpression); - ThrowAssertIsPositiveFailed(value, userMessage); + ThrowAssertIsPositiveFailed(value, message, valueExpression); return; } @@ -238,8 +232,7 @@ public static void IsPositive(T value, string? message = "", [CallerArgumentE return; } - string userMessage2 = BuildUserMessageForValueExpression(message, valueExpression); - ThrowAssertIsPositiveFailed(value, userMessage2); + ThrowAssertIsPositiveFailed(value, message, valueExpression); } #endregion // IsPositive @@ -275,15 +268,13 @@ public static void IsNegative(T value, string? message = "", [CallerArgumentE // Handle special case for floating point NaN values if (value is float.NaN) { - string userMessage = BuildUserMessageForValueExpression(message, valueExpression); - ThrowAssertIsNegativeFailed(value, userMessage); + ThrowAssertIsNegativeFailed(value, message, valueExpression); return; } if (value is double.NaN) { - string userMessage = BuildUserMessageForValueExpression(message, valueExpression); - ThrowAssertIsNegativeFailed(value, userMessage); + ThrowAssertIsNegativeFailed(value, message, valueExpression); return; } @@ -292,79 +283,66 @@ public static void IsNegative(T value, string? message = "", [CallerArgumentE return; } - string userMessage2 = BuildUserMessageForValueExpression(message, valueExpression); - ThrowAssertIsNegativeFailed(value, userMessage2); + ThrowAssertIsNegativeFailed(value, message, valueExpression); } #endregion // IsNegative [DoesNotReturn] - private static void ThrowAssertIsGreaterThanFailed(T lowerBound, T value, string userMessage) + private static void ThrowAssertIsGreaterThanFailed(T lowerBound, T value, string? userMessage, string lowerBoundExpression, string valueExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsGreaterThanFailMsg, - userMessage, - ReplaceNulls(lowerBound), - ReplaceNulls(value)); - ThrowAssertFailed("Assert.IsGreaterThan", finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + msg += Environment.NewLine + FrameworkMessages.IsGreaterThanFailNew; + msg += Environment.NewLine + FormatParameter(nameof(lowerBound), lowerBoundExpression, lowerBound) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.IsGreaterThan", msg); } [DoesNotReturn] - private static void ThrowAssertIsGreaterThanOrEqualToFailed(T lowerBound, T value, string userMessage) + private static void ThrowAssertIsGreaterThanOrEqualToFailed(T lowerBound, T value, string? userMessage, string lowerBoundExpression, string valueExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsGreaterThanOrEqualToFailMsg, - userMessage, - ReplaceNulls(lowerBound), - ReplaceNulls(value)); - ThrowAssertFailed("Assert.IsGreaterThanOrEqualTo", finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + msg += Environment.NewLine + FrameworkMessages.IsGreaterThanOrEqualToFailNew; + msg += Environment.NewLine + FormatParameter(nameof(lowerBound), lowerBoundExpression, lowerBound) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.IsGreaterThanOrEqualTo", msg); } [DoesNotReturn] - private static void ThrowAssertIsLessThanFailed(T upperBound, T value, string userMessage) + private static void ThrowAssertIsLessThanFailed(T upperBound, T value, string? userMessage, string upperBoundExpression, string valueExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsLessThanFailMsg, - userMessage, - ReplaceNulls(upperBound), - ReplaceNulls(value)); - ThrowAssertFailed("Assert.IsLessThan", finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + msg += Environment.NewLine + FrameworkMessages.IsLessThanFailNew; + msg += Environment.NewLine + FormatParameter(nameof(upperBound), upperBoundExpression, upperBound) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.IsLessThan", msg); } [DoesNotReturn] - private static void ThrowAssertIsLessThanOrEqualToFailed(T upperBound, T value, string userMessage) + private static void ThrowAssertIsLessThanOrEqualToFailed(T upperBound, T value, string? userMessage, string upperBoundExpression, string valueExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsLessThanOrEqualToFailMsg, - userMessage, - ReplaceNulls(upperBound), - ReplaceNulls(value)); - ThrowAssertFailed("Assert.IsLessThanOrEqualTo", finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + msg += Environment.NewLine + FrameworkMessages.IsLessThanOrEqualToFailNew; + msg += Environment.NewLine + FormatParameter(nameof(upperBound), upperBoundExpression, upperBound) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.IsLessThanOrEqualTo", msg); } [DoesNotReturn] - private static void ThrowAssertIsPositiveFailed(T value, string userMessage) + private static void ThrowAssertIsPositiveFailed(T value, string? userMessage, string valueExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsPositiveFailMsg, - userMessage, - ReplaceNulls(value)); - ThrowAssertFailed("Assert.IsPositive", finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + msg += Environment.NewLine + FrameworkMessages.IsPositiveFailNew; + msg += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.IsPositive", msg); } [DoesNotReturn] - private static void ThrowAssertIsNegativeFailed(T value, string userMessage) + private static void ThrowAssertIsNegativeFailed(T value, string? userMessage, string valueExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsNegativeFailMsg, - userMessage, - ReplaceNulls(value)); - ThrowAssertFailed("Assert.IsNegative", finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + msg += Environment.NewLine + FrameworkMessages.IsNegativeFailNew; + msg += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.IsNegative", msg); } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs index a574b23c53..7ff76afcb9 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -42,7 +42,12 @@ public void IsGreaterThanShouldThrowWithMessage() // Assert action.Should().Throw() - .WithMessage("Assert.IsGreaterThan failed. Actual value <5> is not greater than expected value <10>. 'lowerBound' expression: '10', 'value' expression: '5'. A Message"); + .WithMessage(""" + Assert.IsGreaterThan failed. A Message + Expected value to be greater than the specified bound. + lowerBound: 10 + value: 5 + """); } public void IsGreaterThanShouldWorkWithDoubles() => @@ -86,7 +91,12 @@ public void IsGreaterThanOrEqualToShouldThrowWithMessage() // Assert action.Should().Throw() - .WithMessage("Assert.IsGreaterThanOrEqualTo failed. Actual value <5> is not greater than or equal to expected value <10>. 'lowerBound' expression: '10', 'value' expression: '5'. A Message"); + .WithMessage(""" + Assert.IsGreaterThanOrEqualTo failed. A Message + Expected value to be greater than or equal to the specified bound. + lowerBound: 10 + value: 5 + """); } public void IsGreaterThanOrEqualToShouldWorkWithDoubles() => @@ -130,7 +140,12 @@ public void IsLessThanShouldThrowWithMessage() // Assert action.Should().Throw() - .WithMessage("Assert.IsLessThan failed. Actual value <10> is not less than expected value <5>. 'upperBound' expression: '5', 'value' expression: '10'. A Message"); + .WithMessage(""" + Assert.IsLessThan failed. A Message + Expected value to be less than the specified bound. + upperBound: 5 + value: 10 + """); } public void IsLessThanShouldWorkWithDoubles() => @@ -174,7 +189,12 @@ public void IsLessThanOrEqualToShouldThrowWithMessage() // Assert action.Should().Throw() - .WithMessage("Assert.IsLessThanOrEqualTo failed. Actual value <10> is not less than or equal to expected value <5>. 'upperBound' expression: '5', 'value' expression: '10'. A Message"); + .WithMessage(""" + Assert.IsLessThanOrEqualTo failed. A Message + Expected value to be less than or equal to the specified bound. + upperBound: 5 + value: 10 + """); } public void IsLessThanOrEqualToShouldWorkWithDoubles() => @@ -233,7 +253,11 @@ public void IsPositiveShouldThrowWithMessage() // Assert action.Should().Throw() - .WithMessage("Assert.IsPositive failed. Expected value <-5> to be positive. 'value' expression: '-5'. A Message"); + .WithMessage(""" + Assert.IsPositive failed. A Message + Expected a positive value. + value: -5 + """); } public void IsPositiveShouldWorkWithDoubles() => @@ -298,7 +322,11 @@ public void IsNegativeShouldThrowWithMessage() // Assert action.Should().Throw() - .WithMessage("Assert.IsNegative failed. Expected value <5> to be negative. 'value' expression: '5'. A Message"); + .WithMessage(""" + Assert.IsNegative failed. A Message + Expected a negative value. + value: 5 + """); } public void IsNegativeShouldWorkWithDoubles() => @@ -314,4 +342,232 @@ public void IsNegativeShouldThrowForZeroDouble() } #endregion + + #region IComparable truncation and newline escaping + + public void IsGreaterThan_WithLongExpression_ShouldTruncateExpression() + { + int aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = 10; + + Action action = () => Assert.IsGreaterThan(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 5); + action.Should().Throw() + .WithMessage(""" + Assert.IsGreaterThan failed. + Expected value to be greater than the specified bound. + lowerBound (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 10 + value: 5 + """); + } + + public void IsGreaterThan_WithLongToStringValue_ShouldTruncateValue() + { + var lowerBound = new ComparableWithLongToString(10); + var value = new ComparableWithLongToString(5); + + Action action = () => Assert.IsGreaterThan(lowerBound, value); + action.Should().Throw() + .WithMessage($""" + Assert.IsGreaterThan failed. + Expected value to be greater than the specified bound. + lowerBound: {new string('V', 256)}... (300 chars) + value: {new string('V', 256)}... (300 chars) + """); + } + + public void IsGreaterThan_WithNewlineInToString_ShouldEscapeNewlines() + { + var lowerBound = new ComparableWithNewlineToString(10); + var value = new ComparableWithNewlineToString(5); + + Action action = () => Assert.IsGreaterThan(lowerBound, value); + action.Should().Throw() + .WithMessage(""" + Assert.IsGreaterThan failed. + Expected value to be greater than the specified bound. + lowerBound: line1\r\nline2 + value: line1\r\nline2 + """); + } + + public void IsGreaterThanOrEqualTo_WithLongExpression_ShouldTruncateExpression() + { + int aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = 10; + + Action action = () => Assert.IsGreaterThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 5); + action.Should().Throw() + .WithMessage(""" + Assert.IsGreaterThanOrEqualTo failed. + Expected value to be greater than or equal to the specified bound. + lowerBound (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 10 + value: 5 + """); + } + + public void IsGreaterThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() + { + var lowerBound = new ComparableWithLongToString(10); + var value = new ComparableWithLongToString(5); + + Action action = () => Assert.IsGreaterThanOrEqualTo(lowerBound, value); + action.Should().Throw() + .WithMessage($""" + Assert.IsGreaterThanOrEqualTo failed. + Expected value to be greater than or equal to the specified bound. + lowerBound: {new string('V', 256)}... (300 chars) + value: {new string('V', 256)}... (300 chars) + """); + } + + public void IsGreaterThanOrEqualTo_WithNewlineInToString_ShouldEscapeNewlines() + { + var lowerBound = new ComparableWithNewlineToString(10); + var value = new ComparableWithNewlineToString(5); + + Action action = () => Assert.IsGreaterThanOrEqualTo(lowerBound, value); + action.Should().Throw() + .WithMessage(""" + Assert.IsGreaterThanOrEqualTo failed. + Expected value to be greater than or equal to the specified bound. + lowerBound: line1\r\nline2 + value: line1\r\nline2 + """); + } + + public void IsLessThan_WithLongExpression_ShouldTruncateExpression() + { + int aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = 5; + + Action action = () => Assert.IsLessThan(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 10); + action.Should().Throw() + .WithMessage(""" + Assert.IsLessThan failed. + Expected value to be less than the specified bound. + upperBound (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 5 + value: 10 + """); + } + + public void IsLessThan_WithLongToStringValue_ShouldTruncateValue() + { + var upperBound = new ComparableWithLongToString(5); + var value = new ComparableWithLongToString(10); + + Action action = () => Assert.IsLessThan(upperBound, value); + action.Should().Throw() + .WithMessage($""" + Assert.IsLessThan failed. + Expected value to be less than the specified bound. + upperBound: {new string('V', 256)}... (300 chars) + value: {new string('V', 256)}... (300 chars) + """); + } + + public void IsLessThan_WithNewlineInToString_ShouldEscapeNewlines() + { + var upperBound = new ComparableWithNewlineToString(5); + var value = new ComparableWithNewlineToString(10); + + Action action = () => Assert.IsLessThan(upperBound, value); + action.Should().Throw() + .WithMessage(""" + Assert.IsLessThan failed. + Expected value to be less than the specified bound. + upperBound: line1\r\nline2 + value: line1\r\nline2 + """); + } + + public void IsLessThanOrEqualTo_WithLongExpression_ShouldTruncateExpression() + { + int aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = 5; + + Action action = () => Assert.IsLessThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 10); + action.Should().Throw() + .WithMessage(""" + Assert.IsLessThanOrEqualTo failed. + Expected value to be less than or equal to the specified bound. + upperBound (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 5 + value: 10 + """); + } + + public void IsLessThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() + { + var upperBound = new ComparableWithLongToString(5); + var value = new ComparableWithLongToString(10); + + Action action = () => Assert.IsLessThanOrEqualTo(upperBound, value); + action.Should().Throw() + .WithMessage($""" + Assert.IsLessThanOrEqualTo failed. + Expected value to be less than or equal to the specified bound. + upperBound: {new string('V', 256)}... (300 chars) + value: {new string('V', 256)}... (300 chars) + """); + } + + public void IsLessThanOrEqualTo_WithNewlineInToString_ShouldEscapeNewlines() + { + var upperBound = new ComparableWithNewlineToString(5); + var value = new ComparableWithNewlineToString(10); + + Action action = () => Assert.IsLessThanOrEqualTo(upperBound, value); + action.Should().Throw() + .WithMessage(""" + Assert.IsLessThanOrEqualTo failed. + Expected value to be less than or equal to the specified bound. + upperBound: line1\r\nline2 + value: line1\r\nline2 + """); + } + + public void IsPositive_WithLongExpression_ShouldTruncateExpression() + { + int aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = -5; + + Action action = () => Assert.IsPositive(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.IsPositive failed. + Expected a positive value. + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): -5 + """); + } + + public void IsNegative_WithLongExpression_ShouldTruncateExpression() + { + int aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = 5; + + Action action = () => Assert.IsNegative(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.IsNegative failed. + Expected a negative value. + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 5 + """); + } + + #endregion + + private sealed class ComparableWithLongToString : IComparable + { + private readonly int _value; + + public ComparableWithLongToString(int value) => _value = value; + + public int CompareTo(ComparableWithLongToString? other) => _value.CompareTo(other?._value ?? 0); + + public override string ToString() => new string('V', 300); + } + + private sealed class ComparableWithNewlineToString : IComparable + { + private readonly int _value; + + public ComparableWithNewlineToString(int value) => _value = value; + + public int CompareTo(ComparableWithNewlineToString? other) => _value.CompareTo(other?._value ?? 0); + + public override string ToString() => "line1\r\nline2"; + } } From 23758d2a89e61c102ced14f1ea980660131da868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:53:09 +0100 Subject: [PATCH 09/58] Improve HasCount/IsEmpty/IsNotEmpty assertion error messages --- .../TestFramework/Assertions/Assert.Count.cs | 44 ++++----- .../Assertions/AssertTests.Items.cs | 92 ++++++++++++++++--- 2 files changed, 98 insertions(+), 38 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs index 555d341686..80e29e1a5e 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs @@ -20,6 +20,7 @@ public readonly struct AssertCountInterpolatedStringHandler private readonly StringBuilder? _builder; private readonly int _expectedCount; private readonly int _actualCount; + private readonly IEnumerable? _collection; public AssertCountInterpolatedStringHandler(int literalLength, int formattedCount, int count, IEnumerable collection, out bool shouldAppend) { @@ -29,6 +30,7 @@ public AssertCountInterpolatedStringHandler(int literalLength, int formattedCoun if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _collection = collection; } } @@ -40,6 +42,7 @@ public AssertCountInterpolatedStringHandler(int literalLength, int formattedCoun if (shouldAppend) { _builder = new StringBuilder(literalLength + formattedCount); + _collection = collection; } } @@ -47,8 +50,7 @@ internal void ComputeAssertion(string assertionName, string collectionExpression { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "collection", collectionExpression) + " "); - ThrowAssertCountFailed(assertionName, _expectedCount, _actualCount, _builder.ToString()); + ThrowAssertCountFailed(assertionName, _expectedCount, _actualCount, _collection!, _builder.ToString(), collectionExpression); } } @@ -115,8 +117,7 @@ internal void ComputeAssertion(string collectionExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "collection", collectionExpression) + " "); - ThrowAssertIsNotEmptyFailed(_builder.ToString()); + ThrowAssertIsNotEmptyFailed(_builder.ToString(), collectionExpression); } } @@ -202,8 +203,7 @@ public static void IsNotEmpty(IEnumerable collection, string? message = "" return; } - string userMessage = BuildUserMessageForCollectionExpression(message, collectionExpression); - ThrowAssertIsNotEmptyFailed(userMessage); + ThrowAssertIsNotEmptyFailed(message, collectionExpression); } /// @@ -222,8 +222,7 @@ public static void IsNotEmpty(IEnumerable collection, string? message = "", [Cal return; } - string userMessage = BuildUserMessageForCollectionExpression(message, collectionExpression); - ThrowAssertIsNotEmptyFailed(userMessage); + ThrowAssertIsNotEmptyFailed(message, collectionExpression); } #endregion // IsNotEmpty @@ -326,32 +325,29 @@ private static void HasCount(string assertionName, int expected, IEnumerable< return; } - string userMessage = BuildUserMessageForCollectionExpression(message, collectionExpression); - ThrowAssertCountFailed(assertionName, expected, actualCount, userMessage); + ThrowAssertCountFailed(assertionName, expected, actualCount, collection, message, collectionExpression); } private static void HasCount(string assertionName, int expected, IEnumerable collection, string? message, string collectionExpression) => HasCount(assertionName, expected, collection.Cast(), message, collectionExpression); [DoesNotReturn] - private static void ThrowAssertCountFailed(string assertionName, int expectedCount, int actualCount, string userMessage) + private static void ThrowAssertCountFailed(string assertionName, int expectedCount, int actualCount, IEnumerable collection, string? userMessage, string collectionExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.HasCountFailMsg, - userMessage, - expectedCount, - actualCount); - ThrowAssertFailed($"Assert.{assertionName}", finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + msg += Environment.NewLine + FrameworkMessages.HasCountFailNew; + msg += FormatCollectionParameter(nameof(collection), collectionExpression, collection); + msg += $"{Environment.NewLine} expectedCount: {expectedCount}"; + msg += $"{Environment.NewLine} actualCount: {actualCount}"; + ThrowAssertFailed($"Assert.{assertionName}", msg); } [DoesNotReturn] - private static void ThrowAssertIsNotEmptyFailed(string userMessage) + private static void ThrowAssertIsNotEmptyFailed(string? userMessage, string collectionExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsNotEmptyFailMsg, - userMessage); - ThrowAssertFailed("Assert.IsNotEmpty", finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + msg += Environment.NewLine + FrameworkMessages.IsNotEmptyFailNew; + msg += FormatExpressionParameter("collection", collectionExpression); + ThrowAssertFailed("Assert.IsNotEmpty", msg); } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs index 98a5160f29..8ef140805b 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs @@ -25,7 +25,13 @@ public void Count_WhenCountIsNotSame_ShouldFail() var collection = new List { 1 }; Action action = () => Assert.HasCount(3, collection); action.Should().Throw() - .WithMessage("Assert.HasCount failed. Expected collection of size 3. Actual: 1. 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.HasCount failed. + Expected collection to have the specified number of elements. + collection: [1] (1 element) + expectedCount: 3 + actualCount: 1 + """); } public async Task Count_InterpolatedString_WhenCountIsNotSame_ShouldFail() @@ -34,7 +40,13 @@ public async Task Count_InterpolatedString_WhenCountIsNotSame_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.HasCount(1, Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.HasCount failed. Expected collection of size 1. Actual: 0. 'collection' expression: 'Array.Empty()'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.HasCount failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected collection to have the specified number of elements. + collection (Array.Empty()): [] (0 elements) + expectedCount: 1 + actualCount: 0 + """); o.WasToStringCalled.Should().BeTrue(); } @@ -53,7 +65,13 @@ public void NotAny_WhenNotEmpty_ShouldFail() var collection = new List { 1 }; Action action = () => Assert.IsEmpty(collection); action.Should().Throw() - .WithMessage("Assert.IsEmpty failed. Expected collection of size 0. Actual: 1. 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.IsEmpty failed. + Expected collection to have the specified number of elements. + collection: [1] (1 element) + expectedCount: 0 + actualCount: 1 + """); } public async Task NotAny_InterpolatedString_WhenNotEmpty_ShouldFail() @@ -63,7 +81,13 @@ public async Task NotAny_InterpolatedString_WhenNotEmpty_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsEmpty(collection, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsEmpty failed. Expected collection of size 0. Actual: 1. 'collection' expression: 'collection'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsEmpty failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected collection to have the specified number of elements. + collection: [1] (1 element) + expectedCount: 0 + actualCount: 1 + """); o.WasToStringCalled.Should().BeTrue(); } @@ -86,14 +110,22 @@ public void Single_WhenNoItems_ShouldFail() { Action action = () => Assert.ContainsSingle(Array.Empty()); action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected collection to contain exactly one element but found 0 element(s). 'collection' expression: 'Array.Empty()'."); + .WithMessage(""" + Assert.ContainsSingle failed. + Expected collection to contain exactly one element but found 0 element(s). + collection: Array.Empty() + """); } public void Single_WhenMultipleItems_ShouldFail() { Action action = () => Assert.ContainsSingle([1, 2, 3]); action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected collection to contain exactly one element but found 3 element(s). 'collection' expression: '[1, 2, 3]'."); + .WithMessage(""" + Assert.ContainsSingle failed. + Expected collection to contain exactly one element but found 3 element(s). + collection: [1, 2, 3] + """); } public async Task Single_InterpolatedString_WhenNoItem_ShouldFail() @@ -102,7 +134,11 @@ public async Task Single_InterpolatedString_WhenNoItem_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.ContainsSingle(Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.ContainsSingle failed. Expected collection to contain exactly one element but found 0 element(s). 'collection' expression: 'Array.Empty()'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.ContainsSingle failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected collection to contain exactly one element but found 0 element(s). + collection: Array.Empty() + """); o.WasToStringCalled.Should().BeTrue(); } @@ -112,7 +148,11 @@ public async Task Single_InterpolatedString_WhenMultipleItems_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.ContainsSingle([1, 2, 3], $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.ContainsSingle failed. Expected collection to contain exactly one element but found 3 element(s). 'collection' expression: '[1, 2, 3]'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.ContainsSingle failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected collection to contain exactly one element but found 3 element(s). + collection: [1, 2, 3] + """); o.WasToStringCalled.Should().BeTrue(); } @@ -137,7 +177,11 @@ public void SinglePredicate_WhenNoItemMatches_ShouldFail() var collection = new List { 1, 3, 5 }; Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection); action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 0 item(s). 'predicate' expression: 'x => x % 2 == 0', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.ContainsSingle failed. + Expected exactly one item to match the predicate but found 0 item(s). + predicate: x => x % 2 == 0 + """); } public void SinglePredicate_WhenMultipleItemsMatch_ShouldFail() @@ -145,7 +189,11 @@ public void SinglePredicate_WhenMultipleItemsMatch_ShouldFail() var collection = new List { 2, 4, 6 }; Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection); action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 3 item(s). 'predicate' expression: 'x => x % 2 == 0', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.ContainsSingle failed. + Expected exactly one item to match the predicate but found 3 item(s). + predicate: x => x % 2 == 0 + """); } public void SinglePredicate_Message_WhenNoItemMatches_ShouldFail() @@ -153,7 +201,11 @@ public void SinglePredicate_Message_WhenNoItemMatches_ShouldFail() var collection = new List { 1, 3, 5 }; Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection, "No even numbers found: test"); action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 0 item(s). 'predicate' expression: 'x => x % 2 == 0', 'collection' expression: 'collection'. No even numbers found: test"); + .WithMessage(""" + Assert.ContainsSingle failed. No even numbers found: test + Expected exactly one item to match the predicate but found 0 item(s). + predicate: x => x % 2 == 0 + """); } public void SinglePredicate_Message_WhenMultipleItemsMatch_ShouldFail() @@ -161,7 +213,11 @@ public void SinglePredicate_Message_WhenMultipleItemsMatch_ShouldFail() var collection = new List { 2, 4, 6 }; Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection, "Too many even numbers: test"); action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 3 item(s). 'predicate' expression: 'x => x % 2 == 0', 'collection' expression: 'collection'. Too many even numbers: test"); + .WithMessage(""" + Assert.ContainsSingle failed. Too many even numbers: test + Expected exactly one item to match the predicate but found 3 item(s). + predicate: x => x % 2 == 0 + """); } public void Any_WhenOneItem_ShouldPass() @@ -194,7 +250,11 @@ public void Any_WhenNoItem_ShouldFail() { Action action = () => Assert.IsNotEmpty(Array.Empty()); action.Should().Throw() - .WithMessage("Assert.IsNotEmpty failed. Expected collection to contain any item but it is empty. 'collection' expression: 'Array.Empty()'."); + .WithMessage(""" + Assert.IsNotEmpty failed. + Expected collection to contain any item but it is empty. + collection: Array.Empty() + """); } public async Task Any_InterpolatedString_WhenNoItem_ShouldFail() @@ -203,7 +263,11 @@ public async Task Any_InterpolatedString_WhenNoItem_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.IsNotEmpty(Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) - .WithMessage($"Assert.IsNotEmpty failed. Expected collection to contain any item but it is empty. 'collection' expression: 'Array.Empty()'. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {string.Format(null, "{0:tt}", dateTime)}, {string.Format(null, "{0,5:tt}", dateTime)}"); + .WithMessage(""" + Assert.IsNotEmpty failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected collection to contain any item but it is empty. + collection: Array.Empty() + """); o.WasToStringCalled.Should().BeTrue(); } } From 3705c74453841aedf5fd2befe235844ff6b66b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:53:16 +0100 Subject: [PATCH 10/58] Improve ThrowsException assertion error messages --- .../Assertions/Assert.ThrowsException.cs | 76 +++++++++---------- .../AssertTests.ThrowsExceptionTests.cs | 76 ++++++++++++++++--- 2 files changed, 101 insertions(+), 51 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index b5478a28a6..108330d4df 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -42,8 +42,7 @@ internal TException ComputeAssertion(string actionExpression) { if (_state.FailAction is not null) { - _builder!.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "action", actionExpression) + " "); - _state.FailAction(_builder!.ToString()); + _state.FailAction(_builder!.ToString(), actionExpression); } else { @@ -113,8 +112,7 @@ internal TException ComputeAssertion(string actionExpression) { if (_state.FailAction is not null) { - _builder!.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "action", actionExpression) + " "); - _state.FailAction(_builder!.ToString()); + _state.FailAction(_builder!.ToString(), actionExpression); } else { @@ -327,7 +325,7 @@ private static TException ThrowsException(Action action, bool isStri ThrowsExceptionState state = IsThrowsFailing(action, isStrictType, assertMethodName); if (state.FailAction is not null) { - state.FailAction(BuildUserMessageForActionExpression(message, actionExpression)); + state.FailAction(message ?? string.Empty, actionExpression); } else { @@ -347,7 +345,7 @@ private static TException ThrowsException(Action action, bool isStri ThrowsExceptionState state = IsThrowsFailing(action, isStrictType, assertMethodName); if (state.FailAction is not null) { - state.FailAction(BuildUserMessageForActionExpression(messageBuilder(state.ExceptionThrown), actionExpression)); + state.FailAction(messageBuilder(state.ExceptionThrown), actionExpression); } else { @@ -483,7 +481,7 @@ private static async Task ThrowsExceptionAsync(Func(action, isStrictType, assertMethodName).ConfigureAwait(false); if (state.FailAction is not null) { - state.FailAction(BuildUserMessageForActionExpression(message, actionExpression)); + state.FailAction(message ?? string.Empty, actionExpression); } else { @@ -503,7 +501,7 @@ private static async Task ThrowsExceptionAsync(Func(action, isStrictType, assertMethodName).ConfigureAwait(false); if (state.FailAction is not null) { - state.FailAction(BuildUserMessageForActionExpression(messageBuilder(state.ExceptionThrown), actionExpression)); + state.FailAction(messageBuilder(state.ExceptionThrown), actionExpression); } else { @@ -530,27 +528,25 @@ private static async Task IsThrowsAsyncFailingAsync + (userMessage, actionExpr) => { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.WrongExceptionThrown, - userMessage, - typeof(TException), - ex.GetType()); - ThrowAssertFailed("Assert." + assertMethodName, finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; + msg += Environment.NewLine + FrameworkMessages.WrongExceptionThrownNew; + msg += FormatExpressionParameter(nameof(action), actionExpr); + msg += Environment.NewLine + $" expectedExceptionType: {typeof(TException)}"; + msg += Environment.NewLine + $" actualExceptionType: {ex.GetType()}"; + ThrowAssertFailed("Assert." + assertMethodName, msg); }, ex); } return ThrowsExceptionState.CreateFailingState( - failAction: userMessage => + failAction: (userMessage, actionExpr) => { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.NoExceptionThrown, - userMessage, - typeof(TException)); - ThrowAssertFailed("Assert." + assertMethodName, finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; + msg += Environment.NewLine + FrameworkMessages.NoExceptionThrownNew; + msg += FormatExpressionParameter(nameof(action), actionExpr); + msg += Environment.NewLine + $" expectedExceptionType: {typeof(TException)}"; + ThrowAssertFailed("Assert." + assertMethodName, msg); }, null); } @@ -570,27 +566,25 @@ private static ThrowsExceptionState IsThrowsFailing(Action action, b return isExceptionOfType ? ThrowsExceptionState.CreateNotFailingState(ex) : ThrowsExceptionState.CreateFailingState( - userMessage => + (userMessage, actionExpr) => { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.WrongExceptionThrown, - userMessage, - typeof(TException), - ex.GetType()); - ThrowAssertFailed("Assert." + assertMethodName, finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; + msg += Environment.NewLine + FrameworkMessages.WrongExceptionThrownNew; + msg += FormatExpressionParameter(nameof(action), actionExpr); + msg += Environment.NewLine + $" expectedExceptionType: {typeof(TException)}"; + msg += Environment.NewLine + $" actualExceptionType: {ex.GetType()}"; + ThrowAssertFailed("Assert." + assertMethodName, msg); }, ex); } return ThrowsExceptionState.CreateFailingState( - failAction: userMessage => + failAction: (userMessage, actionExpr) => { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.NoExceptionThrown, - userMessage, - typeof(TException)); - ThrowAssertFailed("Assert." + assertMethodName, finalMessage); + string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; + msg += Environment.NewLine + FrameworkMessages.NoExceptionThrownNew; + msg += FormatExpressionParameter(nameof(action), actionExpr); + msg += Environment.NewLine + $" expectedExceptionType: {typeof(TException)}"; + ThrowAssertFailed("Assert." + assertMethodName, msg); }, null); } @@ -598,9 +592,9 @@ private readonly struct ThrowsExceptionState { public Exception? ExceptionThrown { get; } - public Action? FailAction { get; } + public Action? FailAction { get; } - private ThrowsExceptionState(Exception? exceptionThrown, Action? failAction) + private ThrowsExceptionState(Exception? exceptionThrown, Action? failAction) { // If the assert is failing, failAction should be non-null, and exceptionWhenNotFailing may or may not be null. // If the assert is not failing, exceptionWhenNotFailing should be non-null, and failAction should be null. @@ -608,7 +602,7 @@ private ThrowsExceptionState(Exception? exceptionThrown, Action? failAct FailAction = failAction; } - public static ThrowsExceptionState CreateFailingState(Action failAction, Exception? exceptionThrown) + public static ThrowsExceptionState CreateFailingState(Action failAction, Exception? exceptionThrown) => new(exceptionThrown, failAction); public static ThrowsExceptionState CreateNotFailingState(Exception exception) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs index c41eba3302..4b9af24404 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs @@ -70,7 +70,13 @@ public void ThrowsAsync_WhenExceptionIsNotExpectedType_ShouldThrow() Action action = t.Wait; action.Should().Throw() .WithInnerException() - .WithMessage("Assert.ThrowsAsync failed. Expected exception type:. Actual exception type:. 'action' expression: '() => throw new Exception()'."); + .WithMessage(""" + Assert.ThrowsAsync failed. + Wrong exception type was thrown. + action: () => throw new Exception() + expectedExceptionType: System.ArgumentException + actualExceptionType: System.Exception + """); } public void ThrowsExactlyAsync_WhenExceptionIsDerivedFromExpectedType_ShouldThrow() @@ -79,7 +85,13 @@ public void ThrowsExactlyAsync_WhenExceptionIsDerivedFromExpectedType_ShouldThro Action action = t.Wait; action.Should().Throw() .WithInnerException() - .WithMessage("Assert.ThrowsExactlyAsync failed. Expected exception type:. Actual exception type:. 'action' expression: '() => throw new ArgumentNullException()'."); + .WithMessage(""" + Assert.ThrowsExactlyAsync failed. + Wrong exception type was thrown. + action: () => throw new ArgumentNullException() + expectedExceptionType: System.ArgumentException + actualExceptionType: System.ArgumentNullException + """); } public void Throws_WithMessageBuilder_Passes() @@ -105,7 +117,12 @@ public void Throws_WithMessageBuilder_FailsBecauseNoException() return "message constructed via builder."; }); action.Should().Throw() - .WithMessage("Assert.Throws failed. Expected exception type: but no exception was thrown. 'action' expression: '() => { }'. message constructed via builder."); + .WithMessage(""" + Assert.Throws failed. message constructed via builder. + No exception was thrown. + action: () => { } + expectedExceptionType: System.ArgumentNullException + """); wasBuilderCalled.Should().BeTrue(); exceptionPassedToBuilder.Should().BeNull(); @@ -122,7 +139,13 @@ public void Throws_WithMessageBuilder_FailsBecauseTypeMismatch() return "message constructed via builder."; }); action.Should().Throw() - .WithMessage("Assert.Throws failed. Expected exception type:. Actual exception type:. 'action' expression: '() => throw new ArgumentOutOfRangeException(\"MyParamNameHere\")'. message constructed via builder."); + .WithMessage(""" + Assert.Throws failed. message constructed via builder. + Wrong exception type was thrown. + action: () => throw new ArgumentOutOfRangeException("MyParamNameHere") + expectedExceptionType: System.ArgumentNullException + actualExceptionType: System.ArgumentOutOfRangeException + """); wasBuilderCalled.Should().BeTrue(); exceptionPassedToBuilder.Should().BeOfType(); @@ -152,7 +175,12 @@ public void ThrowsExactly_WithMessageBuilder_FailsBecauseNoException() return "message constructed via builder."; }); action.Should().Throw() - .WithMessage("Assert.ThrowsExactly failed. Expected exception type: but no exception was thrown. 'action' expression: '() => { }'. message constructed via builder."); + .WithMessage(""" + Assert.ThrowsExactly failed. message constructed via builder. + No exception was thrown. + action: () => { } + expectedExceptionType: System.ArgumentNullException + """); wasBuilderCalled.Should().BeTrue(); exceptionPassedToBuilder.Should().BeNull(); @@ -169,7 +197,13 @@ public void ThrowsExactly_WithMessageBuilder_FailsBecauseTypeMismatch() return "message constructed via builder."; }); action.Should().Throw() - .WithMessage("Assert.ThrowsExactly failed. Expected exception type:. Actual exception type:. 'action' expression: '() => throw new ArgumentOutOfRangeException(\"MyParamNameHere\")'. message constructed via builder."); + .WithMessage(""" + Assert.ThrowsExactly failed. message constructed via builder. + Wrong exception type was thrown. + action: () => throw new ArgumentOutOfRangeException("MyParamNameHere") + expectedExceptionType: System.ArgumentNullException + actualExceptionType: System.ArgumentOutOfRangeException + """); wasBuilderCalled.Should().BeTrue(); exceptionPassedToBuilder.Should().BeOfType(); @@ -199,7 +233,12 @@ public async Task ThrowsAsync_WithMessageBuilder_FailsBecauseNoException() return "message constructed via builder."; }); (await action.Should().ThrowAsync()) - .WithMessage("Assert.ThrowsAsync failed. Expected exception type: but no exception was thrown. 'action' expression: '() => Task.CompletedTask'. message constructed via builder."); + .WithMessage(""" + Assert.ThrowsAsync failed. message constructed via builder. + No exception was thrown. + action: () => Task.CompletedTask + expectedExceptionType: System.ArgumentNullException + """); wasBuilderCalled.Should().BeTrue(); exceptionPassedToBuilder.Should().BeNull(); @@ -216,7 +255,13 @@ public async Task ThrowsAsync_WithMessageBuilder_FailsBecauseTypeMismatch() return "message constructed via builder."; }); (await action.Should().ThrowAsync()) - .WithMessage("Assert.ThrowsAsync failed. Expected exception type:. Actual exception type:. 'action' expression: '() => Task.FromException(new ArgumentOutOfRangeException(\"MyParamNameHere\"))'. message constructed via builder."); + .WithMessage(""" + Assert.ThrowsAsync failed. message constructed via builder. + Wrong exception type was thrown. + action: () => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere")) + expectedExceptionType: System.ArgumentNullException + actualExceptionType: System.ArgumentOutOfRangeException + """); wasBuilderCalled.Should().BeTrue(); exceptionPassedToBuilder.Should().BeOfType(); @@ -246,7 +291,12 @@ public async Task ThrowsExactlyAsync_WithMessageBuilder_FailsBecauseNoException( return "message constructed via builder."; }); (await action.Should().ThrowAsync()) - .WithMessage("Assert.ThrowsExactlyAsync failed. Expected exception type: but no exception was thrown. 'action' expression: '() => Task.CompletedTask'. message constructed via builder."); + .WithMessage(""" + Assert.ThrowsExactlyAsync failed. message constructed via builder. + No exception was thrown. + action: () => Task.CompletedTask + expectedExceptionType: System.ArgumentNullException + """); wasBuilderCalled.Should().BeTrue(); exceptionPassedToBuilder.Should().BeNull(); @@ -263,7 +313,13 @@ public async Task ThrowsExactlyAsync_WithMessageBuilder_FailsBecauseTypeMismatch return "message constructed via builder."; }); (await action.Should().ThrowAsync()) - .WithMessage("Assert.ThrowsExactlyAsync failed. Expected exception type:. Actual exception type:. 'action' expression: '() => Task.FromException(new ArgumentOutOfRangeException(\"MyParamNameHere\"))'. message constructed via builder."); + .WithMessage(""" + Assert.ThrowsExactlyAsync failed. message constructed via builder. + Wrong exception type was thrown. + action: () => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere")) + expectedExceptionType: System.ArgumentNullException + actualExceptionType: System.ArgumentOutOfRangeException + """); wasBuilderCalled.Should().BeTrue(); exceptionPassedToBuilder.Should().BeOfType(); From 23cd6274d2d6ba9d84525fab26e44f9dade655db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:53:29 +0100 Subject: [PATCH 11/58] Improve Contains/DoesNotContain/IsInRange assertion error messages --- .../Assertions/Assert.Contains.cs | 199 ++++++----- .../Assertions/AssertTests.Contains.cs | 313 ++++++++++++++++-- .../Assertions/AssertTests.IsInRange.cs | 172 +++++++++- 3 files changed, 552 insertions(+), 132 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs index 819452d1f4..fa44866baa 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs @@ -39,8 +39,7 @@ internal TItem ComputeAssertion(string collectionExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "collection", collectionExpression) + " "); - ThrowAssertContainsSingleFailed(_actualCount, _builder.ToString()); + ThrowAssertContainsSingleFailed(_actualCount, _builder.ToString(), collectionExpression); } return _item!; @@ -164,13 +163,11 @@ public static T ContainsSingle(Func predicate, IEnumerable collec if (string.IsNullOrEmpty(predicateExpression)) { - string userMessage = BuildUserMessageForCollectionExpression(message, collectionExpression); - ThrowAssertContainsSingleFailed(actualCount, userMessage); + ThrowAssertContainsSingleFailed(actualCount, message, collectionExpression); } else { - string userMessage = BuildUserMessageForPredicateExpressionAndCollectionExpression(message, predicateExpression, collectionExpression); - ThrowAssertSingleMatchFailed(actualCount, userMessage); + ThrowAssertSingleMatchFailed(actualCount, message, predicateExpression, collectionExpression); } // Unreachable code but compiler cannot work it out @@ -225,13 +222,11 @@ public static T ContainsSingle(Func predicate, IEnumerable collec if (string.IsNullOrEmpty(predicateExpression)) { - string userMessage = BuildUserMessageForCollectionExpression(message, collectionExpression); - ThrowAssertContainsSingleFailed(matchCount, userMessage); + ThrowAssertContainsSingleFailed(matchCount, message, collectionExpression); } else { - string userMessage = BuildUserMessageForPredicateExpressionAndCollectionExpression(message, predicateExpression, collectionExpression); - ThrowAssertSingleMatchFailed(matchCount, userMessage); + ThrowAssertSingleMatchFailed(matchCount, message, predicateExpression, collectionExpression); } return default; @@ -260,8 +255,7 @@ public static void Contains(T expected, IEnumerable collection, string? me { if (!collection.Contains(expected)) { - string userMessage = BuildUserMessageForExpectedExpressionAndCollectionExpression(message, expectedExpression, collectionExpression); - ThrowAssertContainsItemFailed(userMessage); + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, collection); } } @@ -291,8 +285,7 @@ public static void Contains(object? expected, IEnumerable collection, string? me } } - string userMessage = BuildUserMessageForExpectedExpressionAndCollectionExpression(message, expectedExpression, collectionExpression); - ThrowAssertContainsItemFailed(userMessage); + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, collection); } /// @@ -315,8 +308,7 @@ public static void Contains(T expected, IEnumerable collection, IEqualityC { if (!collection.Contains(expected, comparer)) { - string userMessage = BuildUserMessageForExpectedExpressionAndCollectionExpression(message, expectedExpression, collectionExpression); - ThrowAssertContainsItemFailed(userMessage); + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, collection); } } @@ -348,8 +340,7 @@ public static void Contains(object? expected, IEnumerable collection, IEqualityC } } - string userMessage = BuildUserMessageForExpectedExpressionAndCollectionExpression(message, expectedExpression, collectionExpression); - ThrowAssertContainsItemFailed(userMessage); + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, collection); } /// @@ -371,8 +362,7 @@ public static void Contains(Func predicate, IEnumerable collectio { if (!collection.Any(predicate)) { - string userMessage = BuildUserMessageForPredicateExpressionAndCollectionExpression(message, predicateExpression, collectionExpression); - ThrowAssertContainsPredicateFailed(userMessage); + ThrowAssertContainsPredicateFailed(message, predicateExpression, collectionExpression, collection); } } @@ -403,8 +393,7 @@ public static void Contains(Func predicate, IEnumerable collectio } } - string userMessage = BuildUserMessageForPredicateExpressionAndCollectionExpression(message, predicateExpression, collectionExpression); - ThrowAssertContainsPredicateFailed(userMessage); + ThrowAssertContainsPredicateFailed(message, predicateExpression, collectionExpression, collection); } /// @@ -476,9 +465,7 @@ public static void Contains(string substring, string value, StringComparison com if (!value.Contains(substring, comparisonType)) { - string userMessage = BuildUserMessageForSubstringExpressionAndValueExpression(message, substringExpression, valueExpression); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsFail, value, substring, userMessage); - ThrowAssertFailed("Assert.Contains", finalMessage); + ThrowAssertStringContainsFailed(value, substring, message, substringExpression, valueExpression); } } @@ -505,8 +492,7 @@ public static void DoesNotContain(T notExpected, IEnumerable collection, s { if (collection.Contains(notExpected)) { - string userMessage = BuildUserMessageForNotExpectedExpressionAndCollectionExpression(message, notExpectedExpression, collectionExpression); - ThrowAssertDoesNotContainItemFailed(userMessage); + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, collection); } } @@ -532,8 +518,7 @@ public static void DoesNotContain(object? notExpected, IEnumerable collection, s { if (object.Equals(notExpected, item)) { - string userMessage = BuildUserMessageForNotExpectedExpressionAndCollectionExpression(message, notExpectedExpression, collectionExpression); - ThrowAssertDoesNotContainItemFailed(userMessage); + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, collection); } } } @@ -558,8 +543,7 @@ public static void DoesNotContain(T notExpected, IEnumerable collection, I { if (collection.Contains(notExpected, comparer)) { - string userMessage = BuildUserMessageForNotExpectedExpressionAndCollectionExpression(message, notExpectedExpression, collectionExpression); - ThrowAssertDoesNotContainItemFailed(userMessage); + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, collection); } } @@ -587,8 +571,7 @@ public static void DoesNotContain(object? notExpected, IEnumerable collection, I { if (comparer.Equals(item, notExpected)) { - string userMessage = BuildUserMessageForNotExpectedExpressionAndCollectionExpression(message, notExpectedExpression, collectionExpression); - ThrowAssertDoesNotContainItemFailed(userMessage); + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, collection); } } } @@ -612,8 +595,7 @@ public static void DoesNotContain(Func predicate, IEnumerable col { if (collection.Any(predicate)) { - string userMessage = BuildUserMessageForPredicateExpressionAndCollectionExpression(message, predicateExpression, collectionExpression); - ThrowAssertDoesNotContainPredicateFailed(userMessage); + ThrowAssertDoesNotContainPredicateFailed(message, predicateExpression, collectionExpression, collection); } } @@ -640,8 +622,7 @@ public static void DoesNotContain(Func predicate, IEnumerable col { if (predicate(item)) { - string userMessage = BuildUserMessageForPredicateExpressionAndCollectionExpression(message, predicateExpression, collectionExpression); - ThrowAssertDoesNotContainPredicateFailed(userMessage); + ThrowAssertDoesNotContainPredicateFailed(message, predicateExpression, collectionExpression, collection); } } } @@ -715,9 +696,7 @@ public static void DoesNotContain(string substring, string value, StringComparis if (value.Contains(substring, comparisonType)) { - string userMessage = BuildUserMessageForSubstringExpressionAndValueExpression(message, substringExpression, valueExpression); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.DoesNotContainFail, value, substring, userMessage); - ThrowAssertFailed("Assert.DoesNotContain", finalMessage); + ThrowAssertStringDoesNotContainFailed(value, substring, message, substringExpression, valueExpression); } } @@ -756,73 +735,131 @@ public static void IsInRange(T minValue, T maxValue, T value, string? message if (value.CompareTo(minValue) < 0 || value.CompareTo(maxValue) > 0) { - string userMessage = BuildUserMessageForMinValueExpressionAndMaxValueExpressionAndValueExpression(message, minValueExpression, maxValueExpression, valueExpression); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsInRangeFail, value, minValue, maxValue, userMessage); - ThrowAssertFailed("IsInRange", finalMessage); + ThrowAssertIsInRangeFailed(value, minValue, maxValue, message, minValueExpression, maxValueExpression, valueExpression); } } #endregion // IsInRange [DoesNotReturn] - private static void ThrowAssertSingleMatchFailed(int actualCount, string userMessage) + private static void ThrowAssertSingleMatchFailed(int actualCount, string? userMessage, string predicateExpression, string collectionExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.ContainsSingleMatchFailMsg, - userMessage, - actualCount); - ThrowAssertFailed("Assert.ContainsSingle", finalMessage); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleMatchFailNew, actualCount); + message += FormatExpressionParameter("predicate", predicateExpression) + + FormatExpressionParameter("collection", collectionExpression); + ThrowAssertFailed("Assert.ContainsSingle", message); } [DoesNotReturn] - private static void ThrowAssertContainsSingleFailed(int actualCount, string userMessage) + private static void ThrowAssertContainsSingleFailed(int actualCount, string? userMessage, string collectionExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.ContainsSingleFailMsg, - userMessage, - actualCount); - ThrowAssertFailed("Assert.ContainsSingle", finalMessage); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleFailNew, actualCount); + message += FormatExpressionParameter("collection", collectionExpression); + ThrowAssertFailed("Assert.ContainsSingle", message); } [DoesNotReturn] - private static void ThrowAssertContainsItemFailed(string userMessage) + private static void ThrowAssertContainsItemFailed(string? userMessage, string expectedExpression, string collectionExpression, IEnumerable? collectionValue = null) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.ContainsItemFailMsg, - userMessage); - ThrowAssertFailed("Assert.Contains", finalMessage); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.ContainsItemFailNew; + message += FormatExpressionParameter("expected", expectedExpression); + if (collectionValue is not null) + { + message += FormatCollectionParameter("collection", collectionExpression, collectionValue); + } + else + { + message += FormatExpressionParameter("collection", collectionExpression); + } + + ThrowAssertFailed("Assert.Contains", message); + } + + [DoesNotReturn] + private static void ThrowAssertContainsPredicateFailed(string? userMessage, string predicateExpression, string collectionExpression, IEnumerable? collectionValue = null) + { + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.ContainsPredicateFailNew; + message += FormatExpressionParameter("predicate", predicateExpression); + if (collectionValue is not null) + { + message += FormatCollectionParameter("collection", collectionExpression, collectionValue); + } + else + { + message += FormatExpressionParameter("collection", collectionExpression); + } + + ThrowAssertFailed("Assert.Contains", message); + } + + [DoesNotReturn] + private static void ThrowAssertDoesNotContainItemFailed(string? userMessage, string notExpectedExpression, string collectionExpression, IEnumerable? collectionValue = null) + { + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.DoesNotContainItemFailNew; + message += FormatExpressionParameter("notExpected", notExpectedExpression); + if (collectionValue is not null) + { + message += FormatCollectionParameter("collection", collectionExpression, collectionValue); + } + else + { + message += FormatExpressionParameter("collection", collectionExpression); + } + + ThrowAssertFailed("Assert.DoesNotContain", message); + } + + [DoesNotReturn] + private static void ThrowAssertDoesNotContainPredicateFailed(string? userMessage, string predicateExpression, string collectionExpression, IEnumerable? collectionValue = null) + { + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.DoesNotContainPredicateFailNew; + message += FormatExpressionParameter("predicate", predicateExpression); + if (collectionValue is not null) + { + message += FormatCollectionParameter("collection", collectionExpression, collectionValue); + } + else + { + message += FormatExpressionParameter("collection", collectionExpression); + } + + ThrowAssertFailed("Assert.DoesNotContain", message); } [DoesNotReturn] - private static void ThrowAssertContainsPredicateFailed(string userMessage) + private static void ThrowAssertStringContainsFailed(string value, string substring, string? userMessage, string substringExpression, string valueExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.ContainsPredicateFailMsg, - userMessage); - ThrowAssertFailed("Assert.Contains", finalMessage); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.ContainsStringFailNew; + message += Environment.NewLine + FormatParameter(nameof(substring), substringExpression, substring) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.Contains", message); } [DoesNotReturn] - private static void ThrowAssertDoesNotContainItemFailed(string userMessage) + private static void ThrowAssertStringDoesNotContainFailed(string value, string substring, string? userMessage, string substringExpression, string valueExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.DoesNotContainItemFailMsg, - userMessage); - ThrowAssertFailed("Assert.DoesNotContain", finalMessage); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.DoesNotContainStringFailNew; + message += Environment.NewLine + FormatParameter(nameof(substring), substringExpression, substring) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.DoesNotContain", message); } [DoesNotReturn] - private static void ThrowAssertDoesNotContainPredicateFailed(string userMessage) + private static void ThrowAssertIsInRangeFailed(T value, T minValue, T maxValue, string? userMessage, string minValueExpression, string maxValueExpression, string valueExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.DoesNotContainPredicateFailMsg, - userMessage); - ThrowAssertFailed("Assert.DoesNotContain", finalMessage); + string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + message += Environment.NewLine + FrameworkMessages.IsInRangeFailNew; + message += Environment.NewLine + FormatParameter(nameof(minValue), minValueExpression, minValue) + + Environment.NewLine + FormatParameter(nameof(maxValue), maxValueExpression, maxValue) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.IsInRange", message); } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index 74d12c523a..1f6278fd94 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -338,7 +338,10 @@ public void ContainsSingle_InterpolatedHandler_WithMultipleElements_ThrowsExcept Action action = () => Assert.ContainsSingle(collection, ref handler); // Assert - action.Should().Throw().WithMessage("Assert.ContainsSingle failed. Expected collection to contain exactly one element but found 3 element(s). 'collection' expression: 'collection'. "); + action.Should().Throw().WithMessage(""" + Assert.ContainsSingle failed. + Expected collection to contain exactly one element but found 3 element(s). + """); } /// @@ -368,7 +371,10 @@ public void ContainsSingle_InNonGenericCollection_NoMessage_WithEmptyCollection_ Action action = () => Assert.ContainsSingle(collection); // Assert - action.Should().Throw().WithMessage("Assert.ContainsSingle failed. Expected collection to contain exactly one element but found 0 element(s). 'collection' expression: 'collection'."); + action.Should().Throw().WithMessage(""" + Assert.ContainsSingle failed. + Expected collection to contain exactly one element but found 0 element(s). + """); } /// @@ -383,7 +389,10 @@ public void ContainsSingle_InNonGenericCollection_AssertCustomMessage_WithEmptyC Action action = () => Assert.ContainsSingle(collection, "my custom message"); // Assert - action.Should().Throw().WithMessage("Assert.ContainsSingle failed. Expected collection to contain exactly one element but found 0 element(s). 'collection' expression: 'collection'. my custom message"); + action.Should().Throw().WithMessage(""" + Assert.ContainsSingle failed. my custom message + Expected collection to contain exactly one element but found 0 element(s). + """); } #endregion @@ -417,7 +426,12 @@ public void Contains_ValueExpected_ItemDoesNotExist_ThrowsException() Action action = () => Assert.Contains(20, collection, "Item 20 not found"); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. Expected collection to contain the specified item. 'expected' expression: '20', 'collection' expression: 'collection'. Item 20 not found"); + action.Should().Throw().WithMessage(""" + Assert.Contains failed. Item 20 not found + Expected collection to contain the specified item. + expected: 20 + collection* + """); } /// @@ -433,7 +447,11 @@ public void Contains_InNonGenericCollection_ValueExpected_ItemDoesNotExist_Throw Action action = () => Assert.Contains(expected, collection, $"Item {expected} not found"); // Assert - action.Should().Throw().WithMessage($"*Item {expected} not found*"); + action.Should().Throw().WithMessage(""" + Assert.Contains failed. Item 20 not found + Expected collection to contain the specified item. + collection* + """); } /// @@ -479,7 +497,11 @@ public void Contains_InNonGenericCollection_NullableValueExpected_ItemDoesNotExi Action action = () => Assert.Contains(expected, collection, $"Item {expected} not found"); // Assert - action.Should().Throw().WithMessage($"*Item {expected} not found*"); + action.Should().Throw().WithMessage(""" + Assert.Contains failed. Item not found + Expected collection to contain the specified item. + collection* + """); } /// @@ -528,7 +550,12 @@ public void Contains_WithComparer_ItemDoesNotExist_ThrowsException() Action action = () => Assert.Contains("cherry", collection, comparer, "Missing cherry"); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. Expected collection to contain the specified item. 'expected' expression: '\"cherry\"', 'collection' expression: 'collection'. Missing cherry"); + action.Should().Throw().WithMessage(""" + Assert.Contains failed. Missing cherry + Expected collection to contain the specified item. + expected: "cherry" + collection* + """); } /// @@ -574,7 +601,12 @@ public void Contains_Predicate_NoItemMatches_ThrowsException() Action action = () => Assert.Contains(IsEven, collection, "No even number found"); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. Expected at least one item to match the predicate. 'predicate' expression: 'IsEven', 'collection' expression: 'collection'. No even number found"); + action.Should().Throw().WithMessage(""" + Assert.Contains failed. No even number found + Expected at least one item to match the predicate. + predicate: IsEven + collection* + """); } /// @@ -590,7 +622,12 @@ public void Contains_InNonGenericCollection_Predicate_NoItemMatches_ThrowsExcept Action action = () => Assert.Contains(IsEven, collection, "No even number found"); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. Expected at least one item to match the predicate. 'predicate' expression: 'IsEven', 'collection' expression: 'collection'. No even number found"); + action.Should().Throw().WithMessage(""" + Assert.Contains failed. No even number found + Expected at least one item to match the predicate. + predicate: IsEven + collection* + """); } /// @@ -623,7 +660,12 @@ public void Contains_StringVersion_SubstringNotPresent_ThrowsException() Action action = () => Assert.Contains(substring, value, StringComparison.Ordinal, "Missing substring"); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. String 'The quick brown fox' does not contain string 'lazy'. 'substring' expression: 'substring', 'value' expression: 'value'. Missing substring."); + action.Should().Throw().WithMessage(""" + Assert.Contains failed. Missing substring + String does not contain the expected substring. + substring: "lazy" + value: "The quick brown fox" + """); } public void Contains_HashSetWithCustomComparer_ItemExists_DoesNotThrow() @@ -699,7 +741,12 @@ public void Contains_InNonGenericCollection_WithComparer_ItemDoesNotExist_Throws Action action = () => Assert.Contains("banana", collection, comparer); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. Expected collection to contain the specified item. 'expected' expression: '\"banana\"', 'collection' expression: 'collection'."); + action.Should().Throw().WithMessage(""" + Assert.Contains failed. + Expected collection to contain the specified item. + expected: "banana" + collection* + """); } /// @@ -834,7 +881,12 @@ public void Contains_String_EmptyValue_WithNonEmptySubstring_ThrowsException() Action action = () => Assert.Contains(substring, value); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. String '' does not contain string 'test'. 'substring' expression: 'substring', 'value' expression: 'value'.."); + action.Should().Throw().WithMessage(""" + Assert.Contains failed. + String does not contain the expected substring. + substring: "test" + value: "" + """); } /// @@ -937,7 +989,12 @@ public void DoesNotContain_ValueExpected_ItemPresent_ThrowsException() Action action = () => Assert.DoesNotContain(10, collection, "Item 10 should not be found"); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. Expected collection to not contain the specified item. 'notExpected' expression: '10', 'collection' expression: 'collection'. Item 10 should not be found"); + action.Should().Throw().WithMessage(""" + Assert.DoesNotContain failed. Item 10 should not be found + Expected collection to not contain the specified item. + notExpected: 10 + collection* + """); } /// @@ -968,7 +1025,12 @@ public void DoesNotContain_InNonGenericCollection_ValueExpected_ItemPresent_Thro Action action = () => Assert.DoesNotContain(10, collection, "Assert.DoesNotContain failed. Expected collection to not contain the specified item. Item {0} should not be found"); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. Expected collection to not contain the specified item. 'notExpected' expression: '10', 'collection' expression: 'collection'. Assert.DoesNotContain failed. Expected collection to not contain the specified item. Item {0} should not be found"); + action.Should().Throw().WithMessage(""" + Assert.DoesNotContain failed. Assert.DoesNotContain failed. Expected collection to not contain the specified item. Item {0} should not be found + Expected collection to not contain the specified item. + notExpected: 10 + collection* + """); } /// @@ -1017,7 +1079,12 @@ public void DoesNotContain_WithComparer_ItemPresent_ThrowsException() Action action = () => Assert.DoesNotContain("APPLE", collection, comparer, "Unexpected \"APPLE\""); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. Expected collection to not contain the specified item. 'notExpected' expression: '\"APPLE\"', 'collection' expression: 'collection'. Unexpected \"APPLE\""); + action.Should().Throw().WithMessage(""" + Assert.DoesNotContain failed. Unexpected "APPLE" + Expected collection to not contain the specified item. + notExpected: "APPLE" + collection* + """); } /// @@ -1034,7 +1101,12 @@ public void DoesNotContain_InNonGenericCollection_WithComparer_ItemPresent_Throw Action action = () => Assert.DoesNotContain("APPLE", collection, comparer, "APPLE"); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. Expected collection to not contain the specified item. 'notExpected' expression: '\"APPLE\"', 'collection' expression: 'collection'. APPLE"); + action.Should().Throw().WithMessage(""" + Assert.DoesNotContain failed. APPLE + Expected collection to not contain the specified item. + notExpected: "APPLE" + collection* + """); } /// @@ -1080,7 +1152,12 @@ public void DoesNotContain_Predicate_AtLeastOneItemMatches_ThrowsException() Action action = () => Assert.DoesNotContain(IsEven, collection, "An even number exists"); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. Expected no items to match the predicate. 'predicate' expression: 'IsEven', 'collection' expression: 'collection'. An even number exists"); + action.Should().Throw().WithMessage(""" + Assert.DoesNotContain failed. An even number exists + Expected no items to match the predicate. + predicate: IsEven + collection* + """); } /// @@ -1096,7 +1173,12 @@ public void DoesNotContain_InNonGenericCollection_Predicate_AtLeastOneItemMatche Action action = () => Assert.DoesNotContain(IsEven, collection, "An even number exists"); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. Expected no items to match the predicate. 'predicate' expression: 'IsEven', 'collection' expression: 'collection'. An even number exists"); + action.Should().Throw().WithMessage(""" + Assert.DoesNotContain failed. An even number exists + Expected no items to match the predicate. + predicate: IsEven + collection* + """); } /// @@ -1129,7 +1211,12 @@ public void DoesNotContain_StringVersion_SubstringPresent_ThrowsException() Action action = () => Assert.DoesNotContain(substring, value, StringComparison.Ordinal, "Unexpected substring"); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. String 'The quick brown fox' does contain string 'brown'. 'substring' expression: 'substring', 'value' expression: 'value'. Unexpected substring."); + action.Should().Throw().WithMessage(""" + Assert.DoesNotContain failed. Unexpected substring + String contains the unexpected substring. + substring: "brown" + value: "The quick brown fox" + """); } /// @@ -1164,7 +1251,12 @@ public void DoesNotContain_StringWithComparisonAndMessage_SubstringPresent_Throw Action action = () => Assert.DoesNotContain(substring, value, StringComparison.OrdinalIgnoreCase, "Found unexpected substring"); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. String 'The quick brown fox' does contain string 'BROWN'. 'substring' expression: 'substring', 'value' expression: 'value'. Found unexpected substring."); + action.Should().Throw().WithMessage(""" + Assert.DoesNotContain failed. Found unexpected substring + String contains the unexpected substring. + substring: "BROWN" + value: "The quick brown fox" + """); } /// @@ -1197,7 +1289,12 @@ public void DoesNotContain_StringSimpleOverload_SubstringPresent_ThrowsException Action action = () => Assert.DoesNotContain(substring, value); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. String 'The quick brown fox' does contain string 'brown'. 'substring' expression: 'substring', 'value' expression: 'value'.."); + action.Should().Throw().WithMessage(""" + Assert.DoesNotContain failed. + String contains the unexpected substring. + substring: "brown" + value: "The quick brown fox" + """); } /// @@ -1230,7 +1327,12 @@ public void DoesNotContain_StringWithMessageOnly_SubstringPresent_ThrowsExceptio Action action = () => Assert.DoesNotContain(substring, value, "Found unexpected substring"); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. String 'The quick brown fox' does contain string 'brown'. 'substring' expression: 'substring', 'value' expression: 'value'. Found unexpected substring."); + action.Should().Throw().WithMessage(""" + Assert.DoesNotContain failed. Found unexpected substring + String contains the unexpected substring. + substring: "brown" + value: "The quick brown fox" + """); } /// @@ -1473,7 +1575,11 @@ public void ContainsSinglePredicate_NoItemMatches_ThrowsException() // Assert action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 0 item(s). 'predicate' expression: 'x => x % 2 == 0', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.ContainsSingle failed. + Expected exactly one item to match the predicate but found 0 item(s). + predicate: x => x % 2 == 0 + """); } /// @@ -1490,7 +1596,11 @@ public void ContainsSinglePredicate_InNonGenericCollection_NoItemMatches_ThrowsE // Assert action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 0 item(s). 'predicate' expression: 'x => x is int i && i % 2 == 0', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.ContainsSingle failed. + Expected exactly one item to match the predicate but found 0 item(s). + predicate: x => x is int i && i % 2 == 0 + """); } /// @@ -1507,7 +1617,11 @@ public void ContainsSinglePredicate_MultipleItemsMatch_ThrowsException() // Assert action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 4 item(s). 'predicate' expression: 'x => x % 2 == 0', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.ContainsSingle failed. + Expected exactly one item to match the predicate but found 4 item(s). + predicate: x => x % 2 == 0 + """); } /// @@ -1524,7 +1638,11 @@ public void ContainsSinglePredicate_InNonGenericCollection_MultipleItemsMatch_Th // Assert action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 2 item(s). 'predicate' expression: 'x => x is int i && i % 2 == 0', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.ContainsSingle failed. + Expected exactly one item to match the predicate but found 2 item(s). + predicate: x => x is int i && i % 2 == 0 + """); } /// @@ -1541,7 +1659,11 @@ public void ContainsSinglePredicate_WithMessage_NoItemMatches_ThrowsException() // Assert action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 0 item(s). 'predicate' expression: 'x => x % 2 == 0', 'collection' expression: 'collection'. No even numbers found in collection with 3 items"); + .WithMessage(""" + Assert.ContainsSingle failed. No even numbers found in collection with 3 items + Expected exactly one item to match the predicate but found 0 item(s). + predicate: x => x % 2 == 0 + """); } /// @@ -1558,7 +1680,11 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_NoItemMat // Assert action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 0 item(s). 'predicate' expression: 'x => x is int i && i % 2 == 0', 'collection' expression: 'collection'. No even numbers found in collection with 3 items"); + .WithMessage(""" + Assert.ContainsSingle failed. No even numbers found in collection with 3 items + Expected exactly one item to match the predicate but found 0 item(s). + predicate: x => x is int i && i % 2 == 0 + """); } /// @@ -1575,7 +1701,11 @@ public void ContainsSinglePredicate_WithMessage_MultipleItemsMatch_ThrowsExcepti // Assert action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 3 item(s). 'predicate' expression: 'x => x % 2 == 0', 'collection' expression: 'collection'. Too many even numbers found: 3"); + .WithMessage(""" + Assert.ContainsSingle failed. Too many even numbers found: 3 + Expected exactly one item to match the predicate but found 3 item(s). + predicate: x => x % 2 == 0 + """); } /// @@ -1592,7 +1722,11 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_MultipleI // Assert action.Should().Throw() - .WithMessage("Assert.ContainsSingle failed. Expected exactly one item to match the predicate but found 2 item(s). 'predicate' expression: 'x => x is int i && i % 2 == 0', 'collection' expression: 'collection'. Too many even numbers found: 2"); + .WithMessage(""" + Assert.ContainsSingle failed. Too many even numbers found: 2 + Expected exactly one item to match the predicate but found 2 item(s). + predicate: x => x is int i && i % 2 == 0 + """); } /// @@ -1684,7 +1818,12 @@ public void Contains_ItemNotFound_ShowsSpecificErrorMessage() // Assert action.Should().Throw() - .WithMessage("Assert.Contains failed. Expected collection to contain the specified item. 'expected' expression: '5', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.Contains failed. + Expected collection to contain the specified item. + expected: 5 + collection* + """); } /// @@ -1700,7 +1839,12 @@ public void Contains_InNonGenericCollection_ItemNotFound_ShowsSpecificErrorMessa // Assert action.Should().Throw() - .WithMessage("Assert.Contains failed. Expected collection to contain the specified item. 'expected' expression: '5', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.Contains failed. + Expected collection to contain the specified item. + expected: 5 + collection* + """); } /// @@ -1716,7 +1860,12 @@ public void Contains_PredicateNotMatched_ShowsSpecificErrorMessage() // Assert action.Should().Throw() - .WithMessage("Assert.Contains failed. Expected at least one item to match the predicate. 'predicate' expression: 'x => x % 2 == 0', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.Contains failed. + Expected at least one item to match the predicate. + predicate: x => x % 2 == 0 + collection* + """); } /// @@ -1732,7 +1881,12 @@ public void DoesNotContain_ItemFound_ShowsSpecificErrorMessage() // Assert action.Should().Throw() - .WithMessage("Assert.DoesNotContain failed. Expected collection to not contain the specified item. 'notExpected' expression: '2', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.DoesNotContain failed. + Expected collection to not contain the specified item. + notExpected: 2 + collection* + """); } /// @@ -1748,7 +1902,12 @@ public void DoesNotContain_PredicateMatched_ShowsSpecificErrorMessage() // Assert action.Should().Throw() - .WithMessage("Assert.DoesNotContain failed. Expected no items to match the predicate. 'predicate' expression: 'x => x % 2 == 0', 'collection' expression: 'collection'."); + .WithMessage(""" + Assert.DoesNotContain failed. + Expected no items to match the predicate. + predicate: x => x % 2 == 0 + collection* + """); } public void DoesNotContains_HashSetWithCustomComparer_ItemDoesNotExist_DoesNotThrow() @@ -1792,4 +1951,88 @@ private AlwaysFalseEqualityComparer() } #endregion + + #region Contains/DoesNotContain string truncation and newline escaping + + public void Contains_String_WithLongExpression_ShouldTruncateExpression() + { + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello"; + + Action action = () => Assert.Contains("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.Contains failed. + String does not contain the expected substring. + substring: "world" + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + """); + } + + public void Contains_String_WithLongValue_ShouldTruncateValue() + { + string longValue = new string('x', 300); + + Action action = () => Assert.Contains("world", longValue); + action.Should().Throw() + .WithMessage($""" + Assert.Contains failed. + String does not contain the expected substring. + substring: "world" + value (longValue): "{new string('x', 255)}... (302 chars) + """); + } + + public void Contains_String_WithNewlineInValue_ShouldEscapeNewlines() + { + Action action = () => Assert.Contains("world", "hello\r\nfoo"); + action.Should().Throw() + .WithMessage(""" + Assert.Contains failed. + String does not contain the expected substring. + substring: "world" + value: "hello\r\nfoo" + """); + } + + public void DoesNotContain_String_WithLongExpression_ShouldTruncateExpression() + { + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello world"; + + Action action = () => Assert.DoesNotContain("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotContain failed. + String contains the unexpected substring. + substring: "hello" + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello world" + """); + } + + public void DoesNotContain_String_WithLongValue_ShouldTruncateValue() + { + string longValue = "hello" + new string('x', 300); + + Action action = () => Assert.DoesNotContain("hello", longValue); + action.Should().Throw() + .WithMessage($""" + Assert.DoesNotContain failed. + String contains the unexpected substring. + substring: "hello" + value (longValue): "hello{new string('x', 250)}... (307 chars) + """); + } + + public void DoesNotContain_String_WithNewlineInValue_ShouldEscapeNewlines() + { + Action action = () => Assert.DoesNotContain("hello", "hello\r\nworld"); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotContain failed. + String contains the unexpected substring. + substring: "hello" + value: "hello\r\nworld" + """); + } + + #endregion } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index b9a6646e91..df8615cc5a 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -57,7 +57,13 @@ public void IsInRange_WithValueBelowRange_ThrowsAssertFailedException() // Act & Assert Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().Throw() - .And.Message.Should().Contain("Value '3' is not within the expected range [5..10]"); + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: 5 + maxValue: 10 + value: 3 + """); } public void IsInRange_WithValueAboveRange_ThrowsAssertFailedException() @@ -70,7 +76,13 @@ public void IsInRange_WithValueAboveRange_ThrowsAssertFailedException() // Act & Assert Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().Throw() - .And.Message.Should().Contain("Value '8' is not within the expected range [1..5]"); + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: 1 + maxValue: 5 + value: 8 + """); } public void IsInRange_WithCustomMessage_IncludesCustomMessage() @@ -86,8 +98,13 @@ public void IsInRange_WithCustomMessage_IncludesCustomMessage() // Assert action.Should().ThrowExactly() - .And.Message.Should().Contain("Value '10' is not within the expected range [1..5]") - .And.Contain(customMessage); + .WithMessage(""" + Assert.IsInRange failed. Custom error message + Value is not within the expected range. + minValue: 1 + maxValue: 5 + value: 10 + """); } public void IsInRange_WithDoubleValues_WorksCorrectly() @@ -102,7 +119,7 @@ public void IsInRange_WithDoubleValues_WorksCorrectly() Assert.IsInRange(minValue, maxValue, valueInRange); Action action = () => Assert.IsInRange(minValue, maxValue, valueOutOfRange); action.Should().Throw() - .And.Message.Should().Contain("Value '6' is not within the expected range [1.5..5.5]"); + .WithMessage("Assert.IsInRange failed.*Value is not within the expected range*"); } public void IsInRange_WithDateTimeValues_WorksCorrectly() @@ -119,7 +136,7 @@ public void IsInRange_WithDateTimeValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .And.Message.Should().Contain("is not within the expected range"); + .WithMessage("Assert.IsInRange failed.*Value is not within the expected range*"); } public void IsInRange_WithCharValues_WorksCorrectly() @@ -136,7 +153,7 @@ public void IsInRange_WithCharValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .And.Message.Should().Contain("Value 'a' is not within the expected range [A..Z]"); + .WithMessage("Assert.IsInRange failed.*Value is not within the expected range*"); } public void IsInRange_WithNullMessage_DoesNotThrow() @@ -195,7 +212,13 @@ public void IsInRange_WithAllNegativeValuesBelowRange_ThrowsAssertFailedExceptio // Assert action.Should().ThrowExactly() - .And.Message.Should().Contain("Value '-12' is not within the expected range [-10..-5]"); + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: -10 + maxValue: -5 + value: -12 + """); } public void IsInRange_WithAllNegativeValuesAboveRange_ThrowsAssertFailedException() @@ -210,7 +233,13 @@ public void IsInRange_WithAllNegativeValuesAboveRange_ThrowsAssertFailedExceptio // Assert action.Should().ThrowExactly() - .And.Message.Should().Contain("Value '-3' is not within the expected range [-10..-5]"); + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: -10 + maxValue: -5 + value: -3 + """); } public void IsInRange_WithRangeSpanningNegativeToPositive_ValueInRange_DoesNotThrow() @@ -258,7 +287,13 @@ public void IsInRange_WithRangeSpanningNegativeToPositive_ValueBelowRange_Throws // Assert action.Should().ThrowExactly() - .And.Message.Should().Contain("Value '-7' is not within the expected range [-5..5]"); + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: -5 + maxValue: 5 + value: -7 + """); } public void IsInRange_WithRangeSpanningNegativeToPositive_ValueAboveRange_ThrowsAssertFailedException() @@ -273,7 +308,13 @@ public void IsInRange_WithRangeSpanningNegativeToPositive_ValueAboveRange_Throws // Assert action.Should().ThrowExactly() - .And.Message.Should().Contain("Value '7' is not within the expected range [-5..5]"); + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: -5 + maxValue: 5 + value: 7 + """); } public void IsInRange_WithNegativeDoubleValues_WorksCorrectly() @@ -299,7 +340,7 @@ public void IsInRange_WithMaxValueLessThanMinValue_ThrowsArgumentOutOfRangeExcep // Assert action.Should().ThrowExactly() - .And.Message.Should().Contain("The maximum value must be greater than or equal to the minimum value"); + .WithMessage("The maximum value must be greater than or equal to the minimum value*"); } public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldPassIfValueIsEqual() @@ -322,7 +363,13 @@ public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsSmaller Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() - .And.Message.Should().Contain("Value '4' is not within the expected range [5..5]"); + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: 5 + maxValue: 5 + value: 4 + """); } public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsLarger() @@ -334,7 +381,13 @@ public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsLarger( Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() - .And.Message.Should().Contain("Value '6' is not within the expected range [5..5]"); + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: 5 + maxValue: 5 + value: 6 + """); } public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldPassIfValueIsEqual() @@ -357,7 +410,13 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsSmall Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() - .And.Message.Should().Contain("Value '4' is not within the expected range [5..5]"); + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: 5 + maxValue: 5 + value: 4 + """); } public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsLarger() @@ -369,8 +428,89 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsLarge Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() - .And.Message.Should().Contain("Value '6' is not within the expected range [5..5]"); + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: 5 + maxValue: 5 + value: 6 + """); } #endregion // IsInRange Tests + + #region IsInRange truncation and newline escaping + + public void IsInRange_WithLongExpression_ShouldTruncateExpression() + { + int aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = 20; + + Action action = () => Assert.IsInRange(1, 10, aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue: 1 + maxValue: 10 + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 20 + """); + } + + public void IsInRange_WithLongToStringValue_ShouldTruncateValue() + { + var min = new IsInRangeComparableWithLongToString(1); + var max = new IsInRangeComparableWithLongToString(10); + var value = new IsInRangeComparableWithLongToString(20); + + Action action = () => Assert.IsInRange(min, max, value); + action.Should().Throw() + .WithMessage($""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue (min): {new string('R', 256)}... (300 chars) + maxValue (max): {new string('R', 256)}... (300 chars) + value: {new string('R', 256)}... (300 chars) + """); + } + + public void IsInRange_WithNewlineInToString_ShouldEscapeNewlines() + { + var min = new IsInRangeComparableWithNewlineToString(1); + var max = new IsInRangeComparableWithNewlineToString(10); + var value = new IsInRangeComparableWithNewlineToString(20); + + Action action = () => Assert.IsInRange(min, max, value); + action.Should().Throw() + .WithMessage(""" + Assert.IsInRange failed. + Value is not within the expected range. + minValue (min): line1\r\nline2 + maxValue (max): line1\r\nline2 + value: line1\r\nline2 + """); + } + + #endregion + + private readonly struct IsInRangeComparableWithLongToString : IComparable + { + private readonly int _value; + + public IsInRangeComparableWithLongToString(int value) => _value = value; + + public int CompareTo(IsInRangeComparableWithLongToString other) => _value.CompareTo(other._value); + + public override string ToString() => new string('R', 300); + } + + private readonly struct IsInRangeComparableWithNewlineToString : IComparable + { + private readonly int _value; + + public IsInRangeComparableWithNewlineToString(int value) => _value = value; + + public int CompareTo(IsInRangeComparableWithNewlineToString other) => _value.CompareTo(other._value); + + public override string ToString() => "line1\r\nline2"; + } } From dd88189deb7bc91755e590488cbd75fa759fdb50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:53:39 +0100 Subject: [PATCH 12/58] Improve StartsWith/DoesNotStartWith assertion error messages --- .../Assertions/Assert.StartsWith.cs | 16 +- .../Assertions/AssertTests.StartsWith.cs | 139 ++++++++++++++++++ 2 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs diff --git a/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs b/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs index 6f5c728535..c38e8a0110 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs @@ -76,9 +76,11 @@ public static void StartsWith([NotNull] string? expectedPrefix, [NotNull] string CheckParameterNotNull(expectedPrefix, "Assert.StartsWith", "expectedPrefix"); if (!value.StartsWith(expectedPrefix, comparisonType)) { - string userMessage = BuildUserMessageForExpectedPrefixExpressionAndValueExpression(message, expectedPrefixExpression, valueExpression); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.StartsWithFail, value, expectedPrefix, userMessage); - ThrowAssertFailed("Assert.StartsWith", finalMessage); + string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; + msg += Environment.NewLine + FrameworkMessages.StartsWithFailNew; + msg += Environment.NewLine + FormatParameter(nameof(expectedPrefix), expectedPrefixExpression, expectedPrefix) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.StartsWith", msg); } } @@ -148,9 +150,11 @@ public static void DoesNotStartWith([NotNull] string? notExpectedPrefix, [NotNul CheckParameterNotNull(notExpectedPrefix, "Assert.DoesNotStartWith", "notExpectedPrefix"); if (value.StartsWith(notExpectedPrefix, comparisonType)) { - string userMessage = BuildUserMessageForNotExpectedPrefixExpressionAndValueExpression(message, notExpectedPrefixExpression, valueExpression); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.DoesNotStartWithFail, value, notExpectedPrefix, userMessage); - ThrowAssertFailed("Assert.DoesNotStartWith", finalMessage); + string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; + msg += Environment.NewLine + FrameworkMessages.DoesNotStartWithFailNew; + msg += Environment.NewLine + FormatParameter(nameof(notExpectedPrefix), notExpectedPrefixExpression, notExpectedPrefix) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.DoesNotStartWith", msg); } } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs new file mode 100644 index 0000000000..3f3ef70dac --- /dev/null +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs @@ -0,0 +1,139 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using AwesomeAssertions; + +namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; + +public partial class AssertTests +{ + #region StartsWith + + public void StartsWith_WhenValueStartsWithPrefix_ShouldPass() + => Assert.StartsWith("hello", "hello world"); + + public void StartsWith_WhenValueDoesNotStartWithPrefix_ShouldFail() + { + Action action = () => Assert.StartsWith("world", "hello"); + action.Should().Throw() + .WithMessage(""" + Assert.StartsWith failed. + String does not start with expected prefix. + expectedPrefix: "world" + value: "hello" + """); + } + + public void StartsWith_WithMessage_WhenValueDoesNotStartWithPrefix_ShouldFail() + { + Action action = () => Assert.StartsWith("world", "hello", "User message"); + action.Should().Throw() + .WithMessage(""" + Assert.StartsWith failed. User message + String does not start with expected prefix. + expectedPrefix: "world" + value: "hello" + """); + } + + public void DoesNotStartWith_WhenValueDoesNotStartWithPrefix_ShouldPass() + => Assert.DoesNotStartWith("world", "hello"); + + public void DoesNotStartWith_WhenValueStartsWithPrefix_ShouldFail() + { + Action action = () => Assert.DoesNotStartWith("hello", "hello world"); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotStartWith failed. + String starts with unexpected prefix. + notExpectedPrefix: "hello" + value: "hello world" + """); + } + + #endregion + + #region StartsWith/DoesNotStartWith truncation and newline escaping + + public void StartsWith_WithLongExpression_ShouldTruncateExpression() + { + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello world"; + + Action action = () => Assert.StartsWith("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.StartsWith failed. + String does not start with expected prefix. + expectedPrefix: "world" + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello world" + """); + } + + public void StartsWith_WithLongValue_ShouldTruncateValue() + { + string longValue = new string('x', 300); + + Action action = () => Assert.StartsWith("world", longValue); + action.Should().Throw() + .WithMessage($""" + Assert.StartsWith failed. + String does not start with expected prefix. + expectedPrefix: "world" + value (longValue): "{new string('x', 255)}... (302 chars) + """); + } + + public void StartsWith_WithNewlineInValue_ShouldEscapeNewlines() + { + Action action = () => Assert.StartsWith("world", "hello\r\nworld"); + action.Should().Throw() + .WithMessage(""" + Assert.StartsWith failed. + String does not start with expected prefix. + expectedPrefix: "world" + value: "hello\r\nworld" + """); + } + + public void DoesNotStartWith_WithLongExpression_ShouldTruncateExpression() + { + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello world"; + + Action action = () => Assert.DoesNotStartWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotStartWith failed. + String starts with unexpected prefix. + notExpectedPrefix: "hello" + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello world" + """); + } + + public void DoesNotStartWith_WithLongValue_ShouldTruncateValue() + { + string longValue = "hello" + new string('x', 300); + + Action action = () => Assert.DoesNotStartWith("hello", longValue); + action.Should().Throw() + .WithMessage($""" + Assert.DoesNotStartWith failed. + String starts with unexpected prefix. + notExpectedPrefix: "hello" + value (longValue): "hello{new string('x', 250)}... (307 chars) + """); + } + + public void DoesNotStartWith_WithNewlineInValue_ShouldEscapeNewlines() + { + Action action = () => Assert.DoesNotStartWith("hello", "hello\r\nworld"); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotStartWith failed. + String starts with unexpected prefix. + notExpectedPrefix: "hello" + value: "hello\r\nworld" + """); + } + + #endregion +} From 0c10f638b47474b050f829380ecf8f71c42b0252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:53:44 +0100 Subject: [PATCH 13/58] Improve EndsWith/DoesNotEndWith assertion error messages --- .../Assertions/Assert.EndsWith.cs | 16 +- .../Assertions/AssertTests.EndsWith.cs | 139 ++++++++++++++++++ 2 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs diff --git a/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs b/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs index 772c1d1e48..2c01ed2044 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs @@ -76,9 +76,11 @@ public static void EndsWith([NotNull] string? expectedSuffix, [NotNull] string? CheckParameterNotNull(expectedSuffix, "Assert.EndsWith", "expectedSuffix"); if (!value.EndsWith(expectedSuffix, comparisonType)) { - string userMessage = BuildUserMessageForExpectedSuffixExpressionAndValueExpression(message, expectedSuffixExpression, valueExpression); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.EndsWithFail, value, expectedSuffix, userMessage); - ThrowAssertFailed("Assert.EndsWith", finalMessage); + string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; + msg += Environment.NewLine + FrameworkMessages.EndsWithFailNew; + msg += Environment.NewLine + FormatParameter(nameof(expectedSuffix), expectedSuffixExpression, expectedSuffix) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.EndsWith", msg); } } @@ -150,9 +152,11 @@ public static void DoesNotEndWith([NotNull] string? notExpectedSuffix, [NotNull] CheckParameterNotNull(notExpectedSuffix, "Assert.DoesNotEndWith", "notExpectedSuffix"); if (value.EndsWith(notExpectedSuffix, comparisonType)) { - string userMessage = BuildUserMessageForNotExpectedSuffixExpressionAndValueExpression(message, notExpectedSuffixExpression, valueExpression); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.DoesNotEndWithFail, value, notExpectedSuffix, userMessage); - ThrowAssertFailed("Assert.DoesNotEndWith", finalMessage); + string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; + msg += Environment.NewLine + FrameworkMessages.DoesNotEndWithFailNew; + msg += Environment.NewLine + FormatParameter(nameof(notExpectedSuffix), notExpectedSuffixExpression, notExpectedSuffix) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.DoesNotEndWith", msg); } } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs new file mode 100644 index 0000000000..ccb728e95d --- /dev/null +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs @@ -0,0 +1,139 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using AwesomeAssertions; + +namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; + +public partial class AssertTests +{ + #region EndsWith + + public void EndsWith_WhenValueEndsWithSuffix_ShouldPass() + => Assert.EndsWith("world", "hello world"); + + public void EndsWith_WhenValueDoesNotEndWithSuffix_ShouldFail() + { + Action action = () => Assert.EndsWith("hello", "world"); + action.Should().Throw() + .WithMessage(""" + Assert.EndsWith failed. + String does not end with expected suffix. + expectedSuffix: "hello" + value: "world" + """); + } + + public void EndsWith_WithMessage_WhenValueDoesNotEndWithSuffix_ShouldFail() + { + Action action = () => Assert.EndsWith("hello", "world", "User message"); + action.Should().Throw() + .WithMessage(""" + Assert.EndsWith failed. User message + String does not end with expected suffix. + expectedSuffix: "hello" + value: "world" + """); + } + + public void DoesNotEndWith_WhenValueDoesNotEndWithSuffix_ShouldPass() + => Assert.DoesNotEndWith("hello", "world"); + + public void DoesNotEndWith_WhenValueEndsWithSuffix_ShouldFail() + { + Action action = () => Assert.DoesNotEndWith("world", "hello world"); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotEndWith failed. + String ends with unexpected suffix. + notExpectedSuffix: "world" + value: "hello world" + """); + } + + #endregion + + #region EndsWith/DoesNotEndWith truncation and newline escaping + + public void EndsWith_WithLongExpression_ShouldTruncateExpression() + { + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello world"; + + Action action = () => Assert.EndsWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.EndsWith failed. + String does not end with expected suffix. + expectedSuffix: "hello" + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello world" + """); + } + + public void EndsWith_WithLongValue_ShouldTruncateValue() + { + string longValue = new string('x', 300); + + Action action = () => Assert.EndsWith("world", longValue); + action.Should().Throw() + .WithMessage($""" + Assert.EndsWith failed. + String does not end with expected suffix. + expectedSuffix: "world" + value (longValue): "{new string('x', 255)}... (302 chars) + """); + } + + public void EndsWith_WithNewlineInValue_ShouldEscapeNewlines() + { + Action action = () => Assert.EndsWith("world", "hello\r\nfoo"); + action.Should().Throw() + .WithMessage(""" + Assert.EndsWith failed. + String does not end with expected suffix. + expectedSuffix: "world" + value: "hello\r\nfoo" + """); + } + + public void DoesNotEndWith_WithLongExpression_ShouldTruncateExpression() + { + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello world"; + + Action action = () => Assert.DoesNotEndWith("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotEndWith failed. + String ends with unexpected suffix. + notExpectedSuffix: "world" + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello world" + """); + } + + public void DoesNotEndWith_WithLongValue_ShouldTruncateValue() + { + string longValue = new string('x', 300) + "world"; + + Action action = () => Assert.DoesNotEndWith("world", longValue); + action.Should().Throw() + .WithMessage($""" + Assert.DoesNotEndWith failed. + String ends with unexpected suffix. + notExpectedSuffix: "world" + value (longValue): "{new string('x', 255)}... (307 chars) + """); + } + + public void DoesNotEndWith_WithNewlineInValue_ShouldEscapeNewlines() + { + Action action = () => Assert.DoesNotEndWith("world", "hello\r\nworld"); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotEndWith failed. + String ends with unexpected suffix. + notExpectedSuffix: "world" + value: "hello\r\nworld" + """); + } + + #endregion +} From 14a6ec33c7f712fa6fac86b488ff396ee7703280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:53:50 +0100 Subject: [PATCH 14/58] Improve MatchesRegex/DoesNotMatchRegex assertion error messages --- .../Assertions/Assert.Matches.cs | 16 ++- .../Assertions/AssertTests.MatchesRegex.cs | 127 ++++++++++++++++++ 2 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs b/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs index b204970b6d..c2a8ad6827 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs @@ -44,9 +44,11 @@ public static void MatchesRegex([NotNull] Regex? pattern, [NotNull] string? valu if (!pattern.IsMatch(value)) { - string userMessage = BuildUserMessageForPatternExpressionAndValueExpression(message, patternExpression, valueExpression); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsMatchFail, value, pattern, userMessage); - ThrowAssertFailed("Assert.MatchesRegex", finalMessage); + string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; + msg += Environment.NewLine + FrameworkMessages.MatchesRegexFailNew; + msg += Environment.NewLine + FormatParameter(nameof(pattern), patternExpression, pattern) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.MatchesRegex", msg); } } @@ -120,9 +122,11 @@ public static void DoesNotMatchRegex([NotNull] Regex? pattern, [NotNull] string? if (pattern.IsMatch(value)) { - string userMessage = BuildUserMessageForPatternExpressionAndValueExpression(message, patternExpression, valueExpression); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsNotMatchFail, value, pattern, userMessage); - ThrowAssertFailed("Assert.DoesNotMatchRegex", finalMessage); + string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; + msg += Environment.NewLine + FrameworkMessages.DoesNotMatchRegexFailNew; + msg += Environment.NewLine + FormatParameter(nameof(pattern), patternExpression, pattern) + + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + ThrowAssertFailed("Assert.DoesNotMatchRegex", msg); } } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs new file mode 100644 index 0000000000..20ba088baa --- /dev/null +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs @@ -0,0 +1,127 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using AwesomeAssertions; + +namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; + +public partial class AssertTests +{ + #region MatchesRegex + + public void MatchesRegex_WhenValueMatchesPattern_ShouldPass() + => Assert.MatchesRegex(@"\d+", "abc123"); + + public void MatchesRegex_WhenValueDoesNotMatchPattern_ShouldFail() + { + Action action = () => Assert.MatchesRegex(@"\d+", "abc"); + action.Should().Throw() + .WithMessage(""" + Assert.MatchesRegex failed. + String does not match expected pattern. + pattern: \d+ + value: "abc" + """); + } + + public void DoesNotMatchRegex_WhenValueDoesNotMatchPattern_ShouldPass() + => Assert.DoesNotMatchRegex(@"\d+", "abc"); + + public void DoesNotMatchRegex_WhenValueMatchesPattern_ShouldFail() + { + Action action = () => Assert.DoesNotMatchRegex(@"\d+", "abc123"); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotMatchRegex failed. + String matches pattern but should not. + pattern: \d+ + value: "abc123" + """); + } + + #endregion + + #region MatchesRegex/DoesNotMatchRegex truncation and newline escaping + + public void MatchesRegex_WithLongExpression_ShouldTruncateExpression() + { + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "hello"; + + Action action = () => Assert.MatchesRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.MatchesRegex failed. + String does not match expected pattern. + pattern: \d+ + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + """); + } + + public void MatchesRegex_WithLongValue_ShouldTruncateValue() + { + string longValue = new string('x', 300); + + Action action = () => Assert.MatchesRegex(@"\d+", longValue); + action.Should().Throw() + .WithMessage($""" + Assert.MatchesRegex failed. + String does not match expected pattern. + pattern: \d+ + value (longValue): "{new string('x', 255)}... (302 chars) + """); + } + + public void MatchesRegex_WithNewlineInValue_ShouldEscapeNewlines() + { + Action action = () => Assert.MatchesRegex(@"^\d+$", "hello\r\nworld"); + action.Should().Throw() + .WithMessage(""" + Assert.MatchesRegex failed. + String does not match expected pattern. + pattern: ^\d+$ + value: "hello\r\nworld" + """); + } + + public void DoesNotMatchRegex_WithLongExpression_ShouldTruncateExpression() + { + string aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ = "abc123"; + + Action action = () => Assert.DoesNotMatchRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotMatchRegex failed. + String matches pattern but should not. + pattern: \d+ + value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "abc123" + """); + } + + public void DoesNotMatchRegex_WithLongValue_ShouldTruncateValue() + { + string longValue = new string('1', 300); + + Action action = () => Assert.DoesNotMatchRegex(@"\d+", longValue); + action.Should().Throw() + .WithMessage($""" + Assert.DoesNotMatchRegex failed. + String matches pattern but should not. + pattern: \d+ + value (longValue): "{new string('1', 255)}... (302 chars) + """); + } + + public void DoesNotMatchRegex_WithNewlineInValue_ShouldEscapeNewlines() + { + Action action = () => Assert.DoesNotMatchRegex(@"hello", "hello\r\nworld"); + action.Should().Throw() + .WithMessage(""" + Assert.DoesNotMatchRegex failed. + String matches pattern but should not. + pattern: hello + value: "hello\r\nworld" + """); + } + + #endregion +} From 63e8257f70295164f8af252e9023b944566ce1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 10:54:10 +0100 Subject: [PATCH 15/58] Minor test cleanup for Inconclusive assertion --- .../Assertions/AssertTests.InconclusiveTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.InconclusiveTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.InconclusiveTests.cs index d0b8d8fcc7..68819704e1 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.InconclusiveTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.InconclusiveTests.cs @@ -12,6 +12,6 @@ public void InconclusiveDoesNotThrowWhenMessageContainsInvalidStringFormatCompos { Action action = () => Assert.Inconclusive("{"); action.Should().Throw() - .And.Message.Should().Contain("Assert.Inconclusive failed. {"); + .WithMessage("Assert.Inconclusive failed. {"); } } From f55938778d54bd239492e9344477acda57c0eb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 13:56:11 +0100 Subject: [PATCH 16/58] Address Copilot feedback --- .../TestFramework/Assertions/Assert.cs | 73 +++++++++++++------ .../Assertions/AssertTests.cs | 18 ++--- 2 files changed, 60 insertions(+), 31 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 61c9230df4..280bda1a20 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -97,7 +97,7 @@ internal static string BuildUserMessage(string? format) /// internal static void CheckParameterNotNull([NotNull] object? param, string assertionName, string parameterName) { - if (param == null) + if (param is null) { string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.NullParameterToAssert, parameterName); ThrowAssertFailed(assertionName, finalMessage); @@ -326,40 +326,65 @@ internal static string FormatCollectionParameter(string paramName, string expres : $"{Environment.NewLine} {paramName} ({TruncateExpression(expression)}): {preview}"; } + /// + /// Formats a preview string for a collection, showing element values up to characters. + /// + /// Performance: We avoid enumerating the entire collection when the display is truncated. + /// For ICollection, we read .Count directly (O(1)) to get the total without full enumeration. + /// For non-ICollection enumerables (e.g. LINQ queries, infinite sequences), we stop + /// enumeration as soon as the display budget is exhausted and report "N+ elements" since + /// the true count is unknown. This prevents hangs on lazy/infinite sequences and avoids + /// O(n) enumeration cost when only a prefix is displayed. + /// + /// private static string FormatCollectionPreview(IEnumerable collection, int maxLength = 256) { + // Perf: get count from ICollection (O(1)) to avoid full enumeration just for the count. + int? knownCount = collection is ICollection c ? c.Count : null; + var elements = new List(); - int totalCount = 0; + int enumeratedCount = 0; int currentLength = 0; bool truncated = false; - foreach (object? item in collection) + // Perf: wrap in try-catch so that faulting enumerators (e.g. collection modified during + // iteration, or user-defined iterators that throw) don't bubble up from assertion formatting. + try { - totalCount++; - if (truncated) + foreach (object? item in collection) { - continue; - } + enumeratedCount++; - string formatted = item is IEnumerable innerCollection and not string - ? FormatCollectionPreview(innerCollection, maxLength: 50) - : FormatValue(item, maxLength: 50); + string formatted = item is IEnumerable innerCollection and not string + ? FormatCollectionPreview(innerCollection, maxLength: 50) + : FormatValue(item, maxLength: 50); - // Account for ", " separator between elements - int addedLength = elements.Count > 0 - ? formatted.Length + 2 - : formatted.Length; + // Account for ", " separator between elements + int addedLength = elements.Count > 0 + ? formatted.Length + 2 + : formatted.Length; + + if (currentLength + addedLength > maxLength && elements.Count > 0) + { + truncated = true; + + // Perf: stop enumeration immediately once the display budget is exceeded. + // Without this break, we'd continue iterating potentially millions of + // elements (or hang on infinite sequences) just to compute totalCount. + break; + } - if (currentLength + addedLength > maxLength && elements.Count > 0) - { - truncated = true; - } - else - { elements.Add(formatted); currentLength += addedLength; } } + catch (Exception) + { + // If enumeration fails, report what we've collected so far + truncated = elements.Count > 0; + } + + int totalCount = knownCount ?? enumeratedCount; string elementList = string.Join(", ", elements); if (truncated) @@ -367,7 +392,13 @@ private static string FormatCollectionPreview(IEnumerable collection, int maxLen elementList += ", ..."; } - return $"[{elementList}] ({totalCount} {(totalCount == 1 ? "element" : "elements")})"; + // Perf: when truncated without ICollection, we don't know the real count (would require + // full enumeration). Show "N+ elements" to indicate the count is a lower bound. + string countText = truncated && knownCount is null + ? $"{enumeratedCount}+ elements" + : $"{totalCount} {(totalCount == 1 ? "element" : "elements")}"; + + return $"[{elementList}] ({countText})"; } internal static string FormatParameterWithValue(string paramName, string expression, string formattedValue) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index f5837865e6..a4c2e4357e 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -177,9 +177,9 @@ Expected value to be null. public void FormatCollectionPreview_WhenTotalStringLengthExceeds256_ShouldTruncate() { - // Each element is a 30-char string ? FormatValue wraps in quotes ? "aaa...aaa" = 32 chars + // Each element is a 30-char string -> FormatValue wraps in quotes -> "aaa...aaa" = 32 chars // With ", " separator: first = 32, subsequent = 34 each - // 32 + 634 = 236 = 256, 32 + 734 = 270 > 256 + // 32 + 6*34 = 236 <= 256, 32 + 7*34 = 270 > 256 // So 7 elements should display, then "...", with total count 20 var collection = new List(); for (int i = 0; i < 20; i++) @@ -230,10 +230,10 @@ Expected value to be null. public void FormatCollectionPreview_WhenNestedCollectionIsLarge_ShouldTruncateInnerAt50() { - // Inner collection has many elements ? inner preview string budget is 50 chars + // Inner collection has many elements -> inner preview string budget is 50 chars // Elements 0-9 are 1 char each: "0" takes 1, subsequent take 3 (digit + ", ") - // 1 + 93 = 28 chars for 0-9. Then 10-99 are 2 char digits + 2 sep = 4 each - // 28 + 4n = 50 ? n = 5.5 ? 5 more (10-14). 28 + 54 = 48, next would be 52 > 50 + // 1 + 9*3 = 28 chars for 0-9. Then 10-99 are 2 char digits + 2 sep = 4 each + // 28 + 4n = 50 -> n = 5.5 -> 5 more (10-14). 28 + 5*4 = 48, next would be 52 > 50 // So inner preview shows: 0-14 (15 elements), then "..." var inner = new List(); for (int i = 0; i < 50; i++) @@ -283,14 +283,12 @@ Expected collection to contain the specified item. #endregion } -[TestClass] -public sealed class ObjectWithNewlineToString +internal sealed class ObjectWithNewlineToString { public override string ToString() => "line1\r\nline2\nline3"; } -[TestClass] -public sealed class ObjectWithLongToString +internal sealed class ObjectWithLongToString { public override string ToString() => new string('L', 300); } From dfe9891e17482ec68c50bc03bd9f6a65c7f3bd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sun, 22 Feb 2026 21:16:42 +0100 Subject: [PATCH 17/58] Fix acceptance tests --- .../MSTest.Acceptance.IntegrationTests/OutputTests.cs | 7 ++++++- .../TrxReportTests.cs | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs index 0a2f3d678e..4f260239db 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs @@ -17,7 +17,12 @@ public async Task DetailedOutputIsAsExpected(string tfm) TestHostResult testHostResult = await testHost.ExecuteAsync("--output detailed", cancellationToken: TestContext.CancellationToken); // Assert - testHostResult.AssertOutputContains("Assert.AreEqual failed. Expected:<1>. Actual:<2>."); + testHostResult.AssertOutputContains(""" + Assert.AreEqual failed. + Expected values to be equal. + expected: 1 + actual: 2 + """); testHostResult.AssertOutputContains(""" Standard output Console message diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs index 2943f72d25..87f16e337b 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs @@ -33,7 +33,15 @@ public async Task TrxReport_WhenTestFails_ContainsExceptionInfoInOutput(string t // Verify that exception message is present Assert.Contains(@"", trxContent, trxContent); - Assert.Contains("Assert.AreEqual failed. Expected:<1>. Actual:<2>.", trxContent, trxContent); + Assert.Contains( + """ + Assert.AreEqual failed. + Expected values to be equal. + expected: 1 + actual: 2 + """, + trxContent, + trxContent); // Verify that stack trace is present Assert.Contains(@"", trxContent, trxContent); From f725f6005cd8258e3085888ea4828d3c2082a1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 11 Mar 2026 09:39:35 +0100 Subject: [PATCH 18/58] Fix diff caret position --- .../Assertions/Assert.AreEqual.cs | 2 +- .../Assertions/AssertTests.AreEqualTests.cs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index a9f8078a1f..02ca594974 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -609,7 +609,7 @@ private static string FormatStringDifferenceMessage(string expected, string actu string formattedUserMessage = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; - return formattedUserMessage + Environment.NewLine + lengthInfo + Environment.NewLine + expectedLine + Environment.NewLine + actualLine + Environment.NewLine + new string('-', adjustedCaretPosition) + "^"; + return formattedUserMessage + Environment.NewLine + lengthInfo + Environment.NewLine + expectedLine + Environment.NewLine + actualLine + Environment.NewLine + " " + new string('-', adjustedCaretPosition - 2) + "^"; } [DoesNotReturn] diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index 39ce38389d..e5786a1677 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -1610,7 +1610,7 @@ Assert.AreEqual failed. String lengths are both 4 but differ at index 0. expected: "baaa" actual: "aaaa" - -------------^ + -----------^ """); } @@ -1623,7 +1623,7 @@ Assert.AreEqual failed. String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" - ----------------^ + --------------^ """); } @@ -1636,7 +1636,7 @@ Assert.AreEqual failed. String lengths are both 4 but differ at index 2. expected ("aa\ta"): "aa?a" actual: "aa a" - -------------------------^ + -----------------------^ """); } @@ -1652,7 +1652,7 @@ Assert.AreEqual failed. String lengths are both 201 but differ at index 100. expected: "...aaaaaaaaaaaaaaaaaabcccccccccccccccc..." actual: "...aaaaaaaaaaaaaaaaaadcccccccccccccccc..." - ----------------------------------^ + --------------------------------^ """); } @@ -1665,7 +1665,7 @@ Assert.AreEqual failed. String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" - ----------------^ + --------------^ """); } @@ -1678,7 +1678,7 @@ Assert.AreEqual failed. Expected string length 4 but was 3. expected: "aaaa" actual: "aaa" - ----------------^ + --------------^ """); } @@ -1691,7 +1691,7 @@ Assert.AreEqual failed. Expected string length 3 but was 4. expected: "aaa" actual: "aaab" - ----------------^ + --------------^ """); } @@ -1704,7 +1704,7 @@ Assert.AreEqual failed. My custom message String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" - ----------------^ + --------------^ """); } @@ -1717,7 +1717,7 @@ Assert.AreEqual failed. Expected string length 2 but was 4. expected: "??" actual: "aaab" - -------------^ + -----------^ """); } From 9c96c9b761d052704efeb662578b65d8d0258290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 11 Mar 2026 09:46:45 +0100 Subject: [PATCH 19/58] Use X more chars instead of total length --- .../TestFramework/Assertions/Assert.cs | 4 ++-- .../Assertions/AssertTests.AreEqualTests.cs | 8 ++++---- .../Assertions/AssertTests.AreSame.cs | 8 ++++---- .../Assertions/AssertTests.Contains.cs | 4 ++-- .../Assertions/AssertTests.EndsWith.cs | 4 ++-- .../Assertions/AssertTests.IComparableTests.cs | 18 +++++++++--------- .../AssertTests.IsExactInstanceOfTypeTests.cs | 6 +++--- .../Assertions/AssertTests.IsInRange.cs | 6 +++--- .../AssertTests.IsInstanceOfTypeTests.cs | 4 ++-- .../Assertions/AssertTests.MatchesRegex.cs | 4 ++-- .../Assertions/AssertTests.StartsWith.cs | 4 ++-- .../Assertions/AssertTests.cs | 8 ++++---- 12 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 280bda1a20..e1d8bcded9 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -171,9 +171,9 @@ private static string Truncate(string value, int maxLength) => value.Length <= maxLength ? value #if NETCOREAPP3_1_OR_GREATER - : string.Concat(value.AsSpan(0, maxLength), "... (", value.Length.ToString(CultureInfo.InvariantCulture), " chars)"); + : string.Concat(value.AsSpan(0, maxLength), "... (", (value.Length - maxLength).ToString(CultureInfo.InvariantCulture), " more chars)"); #else - : value.Substring(0, maxLength) + $"... ({value.Length} chars)"; + : value.Substring(0, maxLength) + $"... ({value.Length - maxLength} more chars)"; #endif private static string EscapeNewlines(string value) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index e5786a1677..c45155620f 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -1952,8 +1952,8 @@ public void AreEqual_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.AreEqual failed. Expected values to be equal. - expected: {new string('L', 256)}... (300 chars) - actual: {new string('L', 256)}... (300 chars) + expected: {new string('L', 256)}... (44 more chars) + actual: {new string('L', 256)}... (44 more chars) """); } @@ -1995,8 +1995,8 @@ public void AreNotEqual_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.AreNotEqual failed. Expected values to differ. - notExpected (obj): {new string('L', 256)}... (300 chars) - actual (obj): {new string('L', 256)}... (300 chars) + notExpected (obj): {new string('L', 256)}... (44 more chars) + actual (obj): {new string('L', 256)}... (44 more chars) """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index b2157ff8a0..5a136b928d 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -169,8 +169,8 @@ public void AreSame_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.AreSame failed. Expected references to be the same. - expected (new ObjectWithLongToString()): {new string('L', 256)}... (300 chars) (HashCode=*) - actual (new ObjectWithLongToString()): {new string('L', 256)}... (300 chars) (HashCode=*) + expected (new ObjectWithLongToString()): {new string('L', 256)}... (44 more chars) (HashCode=*) + actual (new ObjectWithLongToString()): {new string('L', 256)}... (44 more chars) (HashCode=*) """); } @@ -209,8 +209,8 @@ public void AreNotSame_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.AreNotSame failed. Expected references to be different. - notExpected (obj): {new string('L', 256)}... (300 chars) - actual (obj): {new string('L', 256)}... (300 chars) + notExpected (obj): {new string('L', 256)}... (44 more chars) + actual (obj): {new string('L', 256)}... (44 more chars) """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index 1f6278fd94..ba587d5c24 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -1978,7 +1978,7 @@ public void Contains_String_WithLongValue_ShouldTruncateValue() Assert.Contains failed. String does not contain the expected substring. substring: "world" - value (longValue): "{new string('x', 255)}... (302 chars) + value (longValue): "{new string('x', 255)}... (46 more chars) """); } @@ -2018,7 +2018,7 @@ public void DoesNotContain_String_WithLongValue_ShouldTruncateValue() Assert.DoesNotContain failed. String contains the unexpected substring. substring: "hello" - value (longValue): "hello{new string('x', 250)}... (307 chars) + value (longValue): "hello{new string('x', 250)}... (51 more chars) """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs index ccb728e95d..8439ec6d46 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs @@ -79,7 +79,7 @@ public void EndsWith_WithLongValue_ShouldTruncateValue() Assert.EndsWith failed. String does not end with expected suffix. expectedSuffix: "world" - value (longValue): "{new string('x', 255)}... (302 chars) + value (longValue): "{new string('x', 255)}... (46 more chars) """); } @@ -119,7 +119,7 @@ public void DoesNotEndWith_WithLongValue_ShouldTruncateValue() Assert.DoesNotEndWith failed. String ends with unexpected suffix. notExpectedSuffix: "world" - value (longValue): "{new string('x', 255)}... (307 chars) + value (longValue): "{new string('x', 255)}... (51 more chars) """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs index 7ff76afcb9..0bfd049814 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -369,8 +369,8 @@ public void IsGreaterThan_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsGreaterThan failed. Expected value to be greater than the specified bound. - lowerBound: {new string('V', 256)}... (300 chars) - value: {new string('V', 256)}... (300 chars) + lowerBound: {new string('V', 256)}... (44 more chars) + value: {new string('V', 256)}... (44 more chars) """); } @@ -413,8 +413,8 @@ public void IsGreaterThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsGreaterThanOrEqualTo failed. Expected value to be greater than or equal to the specified bound. - lowerBound: {new string('V', 256)}... (300 chars) - value: {new string('V', 256)}... (300 chars) + lowerBound: {new string('V', 256)}... (44 more chars) + value: {new string('V', 256)}... (44 more chars) """); } @@ -457,8 +457,8 @@ public void IsLessThan_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsLessThan failed. Expected value to be less than the specified bound. - upperBound: {new string('V', 256)}... (300 chars) - value: {new string('V', 256)}... (300 chars) + upperBound: {new string('V', 256)}... (44 more chars) + value: {new string('V', 256)}... (44 more chars) """); } @@ -501,8 +501,8 @@ public void IsLessThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsLessThanOrEqualTo failed. Expected value to be less than or equal to the specified bound. - upperBound: {new string('V', 256)}... (300 chars) - value: {new string('V', 256)}... (300 chars) + upperBound: {new string('V', 256)}... (44 more chars) + value: {new string('V', 256)}... (44 more chars) """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index f4b24d3137..fa61b753b3 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -385,7 +385,7 @@ public void IsExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsExactInstanceOfType failed. Expected value to be exactly of the specified type. - value (obj): {new string('L', 256)}... (300 chars) + value (obj): {new string('L', 256)}... (44 more chars) expectedType: System.Int32 actualType: *ObjectWithLongToString """); @@ -430,7 +430,7 @@ public void IsNotExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsNotExactInstanceOfType failed. Value should not be exactly of the specified type. - value (obj): {new string('L', 256)}... (300 chars) + value (obj): {new string('L', 256)}... (44 more chars) wrongType: *ObjectWithLongToString actualType: *ObjectWithLongToString """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index df8615cc5a..72492d7231 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -467,9 +467,9 @@ public void IsInRange_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsInRange failed. Value is not within the expected range. - minValue (min): {new string('R', 256)}... (300 chars) - maxValue (max): {new string('R', 256)}... (300 chars) - value: {new string('R', 256)}... (300 chars) + minValue (min): {new string('R', 256)}... (44 more chars) + maxValue (max): {new string('R', 256)}... (44 more chars) + value: {new string('R', 256)}... (44 more chars) """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 318bb61968..da4d97d728 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -301,7 +301,7 @@ public void IsInstanceOfType_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsInstanceOfType failed. Expected value to be of the specified type. - value (obj): {new string('L', 256)}... (300 chars) + value (obj): {new string('L', 256)}... (44 more chars) expectedType: System.Int32 actualType: *ObjectWithLongToString """); @@ -346,7 +346,7 @@ public void IsNotInstanceOfType_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsNotInstanceOfType failed. Value should not be of the specified type. - value (obj): {new string('L', 256)}... (300 chars) + value (obj): {new string('L', 256)}... (44 more chars) wrongType: *ObjectWithLongToString actualType: *ObjectWithLongToString """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs index 20ba088baa..e7f1452370 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs @@ -67,7 +67,7 @@ public void MatchesRegex_WithLongValue_ShouldTruncateValue() Assert.MatchesRegex failed. String does not match expected pattern. pattern: \d+ - value (longValue): "{new string('x', 255)}... (302 chars) + value (longValue): "{new string('x', 255)}... (46 more chars) """); } @@ -107,7 +107,7 @@ public void DoesNotMatchRegex_WithLongValue_ShouldTruncateValue() Assert.DoesNotMatchRegex failed. String matches pattern but should not. pattern: \d+ - value (longValue): "{new string('1', 255)}... (302 chars) + value (longValue): "{new string('1', 255)}... (46 more chars) """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs index 3f3ef70dac..90343239b3 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs @@ -79,7 +79,7 @@ public void StartsWith_WithLongValue_ShouldTruncateValue() Assert.StartsWith failed. String does not start with expected prefix. expectedPrefix: "world" - value (longValue): "{new string('x', 255)}... (302 chars) + value (longValue): "{new string('x', 255)}... (46 more chars) """); } @@ -119,7 +119,7 @@ public void DoesNotStartWith_WithLongValue_ShouldTruncateValue() Assert.DoesNotStartWith failed. String starts with unexpected prefix. notExpectedPrefix: "hello" - value (longValue): "hello{new string('x', 250)}... (307 chars) + value (longValue): "hello{new string('x', 250)}... (51 more chars) """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index a4c2e4357e..f4ac8dd809 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -73,8 +73,8 @@ public void FormatValue_WhenStringExceedsMaxLength_ShouldTruncateWithEllipsis() // FormatValue truncation applies to non-string-diff contexts like IsNull // 300 'x' chars -> quoted as "xxx..." (302 chars total) -> truncated at 256 chars with ellipsis string longValue = new('x', 300); - // Truncate takes first 256 chars of quoted string: opening quote + 255 x's, then appends "... (302 chars)" - string expectedValue = "\"" + new string('x', 255) + "... (302 chars)"; + // Truncate takes first 256 chars of quoted string: opening quote + 255 x's, then appends "... (46 more chars)" + string expectedValue = "\"" + new string('x', 255) + "... (46 more chars)"; Action action = () => Assert.IsNull(longValue); action.Should().Throw() @@ -103,7 +103,7 @@ public void FormatValue_WhenCustomToStringExceedsMaxLength_ShouldTruncate() { // Custom ToString returns 300 chars ? truncated at 256 var obj = new ObjectWithLongToString(); - string expectedValue = new string('L', 256) + "... (300 chars)"; + string expectedValue = new string('L', 256) + "... (44 more chars)"; Action action = () => Assert.IsNull(obj); action.Should().Throw() @@ -201,7 +201,7 @@ public void FormatCollectionPreview_WhenElementToStringExceeds50_ShouldTruncateE { // Element has 80-char string ? FormatValue(maxLength:50) ? "zzz..." (82 chars quoted) ? truncated at 50 var collection = new List { new string('z', 80), "short" }; - string expectedFirstElement = "\"" + new string('z', 49) + "... (82 chars)"; + string expectedFirstElement = "\"" + new string('z', 49) + "... (32 more chars)"; Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() From 632c3c10dfb8cc466b684dc2a3afc173c5b33205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 11 Mar 2026 09:58:14 +0100 Subject: [PATCH 20/58] Use item instead of element --- .../TestFramework/Assertions/Assert.cs | 6 ++--- .../Resources/FrameworkMessages.resx | 4 ++-- .../Resources/xlf/FrameworkMessages.cs.xlf | 8 +++---- .../Resources/xlf/FrameworkMessages.de.xlf | 8 +++---- .../Resources/xlf/FrameworkMessages.es.xlf | 8 +++---- .../Resources/xlf/FrameworkMessages.fr.xlf | 8 +++---- .../Resources/xlf/FrameworkMessages.it.xlf | 8 +++---- .../Resources/xlf/FrameworkMessages.ja.xlf | 8 +++---- .../Resources/xlf/FrameworkMessages.ko.xlf | 8 +++---- .../Resources/xlf/FrameworkMessages.pl.xlf | 8 +++---- .../Resources/xlf/FrameworkMessages.pt-BR.xlf | 8 +++---- .../Resources/xlf/FrameworkMessages.ru.xlf | 8 +++---- .../Resources/xlf/FrameworkMessages.tr.xlf | 8 +++---- .../xlf/FrameworkMessages.zh-Hans.xlf | 8 +++---- .../xlf/FrameworkMessages.zh-Hant.xlf | 8 +++---- .../Assertions/AssertTests.Contains.cs | 6 ++--- .../Assertions/AssertTests.Items.cs | 24 +++++++++---------- .../Assertions/AssertTests.cs | 14 +++++------ 18 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index e1d8bcded9..c383238291 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -393,10 +393,10 @@ private static string FormatCollectionPreview(IEnumerable collection, int maxLen } // Perf: when truncated without ICollection, we don't know the real count (would require - // full enumeration). Show "N+ elements" to indicate the count is a lower bound. + // full enumeration). Show "N+ items" to indicate the count is a lower bound. string countText = truncated && knownCount is null - ? $"{enumeratedCount}+ elements" - : $"{totalCount} {(totalCount == 1 ? "element" : "elements")}"; + ? $"{enumeratedCount}+ items" + : $"{totalCount} {(totalCount == 1 ? "item" : "items")}"; return $"[{elementList}] ({countText})"; } diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index a2308fb26d..021e98fcef 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -334,10 +334,10 @@ Actual: {2} Expected exactly one item to match the predicate but found {0} item(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. Expected collection to contain any item but it is empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index 6a9f1e9e76..3a55011531 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Skutečnost: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index d3abf80bd0..9140235903 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Tatsächlich: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index c7a82dba08..6416d88204 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Real: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index ad48f54900..dd1f2d262e 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Réel : {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index 9dfcbe6442..68900310c3 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Effettivo: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index cd8d26e44b..d88c519410 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Actual: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index 88fb07d606..a1df05f673 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Actual: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index c184b50ba4..510bf94e6a 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Rzeczywiste: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index 369b210b24..08f42d5be8 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Real: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index 9a81c2d917..4a565ec9cb 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Actual: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index 4659b8ad12..46ad51880f 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Gerçekte olan: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index 33cb8bc4a0..ec618b8862 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Actual: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index f2f38200b9..328ecf7d3a 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -123,8 +123,8 @@ - Expected collection to contain exactly one element but found {0} element(s). - Expected collection to contain exactly one element but found {0} element(s). + Expected collection to contain exactly one item but found {0} item(s). + Expected collection to contain exactly one item but found {0} item(s). @@ -232,8 +232,8 @@ Actual: {2} - Expected collection to have the specified number of elements. - Expected collection to have the specified number of elements. + Expected collection to have the specified number of items. + Expected collection to have the specified number of items. diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index ba587d5c24..35c94258ac 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -340,7 +340,7 @@ public void ContainsSingle_InterpolatedHandler_WithMultipleElements_ThrowsExcept // Assert action.Should().Throw().WithMessage(""" Assert.ContainsSingle failed. - Expected collection to contain exactly one element but found 3 element(s). + Expected collection to contain exactly one item but found 3 item(s). """); } @@ -373,7 +373,7 @@ public void ContainsSingle_InNonGenericCollection_NoMessage_WithEmptyCollection_ // Assert action.Should().Throw().WithMessage(""" Assert.ContainsSingle failed. - Expected collection to contain exactly one element but found 0 element(s). + Expected collection to contain exactly one item but found 0 item(s). """); } @@ -391,7 +391,7 @@ public void ContainsSingle_InNonGenericCollection_AssertCustomMessage_WithEmptyC // Assert action.Should().Throw().WithMessage(""" Assert.ContainsSingle failed. my custom message - Expected collection to contain exactly one element but found 0 element(s). + Expected collection to contain exactly one item but found 0 item(s). """); } #endregion diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs index 8ef140805b..2f673bf8c7 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs @@ -27,8 +27,8 @@ public void Count_WhenCountIsNotSame_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.HasCount failed. - Expected collection to have the specified number of elements. - collection: [1] (1 element) + Expected collection to have the specified number of items. + collection: [1] (1 item) expectedCount: 3 actualCount: 1 """); @@ -42,8 +42,8 @@ public async Task Count_InterpolatedString_WhenCountIsNotSame_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.HasCount failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected collection to have the specified number of elements. - collection (Array.Empty()): [] (0 elements) + Expected collection to have the specified number of items. + collection (Array.Empty()): [] (0 items) expectedCount: 1 actualCount: 0 """); @@ -67,8 +67,8 @@ public void NotAny_WhenNotEmpty_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.IsEmpty failed. - Expected collection to have the specified number of elements. - collection: [1] (1 element) + Expected collection to have the specified number of items. + collection: [1] (1 item) expectedCount: 0 actualCount: 1 """); @@ -83,8 +83,8 @@ public async Task NotAny_InterpolatedString_WhenNotEmpty_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsEmpty failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected collection to have the specified number of elements. - collection: [1] (1 element) + Expected collection to have the specified number of items. + collection: [1] (1 item) expectedCount: 0 actualCount: 1 """); @@ -112,7 +112,7 @@ public void Single_WhenNoItems_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.ContainsSingle failed. - Expected collection to contain exactly one element but found 0 element(s). + Expected collection to contain exactly one item but found 0 item(s). collection: Array.Empty() """); } @@ -123,7 +123,7 @@ public void Single_WhenMultipleItems_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.ContainsSingle failed. - Expected collection to contain exactly one element but found 3 element(s). + Expected collection to contain exactly one item but found 3 item(s). collection: [1, 2, 3] """); } @@ -136,7 +136,7 @@ public async Task Single_InterpolatedString_WhenNoItem_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.ContainsSingle failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected collection to contain exactly one element but found 0 element(s). + Expected collection to contain exactly one item but found 0 item(s). collection: Array.Empty() """); o.WasToStringCalled.Should().BeTrue(); @@ -150,7 +150,7 @@ public async Task Single_InterpolatedString_WhenMultipleItems_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.ContainsSingle failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected collection to contain exactly one element but found 3 element(s). + Expected collection to contain exactly one item but found 3 item(s). collection: [1, 2, 3] """); o.WasToStringCalled.Should().BeTrue(); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index f4ac8dd809..e2765f1b11 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -171,7 +171,7 @@ public void FormatValue_WhenValueIsCollection_ShouldShowPreview() .WithMessage(""" Assert.IsNull failed. Expected value to be null. - value (collection): [1, 2, 3] (3 elements) + value (collection): [1, 2, 3] (3 items) """); } @@ -193,7 +193,7 @@ public void FormatCollectionPreview_WhenTotalStringLengthExceeds256_ShouldTrunca Assert.Contains failed. Expected collection to contain the specified item. expected: "not-there" - collection*[*...*] (20 elements) + collection*[*...*] (20 items) """); } @@ -209,7 +209,7 @@ public void FormatCollectionPreview_WhenElementToStringExceeds50_ShouldTruncateE Assert.Contains failed. Expected collection to contain the specified item. expected: "not-there" - collection*[{expectedFirstElement}, "short"] (2 elements) + collection*[{expectedFirstElement}, "short"] (2 items) """); } @@ -224,7 +224,7 @@ public void FormatCollectionPreview_WhenCollectionContainsNestedCollections_Shou .WithMessage(""" Assert.IsNull failed. Expected value to be null. - value (outer): [[1, 2] (2 elements), [3, 4] (2 elements)] (2 elements) + value (outer): [[1, 2] (2 items), [3, 4] (2 items)] (2 items) """); } @@ -248,7 +248,7 @@ public void FormatCollectionPreview_WhenNestedCollectionIsLarge_ShouldTruncateIn .WithMessage(""" Assert.IsNull failed. Expected value to be null. - value (outer): [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...] (50 elements)] (1 element) + value (outer): [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...] (50 items)] (1 item) """); } @@ -262,7 +262,7 @@ public void FormatCollectionPreview_WhenElementContainsNewlines_ShouldEscapeThem Assert.Contains failed. Expected collection to contain the specified item. expected: "not-there" - collection*["line1\nline2", "ok"] (2 elements) + collection*["line1\nline2", "ok"] (2 items) """); } @@ -276,7 +276,7 @@ public void FormatCollectionPreview_WhenSingleElement_ShouldShowSingularForm() Assert.Contains failed. Expected collection to contain the specified item. expected: 99 - collection*[42] (1 element) + collection*[42] (1 item) """); } From fa263f2b44f2c27a66331dcd4338524402230d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 11 Mar 2026 10:19:01 +0100 Subject: [PATCH 21/58] Use more items --- .../TestFramework/Assertions/Assert.cs | 19 +++++++++++++++---- .../Assertions/AssertTests.cs | 6 +++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index c383238291..8cfcff7108 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -385,6 +385,7 @@ private static string FormatCollectionPreview(IEnumerable collection, int maxLen } int totalCount = knownCount ?? enumeratedCount; + int displayedCount = elements.Count; string elementList = string.Join(", ", elements); if (truncated) @@ -392,11 +393,21 @@ private static string FormatCollectionPreview(IEnumerable collection, int maxLen elementList += ", ..."; } + // When truncated, show remaining count (how many more are not displayed). // Perf: when truncated without ICollection, we don't know the real count (would require - // full enumeration). Show "N+ items" to indicate the count is a lower bound. - string countText = truncated && knownCount is null - ? $"{enumeratedCount}+ items" - : $"{totalCount} {(totalCount == 1 ? "item" : "items")}"; + // full enumeration). Show "N+ more items" to indicate the remaining is a lower bound. + string countText; + if (truncated) + { + int remaining = totalCount - displayedCount; + countText = knownCount is null + ? $"{remaining}+ more items" + : $"{remaining} more {(remaining == 1 ? "item" : "items")}"; + } + else + { + countText = $"{totalCount} {(totalCount == 1 ? "item" : "items")}"; + } return $"[{elementList}] ({countText})"; } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index e2765f1b11..9a9a198e56 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -189,11 +189,11 @@ public void FormatCollectionPreview_WhenTotalStringLengthExceeds256_ShouldTrunca Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() - .WithMessage(""" + .WithMessage($""" Assert.Contains failed. Expected collection to contain the specified item. expected: "not-there" - collection*[*...*] (20 items) + collection: ["{new string('a', 30)}", "{new string('b', 30)}", "{new string('c', 30)}", "{new string('d', 30)}", "{new string('e', 30)}", "{new string('f', 30)}", "{new string('g', 30)}", ...] (13 more items) """); } @@ -248,7 +248,7 @@ public void FormatCollectionPreview_WhenNestedCollectionIsLarge_ShouldTruncateIn .WithMessage(""" Assert.IsNull failed. Expected value to be null. - value (outer): [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...] (50 items)] (1 item) + value (outer): [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...] (35 more items)] (1 item) """); } From 282218264220b3a82ddd7ea348b78a8b3d470c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 11 Mar 2026 12:26:06 +0100 Subject: [PATCH 22/58] Updates --- .../Assertions/Assert.Contains.cs | 8 ++-- .../TestFramework/Assertions/Assert.Count.cs | 2 +- .../TestFramework/Assertions/Assert.cs | 39 ++++++++----------- .../Assertions/AssertTests.AreEqualTests.cs | 10 ++--- .../Assertions/AssertTests.AreSame.cs | 10 ++--- .../Assertions/AssertTests.Contains.cs | 6 +-- .../Assertions/AssertTests.EndsWith.cs | 6 +-- .../AssertTests.IComparableTests.cs | 18 ++++----- .../AssertTests.IsExactInstanceOfTypeTests.cs | 6 +-- .../Assertions/AssertTests.IsInRange.cs | 8 ++-- .../AssertTests.IsInstanceOfTypeTests.cs | 6 +-- .../Assertions/AssertTests.MatchesRegex.cs | 6 +-- .../Assertions/AssertTests.StartsWith.cs | 6 +-- .../Assertions/AssertTests.cs | 12 +++--- 14 files changed, 68 insertions(+), 75 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs index fa44866baa..c573ab0761 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs @@ -768,7 +768,7 @@ private static void ThrowAssertContainsItemFailed(string? userMessage, string ex message += FormatExpressionParameter("expected", expectedExpression); if (collectionValue is not null) { - message += FormatCollectionParameter("collection", collectionExpression, collectionValue); + message += FormatCollectionParameter(collectionExpression, collectionValue); } else { @@ -786,7 +786,7 @@ private static void ThrowAssertContainsPredicateFailed(string? userMessage, stri message += FormatExpressionParameter("predicate", predicateExpression); if (collectionValue is not null) { - message += FormatCollectionParameter("collection", collectionExpression, collectionValue); + message += FormatCollectionParameter(collectionExpression, collectionValue); } else { @@ -804,7 +804,7 @@ private static void ThrowAssertDoesNotContainItemFailed(string? userMessage, str message += FormatExpressionParameter("notExpected", notExpectedExpression); if (collectionValue is not null) { - message += FormatCollectionParameter("collection", collectionExpression, collectionValue); + message += FormatCollectionParameter(collectionExpression, collectionValue); } else { @@ -822,7 +822,7 @@ private static void ThrowAssertDoesNotContainPredicateFailed(string? userMessage message += FormatExpressionParameter("predicate", predicateExpression); if (collectionValue is not null) { - message += FormatCollectionParameter("collection", collectionExpression, collectionValue); + message += FormatCollectionParameter(collectionExpression, collectionValue); } else { diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs index 80e29e1a5e..a6e54464e2 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs @@ -336,7 +336,7 @@ private static void ThrowAssertCountFailed(string assertionName, int expectedCou { string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; msg += Environment.NewLine + FrameworkMessages.HasCountFailNew; - msg += FormatCollectionParameter(nameof(collection), collectionExpression, collection); + msg += FormatCollectionParameter(collectionExpression, collection); msg += $"{Environment.NewLine} expectedCount: {expectedCount}"; msg += $"{Environment.NewLine} actualCount: {actualCount}"; ThrowAssertFailed($"Assert.{assertionName}", msg); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 8cfcff7108..aeaa547109 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -171,9 +171,9 @@ private static string Truncate(string value, int maxLength) => value.Length <= maxLength ? value #if NETCOREAPP3_1_OR_GREATER - : string.Concat(value.AsSpan(0, maxLength), "... (", (value.Length - maxLength).ToString(CultureInfo.InvariantCulture), " more chars)"); + : string.Concat(value.AsSpan(0, maxLength), "... ", (value.Length - maxLength).ToString(CultureInfo.InvariantCulture), " more"); #else - : value.Substring(0, maxLength) + $"... ({value.Length - maxLength} more chars)"; + : value.Substring(0, maxLength) + $"... {value.Length - maxLength} more"; #endif private static string EscapeNewlines(string value) @@ -318,12 +318,13 @@ internal static string FormatExpressionParameter(string paramName, string expres /// /// Formats a collection parameter line showing a preview of the collection elements. /// - internal static string FormatCollectionParameter(string paramName, string expression, IEnumerable collection) + internal static string FormatCollectionParameter(string expression, IEnumerable collection) { string preview = FormatCollectionPreview(collection); - return string.IsNullOrEmpty(expression) || expression == paramName - ? $"{Environment.NewLine} {paramName}: {preview}" - : $"{Environment.NewLine} {paramName} ({TruncateExpression(expression)}): {preview}"; + + return string.IsNullOrEmpty(expression) || expression == "collection" + ? $"{Environment.NewLine} collection: {preview}" + : $"{Environment.NewLine} collection ({TruncateExpression(expression)}): {preview}"; } /// @@ -389,27 +390,19 @@ private static string FormatCollectionPreview(IEnumerable collection, int maxLen string elementList = string.Join(", ", elements); if (truncated) - { - elementList += ", ..."; - } - - // When truncated, show remaining count (how many more are not displayed). - // Perf: when truncated without ICollection, we don't know the real count (would require - // full enumeration). Show "N+ more items" to indicate the remaining is a lower bound. - string countText; - if (truncated) { int remaining = totalCount - displayedCount; - countText = knownCount is null - ? $"{remaining}+ more items" - : $"{remaining} more {(remaining == 1 ? "item" : "items")}"; - } - else - { - countText = $"{totalCount} {(totalCount == 1 ? "item" : "items")}"; + string remainingText = knownCount is null + ? $"{remaining}+" + : $"{remaining}"; + elementList += $", ... {remainingText} more"; } - return $"[{elementList}] ({countText})"; + string countText = truncated + ? string.Empty + : $" ({totalCount} {(totalCount == 1 ? "item" : "items")})"; + + return $"[{elementList}]{countText}"; } internal static string FormatParameterWithValue(string paramName, string expression, string formattedValue) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index c45155620f..0eca0cc1f1 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -1952,8 +1952,8 @@ public void AreEqual_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.AreEqual failed. Expected values to be equal. - expected: {new string('L', 256)}... (44 more chars) - actual: {new string('L', 256)}... (44 more chars) + expected: {new string('L', 256)}... 44 more + actual: {new string('L', 256)}... 44 more """); } @@ -1995,8 +1995,8 @@ public void AreNotEqual_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.AreNotEqual failed. Expected values to differ. - notExpected (obj): {new string('L', 256)}... (44 more chars) - actual (obj): {new string('L', 256)}... (44 more chars) + notExpected (obj): {new string('L', 256)}... 44 more + actual (obj): {new string('L', 256)}... 44 more """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index 5a136b928d..52062c45d9 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -169,8 +169,8 @@ public void AreSame_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.AreSame failed. Expected references to be the same. - expected (new ObjectWithLongToString()): {new string('L', 256)}... (44 more chars) (HashCode=*) - actual (new ObjectWithLongToString()): {new string('L', 256)}... (44 more chars) (HashCode=*) + expected (new ObjectWithLongToString()): {new string('L', 256)}... 44 more (HashCode=*) + actual (new ObjectWithLongToString()): {new string('L', 256)}... 44 more (HashCode=*) """); } @@ -209,8 +209,8 @@ public void AreNotSame_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.AreNotSame failed. Expected references to be different. - notExpected (obj): {new string('L', 256)}... (44 more chars) - actual (obj): {new string('L', 256)}... (44 more chars) + notExpected (obj): {new string('L', 256)}... 44 more + actual (obj): {new string('L', 256)}... 44 more """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index 35c94258ac..f653e7c189 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -1978,7 +1978,7 @@ public void Contains_String_WithLongValue_ShouldTruncateValue() Assert.Contains failed. String does not contain the expected substring. substring: "world" - value (longValue): "{new string('x', 255)}... (46 more chars) + value (longValue): "{new string('x', 255)}... 46 more """); } @@ -2018,7 +2018,7 @@ public void DoesNotContain_String_WithLongValue_ShouldTruncateValue() Assert.DoesNotContain failed. String contains the unexpected substring. substring: "hello" - value (longValue): "hello{new string('x', 250)}... (51 more chars) + value (longValue): "hello{new string('x', 250)}... 51 more """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs index 8439ec6d46..b1c8f3a9da 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -79,7 +79,7 @@ public void EndsWith_WithLongValue_ShouldTruncateValue() Assert.EndsWith failed. String does not end with expected suffix. expectedSuffix: "world" - value (longValue): "{new string('x', 255)}... (46 more chars) + value (longValue): "{new string('x', 255)}... 46 more """); } @@ -119,7 +119,7 @@ public void DoesNotEndWith_WithLongValue_ShouldTruncateValue() Assert.DoesNotEndWith failed. String ends with unexpected suffix. notExpectedSuffix: "world" - value (longValue): "{new string('x', 255)}... (51 more chars) + value (longValue): "{new string('x', 255)}... 51 more """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs index 0bfd049814..91fb83b9bb 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -369,8 +369,8 @@ public void IsGreaterThan_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsGreaterThan failed. Expected value to be greater than the specified bound. - lowerBound: {new string('V', 256)}... (44 more chars) - value: {new string('V', 256)}... (44 more chars) + lowerBound: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -413,8 +413,8 @@ public void IsGreaterThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsGreaterThanOrEqualTo failed. Expected value to be greater than or equal to the specified bound. - lowerBound: {new string('V', 256)}... (44 more chars) - value: {new string('V', 256)}... (44 more chars) + lowerBound: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -457,8 +457,8 @@ public void IsLessThan_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsLessThan failed. Expected value to be less than the specified bound. - upperBound: {new string('V', 256)}... (44 more chars) - value: {new string('V', 256)}... (44 more chars) + upperBound: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -501,8 +501,8 @@ public void IsLessThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsLessThanOrEqualTo failed. Expected value to be less than or equal to the specified bound. - upperBound: {new string('V', 256)}... (44 more chars) - value: {new string('V', 256)}... (44 more chars) + upperBound: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index fa61b753b3..95df717c92 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -385,7 +385,7 @@ public void IsExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsExactInstanceOfType failed. Expected value to be exactly of the specified type. - value (obj): {new string('L', 256)}... (44 more chars) + value (obj): {new string('L', 256)}... 44 more expectedType: System.Int32 actualType: *ObjectWithLongToString """); @@ -430,7 +430,7 @@ public void IsNotExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsNotExactInstanceOfType failed. Value should not be exactly of the specified type. - value (obj): {new string('L', 256)}... (44 more chars) + value (obj): {new string('L', 256)}... 44 more wrongType: *ObjectWithLongToString actualType: *ObjectWithLongToString """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index 72492d7231..549bfd9e65 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -467,9 +467,9 @@ public void IsInRange_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsInRange failed. Value is not within the expected range. - minValue (min): {new string('R', 256)}... (44 more chars) - maxValue (max): {new string('R', 256)}... (44 more chars) - value: {new string('R', 256)}... (44 more chars) + minValue (min): {new string('R', 256)}... 44 more + maxValue (max): {new string('R', 256)}... 44 more + value: {new string('R', 256)}... 44 more """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index da4d97d728..c98e2d112b 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -301,7 +301,7 @@ public void IsInstanceOfType_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsInstanceOfType failed. Expected value to be of the specified type. - value (obj): {new string('L', 256)}... (44 more chars) + value (obj): {new string('L', 256)}... 44 more expectedType: System.Int32 actualType: *ObjectWithLongToString """); @@ -346,7 +346,7 @@ public void IsNotInstanceOfType_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.IsNotInstanceOfType failed. Value should not be of the specified type. - value (obj): {new string('L', 256)}... (44 more chars) + value (obj): {new string('L', 256)}... 44 more wrongType: *ObjectWithLongToString actualType: *ObjectWithLongToString """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs index e7f1452370..936ae1ebc1 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -67,7 +67,7 @@ public void MatchesRegex_WithLongValue_ShouldTruncateValue() Assert.MatchesRegex failed. String does not match expected pattern. pattern: \d+ - value (longValue): "{new string('x', 255)}... (46 more chars) + value (longValue): "{new string('x', 255)}... 46 more """); } @@ -107,7 +107,7 @@ public void DoesNotMatchRegex_WithLongValue_ShouldTruncateValue() Assert.DoesNotMatchRegex failed. String matches pattern but should not. pattern: \d+ - value (longValue): "{new string('1', 255)}... (46 more chars) + value (longValue): "{new string('1', 255)}... 46 more """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs index 90343239b3..cab465f361 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -79,7 +79,7 @@ public void StartsWith_WithLongValue_ShouldTruncateValue() Assert.StartsWith failed. String does not start with expected prefix. expectedPrefix: "world" - value (longValue): "{new string('x', 255)}... (46 more chars) + value (longValue): "{new string('x', 255)}... 46 more """); } @@ -119,7 +119,7 @@ public void DoesNotStartWith_WithLongValue_ShouldTruncateValue() Assert.DoesNotStartWith failed. String starts with unexpected prefix. notExpectedPrefix: "hello" - value (longValue): "hello{new string('x', 250)}... (51 more chars) + value (longValue): "hello{new string('x', 250)}... 51 more """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index 9a9a198e56..a39430af58 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -73,8 +73,8 @@ public void FormatValue_WhenStringExceedsMaxLength_ShouldTruncateWithEllipsis() // FormatValue truncation applies to non-string-diff contexts like IsNull // 300 'x' chars -> quoted as "xxx..." (302 chars total) -> truncated at 256 chars with ellipsis string longValue = new('x', 300); - // Truncate takes first 256 chars of quoted string: opening quote + 255 x's, then appends "... (46 more chars)" - string expectedValue = "\"" + new string('x', 255) + "... (46 more chars)"; + // Truncate takes first 256 chars of quoted string: opening quote + 255 x's, then appends "... 46 more" + string expectedValue = "\"" + new string('x', 255) + "... 46 more"; Action action = () => Assert.IsNull(longValue); action.Should().Throw() @@ -103,7 +103,7 @@ public void FormatValue_WhenCustomToStringExceedsMaxLength_ShouldTruncate() { // Custom ToString returns 300 chars ? truncated at 256 var obj = new ObjectWithLongToString(); - string expectedValue = new string('L', 256) + "... (44 more chars)"; + string expectedValue = new string('L', 256) + "... 44 more"; Action action = () => Assert.IsNull(obj); action.Should().Throw() @@ -193,7 +193,7 @@ public void FormatCollectionPreview_WhenTotalStringLengthExceeds256_ShouldTrunca Assert.Contains failed. Expected collection to contain the specified item. expected: "not-there" - collection: ["{new string('a', 30)}", "{new string('b', 30)}", "{new string('c', 30)}", "{new string('d', 30)}", "{new string('e', 30)}", "{new string('f', 30)}", "{new string('g', 30)}", ...] (13 more items) + collection: ["{new string('a', 30)}", "{new string('b', 30)}", "{new string('c', 30)}", "{new string('d', 30)}", "{new string('e', 30)}", "{new string('f', 30)}", "{new string('g', 30)}", ... 13 more] """); } @@ -201,7 +201,7 @@ public void FormatCollectionPreview_WhenElementToStringExceeds50_ShouldTruncateE { // Element has 80-char string ? FormatValue(maxLength:50) ? "zzz..." (82 chars quoted) ? truncated at 50 var collection = new List { new string('z', 80), "short" }; - string expectedFirstElement = "\"" + new string('z', 49) + "... (32 more chars)"; + string expectedFirstElement = "\"" + new string('z', 49) + "... 32 more"; Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() @@ -248,7 +248,7 @@ public void FormatCollectionPreview_WhenNestedCollectionIsLarge_ShouldTruncateIn .WithMessage(""" Assert.IsNull failed. Expected value to be null. - value (outer): [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...] (35 more items)] (1 item) + value (outer): [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 35 more]] (1 item) """); } From 39b59ebe6f13e79cd2bc913e890830782c9c14f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 11 Mar 2026 16:09:26 +0100 Subject: [PATCH 23/58] Simplify user message handling --- src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 02ca594974..84e10e09a8 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -534,7 +534,7 @@ private static string FormatStringComparisonMessage(string? expected, string? ac // Handle null cases if (expected is null || actual is null) { - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; + string message = userMessage; message += Environment.NewLine + FormatParameter(nameof(expected), expectedExpression, expected) + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); return message; From 60d17a90117bb0550c2c2179c4908509d80b1e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 11 Mar 2026 16:14:59 +0100 Subject: [PATCH 24/58] Update hash text --- .../Assertions/Assert.AreSame.cs | 4 +-- .../Assertions/AssertTests.AreSame.cs | 36 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 5f40000fb5..88fe7104b8 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -196,10 +196,10 @@ private static void ThrowAssertAreSameFailed(T? expected, T? actual, string? string actualFormatted = FormatValue(actual); bool sameToString = expected is not null && actual is not null && expectedFormatted == actualFormatted; string expectedValue = sameToString - ? expectedFormatted + $" (HashCode={RuntimeHelpers.GetHashCode(expected!)})" + ? expectedFormatted + $" (Hash={RuntimeHelpers.GetHashCode(expected!)})" : expectedFormatted; string actualValue = sameToString - ? actualFormatted + $" (HashCode={RuntimeHelpers.GetHashCode(actual!)})" + ? actualFormatted + $" (Hash={RuntimeHelpers.GetHashCode(actual!)})" : actualFormatted; // If value types, add diagnostic hint before parameter details diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index 52062c45d9..2de6fe88c0 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -19,8 +19,8 @@ public void AreSame_PassDifferentObject_ShouldFail() action.Should().Throw().WithMessage(""" Assert.AreSame failed. Expected references to be the same. - expected (new object()): (HashCode=*) - actual (new object()): (HashCode=*) + expected (new object()): (Hash=*) + actual (new object()): (Hash=*) """); } @@ -36,8 +36,8 @@ public void AreSame_StringMessage_PassDifferentObject_ShouldFail() action.Should().Throw().WithMessage(""" Assert.AreSame failed. User-provided message Expected references to be the same. - expected (new object()): (HashCode=*) - actual (new object()): (HashCode=*) + expected (new object()): (Hash=*) + actual (new object()): (Hash=*) """); } @@ -56,8 +56,8 @@ public async Task AreSame_InterpolatedString_PassDifferentObject_ShouldFail() (await action.Should().ThrowAsync()).WithMessage(""" Assert.AreSame failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected references to be the same. - expected (new object()): (HashCode=*) - actual (new object()): (HashCode=*) + expected (new object()): (Hash=*) + actual (new object()): (Hash=*) """); o.WasToStringCalled.Should().BeTrue(); } @@ -71,8 +71,8 @@ public void AreSame_BothAreValueTypes_ShouldFailWithSpecializedMessage() action.Should().Throw().WithMessage(""" Assert.AreSame failed. Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). - expected: 1 (HashCode=*) - actual: 1 (HashCode=*) + expected: 1 (Hash=*) + actual: 1 (Hash=*) """); } @@ -82,8 +82,8 @@ public void AreSame_StringMessage_BothAreValueTypes_ShouldFailWithSpecializedMes action.Should().Throw().WithMessage(""" Assert.AreSame failed. User-provided message Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). - expected: 1 (HashCode=*) - actual: 1 (HashCode=*) + expected: 1 (Hash=*) + actual: 1 (Hash=*) """); } @@ -93,8 +93,8 @@ public void AreSame_InterpolatedString_BothAreValueTypes_ShouldFailWithSpecializ action.Should().Throw().WithMessage(""" Assert.AreSame failed. User-provided message System.Object Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). - expected: 1 (HashCode=*) - actual: 1 (HashCode=*) + expected: 1 (Hash=*) + actual: 1 (Hash=*) """); } @@ -157,8 +157,8 @@ public void AreSame_WithLongExpression_ShouldTruncateExpression() .WithMessage(""" Assert.AreSame failed. Expected references to be the same. - expected (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): (HashCode=*) - actual (new object()): (HashCode=*) + expected (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): (Hash=*) + actual (new object()): (Hash=*) """); } @@ -169,8 +169,8 @@ public void AreSame_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.AreSame failed. Expected references to be the same. - expected (new ObjectWithLongToString()): {new string('L', 256)}... 44 more (HashCode=*) - actual (new ObjectWithLongToString()): {new string('L', 256)}... 44 more (HashCode=*) + expected (new ObjectWithLongToString()): {new string('L', 256)}... 44 more (Hash=*) + actual (new ObjectWithLongToString()): {new string('L', 256)}... 44 more (Hash=*) """); } @@ -181,8 +181,8 @@ public void AreSame_WithNewlineInToString_ShouldEscapeNewlines() .WithMessage(""" Assert.AreSame failed. Expected references to be the same. - expected (new ObjectWithNewlineToString()): line1\r\nline2\nline3 (HashCode=*) - actual (new ObjectWithNewlineToString()): line1\r\nline2\nline3 (HashCode=*) + expected (new ObjectWithNewlineToString()): line1\r\nline2\nline3 (Hash=*) + actual (new ObjectWithNewlineToString()): line1\r\nline2\nline3 (Hash=*) """); } From 44c6ca1dce908373bb66beb1876f5bee01616b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 11 Mar 2026 22:19:08 +0100 Subject: [PATCH 25/58] Improve --- .../TestFramework/Assertions/Assert.cs | 14 ++++++-------- .../Assertions/AssertTests.AreEqualTests.cs | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index aeaa547109..9c0a9863ee 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -54,10 +54,11 @@ internal static void ThrowAssertFailed(string assertionName, string? message) // When there's no user message (message starts with newline for parameter details), // the format produces a trailing space before the newline ("failed. \\r\\n"). - // Remove it to avoid trailing whitespace on the first line. + // Remove it to avoid trailing whitespace on the first line while preserving localization. if (message is not null && message.StartsWith(Environment.NewLine, StringComparison.Ordinal)) { - formattedMessage = $"{assertionName} failed.{message}"; + string prefix = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AssertionFailed, assertionName, string.Empty); + formattedMessage = prefix.TrimEnd() + message; } throw new AssertFailedException(formattedMessage); @@ -125,12 +126,9 @@ internal static string FormatValue(T? value, int maxLength = 256) return FormatCollectionPreview(enumerable); } - Type type = typeof(T); - if (type == typeof(object)) - { - // If the static type is object, use the runtime type - type = value.GetType(); - } + // Always use the runtime type for non-null values so that interface/base-class + // typed parameters still resolve the actual overridden ToString(). + Type type = value.GetType(); if (type.IsPrimitive || value is decimal or DateTime or DateTimeOffset or TimeSpan or Guid or Enum) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index 0eca0cc1f1..e34dfc5a02 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -1634,7 +1634,7 @@ public void AreEqualStringWithSpecialCharactersShouldEscape() .WithMessage(""" Assert.AreEqual failed. String lengths are both 4 but differ at index 2. - expected ("aa\ta"): "aa?a" + expected ("aa\ta"): "aa␉a" actual: "aa a" -----------------------^ """); From 2610e3acf3305319680b0d98f2307faa3c473c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 12 Mar 2026 09:54:38 +0100 Subject: [PATCH 26/58] Move expressions to first line Assert.AreEqual("aaaa", "aaab") failed. String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" --------------^ --- .../Assertions/Assert.AreEqual.cs | 87 +++--- .../Assertions/Assert.AreSame.cs | 17 +- .../Assertions/Assert.Contains.cs | 67 ++--- .../TestFramework/Assertions/Assert.Count.cs | 7 +- .../Assertions/Assert.EndsWith.cs | 16 +- .../Assertions/Assert.IComparable.cs | 38 ++- .../Assert.IsExactInstanceOfType.cs | 6 +- .../Assertions/Assert.IsInstanceOfType.cs | 6 +- .../TestFramework/Assertions/Assert.IsNull.cs | 6 +- .../TestFramework/Assertions/Assert.IsTrue.cs | 6 +- .../Assertions/Assert.Matches.cs | 16 +- .../Assertions/Assert.StartsWith.cs | 16 +- .../TestFramework/Assertions/Assert.cs | 87 ++++-- .../Assertions/AssertTests.AreEqualTests.cs | 266 +++++++++--------- .../Assertions/AssertTests.AreSame.cs | 84 +++--- .../Assertions/AssertTests.Contains.cs | 193 +++++-------- .../Assertions/AssertTests.EndsWith.cs | 36 +-- .../AssertTests.IComparableTests.cs | 84 +++--- .../AssertTests.IsExactInstanceOfTypeTests.cs | 66 ++--- .../Assertions/AssertTests.IsInRange.cs | 70 ++--- .../AssertTests.IsInstanceOfTypeTests.cs | 46 +-- .../Assertions/AssertTests.IsNull.cs | 18 +- .../Assertions/AssertTests.IsTrueTests.cs | 68 ++--- .../Assertions/AssertTests.Items.cs | 42 ++- .../Assertions/AssertTests.MatchesRegex.cs | 32 +-- .../Assertions/AssertTests.StartsWith.cs | 36 +-- .../AssertTests.ThrowsExceptionTests.cs | 2 +- .../Assertions/AssertTests.cs | 46 ++- 28 files changed, 737 insertions(+), 727 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 84e10e09a8..0b08c2a036 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -529,14 +529,16 @@ private static bool AreEqualFailing(decimal expected, decimal actual, decimal de private static bool AreEqualFailing(long expected, long actual, long delta) => Math.Abs(expected - actual) > delta; - private static string FormatStringComparisonMessage(string? expected, string? actual, string userMessage, string expectedExpression, string actualExpression) + private static string FormatStringComparisonMessage(string? expected, string? actual, string userMessage) { // Handle null cases if (expected is null || actual is null) { string message = userMessage; - message += Environment.NewLine + FormatParameter(nameof(expected), expectedExpression, expected) - + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); + message += FormatAlignedParameters( + (nameof(expected), FormatValue(expected)), + (nameof(actual), FormatValue(actual))); + return message; } @@ -550,7 +552,7 @@ private static string FormatStringComparisonMessage(string? expected, string? ac } // Format the enhanced string comparison message - return FormatStringDifferenceMessage(expected, actual, diffIndex, userMessage, expectedExpression, actualExpression); + return FormatStringDifferenceMessage(expected, actual, diffIndex, userMessage); } private static int FindFirstStringDifference(string expected, string actual) @@ -569,7 +571,7 @@ private static int FindFirstStringDifference(string expected, string actual) return expected.Length != actual.Length ? minLength : -1; } - private static string FormatStringDifferenceMessage(string expected, string actual, int diffIndex, string userMessage, string expectedExpression, string actualExpression) + private static string FormatStringDifferenceMessage(string expected, string actual, int diffIndex, string userMessage) { string lengthInfo = expected.Length == actual.Length ? string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreEqualStringDiffLengthBothMsg, expected.Length, diffIndex) @@ -582,27 +584,15 @@ private static string FormatStringDifferenceMessage(string expected, string actu string actualPreview = tuple.Item2; int caretPosition = tuple.Item3; - // Build parameter line prefixes with expression info - // Skip expression when it's redundant (equals the quoted string value) - string expectedQuoted = $"\"{expected}\""; - string actualQuoted = $"\"{actual}\""; - string expectedPrefix = (expectedExpression == nameof(expected) || IsExpressionRedundant(expectedExpression, expectedQuoted)) - ? " expected: " - : $" expected ({TruncateExpression(expectedExpression)}): "; - string actualPrefix = (actualExpression == nameof(actual) || IsExpressionRedundant(actualExpression, actualQuoted)) - ? " actual: " - : $" actual ({TruncateExpression(actualExpression)}): "; - - // Calculate the maximum prefix length to align the caret properly - int maxPrefixLength = Math.Max(expectedPrefix.Length, actualPrefix.Length); + // Fixed prefixes - expressions are now shown on the first line + string expectedPrefix = " expected: "; + string actualPrefix = " actual: "; - // Pad shorter prefix to match the longer one for proper alignment - string paddedExpectedPrefix = expectedPrefix.PadRight(maxPrefixLength); - string paddedActualPrefix = actualPrefix.PadRight(maxPrefixLength); + int maxPrefixLength = expectedPrefix.Length; // " expected: " is always the longest // Build the formatted lines with proper alignment - string expectedLine = paddedExpectedPrefix + $"\"{expectedPreview}\""; - string actualLine = paddedActualPrefix + $"\"{actualPreview}\""; + string expectedLine = expectedPrefix + $"\"{expectedPreview}\""; + string actualLine = actualPrefix + $"\"{actualPreview}\""; // The caret should align under the difference in the string content int adjustedCaretPosition = maxPrefixLength + 1 + caretPosition; // +1 for the opening quote @@ -615,60 +605,67 @@ private static string FormatStringDifferenceMessage(string expected, string actu [DoesNotReturn] private static void ThrowAssertAreEqualFailed(object? expected, object? actual, string? userMessage, string expectedExpression, string actualExpression) { + string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; if (actual is not null && expected is not null && !actual.GetType().Equals(expected.GetType())) { message += Environment.NewLine + FrameworkMessages.AreEqualFailNew; - message += $"{Environment.NewLine}{FormatParameter(nameof(expected), expectedExpression, expected)} ({expected.GetType().FullName})" - + $"{Environment.NewLine}{FormatParameter(nameof(actual), actualExpression, actual)} ({actual.GetType().FullName})"; + message += FormatAlignedParameters( + (nameof(expected), $"{FormatValue(expected)} ({expected.GetType().FullName})"), + (nameof(actual), $"{FormatValue(actual)} ({actual.GetType().FullName})")); } else if (expected is string expectedString && actual is string actualString) { - message = FormatStringComparisonMessage(expectedString, actualString, message, expectedExpression, actualExpression); - ThrowAssertFailed("Assert.AreEqual", message); + message = FormatStringComparisonMessage(expectedString, actualString, message); + ThrowAssertFailed(callSite, message); return; } else { message += Environment.NewLine + FrameworkMessages.AreEqualFailNew; - message += Environment.NewLine + FormatParameter(nameof(expected), expectedExpression, expected) - + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); + message += FormatAlignedParameters( + (nameof(expected), FormatValue(expected)), + (nameof(actual), FormatValue(actual))); } - ThrowAssertFailed("Assert.AreEqual", message); + ThrowAssertFailed(callSite, message); } [DoesNotReturn] private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, string? userMessage, string expectedExpression, string actualExpression) where T : struct, IConvertible { + string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreEqualDeltaNoGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - message += Environment.NewLine + FormatParameter(nameof(expected), expectedExpression, expected) - + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); - ThrowAssertFailed("Assert.AreEqual", message); + message += FormatAlignedParameters( + (nameof(expected), FormatValue(expected)), + (nameof(actual), FormatValue(actual))); + ThrowAssertFailed(callSite, message); } [DoesNotReturn] private static void ThrowAssertAreEqualFailed(string? expected, string? actual, bool ignoreCase, CultureInfo culture, string? userMessage, string expectedExpression, string actualExpression) { + string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; // If the user requested to match case, and the difference between expected/actual is casing only, then we use a different message. if (!ignoreCase && CompareInternal(expected, actual, ignoreCase: true, culture) == 0) { message += Environment.NewLine + FrameworkMessages.AreEqualCaseDiffersMsg; - message += Environment.NewLine + FormatParameter(nameof(expected), expectedExpression, expected) - + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); + message += FormatAlignedParameters( + (nameof(expected), FormatValue(expected)), + (nameof(actual), FormatValue(actual))); } else { // Use enhanced string comparison for string-specific failures - message = FormatStringComparisonMessage(expected, actual, message, expectedExpression, actualExpression); + message = FormatStringComparisonMessage(expected, actual, message); } - ThrowAssertFailed("Assert.AreEqual", message); + ThrowAssertFailed(callSite, message); } /// @@ -1181,11 +1178,13 @@ private static bool AreNotEqualFailing(double notExpected, double actual, double private static void ThrowAssertAreNotEqualFailed(T notExpected, T actual, T delta, string? userMessage, string notExpectedExpression, string actualExpression) where T : struct, IConvertible { + string callSite = FormatCallSite("Assert.AreNotEqual", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreNotEqualDeltaGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); - message += Environment.NewLine + FormatParameter(nameof(notExpected), notExpectedExpression, notExpected) - + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); - ThrowAssertFailed("Assert.AreNotEqual", message); + message += FormatAlignedParameters( + (nameof(notExpected), FormatValue(notExpected)), + (nameof(actual), FormatValue(actual))); + ThrowAssertFailed(callSite, message); } /// @@ -1385,11 +1384,13 @@ private static bool AreNotEqualFailing(T? notExpected, T? actual, IEqualityCo [DoesNotReturn] private static void ThrowAssertAreNotEqualFailed(object? notExpected, object? actual, string? userMessage, string notExpectedExpression, string actualExpression) { + string callSite = FormatCallSite("Assert.AreNotEqual", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.AreNotEqualFailNew; - message += Environment.NewLine + FormatParameter(nameof(notExpected), notExpectedExpression, notExpected) - + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); - ThrowAssertFailed("Assert.AreNotEqual", message); + message += FormatAlignedParameters( + (nameof(notExpected), FormatValue(notExpected)), + (nameof(actual), FormatValue(actual))); + ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 88fe7104b8..b85e4b1dbf 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -188,6 +188,7 @@ private static bool IsAreSameFailing(T? expected, T? actual) [DoesNotReturn] private static void ThrowAssertAreSameFailed(T? expected, T? actual, string? userMessage, string expectedExpression, string actualExpression) { + string callSite = FormatCallSite("Assert.AreSame", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; // When both values have the same string representation, include hash codes @@ -212,11 +213,11 @@ private static void ThrowAssertAreSameFailed(T? expected, T? actual, string? message += Environment.NewLine + FrameworkMessages.AreSameFailNew; } - // Check expression redundancy against the base formatted value (without hashcode) - message += Environment.NewLine + FormatParameterWithExpressionCheck(nameof(expected), expectedExpression, expectedFormatted, expectedValue) - + Environment.NewLine + FormatParameterWithExpressionCheck(nameof(actual), actualExpression, actualFormatted, actualValue); + message += FormatAlignedParameters( + (nameof(expected), expectedValue), + (nameof(actual), actualValue)); - ThrowAssertFailed("Assert.AreSame", message); + ThrowAssertFailed(callSite, message); } /// @@ -270,10 +271,12 @@ private static bool IsAreNotSameFailing(T? notExpected, T? actual) [DoesNotReturn] private static void ThrowAssertAreNotSameFailed(T? notExpected, T? actual, string? userMessage, string notExpectedExpression, string actualExpression) { + string callSite = FormatCallSite("Assert.AreNotSame", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.AreNotSameFailNew; - message += Environment.NewLine + FormatParameter(nameof(notExpected), notExpectedExpression, notExpected) - + Environment.NewLine + FormatParameter(nameof(actual), actualExpression, actual); - ThrowAssertFailed("Assert.AreNotSame", message); + message += FormatAlignedParameters( + (nameof(notExpected), FormatValue(notExpected)), + (nameof(actual), FormatValue(actual))); + ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs index c573ab0761..a1debff78a 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs @@ -744,122 +744,111 @@ public static void IsInRange(T minValue, T maxValue, T value, string? message [DoesNotReturn] private static void ThrowAssertSingleMatchFailed(int actualCount, string? userMessage, string predicateExpression, string collectionExpression) { + string callSite = FormatCallSite("Assert.ContainsSingle", ("predicate", predicateExpression), ("collection", collectionExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleMatchFailNew, actualCount); - message += FormatExpressionParameter("predicate", predicateExpression) - + FormatExpressionParameter("collection", collectionExpression); - ThrowAssertFailed("Assert.ContainsSingle", message); + ThrowAssertFailed(callSite, message); } [DoesNotReturn] private static void ThrowAssertContainsSingleFailed(int actualCount, string? userMessage, string collectionExpression) { + string callSite = FormatCallSite("Assert.ContainsSingle", ("collection", collectionExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleFailNew, actualCount); - message += FormatExpressionParameter("collection", collectionExpression); - ThrowAssertFailed("Assert.ContainsSingle", message); + ThrowAssertFailed(callSite, message); } [DoesNotReturn] private static void ThrowAssertContainsItemFailed(string? userMessage, string expectedExpression, string collectionExpression, IEnumerable? collectionValue = null) { + string callSite = FormatCallSite("Assert.Contains", ("expected", expectedExpression), ("collection", collectionExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.ContainsItemFailNew; - message += FormatExpressionParameter("expected", expectedExpression); if (collectionValue is not null) { message += FormatCollectionParameter(collectionExpression, collectionValue); } - else - { - message += FormatExpressionParameter("collection", collectionExpression); - } - ThrowAssertFailed("Assert.Contains", message); + ThrowAssertFailed(callSite, message); } [DoesNotReturn] private static void ThrowAssertContainsPredicateFailed(string? userMessage, string predicateExpression, string collectionExpression, IEnumerable? collectionValue = null) { + string callSite = FormatCallSite("Assert.Contains", ("predicate", predicateExpression), ("collection", collectionExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.ContainsPredicateFailNew; - message += FormatExpressionParameter("predicate", predicateExpression); if (collectionValue is not null) { message += FormatCollectionParameter(collectionExpression, collectionValue); } - else - { - message += FormatExpressionParameter("collection", collectionExpression); - } - ThrowAssertFailed("Assert.Contains", message); + ThrowAssertFailed(callSite, message); } [DoesNotReturn] private static void ThrowAssertDoesNotContainItemFailed(string? userMessage, string notExpectedExpression, string collectionExpression, IEnumerable? collectionValue = null) { + string callSite = FormatCallSite("Assert.DoesNotContain", ("notExpected", notExpectedExpression), ("collection", collectionExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.DoesNotContainItemFailNew; - message += FormatExpressionParameter("notExpected", notExpectedExpression); if (collectionValue is not null) { message += FormatCollectionParameter(collectionExpression, collectionValue); } - else - { - message += FormatExpressionParameter("collection", collectionExpression); - } - ThrowAssertFailed("Assert.DoesNotContain", message); + ThrowAssertFailed(callSite, message); } [DoesNotReturn] private static void ThrowAssertDoesNotContainPredicateFailed(string? userMessage, string predicateExpression, string collectionExpression, IEnumerable? collectionValue = null) { + string callSite = FormatCallSite("Assert.DoesNotContain", ("predicate", predicateExpression), ("collection", collectionExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.DoesNotContainPredicateFailNew; - message += FormatExpressionParameter("predicate", predicateExpression); if (collectionValue is not null) { message += FormatCollectionParameter(collectionExpression, collectionValue); } - else - { - message += FormatExpressionParameter("collection", collectionExpression); - } - ThrowAssertFailed("Assert.DoesNotContain", message); + ThrowAssertFailed(callSite, message); } [DoesNotReturn] private static void ThrowAssertStringContainsFailed(string value, string substring, string? userMessage, string substringExpression, string valueExpression) { + string callSite = FormatCallSite("Assert.Contains", (nameof(substring), substringExpression), (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.ContainsStringFailNew; - message += Environment.NewLine + FormatParameter(nameof(substring), substringExpression, substring) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.Contains", message); + message += FormatAlignedParameters( + (nameof(substring), FormatValue(substring)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, message); } [DoesNotReturn] private static void ThrowAssertStringDoesNotContainFailed(string value, string substring, string? userMessage, string substringExpression, string valueExpression) { + string callSite = FormatCallSite("Assert.DoesNotContain", (nameof(substring), substringExpression), (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.DoesNotContainStringFailNew; - message += Environment.NewLine + FormatParameter(nameof(substring), substringExpression, substring) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.DoesNotContain", message); + message += FormatAlignedParameters( + (nameof(substring), FormatValue(substring)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, message); } [DoesNotReturn] private static void ThrowAssertIsInRangeFailed(T value, T minValue, T maxValue, string? userMessage, string minValueExpression, string maxValueExpression, string valueExpression) { + string callSite = FormatCallSite("Assert.IsInRange", (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.IsInRangeFailNew; - message += Environment.NewLine + FormatParameter(nameof(minValue), minValueExpression, minValue) - + Environment.NewLine + FormatParameter(nameof(maxValue), maxValueExpression, maxValue) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.IsInRange", message); + message += FormatAlignedParameters( + (nameof(minValue), FormatValue(minValue)), + (nameof(maxValue), FormatValue(maxValue)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs index a6e54464e2..04b1cd5c32 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs @@ -334,20 +334,21 @@ private static void HasCount(string assertionName, int expected, IEnumerable col [DoesNotReturn] private static void ThrowAssertCountFailed(string assertionName, int expectedCount, int actualCount, IEnumerable collection, string? userMessage, string collectionExpression) { + string callSite = FormatCallSite($"Assert.{assertionName}", ("collection", collectionExpression)); string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; msg += Environment.NewLine + FrameworkMessages.HasCountFailNew; msg += FormatCollectionParameter(collectionExpression, collection); msg += $"{Environment.NewLine} expectedCount: {expectedCount}"; msg += $"{Environment.NewLine} actualCount: {actualCount}"; - ThrowAssertFailed($"Assert.{assertionName}", msg); + ThrowAssertFailed(callSite, msg); } [DoesNotReturn] private static void ThrowAssertIsNotEmptyFailed(string? userMessage, string collectionExpression) { + string callSite = FormatCallSite("Assert.IsNotEmpty", ("collection", collectionExpression)); string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; msg += Environment.NewLine + FrameworkMessages.IsNotEmptyFailNew; - msg += FormatExpressionParameter("collection", collectionExpression); - ThrowAssertFailed("Assert.IsNotEmpty", msg); + ThrowAssertFailed(callSite, msg); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs b/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs index 2c01ed2044..1b1bc6ef7f 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs @@ -76,11 +76,13 @@ public static void EndsWith([NotNull] string? expectedSuffix, [NotNull] string? CheckParameterNotNull(expectedSuffix, "Assert.EndsWith", "expectedSuffix"); if (!value.EndsWith(expectedSuffix, comparisonType)) { + string callSite = FormatCallSite("Assert.EndsWith", (nameof(expectedSuffix), expectedSuffixExpression), (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; msg += Environment.NewLine + FrameworkMessages.EndsWithFailNew; - msg += Environment.NewLine + FormatParameter(nameof(expectedSuffix), expectedSuffixExpression, expectedSuffix) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.EndsWith", msg); + msg += FormatAlignedParameters( + (nameof(expectedSuffix), FormatValue(expectedSuffix)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, msg); } } @@ -152,11 +154,13 @@ public static void DoesNotEndWith([NotNull] string? notExpectedSuffix, [NotNull] CheckParameterNotNull(notExpectedSuffix, "Assert.DoesNotEndWith", "notExpectedSuffix"); if (value.EndsWith(notExpectedSuffix, comparisonType)) { + string callSite = FormatCallSite("Assert.DoesNotEndWith", (nameof(notExpectedSuffix), notExpectedSuffixExpression), (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; msg += Environment.NewLine + FrameworkMessages.DoesNotEndWithFailNew; - msg += Environment.NewLine + FormatParameter(nameof(notExpectedSuffix), notExpectedSuffixExpression, notExpectedSuffix) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.DoesNotEndWith", msg); + msg += FormatAlignedParameters( + (nameof(notExpectedSuffix), FormatValue(notExpectedSuffix)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, msg); } } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs b/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs index c4cc5c3183..5767ee98a4 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs @@ -291,58 +291,68 @@ public static void IsNegative(T value, string? message = "", [CallerArgumentE [DoesNotReturn] private static void ThrowAssertIsGreaterThanFailed(T lowerBound, T value, string? userMessage, string lowerBoundExpression, string valueExpression) { + string callSite = FormatCallSite("Assert.IsGreaterThan", (nameof(lowerBound), lowerBoundExpression), (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; msg += Environment.NewLine + FrameworkMessages.IsGreaterThanFailNew; - msg += Environment.NewLine + FormatParameter(nameof(lowerBound), lowerBoundExpression, lowerBound) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.IsGreaterThan", msg); + msg += FormatAlignedParameters( + (nameof(lowerBound), FormatValue(lowerBound)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, msg); } [DoesNotReturn] private static void ThrowAssertIsGreaterThanOrEqualToFailed(T lowerBound, T value, string? userMessage, string lowerBoundExpression, string valueExpression) { + string callSite = FormatCallSite("Assert.IsGreaterThanOrEqualTo", (nameof(lowerBound), lowerBoundExpression), (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; msg += Environment.NewLine + FrameworkMessages.IsGreaterThanOrEqualToFailNew; - msg += Environment.NewLine + FormatParameter(nameof(lowerBound), lowerBoundExpression, lowerBound) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.IsGreaterThanOrEqualTo", msg); + msg += FormatAlignedParameters( + (nameof(lowerBound), FormatValue(lowerBound)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, msg); } [DoesNotReturn] private static void ThrowAssertIsLessThanFailed(T upperBound, T value, string? userMessage, string upperBoundExpression, string valueExpression) { + string callSite = FormatCallSite("Assert.IsLessThan", (nameof(upperBound), upperBoundExpression), (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; msg += Environment.NewLine + FrameworkMessages.IsLessThanFailNew; - msg += Environment.NewLine + FormatParameter(nameof(upperBound), upperBoundExpression, upperBound) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.IsLessThan", msg); + msg += FormatAlignedParameters( + (nameof(upperBound), FormatValue(upperBound)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, msg); } [DoesNotReturn] private static void ThrowAssertIsLessThanOrEqualToFailed(T upperBound, T value, string? userMessage, string upperBoundExpression, string valueExpression) { + string callSite = FormatCallSite("Assert.IsLessThanOrEqualTo", (nameof(upperBound), upperBoundExpression), (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; msg += Environment.NewLine + FrameworkMessages.IsLessThanOrEqualToFailNew; - msg += Environment.NewLine + FormatParameter(nameof(upperBound), upperBoundExpression, upperBound) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.IsLessThanOrEqualTo", msg); + msg += FormatAlignedParameters( + (nameof(upperBound), FormatValue(upperBound)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, msg); } [DoesNotReturn] private static void ThrowAssertIsPositiveFailed(T value, string? userMessage, string valueExpression) { + string callSite = FormatCallSite("Assert.IsPositive", (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; msg += Environment.NewLine + FrameworkMessages.IsPositiveFailNew; msg += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.IsPositive", msg); + ThrowAssertFailed(callSite, msg); } [DoesNotReturn] private static void ThrowAssertIsNegativeFailed(T value, string? userMessage, string valueExpression) { + string callSite = FormatCallSite("Assert.IsNegative", (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; msg += Environment.NewLine + FrameworkMessages.IsNegativeFailNew; msg += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.IsNegative", msg); + ThrowAssertFailed(callSite, msg); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs index 5f8fa68c2c..904d24f39b 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs @@ -322,6 +322,7 @@ private static bool IsExactInstanceOfTypeFailing([NotNullWhen(false)] object? va [DoesNotReturn] private static void ThrowAssertIsExactInstanceOfTypeFailed(object? value, Type? expectedType, string? userMessage, string valueExpression) { + string callSite = FormatCallSite("Assert.IsExactInstanceOfType", (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; if (expectedType is not null && value is not null) { @@ -335,7 +336,7 @@ private static void ThrowAssertIsExactInstanceOfTypeFailed(object? value, Type? + Environment.NewLine + $" actualType: {value.GetType()}"; } - ThrowAssertFailed("Assert.IsExactInstanceOfType", message); + ThrowAssertFailed(callSite, message); } /// @@ -400,6 +401,7 @@ private static bool IsNotExactInstanceOfTypeFailing(object? value, [NotNullWhen( [DoesNotReturn] private static void ThrowAssertIsNotExactInstanceOfTypeFailed(object? value, Type? wrongType, string? userMessage, string valueExpression) { + string callSite = FormatCallSite("Assert.IsNotExactInstanceOfType", (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; if (wrongType is not null) { @@ -413,6 +415,6 @@ private static void ThrowAssertIsNotExactInstanceOfTypeFailed(object? value, Typ + Environment.NewLine + $" actualType: {value!.GetType()}"; } - ThrowAssertFailed("Assert.IsNotExactInstanceOfType", message); + ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index afb997ef4a..d8bd8117bd 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -329,6 +329,7 @@ private static bool IsInstanceOfTypeFailing([NotNullWhen(false)] object? value, [DoesNotReturn] private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expectedType, string? userMessage, string valueExpression) { + string callSite = FormatCallSite("Assert.IsInstanceOfType", (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; if (expectedType is not null && value is not null) { @@ -342,7 +343,7 @@ private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expec + Environment.NewLine + $" actualType: {value.GetType()}"; } - ThrowAssertFailed("Assert.IsInstanceOfType", message); + ThrowAssertFailed(callSite, message); } /// @@ -409,6 +410,7 @@ private static bool IsNotInstanceOfTypeFailing(object? value, [NotNullWhen(false [DoesNotReturn] private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wrongType, string? userMessage, string valueExpression) { + string callSite = FormatCallSite("Assert.IsNotInstanceOfType", (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; if (wrongType is not null) { @@ -422,6 +424,6 @@ private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wr + Environment.NewLine + $" actualType: {value!.GetType()}"; } - ThrowAssertFailed("Assert.IsNotInstanceOfType", message); + ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 8de60e7629..4b447ea7de 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -161,10 +161,11 @@ public static void IsNull(object? value, string? message = "", [CallerArgumentEx [DoesNotReturn] private static void ThrowAssertIsNullFailed(object? value, string? userMessage, string valueExpression) { + string callSite = FormatCallSite("Assert.IsNull", (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.IsNullFailNew; message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.IsNull", message); + ThrowAssertFailed(callSite, message); } /// @@ -206,9 +207,10 @@ public static void IsNotNull([NotNull] object? value, string? message = "", [Cal [DoesNotReturn] private static void ThrowAssertIsNotNullFailed(string? userMessage, string valueExpression) { + string callSite = FormatCallSite("Assert.IsNotNull", ("value", valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.IsNotNullFailNew; message += Environment.NewLine + FormatParameter("value", valueExpression, null); - ThrowAssertFailed("Assert.IsNotNull", message); + ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index a9dcae1299..1ea772f961 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -162,10 +162,11 @@ private static bool IsTrueFailing(bool? condition) [DoesNotReturn] private static void ThrowAssertIsTrueFailed(bool? condition, string? userMessage, string conditionExpression) { + string callSite = FormatCallSite("Assert.IsTrue", (nameof(condition), conditionExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.IsTrueFailNew; message += Environment.NewLine + FormatParameter(nameof(condition), conditionExpression, condition); - ThrowAssertFailed("Assert.IsTrue", message); + ThrowAssertFailed(callSite, message); } /// @@ -206,9 +207,10 @@ private static bool IsFalseFailing(bool? condition) [DoesNotReturn] private static void ThrowAssertIsFalseFailed(bool? condition, string? userMessage, string conditionExpression) { + string callSite = FormatCallSite("Assert.IsFalse", (nameof(condition), conditionExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; message += Environment.NewLine + FrameworkMessages.IsFalseFailNew; message += Environment.NewLine + FormatParameter(nameof(condition), conditionExpression, condition); - ThrowAssertFailed("Assert.IsFalse", message); + ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs b/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs index c2a8ad6827..ce2f23fe09 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs @@ -44,11 +44,13 @@ public static void MatchesRegex([NotNull] Regex? pattern, [NotNull] string? valu if (!pattern.IsMatch(value)) { + string callSite = FormatCallSite("Assert.MatchesRegex", (nameof(pattern), patternExpression), (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; msg += Environment.NewLine + FrameworkMessages.MatchesRegexFailNew; - msg += Environment.NewLine + FormatParameter(nameof(pattern), patternExpression, pattern) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.MatchesRegex", msg); + msg += FormatAlignedParameters( + (nameof(pattern), FormatValue(pattern)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, msg); } } @@ -122,11 +124,13 @@ public static void DoesNotMatchRegex([NotNull] Regex? pattern, [NotNull] string? if (pattern.IsMatch(value)) { + string callSite = FormatCallSite("Assert.DoesNotMatchRegex", (nameof(pattern), patternExpression), (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; msg += Environment.NewLine + FrameworkMessages.DoesNotMatchRegexFailNew; - msg += Environment.NewLine + FormatParameter(nameof(pattern), patternExpression, pattern) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.DoesNotMatchRegex", msg); + msg += FormatAlignedParameters( + (nameof(pattern), FormatValue(pattern)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, msg); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs b/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs index c38e8a0110..47f94e657e 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs @@ -76,11 +76,13 @@ public static void StartsWith([NotNull] string? expectedPrefix, [NotNull] string CheckParameterNotNull(expectedPrefix, "Assert.StartsWith", "expectedPrefix"); if (!value.StartsWith(expectedPrefix, comparisonType)) { + string callSite = FormatCallSite("Assert.StartsWith", (nameof(expectedPrefix), expectedPrefixExpression), (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; msg += Environment.NewLine + FrameworkMessages.StartsWithFailNew; - msg += Environment.NewLine + FormatParameter(nameof(expectedPrefix), expectedPrefixExpression, expectedPrefix) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.StartsWith", msg); + msg += FormatAlignedParameters( + (nameof(expectedPrefix), FormatValue(expectedPrefix)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, msg); } } @@ -150,11 +152,13 @@ public static void DoesNotStartWith([NotNull] string? notExpectedPrefix, [NotNul CheckParameterNotNull(notExpectedPrefix, "Assert.DoesNotStartWith", "notExpectedPrefix"); if (value.StartsWith(notExpectedPrefix, comparisonType)) { + string callSite = FormatCallSite("Assert.DoesNotStartWith", (nameof(notExpectedPrefix), notExpectedPrefixExpression), (nameof(value), valueExpression)); string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; msg += Environment.NewLine + FrameworkMessages.DoesNotStartWithFailNew; - msg += Environment.NewLine + FormatParameter(nameof(notExpectedPrefix), notExpectedPrefixExpression, notExpectedPrefix) - + Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - ThrowAssertFailed("Assert.DoesNotStartWith", msg); + msg += FormatAlignedParameters( + (nameof(notExpectedPrefix), FormatValue(notExpectedPrefix)), + (nameof(value), FormatValue(value))); + ThrowAssertFailed(callSite, msg); } } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 9c0a9863ee..7988a6a684 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -286,27 +286,14 @@ internal static string FormatParameter(string paramName, string expression, T { string formattedValue = FormatValue(value); - // If expression is a typed numeric literal more specific than the value, use it as the display - if (IsExpressionMoreSpecificNumericLiteral(expression, formattedValue)) - { - return $" {paramName}: {expression}"; - } - - // Skip expression when it matches the parameter name (e.g., "minValue (minValue): 5" → "minValue: 5") - if (expression == paramName || IsExpressionRedundant(expression, formattedValue)) - { - return $" {paramName}: {formattedValue}"; - } - - // Default case: show both expression and value - return $" {paramName} ({TruncateExpression(expression)}): {formattedValue}"; + return $" {paramName}: {formattedValue}"; } /// /// Formats a parameter line showing only the expression (no value). - /// Used for parameters like collections, predicates, and actions where the + /// Used for parameters like predicates and actions where the /// runtime value's ToString() is not useful. - /// Returns empty string if the expression is empty or matches the parameter name (nothing useful to show). + /// Returns empty string if the expression is empty or matches the parameter name. /// internal static string FormatExpressionParameter(string paramName, string expression) => string.IsNullOrEmpty(expression) || expression == paramName @@ -320,9 +307,7 @@ internal static string FormatCollectionParameter(string expression, IEnumerable { string preview = FormatCollectionPreview(collection); - return string.IsNullOrEmpty(expression) || expression == "collection" - ? $"{Environment.NewLine} collection: {preview}" - : $"{Environment.NewLine} collection ({TruncateExpression(expression)}): {preview}"; + return $"{Environment.NewLine} collection: {preview}"; } /// @@ -404,18 +389,70 @@ private static string FormatCollectionPreview(IEnumerable collection, int maxLen } internal static string FormatParameterWithValue(string paramName, string expression, string formattedValue) - => (expression == paramName || IsExpressionRedundant(expression, formattedValue)) - ? $" {paramName}: {formattedValue}" - : $" {paramName} ({TruncateExpression(expression)}): {formattedValue}"; + => $" {paramName}: {formattedValue}"; /// /// Formats a parameter line, checking expression redundancy against a base value /// while displaying a different (enriched) display value. /// internal static string FormatParameterWithExpressionCheck(string paramName, string expression, string baseValue, string displayValue) - => (expression == paramName || IsExpressionRedundant(expression, baseValue)) - ? $" {paramName}: {displayValue}" - : $" {paramName} ({TruncateExpression(expression)}): {displayValue}"; + => $" {paramName}: {displayValue}"; + + /// + /// Builds the "Assert.Method(expr1, expr2)" call site string for the first line. + /// Only the primary/semantic parameters are included (not message, culture, delta, etc.). + /// + internal static string FormatCallSite(string methodName, params (string ParamName, string Expression)[] args) + { + var sb = new StringBuilder(methodName); + sb.Append('('); + for (int i = 0; i < args.Length; i++) + { + if (i > 0) + { + sb.Append(", "); + } + + string expression = args[i].Expression; + string paramName = args[i].ParamName; + sb.Append(string.IsNullOrEmpty(expression) || expression == paramName + ? paramName + : TruncateExpression(expression, 50)); + } + + sb.Append(')'); + + return sb.ToString(); + } + + /// + /// Formats multiple parameter lines with aligned values. + /// All labels are padded so that values start at the same column. + /// + internal static string FormatAlignedParameters(params (string Label, string Value)[] parameters) + { + int maxLabelLength = 0; + foreach ((string label, string _) in parameters) + { + if (label.Length > maxLabelLength) + { + maxLabelLength = label.Length; + } + } + + var sb = new StringBuilder(); + foreach ((string label, string value) in parameters) + { + sb.Append(Environment.NewLine); + sb.Append(" "); + sb.Append(label); + sb.Append(':'); + sb.Append(new string(' ', maxLabelLength - label.Length + 1)); + sb.Append(value); + } + + return sb.ToString(); + } private static int CompareInternal(string? expected, string? actual, bool ignoreCase, CultureInfo culture) #pragma warning disable CA1309 // Use ordinal string comparison diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index e34dfc5a02..e4e14bae59 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -20,10 +20,10 @@ public void AreNotEqualShouldFailWhenNotEqualTypeWithMessage() Action action = () => Assert.AreNotEqual(1, 1, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual failed. A Message + Assert.AreNotEqual(*) failed. A Message Expected values to differ. notExpected: 1 - actual: 1 + actual: 1 """); } @@ -38,10 +38,10 @@ public void AreNotEqualShouldFailWhenNotEqualStringWithMessage() Action action = () => Assert.AreNotEqual("A", "A", "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual failed. A Message + Assert.AreNotEqual(*) failed. A Message Expected values to differ. notExpected: "A" - actual: "A" + actual: "A" """); } @@ -63,10 +63,10 @@ public void AreNotEqualShouldFailWhenNotEqualIntWithMessage() Action action = () => Assert.AreNotEqual(1, 1, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual failed. A Message + Assert.AreNotEqual(*) failed. A Message Expected values to differ. notExpected: 1 - actual: 1 + actual: 1 """); } @@ -81,10 +81,10 @@ public void AreNotEqualShouldFailWhenNotEqualLongWithMessage() Action action = () => Assert.AreNotEqual(1L, 1L, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual failed. A Message + Assert.AreNotEqual(*) failed. A Message Expected values to differ. - notExpected: 1L - actual: 1L + notExpected: 1 + actual: 1 """); } @@ -105,10 +105,10 @@ public void AreNotEqualShouldFailWhenNotEqualDecimalWithMessage() Action action = () => Assert.AreNotEqual(0.1M, 0.1M, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual failed. A Message + Assert.AreNotEqual(*) failed. A Message Expected values to differ. - notExpected: 0.1M - actual: 0.1M + notExpected: 0.1 + actual: 0.1 """); } @@ -129,10 +129,10 @@ public void AreNotEqualShouldFailWhenNotEqualDoubleWithMessage() Action action = () => Assert.AreNotEqual(0.1, 0.1, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual failed. A Message + Assert.AreNotEqual(*) failed. A Message Expected values to differ. notExpected: 0.1 - actual: 0.1 + actual: 0.1 """); } @@ -153,10 +153,10 @@ public void AreNotEqualShouldFailWhenFloatDoubleWithMessage() Action action = () => Assert.AreNotEqual(100E-2, 100E-2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual failed. A Message + Assert.AreNotEqual(*) failed. A Message Expected values to differ. notExpected: 1 - actual: 1 + actual: 1 """); } @@ -177,10 +177,10 @@ public void AreEqualShouldFailWhenNotEqualTypeWithMessage() Action action = () => Assert.AreEqual(null, "string", "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. A Message + Assert.AreEqual(*) failed. A Message Expected values to be equal. expected: (null) - actual: "string" + actual: "string" """); } @@ -215,10 +215,10 @@ public void AreEqual_WithEnglishCultureAndDoesNotIgnoreCase_Throws() Action action = () => Assert.AreEqual(expected, actual, false, englishCulture); action.Should().Throw() .WithMessage("""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Case differs. expected: "i" - actual: "I" + actual: "I" """"); } @@ -257,10 +257,10 @@ public void AreEqualShouldFailWhenNotEqualIntWithMessage() Action action = () => Assert.AreEqual(1, 2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. A Message + Assert.AreEqual(*) failed. A Message Expected values to be equal. expected: 1 - actual: 2 + actual: 2 """); } @@ -275,10 +275,10 @@ public void AreEqualShouldFailWhenNotEqualLongWithMessage() Action action = () => Assert.AreEqual(1L, 2L, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. A Message + Assert.AreEqual(*) failed. A Message Expected values to be equal. - expected: 1L - actual: 2L + expected: 1 + actual: 2 """); } @@ -299,10 +299,10 @@ public void AreEqualShouldFailWhenNotEqualDoubleWithMessage() Action action = () => Assert.AreEqual(0.1, 0.2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. A Message + Assert.AreEqual(*) failed. A Message Expected values to be equal. expected: 0.1 - actual: 0.2 + actual: 0.2 """); } @@ -324,10 +324,10 @@ public void AreEqualShouldFailWhenNotEqualDecimalWithMessage() Action action = () => Assert.AreEqual(0.1M, 0.2M, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. A Message + Assert.AreEqual(*) failed. A Message Expected values to be equal. - expected: 0.1M - actual: 0.2M + expected: 0.1 + actual: 0.2 """); } @@ -348,10 +348,10 @@ public void AreEqualShouldFailWhenFloatDoubleWithMessage() Action action = () => Assert.AreEqual(100E-2, 200E-2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. A Message + Assert.AreEqual(*) failed. A Message Expected values to be equal. expected: 1 - actual: 2 + actual: 2 """); } @@ -372,10 +372,10 @@ public void AreEqualTwoObjectsDifferentTypeShouldFail() Action action = () => Assert.AreEqual(new object(), 1); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected values to be equal. - expected (new object()): (System.Object) - actual: 1 (System.Int32) + expected: (System.Object) + actual: 1 (System.Int32) """); } @@ -448,10 +448,10 @@ public async Task GenericAreEqual_InterpolatedString_DifferentValues_ShouldFail( Func action = async () => Assert.AreEqual(0, 1, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected values to be equal. expected: 0 - actual: 1 + actual: 1 """); o.WasToStringCalled.Should().BeTrue(); } @@ -470,10 +470,10 @@ public async Task GenericAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(0, 0, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected values to differ. notExpected: 0 - actual: 0 + actual: 0 """); o.WasToStringCalled.Should().BeTrue(); } @@ -492,10 +492,10 @@ public async Task FloatAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1.0f, 1.1f, 0.001f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than <0.001>. - expected: 1.0f - actual: 1.1f + expected: 1 + actual: 1.1 """); o.WasToStringCalled.Should().BeTrue(); } @@ -514,10 +514,10 @@ public async Task FloatAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0f, 1.1f, 0.2f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than <0.2>. - notExpected: 1.0f - actual: 1.1f + notExpected: 1 + actual: 1.1 """); o.WasToStringCalled.Should().BeTrue(); } @@ -536,10 +536,10 @@ public async Task DecimalAreEqual_InterpolatedString_DifferentValues_ShouldFail( Func action = async () => Assert.AreEqual(1.0m, 1.1m, 0.001m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than <0.001>. - expected: 1.0m - actual: 1.1m + expected: 1.0 + actual: 1.1 """); o.WasToStringCalled.Should().BeTrue(); } @@ -558,10 +558,10 @@ public async Task DecimalAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0m, 1.1m, 0.2m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than <0.2>. - notExpected: 1.0m - actual: 1.1m + notExpected: 1.0 + actual: 1.1 """); o.WasToStringCalled.Should().BeTrue(); } @@ -580,10 +580,10 @@ public async Task LongAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1L, 2L, 0L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than <0>. - expected: 1L - actual: 2L + expected: 1 + actual: 2 """); o.WasToStringCalled.Should().BeTrue(); } @@ -602,10 +602,10 @@ public async Task LongAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1L, 2L, 1L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than <1>. - notExpected: 1L - actual: 2L + notExpected: 1 + actual: 2 """); o.WasToStringCalled.Should().BeTrue(); } @@ -624,10 +624,10 @@ public async Task DoubleAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1.0d, 1.1d, 0.001d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than <0.001>. - expected: 1.0d - actual: 1.1d + expected: 1 + actual: 1.1 """); o.WasToStringCalled.Should().BeTrue(); } @@ -646,10 +646,10 @@ public async Task DoubleAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0d, 1.1d, 0.2d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than <0.2>. - notExpected: 1.0d - actual: 1.1d + notExpected: 1 + actual: 1.1 """); o.WasToStringCalled.Should().BeTrue(); } @@ -823,10 +823,10 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif { Action action = () => Assert.AreEqual(5.0f, 2.0f, 2.0f); // difference is 3. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected a difference no greater than <2>. - expected: 5.0f - actual: 2.0f + expected: 5 + actual: 2 """"); } @@ -834,10 +834,10 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif { Action action = () => Assert.AreEqual(2.0f, 5.0f, 2.0f); // difference is -3. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected a difference no greater than <2>. - expected: 2.0f - actual: 5.0f + expected: 2 + actual: 5 """"); } @@ -851,10 +851,10 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFai { Action action = () => Assert.AreEqual(5.0f, float.NaN, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected a difference no greater than <2>. - expected: 5.0f - actual: float.NaN + expected: 5 + actual: NaN """"); } @@ -862,10 +862,10 @@ public void FloatAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFai { Action action = () => Assert.AreEqual(float.NaN, 5.0f, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected a difference no greater than <2>. - expected: float.NaN - actual: 5.0f + expected: NaN + actual: 5 """"); } @@ -1055,10 +1055,10 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual { Action action = () => Assert.AreNotEqual(5.0f, 4.0f, 2.0f); // difference is 1. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreNotEqual failed. + Assert.AreNotEqual(*) failed. Expected a difference greater than <2>. - notExpected: 5.0f - actual: 4.0f + notExpected: 5 + actual: 4 """"); } @@ -1066,10 +1066,10 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual { Action action = () => Assert.AreNotEqual(4.0f, 5.0f, 2.0f); // difference is -1. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreNotEqual failed. + Assert.AreNotEqual(*) failed. Expected a difference greater than <2>. - notExpected: 4.0f - actual: 5.0f + notExpected: 4 + actual: 5 """"); } @@ -1082,10 +1082,10 @@ public void FloatAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFail { Action action = () => Assert.AreNotEqual(float.NaN, float.NaN, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreNotEqual failed. + Assert.AreNotEqual(*) failed. Expected a difference greater than <2>. - notExpected: float.NaN - actual: float.NaN + notExpected: NaN + actual: NaN """"); } @@ -1271,10 +1271,10 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi Action action = () => Assert.AreEqual(5.0d, 2.0d, 2.0d); // difference is 3. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected a difference no greater than <2>. - expected: 5.0d - actual: 2.0d + expected: 5 + actual: 2 """"); } @@ -1283,10 +1283,10 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi Action action = () => Assert.AreEqual(2.0d, 5.0d, 2.0d); // difference is -3. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected a difference no greater than <2>. - expected: 2.0d - actual: 5.0d + expected: 2 + actual: 5 """"); } @@ -1301,10 +1301,10 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFa Action action = () => Assert.AreEqual(5.0d, double.NaN, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected a difference no greater than <2>. - expected: 5.0d - actual: double.NaN + expected: 5 + actual: NaN """"); } @@ -1313,10 +1313,10 @@ public void DoubleAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFa Action action = () => Assert.AreEqual(double.NaN, 5.0d, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected a difference no greater than <2>. - expected: double.NaN - actual: 5.0d + expected: NaN + actual: 5 """"); } @@ -1514,10 +1514,10 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua Action action = () => Assert.AreNotEqual(5.0d, 4.0d, 2.0d); // difference is 1. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual failed. + Assert.AreNotEqual(*) failed. Expected a difference greater than <2>. - notExpected: 5.0d - actual: 4.0d + notExpected: 5 + actual: 4 """"); } @@ -1526,10 +1526,10 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua Action action = () => Assert.AreNotEqual(4.0d, 5.0d, 2.0d); // difference is -1. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual failed. + Assert.AreNotEqual(*) failed. Expected a difference greater than <2>. - notExpected: 4.0d - actual: 5.0d + notExpected: 4 + actual: 5 """"); } @@ -1543,10 +1543,10 @@ public void DoubleAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFai Action action = () => Assert.AreNotEqual(double.NaN, double.NaN, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual failed. + Assert.AreNotEqual(*) failed. Expected a difference greater than <2>. - notExpected: double.NaN - actual: double.NaN + notExpected: NaN + actual: NaN """"); } @@ -1606,7 +1606,7 @@ public void AreEqualStringDifferenceAtBeginning() Action action = () => Assert.AreEqual("baaa", "aaaa"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. String lengths are both 4 but differ at index 0. expected: "baaa" actual: "aaaa" @@ -1619,7 +1619,7 @@ public void AreEqualStringDifferenceAtEnd() Action action = () => Assert.AreEqual("aaaa", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" @@ -1632,11 +1632,11 @@ public void AreEqualStringWithSpecialCharactersShouldEscape() Action action = () => Assert.AreEqual("aa\ta", "aa a"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. String lengths are both 4 but differ at index 2. - expected ("aa\ta"): "aa␉a" - actual: "aa a" - -----------------------^ + expected: "aa␉a" + actual: "aa a" + -------------^ """); } @@ -1648,7 +1648,7 @@ public void AreEqualLongStringsShouldTruncateAndShowContext() Action action = () => Assert.AreEqual(expected, actual); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. String lengths are both 201 but differ at index 100. expected: "...aaaaaaaaaaaaaaaaaabcccccccccccccccc..." actual: "...aaaaaaaaaaaaaaaaaadcccccccccccccccc..." @@ -1661,7 +1661,7 @@ public void AreEqualStringWithCultureShouldUseEnhancedMessage() Action action = () => Assert.AreEqual("aaaa", "aaab", false, CultureInfo.InvariantCulture); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" @@ -1674,7 +1674,7 @@ public void AreEqualStringWithDifferentLength() Action action = () => Assert.AreEqual("aaaa", "aaa"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected string length 4 but was 3. expected: "aaaa" actual: "aaa" @@ -1687,7 +1687,7 @@ public void AreEqualShorterExpectedString() Action action = () => Assert.AreEqual("aaa", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected string length 3 but was 4. expected: "aaa" actual: "aaab" @@ -1700,7 +1700,7 @@ public void AreEqualStringWithUserMessage() Action action = () => Assert.AreEqual("aaaa", "aaab", "My custom message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. My custom message + Assert.AreEqual(*) failed. My custom message String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" @@ -1713,7 +1713,7 @@ public void AreEqualStringWithEmojis() Action action = () => Assert.AreEqual("??", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected string length 2 but was 4. expected: "??" actual: "aaab" @@ -1935,10 +1935,10 @@ public void AreEqual_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreEqual(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 2); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected values to be equal. - expected (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 1 - actual: 2 + expected: 1 + actual: 2 """); } @@ -1950,10 +1950,10 @@ public void AreEqual_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreEqual(expected, actual); action.Should().Throw() .WithMessage($""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected values to be equal. expected: {new string('L', 256)}... 44 more - actual: {new string('L', 256)}... 44 more + actual: {new string('L', 256)}... 44 more """); } @@ -1965,10 +1965,10 @@ public void AreEqual_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreEqual(expected, actual); action.Should().Throw() .WithMessage(""" - Assert.AreEqual failed. + Assert.AreEqual(*) failed. Expected values to be equal. expected: line1\r\nline2\nline3 - actual: line1\r\nline2\nline3 + actual: line1\r\nline2\nline3 """); } @@ -1979,10 +1979,10 @@ public void AreNotEqual_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreNotEqual(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 1); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual failed. + Assert.AreNotEqual(*) failed. Expected values to differ. - notExpected (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 1 - actual: 1 + notExpected: 1 + actual: 1 """); } @@ -1993,10 +1993,10 @@ public void AreNotEqual_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreNotEqual(obj, obj); action.Should().Throw() .WithMessage($""" - Assert.AreNotEqual failed. + Assert.AreNotEqual(*) failed. Expected values to differ. - notExpected (obj): {new string('L', 256)}... 44 more - actual (obj): {new string('L', 256)}... 44 more + notExpected: {new string('L', 256)}... 44 more + actual: {new string('L', 256)}... 44 more """); } @@ -2007,10 +2007,10 @@ public void AreNotEqual_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreNotEqual(obj, obj); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual failed. + Assert.AreNotEqual(*) failed. Expected values to differ. - notExpected (obj): line1\r\nline2\nline3 - actual (obj): line1\r\nline2\nline3 + notExpected: line1\r\nline2\nline3 + actual: line1\r\nline2\nline3 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index 2de6fe88c0..c4852c267f 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -17,10 +17,10 @@ public void AreSame_PassDifferentObject_ShouldFail() { Action action = () => Assert.AreSame(new object(), new object()); action.Should().Throw().WithMessage(""" - Assert.AreSame failed. + Assert.AreSame(*) failed. Expected references to be the same. - expected (new object()): (Hash=*) - actual (new object()): (Hash=*) + expected: (Hash=*) + actual: (Hash=*) """); } @@ -34,10 +34,10 @@ public void AreSame_StringMessage_PassDifferentObject_ShouldFail() { Action action = () => Assert.AreSame(new object(), new object(), "User-provided message"); action.Should().Throw().WithMessage(""" - Assert.AreSame failed. User-provided message + Assert.AreSame(*) failed. User-provided message Expected references to be the same. - expected (new object()): (Hash=*) - actual (new object()): (Hash=*) + expected: (Hash=*) + actual: (Hash=*) """); } @@ -54,10 +54,10 @@ public async Task AreSame_InterpolatedString_PassDifferentObject_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreSame(new object(), new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()).WithMessage(""" - Assert.AreSame failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreSame(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected references to be the same. - expected (new object()): (Hash=*) - actual (new object()): (Hash=*) + expected: (Hash=*) + actual: (Hash=*) """); o.WasToStringCalled.Should().BeTrue(); } @@ -69,10 +69,10 @@ public void AreSame_BothAreValueTypes_ShouldFailWithSpecializedMessage() { Action action = () => Assert.AreSame(1, 1); action.Should().Throw().WithMessage(""" - Assert.AreSame failed. + Assert.AreSame(*) failed. Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) - actual: 1 (Hash=*) + actual: 1 (Hash=*) """); } @@ -80,10 +80,10 @@ public void AreSame_StringMessage_BothAreValueTypes_ShouldFailWithSpecializedMes { Action action = () => Assert.AreSame(1, 1, "User-provided message"); action.Should().Throw().WithMessage(""" - Assert.AreSame failed. User-provided message + Assert.AreSame(*) failed. User-provided message Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) - actual: 1 (Hash=*) + actual: 1 (Hash=*) """); } @@ -91,10 +91,10 @@ public void AreSame_InterpolatedString_BothAreValueTypes_ShouldFailWithSpecializ { Action action = () => Assert.AreSame(1, 1, $"User-provided message {new object().GetType()}"); action.Should().Throw().WithMessage(""" - Assert.AreSame failed. User-provided message System.Object + Assert.AreSame(*) failed. User-provided message System.Object Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) - actual: 1 (Hash=*) + actual: 1 (Hash=*) """); } @@ -103,10 +103,10 @@ public void AreNotSame_PassSameObject_ShouldFail() object o = new(); Action action = () => Assert.AreNotSame(o, o); action.Should().Throw().WithMessage(""" - Assert.AreNotSame failed. + Assert.AreNotSame(*) failed. Expected references to be different. - notExpected (o): - actual (o): + notExpected: + actual: """); } @@ -118,10 +118,10 @@ public void AreNotSame_StringMessage_PassSameObject_ShouldFail() object o = new(); Action action = () => Assert.AreNotSame(o, o, "User-provided message"); action.Should().Throw().WithMessage(""" - Assert.AreNotSame failed. User-provided message + Assert.AreNotSame(*) failed. User-provided message Expected references to be different. - notExpected (o): - actual (o): + notExpected: + actual: """); } @@ -138,10 +138,10 @@ public async Task AreNotSame_InterpolatedString_PassSameObject_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreNotSame(o, o, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()).WithMessage(""" - Assert.AreNotSame failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotSame(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected references to be different. - notExpected (o): DummyClassTrackingToStringCalls - actual (o): DummyClassTrackingToStringCalls + notExpected: DummyClassTrackingToStringCalls + actual: DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); } @@ -155,10 +155,10 @@ public void AreSame_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreSame(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, new object()); action.Should().Throw() .WithMessage(""" - Assert.AreSame failed. + Assert.AreSame(*) failed. Expected references to be the same. - expected (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): (Hash=*) - actual (new object()): (Hash=*) + expected: (Hash=*) + actual: (Hash=*) """); } @@ -167,10 +167,10 @@ public void AreSame_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreSame(new ObjectWithLongToString(), new ObjectWithLongToString()); action.Should().Throw() .WithMessage($""" - Assert.AreSame failed. + Assert.AreSame(*) failed. Expected references to be the same. - expected (new ObjectWithLongToString()): {new string('L', 256)}... 44 more (Hash=*) - actual (new ObjectWithLongToString()): {new string('L', 256)}... 44 more (Hash=*) + expected: {new string('L', 256)}... 44 more (Hash=*) + actual: {new string('L', 256)}... 44 more (Hash=*) """); } @@ -179,10 +179,10 @@ public void AreSame_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreSame(new ObjectWithNewlineToString(), new ObjectWithNewlineToString()); action.Should().Throw() .WithMessage(""" - Assert.AreSame failed. + Assert.AreSame(*) failed. Expected references to be the same. - expected (new ObjectWithNewlineToString()): line1\r\nline2\nline3 (Hash=*) - actual (new ObjectWithNewlineToString()): line1\r\nline2\nline3 (Hash=*) + expected: line1\r\nline2\nline3 (Hash=*) + actual: line1\r\nline2\nline3 (Hash=*) """); } @@ -193,10 +193,10 @@ public void AreNotSame_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreNotSame(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.AreNotSame failed. + Assert.AreNotSame(*) failed. Expected references to be different. - notExpected (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): - actual (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): + notExpected: + actual: """); } @@ -207,10 +207,10 @@ public void AreNotSame_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreNotSame(obj, obj); action.Should().Throw() .WithMessage($""" - Assert.AreNotSame failed. + Assert.AreNotSame(*) failed. Expected references to be different. - notExpected (obj): {new string('L', 256)}... 44 more - actual (obj): {new string('L', 256)}... 44 more + notExpected: {new string('L', 256)}... 44 more + actual: {new string('L', 256)}... 44 more """); } @@ -221,10 +221,10 @@ public void AreNotSame_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreNotSame(obj, obj); action.Should().Throw() .WithMessage(""" - Assert.AreNotSame failed. + Assert.AreNotSame(*) failed. Expected references to be different. - notExpected (obj): line1\r\nline2\nline3 - actual (obj): line1\r\nline2\nline3 + notExpected: line1\r\nline2\nline3 + actual: line1\r\nline2\nline3 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index f653e7c189..8c083b25a9 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -339,7 +339,7 @@ public void ContainsSingle_InterpolatedHandler_WithMultipleElements_ThrowsExcept // Assert action.Should().Throw().WithMessage(""" - Assert.ContainsSingle failed. + Assert.ContainsSingle(*) failed. Expected collection to contain exactly one item but found 3 item(s). """); } @@ -372,7 +372,7 @@ public void ContainsSingle_InNonGenericCollection_NoMessage_WithEmptyCollection_ // Assert action.Should().Throw().WithMessage(""" - Assert.ContainsSingle failed. + Assert.ContainsSingle(*) failed. Expected collection to contain exactly one item but found 0 item(s). """); } @@ -390,7 +390,7 @@ public void ContainsSingle_InNonGenericCollection_AssertCustomMessage_WithEmptyC // Assert action.Should().Throw().WithMessage(""" - Assert.ContainsSingle failed. my custom message + Assert.ContainsSingle(*) failed. my custom message Expected collection to contain exactly one item but found 0 item(s). """); } @@ -427,10 +427,8 @@ public void Contains_ValueExpected_ItemDoesNotExist_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains failed. Item 20 not found - Expected collection to contain the specified item. - expected: 20 - collection* + Assert.Contains(*) failed. Item 20 not found + Expected collection to contain the specified item.* """); } @@ -448,9 +446,8 @@ public void Contains_InNonGenericCollection_ValueExpected_ItemDoesNotExist_Throw // Assert action.Should().Throw().WithMessage(""" - Assert.Contains failed. Item 20 not found - Expected collection to contain the specified item. - collection* + Assert.Contains(*) failed. Item 20 not found + Expected collection to contain the specified item.* """); } @@ -498,9 +495,8 @@ public void Contains_InNonGenericCollection_NullableValueExpected_ItemDoesNotExi // Assert action.Should().Throw().WithMessage(""" - Assert.Contains failed. Item not found - Expected collection to contain the specified item. - collection* + Assert.Contains(*) failed. Item not found + Expected collection to contain the specified item.* """); } @@ -551,10 +547,8 @@ public void Contains_WithComparer_ItemDoesNotExist_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains failed. Missing cherry - Expected collection to contain the specified item. - expected: "cherry" - collection* + Assert.Contains(*) failed. Missing cherry + Expected collection to contain the specified item.* """); } @@ -602,10 +596,8 @@ public void Contains_Predicate_NoItemMatches_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains failed. No even number found - Expected at least one item to match the predicate. - predicate: IsEven - collection* + Assert.Contains(*) failed. No even number found + Expected at least one item to match the predicate.* """); } @@ -623,10 +615,8 @@ public void Contains_InNonGenericCollection_Predicate_NoItemMatches_ThrowsExcept // Assert action.Should().Throw().WithMessage(""" - Assert.Contains failed. No even number found - Expected at least one item to match the predicate. - predicate: IsEven - collection* + Assert.Contains(*) failed. No even number found + Expected at least one item to match the predicate.* """); } @@ -661,10 +651,10 @@ public void Contains_StringVersion_SubstringNotPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains failed. Missing substring + Assert.Contains(*) failed. Missing substring String does not contain the expected substring. substring: "lazy" - value: "The quick brown fox" + value: "The quick brown fox" """); } @@ -742,10 +732,8 @@ public void Contains_InNonGenericCollection_WithComparer_ItemDoesNotExist_Throws // Assert action.Should().Throw().WithMessage(""" - Assert.Contains failed. - Expected collection to contain the specified item. - expected: "banana" - collection* + Assert.Contains(*) failed. + Expected collection to contain the specified item.* """); } @@ -882,10 +870,10 @@ public void Contains_String_EmptyValue_WithNonEmptySubstring_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains failed. + Assert.Contains(*) failed. String does not contain the expected substring. substring: "test" - value: "" + value: "" """); } @@ -990,10 +978,8 @@ public void DoesNotContain_ValueExpected_ItemPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain failed. Item 10 should not be found - Expected collection to not contain the specified item. - notExpected: 10 - collection* + Assert.DoesNotContain(*) failed. Item 10 should not be found + Expected collection to not contain the specified item.* """); } @@ -1022,14 +1008,12 @@ public void DoesNotContain_InNonGenericCollection_ValueExpected_ItemPresent_Thro var collection = new ArrayList { 5, 10, 15, "a" }; // Act - Action action = () => Assert.DoesNotContain(10, collection, "Assert.DoesNotContain failed. Expected collection to not contain the specified item. Item {0} should not be found"); + Action action = () => Assert.DoesNotContain(10, collection, "Assert.DoesNotContain(*) failed. Expected collection to not contain the specified item. Item {0} should not be found"); // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain failed. Assert.DoesNotContain failed. Expected collection to not contain the specified item. Item {0} should not be found - Expected collection to not contain the specified item. - notExpected: 10 - collection* + Assert.DoesNotContain(*) failed. Assert.DoesNotContain(*) failed. Expected collection to not contain the specified item. Item {0} should not be found + Expected collection to not contain the specified item.* """); } @@ -1080,10 +1064,8 @@ public void DoesNotContain_WithComparer_ItemPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain failed. Unexpected "APPLE" - Expected collection to not contain the specified item. - notExpected: "APPLE" - collection* + Assert.DoesNotContain(*) failed. Unexpected "APPLE" + Expected collection to not contain the specified item.* """); } @@ -1102,10 +1084,8 @@ public void DoesNotContain_InNonGenericCollection_WithComparer_ItemPresent_Throw // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain failed. APPLE - Expected collection to not contain the specified item. - notExpected: "APPLE" - collection* + Assert.DoesNotContain(*) failed. APPLE + Expected collection to not contain the specified item.* """); } @@ -1153,10 +1133,8 @@ public void DoesNotContain_Predicate_AtLeastOneItemMatches_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain failed. An even number exists - Expected no items to match the predicate. - predicate: IsEven - collection* + Assert.DoesNotContain(*) failed. An even number exists + Expected no items to match the predicate.* """); } @@ -1174,10 +1152,8 @@ public void DoesNotContain_InNonGenericCollection_Predicate_AtLeastOneItemMatche // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain failed. An even number exists - Expected no items to match the predicate. - predicate: IsEven - collection* + Assert.DoesNotContain(*) failed. An even number exists + Expected no items to match the predicate.* """); } @@ -1212,10 +1188,10 @@ public void DoesNotContain_StringVersion_SubstringPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain failed. Unexpected substring + Assert.DoesNotContain(*) failed. Unexpected substring String contains the unexpected substring. substring: "brown" - value: "The quick brown fox" + value: "The quick brown fox" """); } @@ -1252,10 +1228,10 @@ public void DoesNotContain_StringWithComparisonAndMessage_SubstringPresent_Throw // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain failed. Found unexpected substring + Assert.DoesNotContain(*) failed. Found unexpected substring String contains the unexpected substring. substring: "BROWN" - value: "The quick brown fox" + value: "The quick brown fox" """); } @@ -1290,10 +1266,10 @@ public void DoesNotContain_StringSimpleOverload_SubstringPresent_ThrowsException // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain failed. + Assert.DoesNotContain(*) failed. String contains the unexpected substring. substring: "brown" - value: "The quick brown fox" + value: "The quick brown fox" """); } @@ -1328,10 +1304,10 @@ public void DoesNotContain_StringWithMessageOnly_SubstringPresent_ThrowsExceptio // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain failed. Found unexpected substring + Assert.DoesNotContain(*) failed. Found unexpected substring String contains the unexpected substring. substring: "brown" - value: "The quick brown fox" + value: "The quick brown fox" """); } @@ -1576,9 +1552,8 @@ public void ContainsSinglePredicate_NoItemMatches_ThrowsException() // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. + Assert.ContainsSingle(*) failed. Expected exactly one item to match the predicate but found 0 item(s). - predicate: x => x % 2 == 0 """); } @@ -1597,9 +1572,8 @@ public void ContainsSinglePredicate_InNonGenericCollection_NoItemMatches_ThrowsE // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. + Assert.ContainsSingle(*) failed. Expected exactly one item to match the predicate but found 0 item(s). - predicate: x => x is int i && i % 2 == 0 """); } @@ -1618,9 +1592,8 @@ public void ContainsSinglePredicate_MultipleItemsMatch_ThrowsException() // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. + Assert.ContainsSingle(*) failed. Expected exactly one item to match the predicate but found 4 item(s). - predicate: x => x % 2 == 0 """); } @@ -1639,9 +1612,8 @@ public void ContainsSinglePredicate_InNonGenericCollection_MultipleItemsMatch_Th // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. + Assert.ContainsSingle(*) failed. Expected exactly one item to match the predicate but found 2 item(s). - predicate: x => x is int i && i % 2 == 0 """); } @@ -1660,9 +1632,8 @@ public void ContainsSinglePredicate_WithMessage_NoItemMatches_ThrowsException() // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. No even numbers found in collection with 3 items + Assert.ContainsSingle(*) failed. No even numbers found in collection with 3 items Expected exactly one item to match the predicate but found 0 item(s). - predicate: x => x % 2 == 0 """); } @@ -1681,9 +1652,8 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_NoItemMat // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. No even numbers found in collection with 3 items + Assert.ContainsSingle(*) failed. No even numbers found in collection with 3 items Expected exactly one item to match the predicate but found 0 item(s). - predicate: x => x is int i && i % 2 == 0 """); } @@ -1702,9 +1672,8 @@ public void ContainsSinglePredicate_WithMessage_MultipleItemsMatch_ThrowsExcepti // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. Too many even numbers found: 3 + Assert.ContainsSingle(*) failed. Too many even numbers found: 3 Expected exactly one item to match the predicate but found 3 item(s). - predicate: x => x % 2 == 0 """); } @@ -1723,9 +1692,8 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_MultipleI // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. Too many even numbers found: 2 + Assert.ContainsSingle(*) failed. Too many even numbers found: 2 Expected exactly one item to match the predicate but found 2 item(s). - predicate: x => x is int i && i % 2 == 0 """); } @@ -1819,10 +1787,9 @@ public void Contains_ItemNotFound_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.Contains failed. - Expected collection to contain the specified item. - expected: 5 - collection* + Assert.Contains(*) failed. + Expected collection to contain the specified item.* + collection: [1, 2, 3] (3 items) """); } @@ -1840,10 +1807,9 @@ public void Contains_InNonGenericCollection_ItemNotFound_ShowsSpecificErrorMessa // Assert action.Should().Throw() .WithMessage(""" - Assert.Contains failed. - Expected collection to contain the specified item. - expected: 5 - collection* + Assert.Contains(*) failed. + Expected collection to contain the specified item.* + collection: [1, 2, 3] (3 items) """); } @@ -1861,10 +1827,9 @@ public void Contains_PredicateNotMatched_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.Contains failed. - Expected at least one item to match the predicate. - predicate: x => x % 2 == 0 - collection* + Assert.Contains(*) failed. + Expected at least one item to match the predicate.* + collection: [1, 3, 5] (3 items) """); } @@ -1882,10 +1847,9 @@ public void DoesNotContain_ItemFound_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain failed. - Expected collection to not contain the specified item. - notExpected: 2 - collection* + Assert.DoesNotContain(*) failed. + Expected collection to not contain the specified item.* + collection: [1, 2, 3] (3 items) """); } @@ -1903,10 +1867,9 @@ public void DoesNotContain_PredicateMatched_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain failed. - Expected no items to match the predicate. - predicate: x => x % 2 == 0 - collection* + Assert.DoesNotContain(*) failed. + Expected no items to match the predicate.* + collection: [1, 2, 3] (3 items) """); } @@ -1961,10 +1924,10 @@ public void Contains_String_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.Contains("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.Contains failed. + Assert.Contains(*) failed. String does not contain the expected substring. substring: "world" - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + value: "hello" """); } @@ -1975,10 +1938,10 @@ public void Contains_String_WithLongValue_ShouldTruncateValue() Action action = () => Assert.Contains("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.Contains failed. + Assert.Contains(*) failed. String does not contain the expected substring. substring: "world" - value (longValue): "{new string('x', 255)}... 46 more + value: "{new string('x', 255)}... 46 more """); } @@ -1987,10 +1950,10 @@ public void Contains_String_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.Contains("world", "hello\r\nfoo"); action.Should().Throw() .WithMessage(""" - Assert.Contains failed. + Assert.Contains(*) failed. String does not contain the expected substring. substring: "world" - value: "hello\r\nfoo" + value: "hello\r\nfoo" """); } @@ -2001,10 +1964,10 @@ public void DoesNotContain_String_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotContain("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain failed. + Assert.DoesNotContain(*) failed. String contains the unexpected substring. substring: "hello" - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello world" + value: "hello world" """); } @@ -2015,10 +1978,10 @@ public void DoesNotContain_String_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotContain("hello", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotContain failed. + Assert.DoesNotContain(*) failed. String contains the unexpected substring. substring: "hello" - value (longValue): "hello{new string('x', 250)}... 51 more + value: "hello{new string('x', 250)}... 51 more """); } @@ -2027,10 +1990,10 @@ public void DoesNotContain_String_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotContain("hello", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain failed. + Assert.DoesNotContain(*) failed. String contains the unexpected substring. substring: "hello" - value: "hello\r\nworld" + value: "hello\r\nworld" """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs index b1c8f3a9da..860c0f6308 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs @@ -17,10 +17,10 @@ public void EndsWith_WhenValueDoesNotEndWithSuffix_ShouldFail() Action action = () => Assert.EndsWith("hello", "world"); action.Should().Throw() .WithMessage(""" - Assert.EndsWith failed. + Assert.EndsWith(*) failed. String does not end with expected suffix. expectedSuffix: "hello" - value: "world" + value: "world" """); } @@ -29,10 +29,10 @@ public void EndsWith_WithMessage_WhenValueDoesNotEndWithSuffix_ShouldFail() Action action = () => Assert.EndsWith("hello", "world", "User message"); action.Should().Throw() .WithMessage(""" - Assert.EndsWith failed. User message + Assert.EndsWith(*) failed. User message String does not end with expected suffix. expectedSuffix: "hello" - value: "world" + value: "world" """); } @@ -44,10 +44,10 @@ public void DoesNotEndWith_WhenValueEndsWithSuffix_ShouldFail() Action action = () => Assert.DoesNotEndWith("world", "hello world"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotEndWith failed. + Assert.DoesNotEndWith(*) failed. String ends with unexpected suffix. notExpectedSuffix: "world" - value: "hello world" + value: "hello world" """); } @@ -62,10 +62,10 @@ public void EndsWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.EndsWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.EndsWith failed. + Assert.EndsWith(*) failed. String does not end with expected suffix. expectedSuffix: "hello" - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello world" + value: "hello world" """); } @@ -76,10 +76,10 @@ public void EndsWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.EndsWith("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.EndsWith failed. + Assert.EndsWith(*) failed. String does not end with expected suffix. expectedSuffix: "world" - value (longValue): "{new string('x', 255)}... 46 more + value: "{new string('x', 255)}... 46 more """); } @@ -88,10 +88,10 @@ public void EndsWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.EndsWith("world", "hello\r\nfoo"); action.Should().Throw() .WithMessage(""" - Assert.EndsWith failed. + Assert.EndsWith(*) failed. String does not end with expected suffix. expectedSuffix: "world" - value: "hello\r\nfoo" + value: "hello\r\nfoo" """); } @@ -102,10 +102,10 @@ public void DoesNotEndWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotEndWith("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotEndWith failed. + Assert.DoesNotEndWith(*) failed. String ends with unexpected suffix. notExpectedSuffix: "world" - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello world" + value: "hello world" """); } @@ -116,10 +116,10 @@ public void DoesNotEndWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotEndWith("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotEndWith failed. + Assert.DoesNotEndWith(*) failed. String ends with unexpected suffix. notExpectedSuffix: "world" - value (longValue): "{new string('x', 255)}... 51 more + value: "{new string('x', 255)}... 51 more """); } @@ -128,10 +128,10 @@ public void DoesNotEndWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotEndWith("world", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotEndWith failed. + Assert.DoesNotEndWith(*) failed. String ends with unexpected suffix. notExpectedSuffix: "world" - value: "hello\r\nworld" + value: "hello\r\nworld" """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs index 91fb83b9bb..98b70edca9 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs @@ -43,10 +43,10 @@ public void IsGreaterThanShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThan failed. A Message + Assert.IsGreaterThan(*) failed. A Message Expected value to be greater than the specified bound. lowerBound: 10 - value: 5 + value: 5 """); } @@ -92,10 +92,10 @@ public void IsGreaterThanOrEqualToShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThanOrEqualTo failed. A Message + Assert.IsGreaterThanOrEqualTo(*) failed. A Message Expected value to be greater than or equal to the specified bound. lowerBound: 10 - value: 5 + value: 5 """); } @@ -141,10 +141,10 @@ public void IsLessThanShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsLessThan failed. A Message + Assert.IsLessThan(*) failed. A Message Expected value to be less than the specified bound. upperBound: 5 - value: 10 + value: 10 """); } @@ -190,10 +190,10 @@ public void IsLessThanOrEqualToShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsLessThanOrEqualTo failed. A Message + Assert.IsLessThanOrEqualTo(*) failed. A Message Expected value to be less than or equal to the specified bound. upperBound: 5 - value: 10 + value: 10 """); } @@ -254,7 +254,7 @@ public void IsPositiveShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsPositive failed. A Message + Assert.IsPositive(*) failed. A Message Expected a positive value. value: -5 """); @@ -323,7 +323,7 @@ public void IsNegativeShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsNegative failed. A Message + Assert.IsNegative(*) failed. A Message Expected a negative value. value: 5 """); @@ -352,10 +352,10 @@ public void IsGreaterThan_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsGreaterThan(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 5); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThan failed. + Assert.IsGreaterThan(*) failed. Expected value to be greater than the specified bound. - lowerBound (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 10 - value: 5 + lowerBound: 10 + value: 5 """); } @@ -367,10 +367,10 @@ public void IsGreaterThan_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsGreaterThan(lowerBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsGreaterThan failed. + Assert.IsGreaterThan(*) failed. Expected value to be greater than the specified bound. lowerBound: {new string('V', 256)}... 44 more - value: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -382,10 +382,10 @@ public void IsGreaterThan_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsGreaterThan(lowerBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThan failed. + Assert.IsGreaterThan(*) failed. Expected value to be greater than the specified bound. lowerBound: line1\r\nline2 - value: line1\r\nline2 + value: line1\r\nline2 """); } @@ -396,10 +396,10 @@ public void IsGreaterThanOrEqualTo_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsGreaterThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 5); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThanOrEqualTo failed. + Assert.IsGreaterThanOrEqualTo(*) failed. Expected value to be greater than or equal to the specified bound. - lowerBound (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 10 - value: 5 + lowerBound: 10 + value: 5 """); } @@ -411,10 +411,10 @@ public void IsGreaterThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsGreaterThanOrEqualTo(lowerBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsGreaterThanOrEqualTo failed. + Assert.IsGreaterThanOrEqualTo(*) failed. Expected value to be greater than or equal to the specified bound. lowerBound: {new string('V', 256)}... 44 more - value: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -426,10 +426,10 @@ public void IsGreaterThanOrEqualTo_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsGreaterThanOrEqualTo(lowerBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThanOrEqualTo failed. + Assert.IsGreaterThanOrEqualTo(*) failed. Expected value to be greater than or equal to the specified bound. lowerBound: line1\r\nline2 - value: line1\r\nline2 + value: line1\r\nline2 """); } @@ -440,10 +440,10 @@ public void IsLessThan_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsLessThan(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 10); action.Should().Throw() .WithMessage(""" - Assert.IsLessThan failed. + Assert.IsLessThan(*) failed. Expected value to be less than the specified bound. - upperBound (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 5 - value: 10 + upperBound: 5 + value: 10 """); } @@ -455,10 +455,10 @@ public void IsLessThan_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsLessThan(upperBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsLessThan failed. + Assert.IsLessThan(*) failed. Expected value to be less than the specified bound. upperBound: {new string('V', 256)}... 44 more - value: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -470,10 +470,10 @@ public void IsLessThan_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsLessThan(upperBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsLessThan failed. + Assert.IsLessThan(*) failed. Expected value to be less than the specified bound. upperBound: line1\r\nline2 - value: line1\r\nline2 + value: line1\r\nline2 """); } @@ -484,10 +484,10 @@ public void IsLessThanOrEqualTo_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsLessThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 10); action.Should().Throw() .WithMessage(""" - Assert.IsLessThanOrEqualTo failed. + Assert.IsLessThanOrEqualTo(*) failed. Expected value to be less than or equal to the specified bound. - upperBound (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 5 - value: 10 + upperBound: 5 + value: 10 """); } @@ -499,10 +499,10 @@ public void IsLessThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsLessThanOrEqualTo(upperBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsLessThanOrEqualTo failed. + Assert.IsLessThanOrEqualTo(*) failed. Expected value to be less than or equal to the specified bound. upperBound: {new string('V', 256)}... 44 more - value: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -514,10 +514,10 @@ public void IsLessThanOrEqualTo_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsLessThanOrEqualTo(upperBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsLessThanOrEqualTo failed. + Assert.IsLessThanOrEqualTo(*) failed. Expected value to be less than or equal to the specified bound. upperBound: line1\r\nline2 - value: line1\r\nline2 + value: line1\r\nline2 """); } @@ -528,9 +528,9 @@ public void IsPositive_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsPositive(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsPositive failed. + Assert.IsPositive(*) failed. Expected a positive value. - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): -5 + value: -5 """); } @@ -541,9 +541,9 @@ public void IsNegative_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsNegative(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsNegative failed. + Assert.IsNegative(*) failed. Expected a negative value. - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 5 + value: 5 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index 95df717c92..ae94b7b71c 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -13,7 +13,7 @@ public void ExactInstanceOfTypeShouldFailWhenValueIsNull() Action action = () => Assert.IsExactInstanceOfType(null, typeof(AssertTests)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. +Assert.IsExactInstanceOfType(*) failed. value: (null) """); } @@ -23,7 +23,7 @@ public void ExactInstanceOfTypeShouldFailWhenTypeIsNull() Action action = () => Assert.IsExactInstanceOfType(5, null); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. +Assert.IsExactInstanceOfType(*) failed. value: 5 """); } @@ -33,7 +33,7 @@ public void ExactInstanceOfTypeShouldFailWhenTypeIsMismatched() Action action = () => Assert.IsExactInstanceOfType(5, typeof(string)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. +Assert.IsExactInstanceOfType(*) failed. Expected value to be exactly of the specified type. value: 5 expectedType: System.String @@ -48,7 +48,7 @@ public void ExactInstanceOfTypeShouldFailOnHigherInstance() Action action = () => Assert.IsExactInstanceOfType(5, typeof(object)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. +Assert.IsExactInstanceOfType(*) failed. Expected value to be exactly of the specified type. value: 5 expectedType: System.Object @@ -62,9 +62,9 @@ public void ExactInstanceOfTypeShouldFailOnDerivedType() Action action = () => Assert.IsExactInstanceOfType(x, typeof(Stream)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. +Assert.IsExactInstanceOfType(*) failed. Expected value to be exactly of the specified type. - value (x): + value: expectedType: System.IO.Stream actualType: System.IO.MemoryStream """); @@ -81,7 +81,7 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() Action action = () => Assert.IsExactInstanceOfType(null, typeof(AssertTests), "User-provided message"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. User-provided message +Assert.IsExactInstanceOfType(*) failed. User-provided message value: (null) """); } @@ -91,7 +91,7 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() Action action = () => Assert.IsExactInstanceOfType(5, null, "User-provided message"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. User-provided message +Assert.IsExactInstanceOfType(*) failed. User-provided message value: 5 """); } @@ -101,7 +101,7 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched Action action = () => Assert.IsExactInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. User-provided message +Assert.IsExactInstanceOfType(*) failed. User-provided message Expected value to be exactly of the specified type. value: 5 expectedType: System.String @@ -119,7 +119,7 @@ public async Task ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenValue Func action = async () => Assert.IsExactInstanceOfType(null, typeof(AssertTests), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsExactInstanceOfType failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsExactInstanceOfType(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* value: (null) """); o.WasToStringCalled.Should().BeTrue(); @@ -131,7 +131,7 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull( Action action = () => Assert.IsExactInstanceOfType(5, null, $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls +Assert.IsExactInstanceOfType(*) failed. User-provided message DummyClassTrackingToStringCalls value: 5 """); o.WasToStringCalled.Should().BeTrue(); @@ -143,7 +143,7 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMisma Action action = () => Assert.IsExactInstanceOfType(5, typeof(string), $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls +Assert.IsExactInstanceOfType(*) failed. User-provided message DummyClassTrackingToStringCalls Expected value to be exactly of the specified type. value: 5 expectedType: System.String @@ -183,9 +183,9 @@ public void ExactInstanceNotOfTypeShouldFailOnExactType() Action action = () => Assert.IsNotExactInstanceOfType(x, typeof(MemoryStream)); action.Should().Throw() .WithMessage(""" -Assert.IsNotExactInstanceOfType failed. +Assert.IsNotExactInstanceOfType(*) failed. Value should not be exactly of the specified type. - value (x): + value: wrongType: System.IO.MemoryStream actualType: System.IO.MemoryStream """); @@ -196,7 +196,7 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() Action action = () => Assert.IsExactInstanceOfType(null); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. +Assert.IsExactInstanceOfType(*) failed. value: (null) """); } @@ -206,7 +206,7 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() Action action = () => Assert.IsExactInstanceOfType(5); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. +Assert.IsExactInstanceOfType(*) failed. Expected value to be exactly of the specified type. value: 5 expectedType: System.String @@ -220,9 +220,9 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenDerivedType_Fails() Action action = () => Assert.IsExactInstanceOfType(x); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. +Assert.IsExactInstanceOfType(*) failed. Expected value to be exactly of the specified type. - value (x): + value: expectedType: System.IO.Stream actualType: System.IO.MemoryStream """); @@ -248,7 +248,7 @@ public void IsExactInstanceOfTypeUsingGenericType_OnHigherInstance_Fails() Action action = () => Assert.IsExactInstanceOfType(5); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType failed. +Assert.IsExactInstanceOfType(*) failed. Expected value to be exactly of the specified type. value: 5 expectedType: System.Object @@ -281,9 +281,9 @@ public void IsNotExactInstanceOfTypeUsingGenericType_OnExactType_Fails() Action action = () => Assert.IsNotExactInstanceOfType(x); action.Should().Throw() .WithMessage(""" -Assert.IsNotExactInstanceOfType failed. +Assert.IsNotExactInstanceOfType(*) failed. Value should not be exactly of the specified type. - value (x): + value: wrongType: System.IO.MemoryStream actualType: System.IO.MemoryStream """); @@ -368,9 +368,9 @@ public void IsExactInstanceOfType_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsExactInstanceOfType failed. + Assert.IsExactInstanceOfType(*) failed. Expected value to be exactly of the specified type. - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + value: "hello" expectedType: System.Int32 actualType: System.String """); @@ -383,9 +383,9 @@ public void IsExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsExactInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage($""" - Assert.IsExactInstanceOfType failed. + Assert.IsExactInstanceOfType(*) failed. Expected value to be exactly of the specified type. - value (obj): {new string('L', 256)}... 44 more + value: {new string('L', 256)}... 44 more expectedType: System.Int32 actualType: *ObjectWithLongToString """); @@ -398,9 +398,9 @@ public void IsExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsExactInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsExactInstanceOfType failed. + Assert.IsExactInstanceOfType(*) failed. Expected value to be exactly of the specified type. - value (obj): line1\r\nline2\nline3 + value: line1\r\nline2\nline3 expectedType: System.Int32 actualType: *ObjectWithNewlineToString """); @@ -413,9 +413,9 @@ public void IsNotExactInstanceOfType_WithLongExpression_ShouldTruncateExpression Action action = () => Assert.IsNotExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(string)); action.Should().Throw() .WithMessage(""" - Assert.IsNotExactInstanceOfType failed. + Assert.IsNotExactInstanceOfType(*) failed. Value should not be exactly of the specified type. - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + value: "hello" wrongType: System.String actualType: System.String """); @@ -428,9 +428,9 @@ public void IsNotExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsNotExactInstanceOfType(obj, typeof(ObjectWithLongToString)); action.Should().Throw() .WithMessage($""" - Assert.IsNotExactInstanceOfType failed. + Assert.IsNotExactInstanceOfType(*) failed. Value should not be exactly of the specified type. - value (obj): {new string('L', 256)}... 44 more + value: {new string('L', 256)}... 44 more wrongType: *ObjectWithLongToString actualType: *ObjectWithLongToString """); @@ -443,9 +443,9 @@ public void IsNotExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines( Action action = () => Assert.IsNotExactInstanceOfType(obj, typeof(ObjectWithNewlineToString)); action.Should().Throw() .WithMessage(""" - Assert.IsNotExactInstanceOfType failed. + Assert.IsNotExactInstanceOfType(*) failed. Value should not be exactly of the specified type. - value (obj): line1\r\nline2\nline3 + value: line1\r\nline2\nline3 wrongType: *ObjectWithNewlineToString actualType: *ObjectWithNewlineToString """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index 549bfd9e65..5087e774ca 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -58,11 +58,11 @@ public void IsInRange_WithValueBelowRange_ThrowsAssertFailedException() Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().Throw() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: 5 maxValue: 10 - value: 3 + value: 3 """); } @@ -77,11 +77,11 @@ public void IsInRange_WithValueAboveRange_ThrowsAssertFailedException() Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().Throw() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: 1 maxValue: 5 - value: 8 + value: 8 """); } @@ -99,11 +99,11 @@ public void IsInRange_WithCustomMessage_IncludesCustomMessage() // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange failed. Custom error message + Assert.IsInRange(*) failed. Custom error message Value is not within the expected range. minValue: 1 maxValue: 5 - value: 10 + value: 10 """); } @@ -119,7 +119,7 @@ public void IsInRange_WithDoubleValues_WorksCorrectly() Assert.IsInRange(minValue, maxValue, valueInRange); Action action = () => Assert.IsInRange(minValue, maxValue, valueOutOfRange); action.Should().Throw() - .WithMessage("Assert.IsInRange failed.*Value is not within the expected range*"); + .WithMessage("Assert.IsInRange(*) failed.*Value is not within the expected range*"); } public void IsInRange_WithDateTimeValues_WorksCorrectly() @@ -136,7 +136,7 @@ public void IsInRange_WithDateTimeValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .WithMessage("Assert.IsInRange failed.*Value is not within the expected range*"); + .WithMessage("Assert.IsInRange(*) failed.*Value is not within the expected range*"); } public void IsInRange_WithCharValues_WorksCorrectly() @@ -153,7 +153,7 @@ public void IsInRange_WithCharValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .WithMessage("Assert.IsInRange failed.*Value is not within the expected range*"); + .WithMessage("Assert.IsInRange(*) failed.*Value is not within the expected range*"); } public void IsInRange_WithNullMessage_DoesNotThrow() @@ -213,11 +213,11 @@ public void IsInRange_WithAllNegativeValuesBelowRange_ThrowsAssertFailedExceptio // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: -10 maxValue: -5 - value: -12 + value: -12 """); } @@ -234,11 +234,11 @@ public void IsInRange_WithAllNegativeValuesAboveRange_ThrowsAssertFailedExceptio // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: -10 maxValue: -5 - value: -3 + value: -3 """); } @@ -288,11 +288,11 @@ public void IsInRange_WithRangeSpanningNegativeToPositive_ValueBelowRange_Throws // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: -5 maxValue: 5 - value: -7 + value: -7 """); } @@ -309,11 +309,11 @@ public void IsInRange_WithRangeSpanningNegativeToPositive_ValueAboveRange_Throws // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: -5 maxValue: 5 - value: 7 + value: 7 """); } @@ -364,11 +364,11 @@ public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsSmaller Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: 5 maxValue: 5 - value: 4 + value: 4 """); } @@ -382,11 +382,11 @@ public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsLarger( Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: 5 maxValue: 5 - value: 6 + value: 6 """); } @@ -411,11 +411,11 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsSmall Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: 5 maxValue: 5 - value: 4 + value: 4 """); } @@ -429,11 +429,11 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsLarge Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: 5 maxValue: 5 - value: 6 + value: 6 """); } @@ -448,11 +448,11 @@ public void IsInRange_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsInRange(1, 10, aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. minValue: 1 maxValue: 10 - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): 20 + value: 20 """); } @@ -465,11 +465,11 @@ public void IsInRange_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsInRange(min, max, value); action.Should().Throw() .WithMessage($""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. - minValue (min): {new string('R', 256)}... 44 more - maxValue (max): {new string('R', 256)}... 44 more - value: {new string('R', 256)}... 44 more + minValue: {new string('R', 256)}... 44 more + maxValue: {new string('R', 256)}... 44 more + value: {new string('R', 256)}... 44 more """); } @@ -482,11 +482,11 @@ public void IsInRange_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsInRange(min, max, value); action.Should().Throw() .WithMessage(""" - Assert.IsInRange failed. + Assert.IsInRange(*) failed. Value is not within the expected range. - minValue (min): line1\r\nline2 - maxValue (max): line1\r\nline2 - value: line1\r\nline2 + minValue: line1\r\nline2 + maxValue: line1\r\nline2 + value: line1\r\nline2 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index c98e2d112b..96268b8c51 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -13,7 +13,7 @@ public void InstanceOfTypeShouldFailWhenValueIsNull() Action action = () => Assert.IsInstanceOfType(null, typeof(AssertTests)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. + Assert.IsInstanceOfType(*) failed. value: (null) """); } @@ -23,7 +23,7 @@ public void InstanceOfTypeShouldFailWhenTypeIsNull() Action action = () => Assert.IsInstanceOfType(5, null); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. + Assert.IsInstanceOfType(*) failed. value: 5 """); } @@ -33,7 +33,7 @@ public void InstanceOfTypeShouldFailWhenTypeIsMismatched() Action action = () => Assert.IsInstanceOfType(5, typeof(string)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. + Assert.IsInstanceOfType(*) failed. Expected value to be of the specified type. value: 5 expectedType: System.String @@ -50,7 +50,7 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() Action action = () => Assert.IsInstanceOfType(null, typeof(AssertTests), "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. User-provided message + Assert.IsInstanceOfType(*) failed. User-provided message value: (null) """); } @@ -60,7 +60,7 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() Action action = () => Assert.IsInstanceOfType(5, null, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. User-provided message + Assert.IsInstanceOfType(*) failed. User-provided message value: 5 """); } @@ -70,7 +70,7 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() Action action = () => Assert.IsInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. User-provided message + Assert.IsInstanceOfType(*) failed. User-provided message Expected value to be of the specified type. value: 5 expectedType: System.String @@ -88,7 +88,7 @@ public async Task InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNul Func action = async () => Assert.IsInstanceOfType(null, typeof(AssertTests), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsInstanceOfType failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsInstanceOfType(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* value: (null) """); o.WasToStringCalled.Should().BeTrue(); @@ -100,7 +100,7 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull() Action action = () => Assert.IsInstanceOfType(5, null, $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls + Assert.IsInstanceOfType(*) failed. User-provided message DummyClassTrackingToStringCalls value: 5 """); o.WasToStringCalled.Should().BeTrue(); @@ -112,7 +112,7 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMismatched Action action = () => Assert.IsInstanceOfType(5, typeof(string), $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. User-provided message DummyClassTrackingToStringCalls + Assert.IsInstanceOfType(*) failed. User-provided message DummyClassTrackingToStringCalls Expected value to be of the specified type. value: 5 expectedType: System.String @@ -145,7 +145,7 @@ public void IsInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() Action action = () => Assert.IsInstanceOfType(null); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. + Assert.IsInstanceOfType(*) failed. value: (null) """); } @@ -155,7 +155,7 @@ public void IsInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() Action action = () => Assert.IsInstanceOfType(5); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. + Assert.IsInstanceOfType(*) failed. Expected value to be of the specified type. value: 5 expectedType: System.String @@ -284,9 +284,9 @@ public void IsInstanceOfType_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. + Assert.IsInstanceOfType(*) failed. Expected value to be of the specified type. - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + value: "hello" expectedType: System.Int32 actualType: System.String """); @@ -299,9 +299,9 @@ public void IsInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage($""" - Assert.IsInstanceOfType failed. + Assert.IsInstanceOfType(*) failed. Expected value to be of the specified type. - value (obj): {new string('L', 256)}... 44 more + value: {new string('L', 256)}... 44 more expectedType: System.Int32 actualType: *ObjectWithLongToString """); @@ -314,9 +314,9 @@ public void IsInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType failed. + Assert.IsInstanceOfType(*) failed. Expected value to be of the specified type. - value (obj): line1\r\nline2\nline3 + value: line1\r\nline2\nline3 expectedType: System.Int32 actualType: *ObjectWithNewlineToString """); @@ -329,9 +329,9 @@ public void IsNotInstanceOfType_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsNotInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(string)); action.Should().Throw() .WithMessage(""" - Assert.IsNotInstanceOfType failed. + Assert.IsNotInstanceOfType(*) failed. Value should not be of the specified type. - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + value: "hello" wrongType: System.String actualType: System.String """); @@ -344,9 +344,9 @@ public void IsNotInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsNotInstanceOfType(obj, typeof(ObjectWithLongToString)); action.Should().Throw() .WithMessage($""" - Assert.IsNotInstanceOfType failed. + Assert.IsNotInstanceOfType(*) failed. Value should not be of the specified type. - value (obj): {new string('L', 256)}... 44 more + value: {new string('L', 256)}... 44 more wrongType: *ObjectWithLongToString actualType: *ObjectWithLongToString """); @@ -359,9 +359,9 @@ public void IsNotInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsNotInstanceOfType(obj, typeof(ObjectWithNewlineToString)); action.Should().Throw() .WithMessage(""" - Assert.IsNotInstanceOfType failed. + Assert.IsNotInstanceOfType(*) failed. Value should not be of the specified type. - value (obj): line1\r\nline2\nline3 + value: line1\r\nline2\nline3 wrongType: *ObjectWithNewlineToString actualType: *ObjectWithNewlineToString """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index ba0142e030..a1a82be26c 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -17,9 +17,9 @@ public void IsNull_PassNonNull_ShouldFail() Action action = () => Assert.IsNull(new object()); action.Should().Throw() .WithMessage(""" - Assert.IsNull failed. + Assert.IsNull(*) failed. Expected value to be null. - value (new object()): + value: """); } @@ -31,9 +31,9 @@ public void IsNull_StringMessage_PassNonNull_ShouldFail() Action action = () => Assert.IsNull(new object(), "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsNull failed. User-provided message + Assert.IsNull(*) failed. User-provided message Expected value to be null. - value (new object()): + value: """); } @@ -51,9 +51,9 @@ public async Task IsNull_InterpolatedString_PassNonNull_ShouldFail() Func action = async () => Assert.IsNull(new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNull failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsNull(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected value to be null. - value (new object()): + value: """); o.WasToStringCalled.Should().BeTrue(); } @@ -86,7 +86,7 @@ public void IsNotNull_PassNull_ShouldFail() Action action = () => Assert.IsNotNull(null); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull failed. + Assert.IsNotNull(*) failed. Expected a non-null value. value: (null) """); @@ -97,7 +97,7 @@ public void IsNotNull_StringMessage_PassNonNull_ShouldFail() Action action = () => Assert.IsNotNull(null, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull failed. User-provided message + Assert.IsNotNull(*) failed. User-provided message Expected a non-null value. value: (null) """); @@ -110,7 +110,7 @@ public async Task IsNotNull_InterpolatedString_PassNonNull_ShouldFail() Func action = async () => Assert.IsNotNull(null, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNotNull failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsNotNull(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a non-null value. value: (null) """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs index f3c5796aeb..0455d71a73 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs @@ -13,9 +13,9 @@ public void IsFalseNullableBooleanShouldFailWithNull() Action action = () => Assert.IsFalse(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsFalse failed. + Assert.IsFalse(*) failed. Expected condition to be false. - condition (nullBool): (null) + condition: (null) """); } @@ -25,9 +25,9 @@ public void IsFalseNullableBooleanShouldFailWithTrue() Action action = () => Assert.IsFalse(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsFalse failed. + Assert.IsFalse(*) failed. Expected condition to be false. - condition (nullBool): True + condition: True """); } @@ -42,7 +42,7 @@ public void IsFalseBooleanShouldFailWithTrue() Action action = () => Assert.IsFalse(true); action.Should().Throw() .WithMessage(""" - Assert.IsFalse failed. + Assert.IsFalse(*) failed. Expected condition to be false. condition: True """); @@ -57,9 +57,9 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithNull() Action action = () => Assert.IsFalse(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsFalse failed. User-provided message + Assert.IsFalse(*) failed. User-provided message Expected condition to be false. - condition (nullBool): (null) + condition: (null) """); } @@ -69,9 +69,9 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithTrue() Action action = () => Assert.IsFalse(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsFalse failed. User-provided message + Assert.IsFalse(*) failed. User-provided message Expected condition to be false. - condition (nullBool): True + condition: True """); } @@ -86,7 +86,7 @@ public void IsFalseBooleanStringMessageShouldFailWithTrue() Action action = () => Assert.IsFalse(true, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsFalse failed. User-provided message + Assert.IsFalse(*) failed. User-provided message Expected condition to be false. condition: True """); @@ -103,9 +103,9 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithN Func action = async () => Assert.IsFalse(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsFalse failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsFalse(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be false. - condition (nullBool): (null) + condition: (null) """); } @@ -117,9 +117,9 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithT Func action = async () => Assert.IsFalse(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsFalse failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsFalse(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be false. - condition (nullBool): True + condition: True """); } @@ -136,7 +136,7 @@ public async Task IsFalseBooleanInterpolatedStringMessageShouldFailWithTrue() Func action = async () => Assert.IsFalse(true, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsFalse failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsFalse(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be false. condition: True """); @@ -151,9 +151,9 @@ public void IsTrueNullableBooleanShouldFailWithNull() Action action = () => Assert.IsTrue(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsTrue failed. + Assert.IsTrue(*) failed. Expected condition to be true. - condition (nullBool): (null) + condition: (null) """); } @@ -163,9 +163,9 @@ public void IsTrueNullableBooleanShouldFailWithFalse() Action action = () => Assert.IsTrue(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsTrue failed. + Assert.IsTrue(*) failed. Expected condition to be true. - condition (nullBool): False + condition: False """); } @@ -180,7 +180,7 @@ public void IsTrueBooleanShouldFailWithFalse() Action action = () => Assert.IsTrue(false); action.Should().Throw() .WithMessage(""" - Assert.IsTrue failed. + Assert.IsTrue(*) failed. Expected condition to be true. condition: False """); @@ -195,9 +195,9 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithNull() Action action = () => Assert.IsTrue(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsTrue failed. User-provided message + Assert.IsTrue(*) failed. User-provided message Expected condition to be true. - condition (nullBool): (null) + condition: (null) """); } @@ -207,9 +207,9 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithFalse() Action action = () => Assert.IsTrue(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsTrue failed. User-provided message + Assert.IsTrue(*) failed. User-provided message Expected condition to be true. - condition (nullBool): False + condition: False """); } @@ -224,7 +224,7 @@ public void IsTrueBooleanStringMessageShouldFailWithFalse() Action action = () => Assert.IsTrue(false, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsTrue failed. User-provided message + Assert.IsTrue(*) failed. User-provided message Expected condition to be true. condition: False """); @@ -241,9 +241,9 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithNu Func action = async () => Assert.IsTrue(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsTrue failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsTrue(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be true. - condition (nullBool): (null) + condition: (null) """); } @@ -255,9 +255,9 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithFa Func action = async () => Assert.IsTrue(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsTrue failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsTrue(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be true. - condition (nullBool): False + condition: False """); } @@ -274,7 +274,7 @@ public async Task IsTrueBooleanInterpolatedStringMessageShouldFailWithFalse() Func action = async () => Assert.IsTrue(false, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsTrue failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsTrue(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be true. condition: False """); @@ -292,9 +292,9 @@ public void IsTrue_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsTrue(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsTrue failed. + Assert.IsTrue(*) failed. Expected condition to be true. - condition (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): False + condition: False """); } @@ -305,9 +305,9 @@ public void IsFalse_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsFalse(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsFalse failed. + Assert.IsFalse(*) failed. Expected condition to be false. - condition (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): True + condition: True """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs index 2f673bf8c7..5723e4b2b2 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -26,7 +26,7 @@ public void Count_WhenCountIsNotSame_ShouldFail() Action action = () => Assert.HasCount(3, collection); action.Should().Throw() .WithMessage(""" - Assert.HasCount failed. + Assert.HasCount(*) failed. Expected collection to have the specified number of items. collection: [1] (1 item) expectedCount: 3 @@ -41,9 +41,9 @@ public async Task Count_InterpolatedString_WhenCountIsNotSame_ShouldFail() Func action = async () => Assert.HasCount(1, Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.HasCount failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.HasCount(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to have the specified number of items. - collection (Array.Empty()): [] (0 items) + collection: [] (0 items) expectedCount: 1 actualCount: 0 """); @@ -66,7 +66,7 @@ public void NotAny_WhenNotEmpty_ShouldFail() Action action = () => Assert.IsEmpty(collection); action.Should().Throw() .WithMessage(""" - Assert.IsEmpty failed. + Assert.IsEmpty(*) failed. Expected collection to have the specified number of items. collection: [1] (1 item) expectedCount: 0 @@ -82,7 +82,7 @@ public async Task NotAny_InterpolatedString_WhenNotEmpty_ShouldFail() Func action = async () => Assert.IsEmpty(collection, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsEmpty failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsEmpty(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to have the specified number of items. collection: [1] (1 item) expectedCount: 0 @@ -111,9 +111,8 @@ public void Single_WhenNoItems_ShouldFail() Action action = () => Assert.ContainsSingle(Array.Empty()); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. + Assert.ContainsSingle(*) failed. Expected collection to contain exactly one item but found 0 item(s). - collection: Array.Empty() """); } @@ -122,9 +121,8 @@ public void Single_WhenMultipleItems_ShouldFail() Action action = () => Assert.ContainsSingle([1, 2, 3]); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. + Assert.ContainsSingle(*) failed. Expected collection to contain exactly one item but found 3 item(s). - collection: [1, 2, 3] """); } @@ -135,9 +133,8 @@ public async Task Single_InterpolatedString_WhenNoItem_ShouldFail() Func action = async () => Assert.ContainsSingle(Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.ContainsSingle failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.ContainsSingle(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to contain exactly one item but found 0 item(s). - collection: Array.Empty() """); o.WasToStringCalled.Should().BeTrue(); } @@ -149,9 +146,8 @@ public async Task Single_InterpolatedString_WhenMultipleItems_ShouldFail() Func action = async () => Assert.ContainsSingle([1, 2, 3], $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.ContainsSingle failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.ContainsSingle(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to contain exactly one item but found 3 item(s). - collection: [1, 2, 3] """); o.WasToStringCalled.Should().BeTrue(); } @@ -178,9 +174,8 @@ public void SinglePredicate_WhenNoItemMatches_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. + Assert.ContainsSingle(*) failed. Expected exactly one item to match the predicate but found 0 item(s). - predicate: x => x % 2 == 0 """); } @@ -190,9 +185,8 @@ public void SinglePredicate_WhenMultipleItemsMatch_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. + Assert.ContainsSingle(*) failed. Expected exactly one item to match the predicate but found 3 item(s). - predicate: x => x % 2 == 0 """); } @@ -202,9 +196,8 @@ public void SinglePredicate_Message_WhenNoItemMatches_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection, "No even numbers found: test"); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. No even numbers found: test + Assert.ContainsSingle(*) failed. No even numbers found: test Expected exactly one item to match the predicate but found 0 item(s). - predicate: x => x % 2 == 0 """); } @@ -214,9 +207,8 @@ public void SinglePredicate_Message_WhenMultipleItemsMatch_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection, "Too many even numbers: test"); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle failed. Too many even numbers: test + Assert.ContainsSingle(*) failed. Too many even numbers: test Expected exactly one item to match the predicate but found 3 item(s). - predicate: x => x % 2 == 0 """); } @@ -251,9 +243,8 @@ public void Any_WhenNoItem_ShouldFail() Action action = () => Assert.IsNotEmpty(Array.Empty()); action.Should().Throw() .WithMessage(""" - Assert.IsNotEmpty failed. + Assert.IsNotEmpty(*) failed. Expected collection to contain any item but it is empty. - collection: Array.Empty() """); } @@ -264,9 +255,8 @@ public async Task Any_InterpolatedString_WhenNoItem_ShouldFail() Func action = async () => Assert.IsNotEmpty(Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNotEmpty failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsNotEmpty(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to contain any item but it is empty. - collection: Array.Empty() """); o.WasToStringCalled.Should().BeTrue(); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs index 936ae1ebc1..325a17bb3b 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs @@ -17,10 +17,10 @@ public void MatchesRegex_WhenValueDoesNotMatchPattern_ShouldFail() Action action = () => Assert.MatchesRegex(@"\d+", "abc"); action.Should().Throw() .WithMessage(""" - Assert.MatchesRegex failed. + Assert.MatchesRegex(*) failed. String does not match expected pattern. pattern: \d+ - value: "abc" + value: "abc" """); } @@ -32,10 +32,10 @@ public void DoesNotMatchRegex_WhenValueMatchesPattern_ShouldFail() Action action = () => Assert.DoesNotMatchRegex(@"\d+", "abc123"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotMatchRegex failed. + Assert.DoesNotMatchRegex(*) failed. String matches pattern but should not. pattern: \d+ - value: "abc123" + value: "abc123" """); } @@ -50,10 +50,10 @@ public void MatchesRegex_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.MatchesRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.MatchesRegex failed. + Assert.MatchesRegex(*) failed. String does not match expected pattern. pattern: \d+ - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello" + value: "hello" """); } @@ -64,10 +64,10 @@ public void MatchesRegex_WithLongValue_ShouldTruncateValue() Action action = () => Assert.MatchesRegex(@"\d+", longValue); action.Should().Throw() .WithMessage($""" - Assert.MatchesRegex failed. + Assert.MatchesRegex(*) failed. String does not match expected pattern. pattern: \d+ - value (longValue): "{new string('x', 255)}... 46 more + value: "{new string('x', 255)}... 46 more """); } @@ -76,10 +76,10 @@ public void MatchesRegex_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.MatchesRegex(@"^\d+$", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.MatchesRegex failed. + Assert.MatchesRegex(*) failed. String does not match expected pattern. pattern: ^\d+$ - value: "hello\r\nworld" + value: "hello\r\nworld" """); } @@ -90,10 +90,10 @@ public void DoesNotMatchRegex_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotMatchRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotMatchRegex failed. + Assert.DoesNotMatchRegex(*) failed. String matches pattern but should not. pattern: \d+ - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "abc123" + value: "abc123" """); } @@ -104,10 +104,10 @@ public void DoesNotMatchRegex_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotMatchRegex(@"\d+", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotMatchRegex failed. + Assert.DoesNotMatchRegex(*) failed. String matches pattern but should not. pattern: \d+ - value (longValue): "{new string('1', 255)}... 46 more + value: "{new string('1', 255)}... 46 more """); } @@ -116,10 +116,10 @@ public void DoesNotMatchRegex_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotMatchRegex(@"hello", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotMatchRegex failed. + Assert.DoesNotMatchRegex(*) failed. String matches pattern but should not. pattern: hello - value: "hello\r\nworld" + value: "hello\r\nworld" """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs index cab465f361..4d8d21399e 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs @@ -17,10 +17,10 @@ public void StartsWith_WhenValueDoesNotStartWithPrefix_ShouldFail() Action action = () => Assert.StartsWith("world", "hello"); action.Should().Throw() .WithMessage(""" - Assert.StartsWith failed. + Assert.StartsWith(*) failed. String does not start with expected prefix. expectedPrefix: "world" - value: "hello" + value: "hello" """); } @@ -29,10 +29,10 @@ public void StartsWith_WithMessage_WhenValueDoesNotStartWithPrefix_ShouldFail() Action action = () => Assert.StartsWith("world", "hello", "User message"); action.Should().Throw() .WithMessage(""" - Assert.StartsWith failed. User message + Assert.StartsWith(*) failed. User message String does not start with expected prefix. expectedPrefix: "world" - value: "hello" + value: "hello" """); } @@ -44,10 +44,10 @@ public void DoesNotStartWith_WhenValueStartsWithPrefix_ShouldFail() Action action = () => Assert.DoesNotStartWith("hello", "hello world"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotStartWith failed. + Assert.DoesNotStartWith(*) failed. String starts with unexpected prefix. notExpectedPrefix: "hello" - value: "hello world" + value: "hello world" """); } @@ -62,10 +62,10 @@ public void StartsWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.StartsWith("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.StartsWith failed. + Assert.StartsWith(*) failed. String does not start with expected prefix. expectedPrefix: "world" - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello world" + value: "hello world" """); } @@ -76,10 +76,10 @@ public void StartsWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.StartsWith("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.StartsWith failed. + Assert.StartsWith(*) failed. String does not start with expected prefix. expectedPrefix: "world" - value (longValue): "{new string('x', 255)}... 46 more + value: "{new string('x', 255)}... 46 more """); } @@ -88,10 +88,10 @@ public void StartsWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.StartsWith("world", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.StartsWith failed. + Assert.StartsWith(*) failed. String does not start with expected prefix. expectedPrefix: "world" - value: "hello\r\nworld" + value: "hello\r\nworld" """); } @@ -102,10 +102,10 @@ public void DoesNotStartWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotStartWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotStartWith failed. + Assert.DoesNotStartWith(*) failed. String starts with unexpected prefix. notExpectedPrefix: "hello" - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): "hello world" + value: "hello world" """); } @@ -116,10 +116,10 @@ public void DoesNotStartWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotStartWith("hello", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotStartWith failed. + Assert.DoesNotStartWith(*) failed. String starts with unexpected prefix. notExpectedPrefix: "hello" - value (longValue): "hello{new string('x', 250)}... 51 more + value: "hello{new string('x', 250)}... 51 more """); } @@ -128,10 +128,10 @@ public void DoesNotStartWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotStartWith("hello", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotStartWith failed. + Assert.DoesNotStartWith(*) failed. String starts with unexpected prefix. notExpectedPrefix: "hello" - value: "hello\r\nworld" + value: "hello\r\nworld" """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs index 4b9af24404..9790e5c3ca 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index a39430af58..e0c18c595e 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -79,9 +79,9 @@ public void FormatValue_WhenStringExceedsMaxLength_ShouldTruncateWithEllipsis() Action action = () => Assert.IsNull(longValue); action.Should().Throw() .WithMessage($""" - Assert.IsNull failed. + Assert.IsNull(*) failed. Expected value to be null. - value (longValue): {expectedValue} + value: {expectedValue} """); } @@ -93,7 +93,7 @@ public void FormatValue_WhenStringIsWithinMaxLength_ShouldNotTruncate() Action action = () => Assert.IsNull(value); action.Should().Throw() .WithMessage($""" - Assert.IsNull failed. + Assert.IsNull(*) failed. Expected value to be null. value: {expectedFullValue} """); @@ -108,9 +108,9 @@ public void FormatValue_WhenCustomToStringExceedsMaxLength_ShouldTruncate() Action action = () => Assert.IsNull(obj); action.Should().Throw() .WithMessage($""" - Assert.IsNull failed. + Assert.IsNull(*) failed. Expected value to be null. - value (obj): {expectedValue} + value: {expectedValue} """); } @@ -122,9 +122,9 @@ public void TruncateExpression_WhenExpressionExceeds100Chars_ShouldShowEllipsis( Action action = () => Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull failed. + Assert.IsNotNull(*) failed. Expected a non-null value. - value (aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisp...): (null) + value: (null) """); } @@ -139,9 +139,9 @@ public void FormatValue_WhenValueContainsNewlines_ShouldEscapeThem() Action action = () => Assert.IsNull(obj); action.Should().Throw() .WithMessage(""" - Assert.IsNull failed. + Assert.IsNull(*) failed. Expected value to be null. - value (obj): line1\r\nline2\nline3 + value: line1\r\nline2\nline3 """); } @@ -152,7 +152,7 @@ public void FormatValue_WhenStringContainsNewlines_ShouldEscapeThem() Action action = () => Assert.IsNull(value); action.Should().Throw() .WithMessage(""" - Assert.IsNull failed. + Assert.IsNull(*) failed. Expected value to be null. value: "hello\nworld" """); @@ -169,9 +169,9 @@ public void FormatValue_WhenValueIsCollection_ShouldShowPreview() Action action = () => Assert.IsNull(collection); action.Should().Throw() .WithMessage(""" - Assert.IsNull failed. + Assert.IsNull(*) failed. Expected value to be null. - value (collection): [1, 2, 3] (3 items) + value: [1, 2, 3] (3 items) """); } @@ -190,9 +190,8 @@ public void FormatCollectionPreview_WhenTotalStringLengthExceeds256_ShouldTrunca Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() .WithMessage($""" - Assert.Contains failed. + Assert.Contains(*) failed. Expected collection to contain the specified item. - expected: "not-there" collection: ["{new string('a', 30)}", "{new string('b', 30)}", "{new string('c', 30)}", "{new string('d', 30)}", "{new string('e', 30)}", "{new string('f', 30)}", "{new string('g', 30)}", ... 13 more] """); } @@ -206,9 +205,8 @@ public void FormatCollectionPreview_WhenElementToStringExceeds50_ShouldTruncateE Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() .WithMessage($""" - Assert.Contains failed. + Assert.Contains(*) failed. Expected collection to contain the specified item. - expected: "not-there" collection*[{expectedFirstElement}, "short"] (2 items) """); } @@ -222,9 +220,9 @@ public void FormatCollectionPreview_WhenCollectionContainsNestedCollections_Shou Action action = () => Assert.IsNull(outer); action.Should().Throw() .WithMessage(""" - Assert.IsNull failed. + Assert.IsNull(*) failed. Expected value to be null. - value (outer): [[1, 2] (2 items), [3, 4] (2 items)] (2 items) + value: [[1, 2] (2 items), [3, 4] (2 items)] (2 items) """); } @@ -246,9 +244,9 @@ public void FormatCollectionPreview_WhenNestedCollectionIsLarge_ShouldTruncateIn Action action = () => Assert.IsNull(outer); action.Should().Throw() .WithMessage(""" - Assert.IsNull failed. + Assert.IsNull(*) failed. Expected value to be null. - value (outer): [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 35 more]] (1 item) + value: [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 35 more]] (1 item) """); } @@ -259,9 +257,8 @@ public void FormatCollectionPreview_WhenElementContainsNewlines_ShouldEscapeThem Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() .WithMessage(""" - Assert.Contains failed. + Assert.Contains(*) failed. Expected collection to contain the specified item. - expected: "not-there" collection*["line1\nline2", "ok"] (2 items) """); } @@ -273,10 +270,9 @@ public void FormatCollectionPreview_WhenSingleElement_ShouldShowSingularForm() Action action = () => Assert.Contains(99, collection); action.Should().Throw() .WithMessage(""" - Assert.Contains failed. + Assert.Contains(*) failed. Expected collection to contain the specified item. - expected: 99 - collection*[42] (1 item) + collection: [42] (1 item) """); } From a402e6de324731f0a53b5e65bd7cf1e8d23a39c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 12 Mar 2026 15:44:44 +0100 Subject: [PATCH 27/58] Avoid using wildcard in expected message --- .../Assertions/AssertTests.AreEqualTests.cs | 110 +++++++++--------- .../Assertions/AssertTests.AreSame.cs | 30 ++--- .../Assertions/AssertTests.Contains.cs | 87 +++++++------- .../Assertions/AssertTests.EndsWith.cs | 18 +-- .../AssertTests.IComparableTests.cs | 40 +++---- .../AssertTests.IsExactInstanceOfTypeTests.cs | 58 ++++----- .../Assertions/AssertTests.IsInRange.cs | 44 ++++--- .../AssertTests.IsInstanceOfTypeTests.cs | 46 ++++---- .../Assertions/AssertTests.IsNull.cs | 12 +- .../Assertions/AssertTests.IsTrueTests.cs | 40 +++---- .../Assertions/AssertTests.Items.cs | 30 ++--- .../Assertions/AssertTests.MatchesRegex.cs | 16 +-- .../Assertions/AssertTests.StartsWith.cs | 18 +-- 13 files changed, 278 insertions(+), 271 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index e4e14bae59..db39b8f0f9 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -20,7 +20,7 @@ public void AreNotEqualShouldFailWhenNotEqualTypeWithMessage() Action action = () => Assert.AreNotEqual(1, 1, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(*) failed. A Message + Assert.AreNotEqual(1, 1) failed. A Message Expected values to differ. notExpected: 1 actual: 1 @@ -38,7 +38,7 @@ public void AreNotEqualShouldFailWhenNotEqualStringWithMessage() Action action = () => Assert.AreNotEqual("A", "A", "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(*) failed. A Message + Assert.AreNotEqual("A", "A") failed. A Message Expected values to differ. notExpected: "A" actual: "A" @@ -63,7 +63,7 @@ public void AreNotEqualShouldFailWhenNotEqualIntWithMessage() Action action = () => Assert.AreNotEqual(1, 1, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(*) failed. A Message + Assert.AreNotEqual(1, 1) failed. A Message Expected values to differ. notExpected: 1 actual: 1 @@ -81,7 +81,7 @@ public void AreNotEqualShouldFailWhenNotEqualLongWithMessage() Action action = () => Assert.AreNotEqual(1L, 1L, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(*) failed. A Message + Assert.AreNotEqual(1L, 1L) failed. A Message Expected values to differ. notExpected: 1 actual: 1 @@ -105,7 +105,7 @@ public void AreNotEqualShouldFailWhenNotEqualDecimalWithMessage() Action action = () => Assert.AreNotEqual(0.1M, 0.1M, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(*) failed. A Message + Assert.AreNotEqual(0.1M, 0.1M) failed. A Message Expected values to differ. notExpected: 0.1 actual: 0.1 @@ -129,7 +129,7 @@ public void AreNotEqualShouldFailWhenNotEqualDoubleWithMessage() Action action = () => Assert.AreNotEqual(0.1, 0.1, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(*) failed. A Message + Assert.AreNotEqual(0.1, 0.1) failed. A Message Expected values to differ. notExpected: 0.1 actual: 0.1 @@ -153,7 +153,7 @@ public void AreNotEqualShouldFailWhenFloatDoubleWithMessage() Action action = () => Assert.AreNotEqual(100E-2, 100E-2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(*) failed. A Message + Assert.AreNotEqual(100E-2, 100E-2) failed. A Message Expected values to differ. notExpected: 1 actual: 1 @@ -177,7 +177,7 @@ public void AreEqualShouldFailWhenNotEqualTypeWithMessage() Action action = () => Assert.AreEqual(null, "string", "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. A Message + Assert.AreEqual(null, "string") failed. A Message Expected values to be equal. expected: (null) actual: "string" @@ -215,7 +215,7 @@ public void AreEqual_WithEnglishCultureAndDoesNotIgnoreCase_Throws() Action action = () => Assert.AreEqual(expected, actual, false, englishCulture); action.Should().Throw() .WithMessage("""" - Assert.AreEqual(*) failed. + Assert.AreEqual(expected, actual) failed. Case differs. expected: "i" actual: "I" @@ -257,7 +257,7 @@ public void AreEqualShouldFailWhenNotEqualIntWithMessage() Action action = () => Assert.AreEqual(1, 2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. A Message + Assert.AreEqual(1, 2) failed. A Message Expected values to be equal. expected: 1 actual: 2 @@ -275,7 +275,7 @@ public void AreEqualShouldFailWhenNotEqualLongWithMessage() Action action = () => Assert.AreEqual(1L, 2L, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. A Message + Assert.AreEqual(1L, 2L) failed. A Message Expected values to be equal. expected: 1 actual: 2 @@ -299,7 +299,7 @@ public void AreEqualShouldFailWhenNotEqualDoubleWithMessage() Action action = () => Assert.AreEqual(0.1, 0.2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. A Message + Assert.AreEqual(0.1, 0.2) failed. A Message Expected values to be equal. expected: 0.1 actual: 0.2 @@ -324,7 +324,7 @@ public void AreEqualShouldFailWhenNotEqualDecimalWithMessage() Action action = () => Assert.AreEqual(0.1M, 0.2M, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. A Message + Assert.AreEqual(0.1M, 0.2M) failed. A Message Expected values to be equal. expected: 0.1 actual: 0.2 @@ -348,7 +348,7 @@ public void AreEqualShouldFailWhenFloatDoubleWithMessage() Action action = () => Assert.AreEqual(100E-2, 200E-2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. A Message + Assert.AreEqual(100E-2, 200E-2) failed. A Message Expected values to be equal. expected: 1 actual: 2 @@ -372,7 +372,7 @@ public void AreEqualTwoObjectsDifferentTypeShouldFail() Action action = () => Assert.AreEqual(new object(), 1); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual(new object(), 1) failed. Expected values to be equal. expected: (System.Object) actual: 1 (System.Int32) @@ -448,7 +448,7 @@ public async Task GenericAreEqual_InterpolatedString_DifferentValues_ShouldFail( Func action = async () => Assert.AreEqual(0, 1, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(0, 1) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected values to be equal. expected: 0 actual: 1 @@ -470,7 +470,7 @@ public async Task GenericAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(0, 0, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(0, 0) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected values to differ. notExpected: 0 actual: 0 @@ -492,7 +492,7 @@ public async Task FloatAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1.0f, 1.1f, 0.001f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(1.0f, 1.1f) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than <0.001>. expected: 1 actual: 1.1 @@ -514,7 +514,7 @@ public async Task FloatAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0f, 1.1f, 0.2f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(1.0f, 1.1f) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than <0.2>. notExpected: 1 actual: 1.1 @@ -536,7 +536,7 @@ public async Task DecimalAreEqual_InterpolatedString_DifferentValues_ShouldFail( Func action = async () => Assert.AreEqual(1.0m, 1.1m, 0.001m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(1.0m, 1.1m) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than <0.001>. expected: 1.0 actual: 1.1 @@ -558,7 +558,7 @@ public async Task DecimalAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0m, 1.1m, 0.2m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(1.0m, 1.1m) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than <0.2>. notExpected: 1.0 actual: 1.1 @@ -580,7 +580,7 @@ public async Task LongAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1L, 2L, 0L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(1L, 2L) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than <0>. expected: 1 actual: 2 @@ -602,7 +602,7 @@ public async Task LongAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1L, 2L, 1L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(1L, 2L) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than <1>. notExpected: 1 actual: 2 @@ -624,7 +624,7 @@ public async Task DoubleAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1.0d, 1.1d, 0.001d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(1.0d, 1.1d) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than <0.001>. expected: 1 actual: 1.1 @@ -646,7 +646,7 @@ public async Task DoubleAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0d, 1.1d, 0.2d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(1.0d, 1.1d) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than <0.2>. notExpected: 1 actual: 1.1 @@ -823,7 +823,7 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif { Action action = () => Assert.AreEqual(5.0f, 2.0f, 2.0f); // difference is 3. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreEqual(*) failed. + Assert.AreEqual(5.0f, 2.0f) failed. Expected a difference no greater than <2>. expected: 5 actual: 2 @@ -834,7 +834,7 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif { Action action = () => Assert.AreEqual(2.0f, 5.0f, 2.0f); // difference is -3. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreEqual(*) failed. + Assert.AreEqual(2.0f, 5.0f) failed. Expected a difference no greater than <2>. expected: 2 actual: 5 @@ -851,7 +851,7 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFai { Action action = () => Assert.AreEqual(5.0f, float.NaN, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreEqual(*) failed. + Assert.AreEqual(5.0f, float.NaN) failed. Expected a difference no greater than <2>. expected: 5 actual: NaN @@ -862,7 +862,7 @@ public void FloatAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFai { Action action = () => Assert.AreEqual(float.NaN, 5.0f, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreEqual(*) failed. + Assert.AreEqual(float.NaN, 5.0f) failed. Expected a difference no greater than <2>. expected: NaN actual: 5 @@ -1055,7 +1055,7 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual { Action action = () => Assert.AreNotEqual(5.0f, 4.0f, 2.0f); // difference is 1. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreNotEqual(*) failed. + Assert.AreNotEqual(5.0f, 4.0f) failed. Expected a difference greater than <2>. notExpected: 5 actual: 4 @@ -1066,7 +1066,7 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual { Action action = () => Assert.AreNotEqual(4.0f, 5.0f, 2.0f); // difference is -1. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreNotEqual(*) failed. + Assert.AreNotEqual(4.0f, 5.0f) failed. Expected a difference greater than <2>. notExpected: 4 actual: 5 @@ -1082,7 +1082,7 @@ public void FloatAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFail { Action action = () => Assert.AreNotEqual(float.NaN, float.NaN, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreNotEqual(*) failed. + Assert.AreNotEqual(float.NaN, float.NaN) failed. Expected a difference greater than <2>. notExpected: NaN actual: NaN @@ -1271,7 +1271,7 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi Action action = () => Assert.AreEqual(5.0d, 2.0d, 2.0d); // difference is 3. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreEqual(*) failed. + Assert.AreEqual(5.0d, 2.0d) failed. Expected a difference no greater than <2>. expected: 5 actual: 2 @@ -1283,7 +1283,7 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi Action action = () => Assert.AreEqual(2.0d, 5.0d, 2.0d); // difference is -3. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreEqual(*) failed. + Assert.AreEqual(2.0d, 5.0d) failed. Expected a difference no greater than <2>. expected: 2 actual: 5 @@ -1301,7 +1301,7 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFa Action action = () => Assert.AreEqual(5.0d, double.NaN, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreEqual(*) failed. + Assert.AreEqual(5.0d, double.NaN) failed. Expected a difference no greater than <2>. expected: 5 actual: NaN @@ -1313,7 +1313,7 @@ public void DoubleAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFa Action action = () => Assert.AreEqual(double.NaN, 5.0d, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreEqual(*) failed. + Assert.AreEqual(double.NaN, 5.0d) failed. Expected a difference no greater than <2>. expected: NaN actual: 5 @@ -1514,7 +1514,7 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua Action action = () => Assert.AreNotEqual(5.0d, 4.0d, 2.0d); // difference is 1. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual(*) failed. + Assert.AreNotEqual(5.0d, 4.0d) failed. Expected a difference greater than <2>. notExpected: 5 actual: 4 @@ -1526,7 +1526,7 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua Action action = () => Assert.AreNotEqual(4.0d, 5.0d, 2.0d); // difference is -1. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual(*) failed. + Assert.AreNotEqual(4.0d, 5.0d) failed. Expected a difference greater than <2>. notExpected: 4 actual: 5 @@ -1543,7 +1543,7 @@ public void DoubleAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFai Action action = () => Assert.AreNotEqual(double.NaN, double.NaN, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual(*) failed. + Assert.AreNotEqual(double.NaN, double.NaN) failed. Expected a difference greater than <2>. notExpected: NaN actual: NaN @@ -1606,7 +1606,7 @@ public void AreEqualStringDifferenceAtBeginning() Action action = () => Assert.AreEqual("baaa", "aaaa"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual("baaa", "aaaa") failed. String lengths are both 4 but differ at index 0. expected: "baaa" actual: "aaaa" @@ -1619,7 +1619,7 @@ public void AreEqualStringDifferenceAtEnd() Action action = () => Assert.AreEqual("aaaa", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual("aaaa", "aaab") failed. String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" @@ -1632,7 +1632,7 @@ public void AreEqualStringWithSpecialCharactersShouldEscape() Action action = () => Assert.AreEqual("aa\ta", "aa a"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual("aa\ta", "aa a") failed. String lengths are both 4 but differ at index 2. expected: "aa␉a" actual: "aa a" @@ -1648,7 +1648,7 @@ public void AreEqualLongStringsShouldTruncateAndShowContext() Action action = () => Assert.AreEqual(expected, actual); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual(expected, actual) failed. String lengths are both 201 but differ at index 100. expected: "...aaaaaaaaaaaaaaaaaabcccccccccccccccc..." actual: "...aaaaaaaaaaaaaaaaaadcccccccccccccccc..." @@ -1661,7 +1661,7 @@ public void AreEqualStringWithCultureShouldUseEnhancedMessage() Action action = () => Assert.AreEqual("aaaa", "aaab", false, CultureInfo.InvariantCulture); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual("aaaa", "aaab") failed. String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" @@ -1674,7 +1674,7 @@ public void AreEqualStringWithDifferentLength() Action action = () => Assert.AreEqual("aaaa", "aaa"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual("aaaa", "aaa") failed. Expected string length 4 but was 3. expected: "aaaa" actual: "aaa" @@ -1687,7 +1687,7 @@ public void AreEqualShorterExpectedString() Action action = () => Assert.AreEqual("aaa", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual("aaa", "aaab") failed. Expected string length 3 but was 4. expected: "aaa" actual: "aaab" @@ -1700,7 +1700,7 @@ public void AreEqualStringWithUserMessage() Action action = () => Assert.AreEqual("aaaa", "aaab", "My custom message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. My custom message + Assert.AreEqual("aaaa", "aaab") failed. My custom message String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" @@ -1713,7 +1713,7 @@ public void AreEqualStringWithEmojis() Action action = () => Assert.AreEqual("??", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual("??", "aaab") failed. Expected string length 2 but was 4. expected: "??" actual: "aaab" @@ -1935,7 +1935,7 @@ public void AreEqual_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreEqual(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 2); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 2) failed. Expected values to be equal. expected: 1 actual: 2 @@ -1950,7 +1950,7 @@ public void AreEqual_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreEqual(expected, actual); action.Should().Throw() .WithMessage($""" - Assert.AreEqual(*) failed. + Assert.AreEqual(expected, actual) failed. Expected values to be equal. expected: {new string('L', 256)}... 44 more actual: {new string('L', 256)}... 44 more @@ -1965,7 +1965,7 @@ public void AreEqual_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreEqual(expected, actual); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(*) failed. + Assert.AreEqual(expected, actual) failed. Expected values to be equal. expected: line1\r\nline2\nline3 actual: line1\r\nline2\nline3 @@ -1979,7 +1979,7 @@ public void AreNotEqual_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreNotEqual(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 1); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(*) failed. + Assert.AreNotEqual(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 1) failed. Expected values to differ. notExpected: 1 actual: 1 @@ -1993,7 +1993,7 @@ public void AreNotEqual_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreNotEqual(obj, obj); action.Should().Throw() .WithMessage($""" - Assert.AreNotEqual(*) failed. + Assert.AreNotEqual(obj, obj) failed. Expected values to differ. notExpected: {new string('L', 256)}... 44 more actual: {new string('L', 256)}... 44 more @@ -2007,7 +2007,7 @@ public void AreNotEqual_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreNotEqual(obj, obj); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(*) failed. + Assert.AreNotEqual(obj, obj) failed. Expected values to differ. notExpected: line1\r\nline2\nline3 actual: line1\r\nline2\nline3 diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index c4852c267f..773564ded3 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -17,7 +17,7 @@ public void AreSame_PassDifferentObject_ShouldFail() { Action action = () => Assert.AreSame(new object(), new object()); action.Should().Throw().WithMessage(""" - Assert.AreSame(*) failed. + Assert.AreSame(new object(), new object()) failed. Expected references to be the same. expected: (Hash=*) actual: (Hash=*) @@ -34,7 +34,7 @@ public void AreSame_StringMessage_PassDifferentObject_ShouldFail() { Action action = () => Assert.AreSame(new object(), new object(), "User-provided message"); action.Should().Throw().WithMessage(""" - Assert.AreSame(*) failed. User-provided message + Assert.AreSame(new object(), new object()) failed. User-provided message Expected references to be the same. expected: (Hash=*) actual: (Hash=*) @@ -54,7 +54,7 @@ public async Task AreSame_InterpolatedString_PassDifferentObject_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreSame(new object(), new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()).WithMessage(""" - Assert.AreSame(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreSame(new object(), new object()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected references to be the same. expected: (Hash=*) actual: (Hash=*) @@ -69,7 +69,7 @@ public void AreSame_BothAreValueTypes_ShouldFailWithSpecializedMessage() { Action action = () => Assert.AreSame(1, 1); action.Should().Throw().WithMessage(""" - Assert.AreSame(*) failed. + Assert.AreSame(1, 1) failed. Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) actual: 1 (Hash=*) @@ -80,7 +80,7 @@ public void AreSame_StringMessage_BothAreValueTypes_ShouldFailWithSpecializedMes { Action action = () => Assert.AreSame(1, 1, "User-provided message"); action.Should().Throw().WithMessage(""" - Assert.AreSame(*) failed. User-provided message + Assert.AreSame(1, 1) failed. User-provided message Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) actual: 1 (Hash=*) @@ -91,7 +91,7 @@ public void AreSame_InterpolatedString_BothAreValueTypes_ShouldFailWithSpecializ { Action action = () => Assert.AreSame(1, 1, $"User-provided message {new object().GetType()}"); action.Should().Throw().WithMessage(""" - Assert.AreSame(*) failed. User-provided message System.Object + Assert.AreSame(1, 1) failed. User-provided message System.Object Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) actual: 1 (Hash=*) @@ -103,7 +103,7 @@ public void AreNotSame_PassSameObject_ShouldFail() object o = new(); Action action = () => Assert.AreNotSame(o, o); action.Should().Throw().WithMessage(""" - Assert.AreNotSame(*) failed. + Assert.AreNotSame(o, o) failed. Expected references to be different. notExpected: actual: @@ -118,7 +118,7 @@ public void AreNotSame_StringMessage_PassSameObject_ShouldFail() object o = new(); Action action = () => Assert.AreNotSame(o, o, "User-provided message"); action.Should().Throw().WithMessage(""" - Assert.AreNotSame(*) failed. User-provided message + Assert.AreNotSame(o, o) failed. User-provided message Expected references to be different. notExpected: actual: @@ -138,7 +138,7 @@ public async Task AreNotSame_InterpolatedString_PassSameObject_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreNotSame(o, o, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()).WithMessage(""" - Assert.AreNotSame(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotSame(o, o) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected references to be different. notExpected: DummyClassTrackingToStringCalls actual: DummyClassTrackingToStringCalls @@ -155,7 +155,7 @@ public void AreSame_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreSame(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, new object()); action.Should().Throw() .WithMessage(""" - Assert.AreSame(*) failed. + Assert.AreSame(aVeryLongVariableNameThatExceedsOneHundredCharacte..., new object()) failed. Expected references to be the same. expected: (Hash=*) actual: (Hash=*) @@ -167,7 +167,7 @@ public void AreSame_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreSame(new ObjectWithLongToString(), new ObjectWithLongToString()); action.Should().Throw() .WithMessage($""" - Assert.AreSame(*) failed. + Assert.AreSame(new ObjectWithLongToString(), new ObjectWithLongToString()) failed. Expected references to be the same. expected: {new string('L', 256)}... 44 more (Hash=*) actual: {new string('L', 256)}... 44 more (Hash=*) @@ -179,7 +179,7 @@ public void AreSame_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreSame(new ObjectWithNewlineToString(), new ObjectWithNewlineToString()); action.Should().Throw() .WithMessage(""" - Assert.AreSame(*) failed. + Assert.AreSame(new ObjectWithNewlineToString(), new ObjectWithNewlineToString()) failed. Expected references to be the same. expected: line1\r\nline2\nline3 (Hash=*) actual: line1\r\nline2\nline3 (Hash=*) @@ -193,7 +193,7 @@ public void AreNotSame_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreNotSame(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.AreNotSame(*) failed. + Assert.AreNotSame(aVeryLongVariableNameThatExceedsOneHundredCharacte..., aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected references to be different. notExpected: actual: @@ -207,7 +207,7 @@ public void AreNotSame_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreNotSame(obj, obj); action.Should().Throw() .WithMessage($""" - Assert.AreNotSame(*) failed. + Assert.AreNotSame(obj, obj) failed. Expected references to be different. notExpected: {new string('L', 256)}... 44 more actual: {new string('L', 256)}... 44 more @@ -221,7 +221,7 @@ public void AreNotSame_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreNotSame(obj, obj); action.Should().Throw() .WithMessage(""" - Assert.AreNotSame(*) failed. + Assert.AreNotSame(obj, obj) failed. Expected references to be different. notExpected: line1\r\nline2\nline3 actual: line1\r\nline2\nline3 diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index 8c083b25a9..70871e5fd5 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -339,7 +339,7 @@ public void ContainsSingle_InterpolatedHandler_WithMultipleElements_ThrowsExcept // Assert action.Should().Throw().WithMessage(""" - Assert.ContainsSingle(*) failed. + Assert.ContainsSingle(collection) failed. Expected collection to contain exactly one item but found 3 item(s). """); } @@ -372,7 +372,7 @@ public void ContainsSingle_InNonGenericCollection_NoMessage_WithEmptyCollection_ // Assert action.Should().Throw().WithMessage(""" - Assert.ContainsSingle(*) failed. + Assert.ContainsSingle(collection) failed. Expected collection to contain exactly one item but found 0 item(s). """); } @@ -390,7 +390,7 @@ public void ContainsSingle_InNonGenericCollection_AssertCustomMessage_WithEmptyC // Assert action.Should().Throw().WithMessage(""" - Assert.ContainsSingle(*) failed. my custom message + Assert.ContainsSingle(collection) failed. my custom message Expected collection to contain exactly one item but found 0 item(s). """); } @@ -427,7 +427,7 @@ public void Contains_ValueExpected_ItemDoesNotExist_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(*) failed. Item 20 not found + Assert.Contains(20, collection) failed. Item 20 not found Expected collection to contain the specified item.* """); } @@ -446,7 +446,7 @@ public void Contains_InNonGenericCollection_ValueExpected_ItemDoesNotExist_Throw // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(*) failed. Item 20 not found + Assert.Contains(expected, collection) failed. Item 20 not found Expected collection to contain the specified item.* """); } @@ -495,7 +495,7 @@ public void Contains_InNonGenericCollection_NullableValueExpected_ItemDoesNotExi // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(*) failed. Item not found + Assert.Contains(expected, collection) failed. Item not found Expected collection to contain the specified item.* """); } @@ -547,7 +547,7 @@ public void Contains_WithComparer_ItemDoesNotExist_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(*) failed. Missing cherry + Assert.Contains("cherry", collection) failed. Missing cherry Expected collection to contain the specified item.* """); } @@ -596,7 +596,7 @@ public void Contains_Predicate_NoItemMatches_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(*) failed. No even number found + Assert.Contains(IsEven, collection) failed. No even number found Expected at least one item to match the predicate.* """); } @@ -615,7 +615,7 @@ public void Contains_InNonGenericCollection_Predicate_NoItemMatches_ThrowsExcept // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(*) failed. No even number found + Assert.Contains(IsEven, collection) failed. No even number found Expected at least one item to match the predicate.* """); } @@ -651,7 +651,7 @@ public void Contains_StringVersion_SubstringNotPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(*) failed. Missing substring + Assert.Contains(substring, value) failed. Missing substring String does not contain the expected substring. substring: "lazy" value: "The quick brown fox" @@ -732,7 +732,7 @@ public void Contains_InNonGenericCollection_WithComparer_ItemDoesNotExist_Throws // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(*) failed. + Assert.Contains("banana", collection) failed. Expected collection to contain the specified item.* """); } @@ -870,7 +870,7 @@ public void Contains_String_EmptyValue_WithNonEmptySubstring_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(*) failed. + Assert.Contains(substring, value) failed. String does not contain the expected substring. substring: "test" value: "" @@ -978,7 +978,7 @@ public void DoesNotContain_ValueExpected_ItemPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(*) failed. Item 10 should not be found + Assert.DoesNotContain(10, collection) failed. Item 10 should not be found Expected collection to not contain the specified item.* """); } @@ -1008,12 +1008,13 @@ public void DoesNotContain_InNonGenericCollection_ValueExpected_ItemPresent_Thro var collection = new ArrayList { 5, 10, 15, "a" }; // Act - Action action = () => Assert.DoesNotContain(10, collection, "Assert.DoesNotContain(*) failed. Expected collection to not contain the specified item. Item {0} should not be found"); + Action action = () => Assert.DoesNotContain(10, collection, "Item 10 should not be found"); // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(*) failed. Assert.DoesNotContain(*) failed. Expected collection to not contain the specified item. Item {0} should not be found - Expected collection to not contain the specified item.* + Assert.DoesNotContain(10, collection) failed. Item 10 should not be found + Expected collection to not contain the specified item. + collection: [5, 10, 15, "a"] (4 items) """); } @@ -1064,7 +1065,7 @@ public void DoesNotContain_WithComparer_ItemPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(*) failed. Unexpected "APPLE" + Assert.DoesNotContain("APPLE", collection) failed. Unexpected "APPLE" Expected collection to not contain the specified item.* """); } @@ -1084,7 +1085,7 @@ public void DoesNotContain_InNonGenericCollection_WithComparer_ItemPresent_Throw // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(*) failed. APPLE + Assert.DoesNotContain("APPLE", collection) failed. APPLE Expected collection to not contain the specified item.* """); } @@ -1133,7 +1134,7 @@ public void DoesNotContain_Predicate_AtLeastOneItemMatches_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(*) failed. An even number exists + Assert.DoesNotContain(IsEven, collection) failed. An even number exists Expected no items to match the predicate.* """); } @@ -1152,7 +1153,7 @@ public void DoesNotContain_InNonGenericCollection_Predicate_AtLeastOneItemMatche // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(*) failed. An even number exists + Assert.DoesNotContain(IsEven, collection) failed. An even number exists Expected no items to match the predicate.* """); } @@ -1188,7 +1189,7 @@ public void DoesNotContain_StringVersion_SubstringPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(*) failed. Unexpected substring + Assert.DoesNotContain(substring, value) failed. Unexpected substring String contains the unexpected substring. substring: "brown" value: "The quick brown fox" @@ -1228,7 +1229,7 @@ public void DoesNotContain_StringWithComparisonAndMessage_SubstringPresent_Throw // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(*) failed. Found unexpected substring + Assert.DoesNotContain(substring, value) failed. Found unexpected substring String contains the unexpected substring. substring: "BROWN" value: "The quick brown fox" @@ -1266,7 +1267,7 @@ public void DoesNotContain_StringSimpleOverload_SubstringPresent_ThrowsException // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(*) failed. + Assert.DoesNotContain(substring, value) failed. String contains the unexpected substring. substring: "brown" value: "The quick brown fox" @@ -1304,7 +1305,7 @@ public void DoesNotContain_StringWithMessageOnly_SubstringPresent_ThrowsExceptio // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(*) failed. Found unexpected substring + Assert.DoesNotContain(substring, value) failed. Found unexpected substring String contains the unexpected substring. substring: "brown" value: "The quick brown fox" @@ -1552,7 +1553,7 @@ public void ContainsSinglePredicate_NoItemMatches_ThrowsException() // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. + Assert.ContainsSingle(x => x % 2 == 0, collection) failed. Expected exactly one item to match the predicate but found 0 item(s). """); } @@ -1572,7 +1573,7 @@ public void ContainsSinglePredicate_InNonGenericCollection_NoItemMatches_ThrowsE // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. + Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) failed. Expected exactly one item to match the predicate but found 0 item(s). """); } @@ -1592,7 +1593,7 @@ public void ContainsSinglePredicate_MultipleItemsMatch_ThrowsException() // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. + Assert.ContainsSingle(x => x % 2 == 0, collection) failed. Expected exactly one item to match the predicate but found 4 item(s). """); } @@ -1612,7 +1613,7 @@ public void ContainsSinglePredicate_InNonGenericCollection_MultipleItemsMatch_Th // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. + Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) failed. Expected exactly one item to match the predicate but found 2 item(s). """); } @@ -1632,7 +1633,7 @@ public void ContainsSinglePredicate_WithMessage_NoItemMatches_ThrowsException() // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. No even numbers found in collection with 3 items + Assert.ContainsSingle(x => x % 2 == 0, collection) failed. No even numbers found in collection with 3 items Expected exactly one item to match the predicate but found 0 item(s). """); } @@ -1652,7 +1653,7 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_NoItemMat // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. No even numbers found in collection with 3 items + Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) failed. No even numbers found in collection with 3 items Expected exactly one item to match the predicate but found 0 item(s). """); } @@ -1672,7 +1673,7 @@ public void ContainsSinglePredicate_WithMessage_MultipleItemsMatch_ThrowsExcepti // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. Too many even numbers found: 3 + Assert.ContainsSingle(x => x % 2 == 0, collection) failed. Too many even numbers found: 3 Expected exactly one item to match the predicate but found 3 item(s). """); } @@ -1692,7 +1693,7 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_MultipleI // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. Too many even numbers found: 2 + Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) failed. Too many even numbers found: 2 Expected exactly one item to match the predicate but found 2 item(s). """); } @@ -1787,7 +1788,7 @@ public void Contains_ItemNotFound_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.Contains(*) failed. + Assert.Contains(5, collection) failed. Expected collection to contain the specified item.* collection: [1, 2, 3] (3 items) """); @@ -1807,7 +1808,7 @@ public void Contains_InNonGenericCollection_ItemNotFound_ShowsSpecificErrorMessa // Assert action.Should().Throw() .WithMessage(""" - Assert.Contains(*) failed. + Assert.Contains(5, collection) failed. Expected collection to contain the specified item.* collection: [1, 2, 3] (3 items) """); @@ -1827,7 +1828,7 @@ public void Contains_PredicateNotMatched_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.Contains(*) failed. + Assert.Contains(x => x % 2 == 0, collection) failed. Expected at least one item to match the predicate.* collection: [1, 3, 5] (3 items) """); @@ -1847,7 +1848,7 @@ public void DoesNotContain_ItemFound_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain(*) failed. + Assert.DoesNotContain(2, collection) failed. Expected collection to not contain the specified item.* collection: [1, 2, 3] (3 items) """); @@ -1867,7 +1868,7 @@ public void DoesNotContain_PredicateMatched_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain(*) failed. + Assert.DoesNotContain(x => x % 2 == 0, collection) failed. Expected no items to match the predicate.* collection: [1, 2, 3] (3 items) """); @@ -1924,7 +1925,7 @@ public void Contains_String_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.Contains("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.Contains(*) failed. + Assert.Contains("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. String does not contain the expected substring. substring: "world" value: "hello" @@ -1938,7 +1939,7 @@ public void Contains_String_WithLongValue_ShouldTruncateValue() Action action = () => Assert.Contains("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.Contains(*) failed. + Assert.Contains("world", longValue) failed. String does not contain the expected substring. substring: "world" value: "{new string('x', 255)}... 46 more @@ -1950,7 +1951,7 @@ public void Contains_String_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.Contains("world", "hello\r\nfoo"); action.Should().Throw() .WithMessage(""" - Assert.Contains(*) failed. + Assert.Contains("world", "hello\r\nfoo") failed. String does not contain the expected substring. substring: "world" value: "hello\r\nfoo" @@ -1964,7 +1965,7 @@ public void DoesNotContain_String_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotContain("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain(*) failed. + Assert.DoesNotContain("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. String contains the unexpected substring. substring: "hello" value: "hello world" @@ -1978,7 +1979,7 @@ public void DoesNotContain_String_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotContain("hello", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotContain(*) failed. + Assert.DoesNotContain("hello", longValue) failed. String contains the unexpected substring. substring: "hello" value: "hello{new string('x', 250)}... 51 more @@ -1990,7 +1991,7 @@ public void DoesNotContain_String_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotContain("hello", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain(*) failed. + Assert.DoesNotContain("hello", "hello\r\nworld") failed. String contains the unexpected substring. substring: "hello" value: "hello\r\nworld" diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs index 860c0f6308..537ec66b74 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs @@ -17,7 +17,7 @@ public void EndsWith_WhenValueDoesNotEndWithSuffix_ShouldFail() Action action = () => Assert.EndsWith("hello", "world"); action.Should().Throw() .WithMessage(""" - Assert.EndsWith(*) failed. + Assert.EndsWith("hello", "world") failed. String does not end with expected suffix. expectedSuffix: "hello" value: "world" @@ -29,7 +29,7 @@ public void EndsWith_WithMessage_WhenValueDoesNotEndWithSuffix_ShouldFail() Action action = () => Assert.EndsWith("hello", "world", "User message"); action.Should().Throw() .WithMessage(""" - Assert.EndsWith(*) failed. User message + Assert.EndsWith("hello", "world") failed. User message String does not end with expected suffix. expectedSuffix: "hello" value: "world" @@ -44,7 +44,7 @@ public void DoesNotEndWith_WhenValueEndsWithSuffix_ShouldFail() Action action = () => Assert.DoesNotEndWith("world", "hello world"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotEndWith(*) failed. + Assert.DoesNotEndWith("world", "hello world") failed. String ends with unexpected suffix. notExpectedSuffix: "world" value: "hello world" @@ -62,7 +62,7 @@ public void EndsWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.EndsWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.EndsWith(*) failed. + Assert.EndsWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. String does not end with expected suffix. expectedSuffix: "hello" value: "hello world" @@ -76,7 +76,7 @@ public void EndsWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.EndsWith("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.EndsWith(*) failed. + Assert.EndsWith("world", longValue) failed. String does not end with expected suffix. expectedSuffix: "world" value: "{new string('x', 255)}... 46 more @@ -88,7 +88,7 @@ public void EndsWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.EndsWith("world", "hello\r\nfoo"); action.Should().Throw() .WithMessage(""" - Assert.EndsWith(*) failed. + Assert.EndsWith("world", "hello\r\nfoo") failed. String does not end with expected suffix. expectedSuffix: "world" value: "hello\r\nfoo" @@ -102,7 +102,7 @@ public void DoesNotEndWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotEndWith("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotEndWith(*) failed. + Assert.DoesNotEndWith("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. String ends with unexpected suffix. notExpectedSuffix: "world" value: "hello world" @@ -116,7 +116,7 @@ public void DoesNotEndWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotEndWith("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotEndWith(*) failed. + Assert.DoesNotEndWith("world", longValue) failed. String ends with unexpected suffix. notExpectedSuffix: "world" value: "{new string('x', 255)}... 51 more @@ -128,7 +128,7 @@ public void DoesNotEndWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotEndWith("world", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotEndWith(*) failed. + Assert.DoesNotEndWith("world", "hello\r\nworld") failed. String ends with unexpected suffix. notExpectedSuffix: "world" value: "hello\r\nworld" diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs index 98b70edca9..d8d25a1e32 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs @@ -43,7 +43,7 @@ public void IsGreaterThanShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThan(*) failed. A Message + Assert.IsGreaterThan(10, 5) failed. A Message Expected value to be greater than the specified bound. lowerBound: 10 value: 5 @@ -92,7 +92,7 @@ public void IsGreaterThanOrEqualToShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThanOrEqualTo(*) failed. A Message + Assert.IsGreaterThanOrEqualTo(10, 5) failed. A Message Expected value to be greater than or equal to the specified bound. lowerBound: 10 value: 5 @@ -141,7 +141,7 @@ public void IsLessThanShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsLessThan(*) failed. A Message + Assert.IsLessThan(5, 10) failed. A Message Expected value to be less than the specified bound. upperBound: 5 value: 10 @@ -190,7 +190,7 @@ public void IsLessThanOrEqualToShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsLessThanOrEqualTo(*) failed. A Message + Assert.IsLessThanOrEqualTo(5, 10) failed. A Message Expected value to be less than or equal to the specified bound. upperBound: 5 value: 10 @@ -254,7 +254,7 @@ public void IsPositiveShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsPositive(*) failed. A Message + Assert.IsPositive(-5) failed. A Message Expected a positive value. value: -5 """); @@ -323,7 +323,7 @@ public void IsNegativeShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsNegative(*) failed. A Message + Assert.IsNegative(5) failed. A Message Expected a negative value. value: 5 """); @@ -352,7 +352,7 @@ public void IsGreaterThan_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsGreaterThan(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 5); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThan(*) failed. + Assert.IsGreaterThan(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 5) failed. Expected value to be greater than the specified bound. lowerBound: 10 value: 5 @@ -367,7 +367,7 @@ public void IsGreaterThan_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsGreaterThan(lowerBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsGreaterThan(*) failed. + Assert.IsGreaterThan(lowerBound, value) failed. Expected value to be greater than the specified bound. lowerBound: {new string('V', 256)}... 44 more value: {new string('V', 256)}... 44 more @@ -382,7 +382,7 @@ public void IsGreaterThan_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsGreaterThan(lowerBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThan(*) failed. + Assert.IsGreaterThan(lowerBound, value) failed. Expected value to be greater than the specified bound. lowerBound: line1\r\nline2 value: line1\r\nline2 @@ -396,7 +396,7 @@ public void IsGreaterThanOrEqualTo_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsGreaterThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 5); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThanOrEqualTo(*) failed. + Assert.IsGreaterThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 5) failed. Expected value to be greater than or equal to the specified bound. lowerBound: 10 value: 5 @@ -411,7 +411,7 @@ public void IsGreaterThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsGreaterThanOrEqualTo(lowerBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsGreaterThanOrEqualTo(*) failed. + Assert.IsGreaterThanOrEqualTo(lowerBound, value) failed. Expected value to be greater than or equal to the specified bound. lowerBound: {new string('V', 256)}... 44 more value: {new string('V', 256)}... 44 more @@ -426,7 +426,7 @@ public void IsGreaterThanOrEqualTo_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsGreaterThanOrEqualTo(lowerBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThanOrEqualTo(*) failed. + Assert.IsGreaterThanOrEqualTo(lowerBound, value) failed. Expected value to be greater than or equal to the specified bound. lowerBound: line1\r\nline2 value: line1\r\nline2 @@ -440,7 +440,7 @@ public void IsLessThan_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsLessThan(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 10); action.Should().Throw() .WithMessage(""" - Assert.IsLessThan(*) failed. + Assert.IsLessThan(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 10) failed. Expected value to be less than the specified bound. upperBound: 5 value: 10 @@ -455,7 +455,7 @@ public void IsLessThan_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsLessThan(upperBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsLessThan(*) failed. + Assert.IsLessThan(upperBound, value) failed. Expected value to be less than the specified bound. upperBound: {new string('V', 256)}... 44 more value: {new string('V', 256)}... 44 more @@ -470,7 +470,7 @@ public void IsLessThan_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsLessThan(upperBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsLessThan(*) failed. + Assert.IsLessThan(upperBound, value) failed. Expected value to be less than the specified bound. upperBound: line1\r\nline2 value: line1\r\nline2 @@ -484,7 +484,7 @@ public void IsLessThanOrEqualTo_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsLessThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 10); action.Should().Throw() .WithMessage(""" - Assert.IsLessThanOrEqualTo(*) failed. + Assert.IsLessThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 10) failed. Expected value to be less than or equal to the specified bound. upperBound: 5 value: 10 @@ -499,7 +499,7 @@ public void IsLessThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsLessThanOrEqualTo(upperBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsLessThanOrEqualTo(*) failed. + Assert.IsLessThanOrEqualTo(upperBound, value) failed. Expected value to be less than or equal to the specified bound. upperBound: {new string('V', 256)}... 44 more value: {new string('V', 256)}... 44 more @@ -514,7 +514,7 @@ public void IsLessThanOrEqualTo_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsLessThanOrEqualTo(upperBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsLessThanOrEqualTo(*) failed. + Assert.IsLessThanOrEqualTo(upperBound, value) failed. Expected value to be less than or equal to the specified bound. upperBound: line1\r\nline2 value: line1\r\nline2 @@ -528,7 +528,7 @@ public void IsPositive_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsPositive(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsPositive(*) failed. + Assert.IsPositive(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected a positive value. value: -5 """); @@ -541,7 +541,7 @@ public void IsNegative_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsNegative(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsNegative(*) failed. + Assert.IsNegative(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected a negative value. value: 5 """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index ae94b7b71c..94676ed0cd 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -13,7 +13,7 @@ public void ExactInstanceOfTypeShouldFailWhenValueIsNull() Action action = () => Assert.IsExactInstanceOfType(null, typeof(AssertTests)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. +Assert.IsExactInstanceOfType(null) failed. value: (null) """); } @@ -23,7 +23,7 @@ public void ExactInstanceOfTypeShouldFailWhenTypeIsNull() Action action = () => Assert.IsExactInstanceOfType(5, null); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. +Assert.IsExactInstanceOfType(5) failed. value: 5 """); } @@ -33,7 +33,7 @@ public void ExactInstanceOfTypeShouldFailWhenTypeIsMismatched() Action action = () => Assert.IsExactInstanceOfType(5, typeof(string)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. +Assert.IsExactInstanceOfType(5) failed. Expected value to be exactly of the specified type. value: 5 expectedType: System.String @@ -48,7 +48,7 @@ public void ExactInstanceOfTypeShouldFailOnHigherInstance() Action action = () => Assert.IsExactInstanceOfType(5, typeof(object)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. +Assert.IsExactInstanceOfType(5) failed. Expected value to be exactly of the specified type. value: 5 expectedType: System.Object @@ -62,7 +62,7 @@ public void ExactInstanceOfTypeShouldFailOnDerivedType() Action action = () => Assert.IsExactInstanceOfType(x, typeof(Stream)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. +Assert.IsExactInstanceOfType(x) failed. Expected value to be exactly of the specified type. value: expectedType: System.IO.Stream @@ -81,7 +81,7 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() Action action = () => Assert.IsExactInstanceOfType(null, typeof(AssertTests), "User-provided message"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. User-provided message +Assert.IsExactInstanceOfType(null) failed. User-provided message value: (null) """); } @@ -91,7 +91,7 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() Action action = () => Assert.IsExactInstanceOfType(5, null, "User-provided message"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. User-provided message +Assert.IsExactInstanceOfType(5) failed. User-provided message value: 5 """); } @@ -101,7 +101,7 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched Action action = () => Assert.IsExactInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. User-provided message +Assert.IsExactInstanceOfType(5) failed. User-provided message Expected value to be exactly of the specified type. value: 5 expectedType: System.String @@ -119,7 +119,7 @@ public async Task ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenValue Func action = async () => Assert.IsExactInstanceOfType(null, typeof(AssertTests), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsExactInstanceOfType(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsExactInstanceOfType(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* value: (null) """); o.WasToStringCalled.Should().BeTrue(); @@ -131,7 +131,7 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull( Action action = () => Assert.IsExactInstanceOfType(5, null, $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. User-provided message DummyClassTrackingToStringCalls +Assert.IsExactInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls value: 5 """); o.WasToStringCalled.Should().BeTrue(); @@ -143,7 +143,7 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMisma Action action = () => Assert.IsExactInstanceOfType(5, typeof(string), $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. User-provided message DummyClassTrackingToStringCalls +Assert.IsExactInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls Expected value to be exactly of the specified type. value: 5 expectedType: System.String @@ -183,7 +183,7 @@ public void ExactInstanceNotOfTypeShouldFailOnExactType() Action action = () => Assert.IsNotExactInstanceOfType(x, typeof(MemoryStream)); action.Should().Throw() .WithMessage(""" -Assert.IsNotExactInstanceOfType(*) failed. +Assert.IsNotExactInstanceOfType(x) failed. Value should not be exactly of the specified type. value: wrongType: System.IO.MemoryStream @@ -196,7 +196,7 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() Action action = () => Assert.IsExactInstanceOfType(null); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. +Assert.IsExactInstanceOfType(null) failed. value: (null) """); } @@ -206,7 +206,7 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() Action action = () => Assert.IsExactInstanceOfType(5); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. +Assert.IsExactInstanceOfType(5) failed. Expected value to be exactly of the specified type. value: 5 expectedType: System.String @@ -220,7 +220,7 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenDerivedType_Fails() Action action = () => Assert.IsExactInstanceOfType(x); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. +Assert.IsExactInstanceOfType(x) failed. Expected value to be exactly of the specified type. value: expectedType: System.IO.Stream @@ -248,7 +248,7 @@ public void IsExactInstanceOfTypeUsingGenericType_OnHigherInstance_Fails() Action action = () => Assert.IsExactInstanceOfType(5); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(*) failed. +Assert.IsExactInstanceOfType(5) failed. Expected value to be exactly of the specified type. value: 5 expectedType: System.Object @@ -281,7 +281,7 @@ public void IsNotExactInstanceOfTypeUsingGenericType_OnExactType_Fails() Action action = () => Assert.IsNotExactInstanceOfType(x); action.Should().Throw() .WithMessage(""" -Assert.IsNotExactInstanceOfType(*) failed. +Assert.IsNotExactInstanceOfType(x) failed. Value should not be exactly of the specified type. value: wrongType: System.IO.MemoryStream @@ -368,7 +368,7 @@ public void IsExactInstanceOfType_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsExactInstanceOfType(*) failed. + Assert.IsExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected value to be exactly of the specified type. value: "hello" expectedType: System.Int32 @@ -383,11 +383,11 @@ public void IsExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsExactInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage($""" - Assert.IsExactInstanceOfType(*) failed. + Assert.IsExactInstanceOfType(obj) failed. Expected value to be exactly of the specified type. value: {new string('L', 256)}... 44 more expectedType: System.Int32 - actualType: *ObjectWithLongToString + actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString """); } @@ -398,11 +398,11 @@ public void IsExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsExactInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsExactInstanceOfType(*) failed. + Assert.IsExactInstanceOfType(obj) failed. Expected value to be exactly of the specified type. value: line1\r\nline2\nline3 expectedType: System.Int32 - actualType: *ObjectWithNewlineToString + actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString """); } @@ -413,7 +413,7 @@ public void IsNotExactInstanceOfType_WithLongExpression_ShouldTruncateExpression Action action = () => Assert.IsNotExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(string)); action.Should().Throw() .WithMessage(""" - Assert.IsNotExactInstanceOfType(*) failed. + Assert.IsNotExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Value should not be exactly of the specified type. value: "hello" wrongType: System.String @@ -428,11 +428,11 @@ public void IsNotExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsNotExactInstanceOfType(obj, typeof(ObjectWithLongToString)); action.Should().Throw() .WithMessage($""" - Assert.IsNotExactInstanceOfType(*) failed. + Assert.IsNotExactInstanceOfType(obj) failed. Value should not be exactly of the specified type. value: {new string('L', 256)}... 44 more - wrongType: *ObjectWithLongToString - actualType: *ObjectWithLongToString + wrongType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString + actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString """); } @@ -443,11 +443,11 @@ public void IsNotExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines( Action action = () => Assert.IsNotExactInstanceOfType(obj, typeof(ObjectWithNewlineToString)); action.Should().Throw() .WithMessage(""" - Assert.IsNotExactInstanceOfType(*) failed. + Assert.IsNotExactInstanceOfType(obj) failed. Value should not be exactly of the specified type. value: line1\r\nline2\nline3 - wrongType: *ObjectWithNewlineToString - actualType: *ObjectWithNewlineToString + wrongType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString + actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index 5087e774ca..b511a61536 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -58,7 +58,7 @@ public void IsInRange_WithValueBelowRange_ThrowsAssertFailedException() Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().Throw() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: 5 maxValue: 10 @@ -77,7 +77,7 @@ public void IsInRange_WithValueAboveRange_ThrowsAssertFailedException() Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().Throw() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: 1 maxValue: 5 @@ -99,7 +99,7 @@ public void IsInRange_WithCustomMessage_IncludesCustomMessage() // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(*) failed. Custom error message + Assert.IsInRange(value) failed. Custom error message Value is not within the expected range. minValue: 1 maxValue: 5 @@ -119,7 +119,13 @@ public void IsInRange_WithDoubleValues_WorksCorrectly() Assert.IsInRange(minValue, maxValue, valueInRange); Action action = () => Assert.IsInRange(minValue, maxValue, valueOutOfRange); action.Should().Throw() - .WithMessage("Assert.IsInRange(*) failed.*Value is not within the expected range*"); + .WithMessage(""" + Assert.IsInRange(valueOutOfRange) failed. + Value is not within the expected range. + minValue: 1.5 + maxValue: 5.5 + value: 6 + """); } public void IsInRange_WithDateTimeValues_WorksCorrectly() @@ -136,7 +142,7 @@ public void IsInRange_WithDateTimeValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .WithMessage("Assert.IsInRange(*) failed.*Value is not within the expected range*"); + .WithMessage("Assert.IsInRange(valueOutOfRange) failed.*Value is not within the expected range*"); } public void IsInRange_WithCharValues_WorksCorrectly() @@ -153,7 +159,7 @@ public void IsInRange_WithCharValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .WithMessage("Assert.IsInRange(*) failed.*Value is not within the expected range*"); + .WithMessage("Assert.IsInRange(valueOutOfRange) failed.*Value is not within the expected range*"); } public void IsInRange_WithNullMessage_DoesNotThrow() @@ -213,7 +219,7 @@ public void IsInRange_WithAllNegativeValuesBelowRange_ThrowsAssertFailedExceptio // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: -10 maxValue: -5 @@ -234,7 +240,7 @@ public void IsInRange_WithAllNegativeValuesAboveRange_ThrowsAssertFailedExceptio // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: -10 maxValue: -5 @@ -288,7 +294,7 @@ public void IsInRange_WithRangeSpanningNegativeToPositive_ValueBelowRange_Throws // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: -5 maxValue: 5 @@ -309,7 +315,7 @@ public void IsInRange_WithRangeSpanningNegativeToPositive_ValueAboveRange_Throws // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: -5 maxValue: 5 @@ -340,7 +346,7 @@ public void IsInRange_WithMaxValueLessThanMinValue_ThrowsArgumentOutOfRangeExcep // Assert action.Should().ThrowExactly() - .WithMessage("The maximum value must be greater than or equal to the minimum value*"); + .WithMessage("The maximum value must be greater than or equal to the minimum value. (Parameter 'maxValue')"); } public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldPassIfValueIsEqual() @@ -364,7 +370,7 @@ public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsSmaller Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: 5 maxValue: 5 @@ -382,7 +388,7 @@ public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsLarger( Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: 5 maxValue: 5 @@ -411,7 +417,7 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsSmall Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: 5 maxValue: 5 @@ -429,7 +435,7 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsLarge Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: 5 maxValue: 5 @@ -448,7 +454,7 @@ public void IsInRange_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsInRange(1, 10, aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Value is not within the expected range. minValue: 1 maxValue: 10 @@ -465,7 +471,7 @@ public void IsInRange_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsInRange(min, max, value); action.Should().Throw() .WithMessage($""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: {new string('R', 256)}... 44 more maxValue: {new string('R', 256)}... 44 more @@ -482,7 +488,7 @@ public void IsInRange_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsInRange(min, max, value); action.Should().Throw() .WithMessage(""" - Assert.IsInRange(*) failed. + Assert.IsInRange(value) failed. Value is not within the expected range. minValue: line1\r\nline2 maxValue: line1\r\nline2 diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 96268b8c51..0dda1f3dc0 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -13,7 +13,7 @@ public void InstanceOfTypeShouldFailWhenValueIsNull() Action action = () => Assert.IsInstanceOfType(null, typeof(AssertTests)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. + Assert.IsInstanceOfType(null) failed. value: (null) """); } @@ -23,7 +23,7 @@ public void InstanceOfTypeShouldFailWhenTypeIsNull() Action action = () => Assert.IsInstanceOfType(5, null); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. + Assert.IsInstanceOfType(5) failed. value: 5 """); } @@ -33,7 +33,7 @@ public void InstanceOfTypeShouldFailWhenTypeIsMismatched() Action action = () => Assert.IsInstanceOfType(5, typeof(string)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. + Assert.IsInstanceOfType(5) failed. Expected value to be of the specified type. value: 5 expectedType: System.String @@ -50,7 +50,7 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() Action action = () => Assert.IsInstanceOfType(null, typeof(AssertTests), "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. User-provided message + Assert.IsInstanceOfType(null) failed. User-provided message value: (null) """); } @@ -60,7 +60,7 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() Action action = () => Assert.IsInstanceOfType(5, null, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. User-provided message + Assert.IsInstanceOfType(5) failed. User-provided message value: 5 """); } @@ -70,7 +70,7 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() Action action = () => Assert.IsInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. User-provided message + Assert.IsInstanceOfType(5) failed. User-provided message Expected value to be of the specified type. value: 5 expectedType: System.String @@ -88,7 +88,7 @@ public async Task InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNul Func action = async () => Assert.IsInstanceOfType(null, typeof(AssertTests), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsInstanceOfType(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsInstanceOfType(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* value: (null) """); o.WasToStringCalled.Should().BeTrue(); @@ -100,7 +100,7 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull() Action action = () => Assert.IsInstanceOfType(5, null, $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. User-provided message DummyClassTrackingToStringCalls + Assert.IsInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls value: 5 """); o.WasToStringCalled.Should().BeTrue(); @@ -112,7 +112,7 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMismatched Action action = () => Assert.IsInstanceOfType(5, typeof(string), $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. User-provided message DummyClassTrackingToStringCalls + Assert.IsInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls Expected value to be of the specified type. value: 5 expectedType: System.String @@ -145,7 +145,7 @@ public void IsInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() Action action = () => Assert.IsInstanceOfType(null); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. + Assert.IsInstanceOfType(null) failed. value: (null) """); } @@ -155,7 +155,7 @@ public void IsInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() Action action = () => Assert.IsInstanceOfType(5); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. + Assert.IsInstanceOfType(5) failed. Expected value to be of the specified type. value: 5 expectedType: System.String @@ -284,7 +284,7 @@ public void IsInstanceOfType_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. + Assert.IsInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected value to be of the specified type. value: "hello" expectedType: System.Int32 @@ -299,11 +299,11 @@ public void IsInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage($""" - Assert.IsInstanceOfType(*) failed. + Assert.IsInstanceOfType(obj) failed. Expected value to be of the specified type. value: {new string('L', 256)}... 44 more expectedType: System.Int32 - actualType: *ObjectWithLongToString + actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString """); } @@ -314,11 +314,11 @@ public void IsInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(*) failed. + Assert.IsInstanceOfType(obj) failed. Expected value to be of the specified type. value: line1\r\nline2\nline3 expectedType: System.Int32 - actualType: *ObjectWithNewlineToString + actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString """); } @@ -329,7 +329,7 @@ public void IsNotInstanceOfType_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsNotInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(string)); action.Should().Throw() .WithMessage(""" - Assert.IsNotInstanceOfType(*) failed. + Assert.IsNotInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Value should not be of the specified type. value: "hello" wrongType: System.String @@ -344,11 +344,11 @@ public void IsNotInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsNotInstanceOfType(obj, typeof(ObjectWithLongToString)); action.Should().Throw() .WithMessage($""" - Assert.IsNotInstanceOfType(*) failed. + Assert.IsNotInstanceOfType(obj) failed. Value should not be of the specified type. value: {new string('L', 256)}... 44 more - wrongType: *ObjectWithLongToString - actualType: *ObjectWithLongToString + wrongType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString + actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString """); } @@ -359,11 +359,11 @@ public void IsNotInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsNotInstanceOfType(obj, typeof(ObjectWithNewlineToString)); action.Should().Throw() .WithMessage(""" - Assert.IsNotInstanceOfType(*) failed. + Assert.IsNotInstanceOfType(obj) failed. Value should not be of the specified type. value: line1\r\nline2\nline3 - wrongType: *ObjectWithNewlineToString - actualType: *ObjectWithNewlineToString + wrongType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString + actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index a1a82be26c..93e8d4509c 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -17,7 +17,7 @@ public void IsNull_PassNonNull_ShouldFail() Action action = () => Assert.IsNull(new object()); action.Should().Throw() .WithMessage(""" - Assert.IsNull(*) failed. + Assert.IsNull(new object()) failed. Expected value to be null. value: """); @@ -31,7 +31,7 @@ public void IsNull_StringMessage_PassNonNull_ShouldFail() Action action = () => Assert.IsNull(new object(), "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsNull(*) failed. User-provided message + Assert.IsNull(new object()) failed. User-provided message Expected value to be null. value: """); @@ -51,7 +51,7 @@ public async Task IsNull_InterpolatedString_PassNonNull_ShouldFail() Func action = async () => Assert.IsNull(new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNull(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsNull(new object()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected value to be null. value: """); @@ -86,7 +86,7 @@ public void IsNotNull_PassNull_ShouldFail() Action action = () => Assert.IsNotNull(null); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull(*) failed. + Assert.IsNotNull(null) failed. Expected a non-null value. value: (null) """); @@ -97,7 +97,7 @@ public void IsNotNull_StringMessage_PassNonNull_ShouldFail() Action action = () => Assert.IsNotNull(null, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull(*) failed. User-provided message + Assert.IsNotNull(null) failed. User-provided message Expected a non-null value. value: (null) """); @@ -110,7 +110,7 @@ public async Task IsNotNull_InterpolatedString_PassNonNull_ShouldFail() Func action = async () => Assert.IsNotNull(null, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNotNull(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsNotNull(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a non-null value. value: (null) """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs index 0455d71a73..980974a46a 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs @@ -13,7 +13,7 @@ public void IsFalseNullableBooleanShouldFailWithNull() Action action = () => Assert.IsFalse(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(*) failed. + Assert.IsFalse(nullBool) failed. Expected condition to be false. condition: (null) """); @@ -25,7 +25,7 @@ public void IsFalseNullableBooleanShouldFailWithTrue() Action action = () => Assert.IsFalse(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(*) failed. + Assert.IsFalse(nullBool) failed. Expected condition to be false. condition: True """); @@ -42,7 +42,7 @@ public void IsFalseBooleanShouldFailWithTrue() Action action = () => Assert.IsFalse(true); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(*) failed. + Assert.IsFalse(true) failed. Expected condition to be false. condition: True """); @@ -57,7 +57,7 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithNull() Action action = () => Assert.IsFalse(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(*) failed. User-provided message + Assert.IsFalse(nullBool) failed. User-provided message Expected condition to be false. condition: (null) """); @@ -69,7 +69,7 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithTrue() Action action = () => Assert.IsFalse(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(*) failed. User-provided message + Assert.IsFalse(nullBool) failed. User-provided message Expected condition to be false. condition: True """); @@ -86,7 +86,7 @@ public void IsFalseBooleanStringMessageShouldFailWithTrue() Action action = () => Assert.IsFalse(true, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(*) failed. User-provided message + Assert.IsFalse(true) failed. User-provided message Expected condition to be false. condition: True """); @@ -103,7 +103,7 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithN Func action = async () => Assert.IsFalse(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsFalse(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsFalse(nullBool) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be false. condition: (null) """); @@ -117,7 +117,7 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithT Func action = async () => Assert.IsFalse(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsFalse(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsFalse(nullBool) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be false. condition: True """); @@ -136,7 +136,7 @@ public async Task IsFalseBooleanInterpolatedStringMessageShouldFailWithTrue() Func action = async () => Assert.IsFalse(true, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsFalse(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsFalse(true) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be false. condition: True """); @@ -151,7 +151,7 @@ public void IsTrueNullableBooleanShouldFailWithNull() Action action = () => Assert.IsTrue(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(*) failed. + Assert.IsTrue(nullBool) failed. Expected condition to be true. condition: (null) """); @@ -163,7 +163,7 @@ public void IsTrueNullableBooleanShouldFailWithFalse() Action action = () => Assert.IsTrue(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(*) failed. + Assert.IsTrue(nullBool) failed. Expected condition to be true. condition: False """); @@ -180,7 +180,7 @@ public void IsTrueBooleanShouldFailWithFalse() Action action = () => Assert.IsTrue(false); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(*) failed. + Assert.IsTrue(false) failed. Expected condition to be true. condition: False """); @@ -195,7 +195,7 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithNull() Action action = () => Assert.IsTrue(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(*) failed. User-provided message + Assert.IsTrue(nullBool) failed. User-provided message Expected condition to be true. condition: (null) """); @@ -207,7 +207,7 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithFalse() Action action = () => Assert.IsTrue(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(*) failed. User-provided message + Assert.IsTrue(nullBool) failed. User-provided message Expected condition to be true. condition: False """); @@ -224,7 +224,7 @@ public void IsTrueBooleanStringMessageShouldFailWithFalse() Action action = () => Assert.IsTrue(false, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(*) failed. User-provided message + Assert.IsTrue(false) failed. User-provided message Expected condition to be true. condition: False """); @@ -241,7 +241,7 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithNu Func action = async () => Assert.IsTrue(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsTrue(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsTrue(nullBool) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be true. condition: (null) """); @@ -255,7 +255,7 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithFa Func action = async () => Assert.IsTrue(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsTrue(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsTrue(nullBool) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be true. condition: False """); @@ -274,7 +274,7 @@ public async Task IsTrueBooleanInterpolatedStringMessageShouldFailWithFalse() Func action = async () => Assert.IsTrue(false, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsTrue(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsTrue(false) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be true. condition: False """); @@ -292,7 +292,7 @@ public void IsTrue_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsTrue(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(*) failed. + Assert.IsTrue(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected condition to be true. condition: False """); @@ -305,7 +305,7 @@ public void IsFalse_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsFalse(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(*) failed. + Assert.IsFalse(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected condition to be false. condition: True """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs index 5723e4b2b2..c81a7375a9 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -26,7 +26,7 @@ public void Count_WhenCountIsNotSame_ShouldFail() Action action = () => Assert.HasCount(3, collection); action.Should().Throw() .WithMessage(""" - Assert.HasCount(*) failed. + Assert.HasCount(collection) failed. Expected collection to have the specified number of items. collection: [1] (1 item) expectedCount: 3 @@ -41,7 +41,7 @@ public async Task Count_InterpolatedString_WhenCountIsNotSame_ShouldFail() Func action = async () => Assert.HasCount(1, Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.HasCount(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.HasCount(Array.Empty()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to have the specified number of items. collection: [] (0 items) expectedCount: 1 @@ -66,7 +66,7 @@ public void NotAny_WhenNotEmpty_ShouldFail() Action action = () => Assert.IsEmpty(collection); action.Should().Throw() .WithMessage(""" - Assert.IsEmpty(*) failed. + Assert.IsEmpty(collection) failed. Expected collection to have the specified number of items. collection: [1] (1 item) expectedCount: 0 @@ -82,7 +82,7 @@ public async Task NotAny_InterpolatedString_WhenNotEmpty_ShouldFail() Func action = async () => Assert.IsEmpty(collection, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsEmpty(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsEmpty(collection) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to have the specified number of items. collection: [1] (1 item) expectedCount: 0 @@ -111,7 +111,7 @@ public void Single_WhenNoItems_ShouldFail() Action action = () => Assert.ContainsSingle(Array.Empty()); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. + Assert.ContainsSingle(Array.Empty()) failed. Expected collection to contain exactly one item but found 0 item(s). """); } @@ -121,7 +121,7 @@ public void Single_WhenMultipleItems_ShouldFail() Action action = () => Assert.ContainsSingle([1, 2, 3]); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. + Assert.ContainsSingle([1, 2, 3]) failed. Expected collection to contain exactly one item but found 3 item(s). """); } @@ -133,7 +133,7 @@ public async Task Single_InterpolatedString_WhenNoItem_ShouldFail() Func action = async () => Assert.ContainsSingle(Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.ContainsSingle(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.ContainsSingle(Array.Empty()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to contain exactly one item but found 0 item(s). """); o.WasToStringCalled.Should().BeTrue(); @@ -146,7 +146,7 @@ public async Task Single_InterpolatedString_WhenMultipleItems_ShouldFail() Func action = async () => Assert.ContainsSingle([1, 2, 3], $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.ContainsSingle(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.ContainsSingle([1, 2, 3]) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to contain exactly one item but found 3 item(s). """); o.WasToStringCalled.Should().BeTrue(); @@ -174,7 +174,7 @@ public void SinglePredicate_WhenNoItemMatches_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. + Assert.ContainsSingle(x => x % 2 == 0, collection) failed. Expected exactly one item to match the predicate but found 0 item(s). """); } @@ -185,7 +185,7 @@ public void SinglePredicate_WhenMultipleItemsMatch_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. + Assert.ContainsSingle(x => x % 2 == 0, collection) failed. Expected exactly one item to match the predicate but found 3 item(s). """); } @@ -196,7 +196,7 @@ public void SinglePredicate_Message_WhenNoItemMatches_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection, "No even numbers found: test"); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. No even numbers found: test + Assert.ContainsSingle(x => x % 2 == 0, collection) failed. No even numbers found: test Expected exactly one item to match the predicate but found 0 item(s). """); } @@ -207,7 +207,7 @@ public void SinglePredicate_Message_WhenMultipleItemsMatch_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection, "Too many even numbers: test"); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(*) failed. Too many even numbers: test + Assert.ContainsSingle(x => x % 2 == 0, collection) failed. Too many even numbers: test Expected exactly one item to match the predicate but found 3 item(s). """); } @@ -243,7 +243,7 @@ public void Any_WhenNoItem_ShouldFail() Action action = () => Assert.IsNotEmpty(Array.Empty()); action.Should().Throw() .WithMessage(""" - Assert.IsNotEmpty(*) failed. + Assert.IsNotEmpty(Array.Empty()) failed. Expected collection to contain any item but it is empty. """); } @@ -255,7 +255,7 @@ public async Task Any_InterpolatedString_WhenNoItem_ShouldFail() Func action = async () => Assert.IsNotEmpty(Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNotEmpty(*) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsNotEmpty(Array.Empty()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to contain any item but it is empty. """); o.WasToStringCalled.Should().BeTrue(); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs index 325a17bb3b..209e3d5c45 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs @@ -17,7 +17,7 @@ public void MatchesRegex_WhenValueDoesNotMatchPattern_ShouldFail() Action action = () => Assert.MatchesRegex(@"\d+", "abc"); action.Should().Throw() .WithMessage(""" - Assert.MatchesRegex(*) failed. + Assert.MatchesRegex(@"\d+", "abc") failed. String does not match expected pattern. pattern: \d+ value: "abc" @@ -32,7 +32,7 @@ public void DoesNotMatchRegex_WhenValueMatchesPattern_ShouldFail() Action action = () => Assert.DoesNotMatchRegex(@"\d+", "abc123"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotMatchRegex(*) failed. + Assert.DoesNotMatchRegex(@"\d+", "abc123") failed. String matches pattern but should not. pattern: \d+ value: "abc123" @@ -50,7 +50,7 @@ public void MatchesRegex_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.MatchesRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.MatchesRegex(*) failed. + Assert.MatchesRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. String does not match expected pattern. pattern: \d+ value: "hello" @@ -64,7 +64,7 @@ public void MatchesRegex_WithLongValue_ShouldTruncateValue() Action action = () => Assert.MatchesRegex(@"\d+", longValue); action.Should().Throw() .WithMessage($""" - Assert.MatchesRegex(*) failed. + Assert.MatchesRegex(@"\d+", longValue) failed. String does not match expected pattern. pattern: \d+ value: "{new string('x', 255)}... 46 more @@ -76,7 +76,7 @@ public void MatchesRegex_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.MatchesRegex(@"^\d+$", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.MatchesRegex(*) failed. + Assert.MatchesRegex(@"^\d+$", "hello\r\nworld") failed. String does not match expected pattern. pattern: ^\d+$ value: "hello\r\nworld" @@ -90,7 +90,7 @@ public void DoesNotMatchRegex_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotMatchRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotMatchRegex(*) failed. + Assert.DoesNotMatchRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. String matches pattern but should not. pattern: \d+ value: "abc123" @@ -104,7 +104,7 @@ public void DoesNotMatchRegex_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotMatchRegex(@"\d+", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotMatchRegex(*) failed. + Assert.DoesNotMatchRegex(@"\d+", longValue) failed. String matches pattern but should not. pattern: \d+ value: "{new string('1', 255)}... 46 more @@ -116,7 +116,7 @@ public void DoesNotMatchRegex_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotMatchRegex(@"hello", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotMatchRegex(*) failed. + Assert.DoesNotMatchRegex(@"hello", "hello\r\nworld") failed. String matches pattern but should not. pattern: hello value: "hello\r\nworld" diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs index 4d8d21399e..537d61df61 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs @@ -17,7 +17,7 @@ public void StartsWith_WhenValueDoesNotStartWithPrefix_ShouldFail() Action action = () => Assert.StartsWith("world", "hello"); action.Should().Throw() .WithMessage(""" - Assert.StartsWith(*) failed. + Assert.StartsWith("world", "hello") failed. String does not start with expected prefix. expectedPrefix: "world" value: "hello" @@ -29,7 +29,7 @@ public void StartsWith_WithMessage_WhenValueDoesNotStartWithPrefix_ShouldFail() Action action = () => Assert.StartsWith("world", "hello", "User message"); action.Should().Throw() .WithMessage(""" - Assert.StartsWith(*) failed. User message + Assert.StartsWith("world", "hello") failed. User message String does not start with expected prefix. expectedPrefix: "world" value: "hello" @@ -44,7 +44,7 @@ public void DoesNotStartWith_WhenValueStartsWithPrefix_ShouldFail() Action action = () => Assert.DoesNotStartWith("hello", "hello world"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotStartWith(*) failed. + Assert.DoesNotStartWith("hello", "hello world") failed. String starts with unexpected prefix. notExpectedPrefix: "hello" value: "hello world" @@ -62,7 +62,7 @@ public void StartsWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.StartsWith("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.StartsWith(*) failed. + Assert.StartsWith("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. String does not start with expected prefix. expectedPrefix: "world" value: "hello world" @@ -76,7 +76,7 @@ public void StartsWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.StartsWith("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.StartsWith(*) failed. + Assert.StartsWith("world", longValue) failed. String does not start with expected prefix. expectedPrefix: "world" value: "{new string('x', 255)}... 46 more @@ -88,7 +88,7 @@ public void StartsWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.StartsWith("world", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.StartsWith(*) failed. + Assert.StartsWith("world", "hello\r\nworld") failed. String does not start with expected prefix. expectedPrefix: "world" value: "hello\r\nworld" @@ -102,7 +102,7 @@ public void DoesNotStartWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotStartWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotStartWith(*) failed. + Assert.DoesNotStartWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. String starts with unexpected prefix. notExpectedPrefix: "hello" value: "hello world" @@ -116,7 +116,7 @@ public void DoesNotStartWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotStartWith("hello", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotStartWith(*) failed. + Assert.DoesNotStartWith("hello", longValue) failed. String starts with unexpected prefix. notExpectedPrefix: "hello" value: "hello{new string('x', 250)}... 51 more @@ -128,7 +128,7 @@ public void DoesNotStartWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotStartWith("hello", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotStartWith(*) failed. + Assert.DoesNotStartWith("hello", "hello\r\nworld") failed. String starts with unexpected prefix. notExpectedPrefix: "hello" value: "hello\r\nworld" From 2028446b1425140cb577d3bd35b38db17dc20fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 12:47:33 +0100 Subject: [PATCH 28/58] Remove redundant item count from fully-displayed collections --- src/TestFramework/TestFramework/Assertions/Assert.cs | 6 +----- .../Assertions/AssertTests.Contains.cs | 12 ++++++------ .../Assertions/AssertTests.Items.cs | 8 ++++---- .../Assertions/AssertTests.cs | 12 ++++++------ 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 7988a6a684..ddf43ced3d 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -381,11 +381,7 @@ private static string FormatCollectionPreview(IEnumerable collection, int maxLen elementList += $", ... {remainingText} more"; } - string countText = truncated - ? string.Empty - : $" ({totalCount} {(totalCount == 1 ? "item" : "items")})"; - - return $"[{elementList}]{countText}"; + return $"[{elementList}]"; } internal static string FormatParameterWithValue(string paramName, string expression, string formattedValue) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index 70871e5fd5..9ef32a3d48 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -1014,7 +1014,7 @@ public void DoesNotContain_InNonGenericCollection_ValueExpected_ItemPresent_Thro action.Should().Throw().WithMessage(""" Assert.DoesNotContain(10, collection) failed. Item 10 should not be found Expected collection to not contain the specified item. - collection: [5, 10, 15, "a"] (4 items) + collection: [5, 10, 15, "a"] """); } @@ -1790,7 +1790,7 @@ public void Contains_ItemNotFound_ShowsSpecificErrorMessage() .WithMessage(""" Assert.Contains(5, collection) failed. Expected collection to contain the specified item.* - collection: [1, 2, 3] (3 items) + collection: [1, 2, 3] """); } @@ -1810,7 +1810,7 @@ public void Contains_InNonGenericCollection_ItemNotFound_ShowsSpecificErrorMessa .WithMessage(""" Assert.Contains(5, collection) failed. Expected collection to contain the specified item.* - collection: [1, 2, 3] (3 items) + collection: [1, 2, 3] """); } @@ -1830,7 +1830,7 @@ public void Contains_PredicateNotMatched_ShowsSpecificErrorMessage() .WithMessage(""" Assert.Contains(x => x % 2 == 0, collection) failed. Expected at least one item to match the predicate.* - collection: [1, 3, 5] (3 items) + collection: [1, 3, 5] """); } @@ -1850,7 +1850,7 @@ public void DoesNotContain_ItemFound_ShowsSpecificErrorMessage() .WithMessage(""" Assert.DoesNotContain(2, collection) failed. Expected collection to not contain the specified item.* - collection: [1, 2, 3] (3 items) + collection: [1, 2, 3] """); } @@ -1870,7 +1870,7 @@ public void DoesNotContain_PredicateMatched_ShowsSpecificErrorMessage() .WithMessage(""" Assert.DoesNotContain(x => x % 2 == 0, collection) failed. Expected no items to match the predicate.* - collection: [1, 2, 3] (3 items) + collection: [1, 2, 3] """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs index c81a7375a9..dbcd8018f3 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs @@ -28,7 +28,7 @@ public void Count_WhenCountIsNotSame_ShouldFail() .WithMessage(""" Assert.HasCount(collection) failed. Expected collection to have the specified number of items. - collection: [1] (1 item) + collection: [1] expectedCount: 3 actualCount: 1 """); @@ -43,7 +43,7 @@ public async Task Count_InterpolatedString_WhenCountIsNotSame_ShouldFail() .WithMessage(""" Assert.HasCount(Array.Empty()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to have the specified number of items. - collection: [] (0 items) + collection: [] expectedCount: 1 actualCount: 0 """); @@ -68,7 +68,7 @@ public void NotAny_WhenNotEmpty_ShouldFail() .WithMessage(""" Assert.IsEmpty(collection) failed. Expected collection to have the specified number of items. - collection: [1] (1 item) + collection: [1] expectedCount: 0 actualCount: 1 """); @@ -84,7 +84,7 @@ public async Task NotAny_InterpolatedString_WhenNotEmpty_ShouldFail() .WithMessage(""" Assert.IsEmpty(collection) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to have the specified number of items. - collection: [1] (1 item) + collection: [1] expectedCount: 0 actualCount: 1 """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index e0c18c595e..8d99e84dda 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -171,7 +171,7 @@ public void FormatValue_WhenValueIsCollection_ShouldShowPreview() .WithMessage(""" Assert.IsNull(*) failed. Expected value to be null. - value: [1, 2, 3] (3 items) + value: [1, 2, 3] """); } @@ -207,7 +207,7 @@ public void FormatCollectionPreview_WhenElementToStringExceeds50_ShouldTruncateE .WithMessage($""" Assert.Contains(*) failed. Expected collection to contain the specified item. - collection*[{expectedFirstElement}, "short"] (2 items) + collection*[{expectedFirstElement}, "short"] """); } @@ -222,7 +222,7 @@ public void FormatCollectionPreview_WhenCollectionContainsNestedCollections_Shou .WithMessage(""" Assert.IsNull(*) failed. Expected value to be null. - value: [[1, 2] (2 items), [3, 4] (2 items)] (2 items) + value: [[1, 2], [3, 4]] """); } @@ -246,7 +246,7 @@ public void FormatCollectionPreview_WhenNestedCollectionIsLarge_ShouldTruncateIn .WithMessage(""" Assert.IsNull(*) failed. Expected value to be null. - value: [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 35 more]] (1 item) + value: [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 35 more]] """); } @@ -259,7 +259,7 @@ public void FormatCollectionPreview_WhenElementContainsNewlines_ShouldEscapeThem .WithMessage(""" Assert.Contains(*) failed. Expected collection to contain the specified item. - collection*["line1\nline2", "ok"] (2 items) + collection*["line1\nline2", "ok"] """); } @@ -272,7 +272,7 @@ public void FormatCollectionPreview_WhenSingleElement_ShouldShowSingularForm() .WithMessage(""" Assert.Contains(*) failed. Expected collection to contain the specified item. - collection: [42] (1 item) + collection: [42] """); } From 52d43b76b8addda0a5af2194796f4b59767bc98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 12:52:38 +0100 Subject: [PATCH 29/58] Display null instead of (null) for null values in assertions --- src/TestFramework/TestFramework/Assertions/Assert.cs | 6 +++--- .../Assertions/AssertTests.AreEqualTests.cs | 2 +- .../AssertTests.IsExactInstanceOfTypeTests.cs | 8 ++++---- .../Assertions/AssertTests.IsInstanceOfTypeTests.cs | 8 ++++---- .../Assertions/AssertTests.IsNull.cs | 6 +++--- .../Assertions/AssertTests.IsTrueTests.cs | 12 ++++++------ .../Assertions/AssertTests.cs | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index ddf43ced3d..26d0f009be 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -112,7 +112,7 @@ internal static string FormatValue(T? value, int maxLength = 256) { if (value is null) { - return "(null)"; + return "null"; } if (value is string s) @@ -192,8 +192,8 @@ private static bool IsExpressionRedundant(string expression, string formattedVal return true; } - // Null literal: expression "null" vs formattedValue "(null)" - if (expression is "null" && formattedValue is "(null)") + // Null literal: expression "null" vs formattedValue "null" + if (expression is "null" && formattedValue is "null") { return true; } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index db39b8f0f9..6f27af57b1 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -179,7 +179,7 @@ public void AreEqualShouldFailWhenNotEqualTypeWithMessage() .WithMessage(""" Assert.AreEqual(null, "string") failed. A Message Expected values to be equal. - expected: (null) + expected: null actual: "string" """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index 94676ed0cd..48224f6944 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -14,7 +14,7 @@ public void ExactInstanceOfTypeShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(null) failed. - value: (null) + value: null """); } @@ -82,7 +82,7 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(null) failed. User-provided message - value: (null) + value: null """); } @@ -120,7 +120,7 @@ public async Task ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenValue (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsExactInstanceOfType(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - value: (null) + value: null """); o.WasToStringCalled.Should().BeTrue(); } @@ -197,7 +197,7 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(null) failed. - value: (null) + value: null """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 0dda1f3dc0..9eb927e8dc 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -14,7 +14,7 @@ public void InstanceOfTypeShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(null) failed. - value: (null) + value: null """); } @@ -51,7 +51,7 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(null) failed. User-provided message - value: (null) + value: null """); } @@ -89,7 +89,7 @@ public async Task InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNul (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsInstanceOfType(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - value: (null) + value: null """); o.WasToStringCalled.Should().BeTrue(); } @@ -146,7 +146,7 @@ public void IsInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(null) failed. - value: (null) + value: null """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index 93e8d4509c..687b444fd6 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -88,7 +88,7 @@ public void IsNotNull_PassNull_ShouldFail() .WithMessage(""" Assert.IsNotNull(null) failed. Expected a non-null value. - value: (null) + value: null """); } @@ -99,7 +99,7 @@ public void IsNotNull_StringMessage_PassNonNull_ShouldFail() .WithMessage(""" Assert.IsNotNull(null) failed. User-provided message Expected a non-null value. - value: (null) + value: null """); } @@ -112,7 +112,7 @@ public async Task IsNotNull_InterpolatedString_PassNonNull_ShouldFail() .WithMessage(""" Assert.IsNotNull(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a non-null value. - value: (null) + value: null """); o.WasToStringCalled.Should().BeTrue(); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs index 980974a46a..3a623744c0 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs @@ -15,7 +15,7 @@ public void IsFalseNullableBooleanShouldFailWithNull() .WithMessage(""" Assert.IsFalse(nullBool) failed. Expected condition to be false. - condition: (null) + condition: null """); } @@ -59,7 +59,7 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithNull() .WithMessage(""" Assert.IsFalse(nullBool) failed. User-provided message Expected condition to be false. - condition: (null) + condition: null """); } @@ -105,7 +105,7 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithN .WithMessage(""" Assert.IsFalse(nullBool) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be false. - condition: (null) + condition: null """); } @@ -153,7 +153,7 @@ public void IsTrueNullableBooleanShouldFailWithNull() .WithMessage(""" Assert.IsTrue(nullBool) failed. Expected condition to be true. - condition: (null) + condition: null """); } @@ -197,7 +197,7 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithNull() .WithMessage(""" Assert.IsTrue(nullBool) failed. User-provided message Expected condition to be true. - condition: (null) + condition: null """); } @@ -243,7 +243,7 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithNu .WithMessage(""" Assert.IsTrue(nullBool) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be true. - condition: (null) + condition: null """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index 8d99e84dda..ff0a3fb711 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -124,7 +124,7 @@ public void TruncateExpression_WhenExpressionExceeds100Chars_ShouldShowEllipsis( .WithMessage(""" Assert.IsNotNull(*) failed. Expected a non-null value. - value: (null) + value: null """); } From 6222540920ec177a98f6b831900622492b34e664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 13:02:19 +0100 Subject: [PATCH 30/58] Use consistent angle bracket format for type display in assertions --- .../Assertions/Assert.AreEqual.cs | 4 +- .../Assert.IsExactInstanceOfType.cs | 8 +-- .../Assertions/Assert.IsInstanceOfType.cs | 8 +-- .../Assertions/Assert.ThrowsException.cs | 12 ++-- .../TestFramework/Assertions/Assert.cs | 5 ++ .../Assertions/AssertTests.AreEqualTests.cs | 6 +- .../AssertTests.IsExactInstanceOfTypeTests.cs | 64 +++++++++---------- .../AssertTests.IsInstanceOfTypeTests.cs | 40 ++++++------ .../AssertTests.ThrowsExceptionTests.cs | 32 +++++----- 9 files changed, 92 insertions(+), 87 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 0b08c2a036..2231f6f275 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -612,8 +612,8 @@ private static void ThrowAssertAreEqualFailed(object? expected, object? actual, { message += Environment.NewLine + FrameworkMessages.AreEqualFailNew; message += FormatAlignedParameters( - (nameof(expected), $"{FormatValue(expected)} ({expected.GetType().FullName})"), - (nameof(actual), $"{FormatValue(actual)} ({actual.GetType().FullName})")); + (nameof(expected), $"{FormatValue(expected)} ({FormatType(expected.GetType())})"), + (nameof(actual), $"{FormatValue(actual)} ({FormatType(actual.GetType())})")); } else if (expected is string expectedString && actual is string actualString) { diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs index 904d24f39b..5a2d344902 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs @@ -332,8 +332,8 @@ private static void ThrowAssertIsExactInstanceOfTypeFailed(object? value, Type? message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (expectedType is not null && value is not null) { - message += Environment.NewLine + $" expectedType: {expectedType}" - + Environment.NewLine + $" actualType: {value.GetType()}"; + message += Environment.NewLine + $" expectedType: {FormatType(expectedType)}" + + Environment.NewLine + $" actualType: {FormatType(value.GetType())}"; } ThrowAssertFailed(callSite, message); @@ -411,8 +411,8 @@ private static void ThrowAssertIsNotExactInstanceOfTypeFailed(object? value, Typ message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (wrongType is not null) { - message += Environment.NewLine + $" wrongType: {wrongType}" - + Environment.NewLine + $" actualType: {value!.GetType()}"; + message += Environment.NewLine + $" wrongType: {FormatType(wrongType)}" + + Environment.NewLine + $" actualType: {FormatType(value!.GetType())}"; } ThrowAssertFailed(callSite, message); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index d8bd8117bd..6626f2dda2 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -339,8 +339,8 @@ private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expec message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (expectedType is not null && value is not null) { - message += Environment.NewLine + $" expectedType: {expectedType}" - + Environment.NewLine + $" actualType: {value.GetType()}"; + message += Environment.NewLine + $" expectedType: {FormatType(expectedType)}" + + Environment.NewLine + $" actualType: {FormatType(value.GetType())}"; } ThrowAssertFailed(callSite, message); @@ -420,8 +420,8 @@ private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wr message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (wrongType is not null) { - message += Environment.NewLine + $" wrongType: {wrongType}" - + Environment.NewLine + $" actualType: {value!.GetType()}"; + message += Environment.NewLine + $" wrongType: {FormatType(wrongType)}" + + Environment.NewLine + $" actualType: {FormatType(value!.GetType())}"; } ThrowAssertFailed(callSite, message); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index 108330d4df..482f274ebd 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -533,8 +533,8 @@ private static async Task IsThrowsAsyncFailingAsync IsThrowsAsyncFailingAsync(Action action, b string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; msg += Environment.NewLine + FrameworkMessages.WrongExceptionThrownNew; msg += FormatExpressionParameter(nameof(action), actionExpr); - msg += Environment.NewLine + $" expectedExceptionType: {typeof(TException)}"; - msg += Environment.NewLine + $" actualExceptionType: {ex.GetType()}"; + msg += Environment.NewLine + $" expectedExceptionType: {FormatType(typeof(TException))}"; + msg += Environment.NewLine + $" actualExceptionType: {FormatType(ex.GetType())}"; ThrowAssertFailed("Assert." + assertMethodName, msg); }, ex); } @@ -583,7 +583,7 @@ private static ThrowsExceptionState IsThrowsFailing(Action action, b string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; msg += Environment.NewLine + FrameworkMessages.NoExceptionThrownNew; msg += FormatExpressionParameter(nameof(action), actionExpr); - msg += Environment.NewLine + $" expectedExceptionType: {typeof(TException)}"; + msg += Environment.NewLine + $" expectedExceptionType: {FormatType(typeof(TException))}"; ThrowAssertFailed("Assert." + assertMethodName, msg); }, null); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 26d0f009be..ae68de4a27 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -152,6 +152,11 @@ internal static string FormatValue(T? value, int maxLength = 256) } // No useful ToString - just return the type name + return FormatType(type); + } + + internal static string FormatType(Type type) + { string typeName = type.FullName ?? type.Name; return $"<{typeName}>"; } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index 6f27af57b1..cee1d18c8f 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -374,8 +374,8 @@ public void AreEqualTwoObjectsDifferentTypeShouldFail() .WithMessage(""" Assert.AreEqual(new object(), 1) failed. Expected values to be equal. - expected: (System.Object) - actual: 1 (System.Int32) + expected: () + actual: 1 () """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index 48224f6944..4faff3036d 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -36,8 +36,8 @@ public void ExactInstanceOfTypeShouldFailWhenTypeIsMismatched() Assert.IsExactInstanceOfType(5) failed. Expected value to be exactly of the specified type. value: 5 - expectedType: System.String - actualType: System.Int32 + expectedType: + actualType: """); } @@ -51,8 +51,8 @@ public void ExactInstanceOfTypeShouldFailOnHigherInstance() Assert.IsExactInstanceOfType(5) failed. Expected value to be exactly of the specified type. value: 5 - expectedType: System.Object - actualType: System.Int32 + expectedType: + actualType: """); } @@ -65,8 +65,8 @@ public void ExactInstanceOfTypeShouldFailOnDerivedType() Assert.IsExactInstanceOfType(x) failed. Expected value to be exactly of the specified type. value: - expectedType: System.IO.Stream - actualType: System.IO.MemoryStream + expectedType: + actualType: """); } @@ -104,8 +104,8 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched Assert.IsExactInstanceOfType(5) failed. User-provided message Expected value to be exactly of the specified type. value: 5 - expectedType: System.String - actualType: System.Int32 + expectedType: + actualType: """); } @@ -146,8 +146,8 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMisma Assert.IsExactInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls Expected value to be exactly of the specified type. value: 5 - expectedType: System.String - actualType: System.Int32 + expectedType: + actualType: """); o.WasToStringCalled.Should().BeTrue(); } @@ -186,8 +186,8 @@ public void ExactInstanceNotOfTypeShouldFailOnExactType() Assert.IsNotExactInstanceOfType(x) failed. Value should not be exactly of the specified type. value: - wrongType: System.IO.MemoryStream - actualType: System.IO.MemoryStream + wrongType: + actualType: """); } @@ -209,8 +209,8 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() Assert.IsExactInstanceOfType(5) failed. Expected value to be exactly of the specified type. value: 5 - expectedType: System.String - actualType: System.Int32 + expectedType: + actualType: """); } @@ -223,8 +223,8 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenDerivedType_Fails() Assert.IsExactInstanceOfType(x) failed. Expected value to be exactly of the specified type. value: - expectedType: System.IO.Stream - actualType: System.IO.MemoryStream + expectedType: + actualType: """); } @@ -251,8 +251,8 @@ public void IsExactInstanceOfTypeUsingGenericType_OnHigherInstance_Fails() Assert.IsExactInstanceOfType(5) failed. Expected value to be exactly of the specified type. value: 5 - expectedType: System.Object - actualType: System.Int32 + expectedType: + actualType: """); } @@ -284,8 +284,8 @@ public void IsNotExactInstanceOfTypeUsingGenericType_OnExactType_Fails() Assert.IsNotExactInstanceOfType(x) failed. Value should not be exactly of the specified type. value: - wrongType: System.IO.MemoryStream - actualType: System.IO.MemoryStream + wrongType: + actualType: """); } @@ -371,8 +371,8 @@ public void IsExactInstanceOfType_WithLongExpression_ShouldTruncateExpression() Assert.IsExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected value to be exactly of the specified type. value: "hello" - expectedType: System.Int32 - actualType: System.String + expectedType: + actualType: """); } @@ -386,8 +386,8 @@ public void IsExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Assert.IsExactInstanceOfType(obj) failed. Expected value to be exactly of the specified type. value: {new string('L', 256)}... 44 more - expectedType: System.Int32 - actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString + expectedType: + actualType: """); } @@ -401,8 +401,8 @@ public void IsExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Assert.IsExactInstanceOfType(obj) failed. Expected value to be exactly of the specified type. value: line1\r\nline2\nline3 - expectedType: System.Int32 - actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString + expectedType: + actualType: """); } @@ -416,8 +416,8 @@ public void IsNotExactInstanceOfType_WithLongExpression_ShouldTruncateExpression Assert.IsNotExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Value should not be exactly of the specified type. value: "hello" - wrongType: System.String - actualType: System.String + wrongType: + actualType: """); } @@ -431,8 +431,8 @@ public void IsNotExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Assert.IsNotExactInstanceOfType(obj) failed. Value should not be exactly of the specified type. value: {new string('L', 256)}... 44 more - wrongType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString - actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString + wrongType: + actualType: """); } @@ -446,8 +446,8 @@ public void IsNotExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines( Assert.IsNotExactInstanceOfType(obj) failed. Value should not be exactly of the specified type. value: line1\r\nline2\nline3 - wrongType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString - actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString + wrongType: + actualType: """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 9eb927e8dc..fb4cb96077 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -36,8 +36,8 @@ public void InstanceOfTypeShouldFailWhenTypeIsMismatched() Assert.IsInstanceOfType(5) failed. Expected value to be of the specified type. value: 5 - expectedType: System.String - actualType: System.Int32 + expectedType: + actualType: """); } @@ -73,8 +73,8 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() Assert.IsInstanceOfType(5) failed. User-provided message Expected value to be of the specified type. value: 5 - expectedType: System.String - actualType: System.Int32 + expectedType: + actualType: """); } @@ -115,8 +115,8 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMismatched Assert.IsInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls Expected value to be of the specified type. value: 5 - expectedType: System.String - actualType: System.Int32 + expectedType: + actualType: """); o.WasToStringCalled.Should().BeTrue(); } @@ -158,8 +158,8 @@ public void IsInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() Assert.IsInstanceOfType(5) failed. Expected value to be of the specified type. value: 5 - expectedType: System.String - actualType: System.Int32 + expectedType: + actualType: """); } @@ -287,8 +287,8 @@ public void IsInstanceOfType_WithLongExpression_ShouldTruncateExpression() Assert.IsInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected value to be of the specified type. value: "hello" - expectedType: System.Int32 - actualType: System.String + expectedType: + actualType: """); } @@ -302,8 +302,8 @@ public void IsInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Assert.IsInstanceOfType(obj) failed. Expected value to be of the specified type. value: {new string('L', 256)}... 44 more - expectedType: System.Int32 - actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString + expectedType: + actualType: """); } @@ -317,8 +317,8 @@ public void IsInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Assert.IsInstanceOfType(obj) failed. Expected value to be of the specified type. value: line1\r\nline2\nline3 - expectedType: System.Int32 - actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString + expectedType: + actualType: """); } @@ -332,8 +332,8 @@ public void IsNotInstanceOfType_WithLongExpression_ShouldTruncateExpression() Assert.IsNotInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Value should not be of the specified type. value: "hello" - wrongType: System.String - actualType: System.String + wrongType: + actualType: """); } @@ -347,8 +347,8 @@ public void IsNotInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Assert.IsNotInstanceOfType(obj) failed. Value should not be of the specified type. value: {new string('L', 256)}... 44 more - wrongType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString - actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithLongToString + wrongType: + actualType: """); } @@ -362,8 +362,8 @@ public void IsNotInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Assert.IsNotInstanceOfType(obj) failed. Value should not be of the specified type. value: line1\r\nline2\nline3 - wrongType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString - actualType: Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests.ObjectWithNewlineToString + wrongType: + actualType: """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs index 9790e5c3ca..615f92712e 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs @@ -74,8 +74,8 @@ public void ThrowsAsync_WhenExceptionIsNotExpectedType_ShouldThrow() Assert.ThrowsAsync failed. Wrong exception type was thrown. action: () => throw new Exception() - expectedExceptionType: System.ArgumentException - actualExceptionType: System.Exception + expectedExceptionType: + actualExceptionType: """); } @@ -89,8 +89,8 @@ public void ThrowsExactlyAsync_WhenExceptionIsDerivedFromExpectedType_ShouldThro Assert.ThrowsExactlyAsync failed. Wrong exception type was thrown. action: () => throw new ArgumentNullException() - expectedExceptionType: System.ArgumentException - actualExceptionType: System.ArgumentNullException + expectedExceptionType: + actualExceptionType: """); } @@ -121,7 +121,7 @@ public void Throws_WithMessageBuilder_FailsBecauseNoException() Assert.Throws failed. message constructed via builder. No exception was thrown. action: () => { } - expectedExceptionType: System.ArgumentNullException + expectedExceptionType: """); wasBuilderCalled.Should().BeTrue(); @@ -143,8 +143,8 @@ public void Throws_WithMessageBuilder_FailsBecauseTypeMismatch() Assert.Throws failed. message constructed via builder. Wrong exception type was thrown. action: () => throw new ArgumentOutOfRangeException("MyParamNameHere") - expectedExceptionType: System.ArgumentNullException - actualExceptionType: System.ArgumentOutOfRangeException + expectedExceptionType: + actualExceptionType: """); wasBuilderCalled.Should().BeTrue(); @@ -179,7 +179,7 @@ public void ThrowsExactly_WithMessageBuilder_FailsBecauseNoException() Assert.ThrowsExactly failed. message constructed via builder. No exception was thrown. action: () => { } - expectedExceptionType: System.ArgumentNullException + expectedExceptionType: """); wasBuilderCalled.Should().BeTrue(); @@ -201,8 +201,8 @@ public void ThrowsExactly_WithMessageBuilder_FailsBecauseTypeMismatch() Assert.ThrowsExactly failed. message constructed via builder. Wrong exception type was thrown. action: () => throw new ArgumentOutOfRangeException("MyParamNameHere") - expectedExceptionType: System.ArgumentNullException - actualExceptionType: System.ArgumentOutOfRangeException + expectedExceptionType: + actualExceptionType: """); wasBuilderCalled.Should().BeTrue(); @@ -237,7 +237,7 @@ public async Task ThrowsAsync_WithMessageBuilder_FailsBecauseNoException() Assert.ThrowsAsync failed. message constructed via builder. No exception was thrown. action: () => Task.CompletedTask - expectedExceptionType: System.ArgumentNullException + expectedExceptionType: """); wasBuilderCalled.Should().BeTrue(); @@ -259,8 +259,8 @@ public async Task ThrowsAsync_WithMessageBuilder_FailsBecauseTypeMismatch() Assert.ThrowsAsync failed. message constructed via builder. Wrong exception type was thrown. action: () => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere")) - expectedExceptionType: System.ArgumentNullException - actualExceptionType: System.ArgumentOutOfRangeException + expectedExceptionType: + actualExceptionType: """); wasBuilderCalled.Should().BeTrue(); @@ -295,7 +295,7 @@ public async Task ThrowsExactlyAsync_WithMessageBuilder_FailsBecauseNoException( Assert.ThrowsExactlyAsync failed. message constructed via builder. No exception was thrown. action: () => Task.CompletedTask - expectedExceptionType: System.ArgumentNullException + expectedExceptionType: """); wasBuilderCalled.Should().BeTrue(); @@ -317,8 +317,8 @@ public async Task ThrowsExactlyAsync_WithMessageBuilder_FailsBecauseTypeMismatch Assert.ThrowsExactlyAsync failed. message constructed via builder. Wrong exception type was thrown. action: () => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere")) - expectedExceptionType: System.ArgumentNullException - actualExceptionType: System.ArgumentOutOfRangeException + expectedExceptionType: + actualExceptionType: """); wasBuilderCalled.Should().BeTrue(); From 6b1cf89cc18568b8a854ac66687a12296ff80ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 13:58:37 +0100 Subject: [PATCH 31/58] Remove angle brackets around delta values in equality assertion messages --- .../Resources/FrameworkMessages.resx | 4 +- .../Resources/xlf/FrameworkMessages.cs.xlf | 8 ++-- .../Resources/xlf/FrameworkMessages.de.xlf | 8 ++-- .../Resources/xlf/FrameworkMessages.es.xlf | 8 ++-- .../Resources/xlf/FrameworkMessages.fr.xlf | 8 ++-- .../Resources/xlf/FrameworkMessages.it.xlf | 8 ++-- .../Resources/xlf/FrameworkMessages.ja.xlf | 8 ++-- .../Resources/xlf/FrameworkMessages.ko.xlf | 8 ++-- .../Resources/xlf/FrameworkMessages.pl.xlf | 8 ++-- .../Resources/xlf/FrameworkMessages.pt-BR.xlf | 8 ++-- .../Resources/xlf/FrameworkMessages.ru.xlf | 8 ++-- .../Resources/xlf/FrameworkMessages.tr.xlf | 8 ++-- .../xlf/FrameworkMessages.zh-Hans.xlf | 8 ++-- .../xlf/FrameworkMessages.zh-Hant.xlf | 8 ++-- .../Assertions/AssertTests.AreEqualTests.cs | 46 +++++++++---------- 15 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index 021e98fcef..bd7318bbc9 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -286,10 +286,10 @@ Actual: {2} The maximum value must be greater than or equal to the minimum value. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. Case differs. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index 3a55011531..a229fece41 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index 9140235903..ab3f60c972 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index 6416d88204..3763d9fb75 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index dd1f2d262e..03a0d4f808 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index 68900310c3..7e12682ae4 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index d88c519410..138c1af1bc 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index a1df05f673..ae11d31c37 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index 510bf94e6a..85a600b21e 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index 08f42d5be8..f625c93b62 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index 4a565ec9cb..742f1cfb95 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index 46ad51880f..c22762c18b 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index ec618b8862..0f22457021 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index 328ecf7d3a..743d50c404 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -23,8 +23,8 @@ - Expected a difference no greater than <{0}>. - Expected a difference no greater than <{0}>. + Expected a difference no greater than {0}. + Expected a difference no greater than {0}. @@ -43,8 +43,8 @@ - Expected a difference greater than <{0}>. - Expected a difference greater than <{0}>. + Expected a difference greater than {0}. + Expected a difference greater than {0}. diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index cee1d18c8f..0efc43a99b 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -493,7 +493,7 @@ public async Task FloatAreEqual_InterpolatedString_DifferentValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreEqual(1.0f, 1.1f) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference no greater than <0.001>. + Expected a difference no greater than 0.001. expected: 1 actual: 1.1 """); @@ -515,7 +515,7 @@ public async Task FloatAreNotEqual_InterpolatedString_SameValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreNotEqual(1.0f, 1.1f) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference greater than <0.2>. + Expected a difference greater than 0.2. notExpected: 1 actual: 1.1 """); @@ -537,7 +537,7 @@ public async Task DecimalAreEqual_InterpolatedString_DifferentValues_ShouldFail( (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreEqual(1.0m, 1.1m) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference no greater than <0.001>. + Expected a difference no greater than 0.001. expected: 1.0 actual: 1.1 """); @@ -559,7 +559,7 @@ public async Task DecimalAreNotEqual_InterpolatedString_SameValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreNotEqual(1.0m, 1.1m) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference greater than <0.2>. + Expected a difference greater than 0.2. notExpected: 1.0 actual: 1.1 """); @@ -581,7 +581,7 @@ public async Task LongAreEqual_InterpolatedString_DifferentValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreEqual(1L, 2L) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference no greater than <0>. + Expected a difference no greater than 0. expected: 1 actual: 2 """); @@ -603,7 +603,7 @@ public async Task LongAreNotEqual_InterpolatedString_SameValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreNotEqual(1L, 2L) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference greater than <1>. + Expected a difference greater than 1. notExpected: 1 actual: 2 """); @@ -625,7 +625,7 @@ public async Task DoubleAreEqual_InterpolatedString_DifferentValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreEqual(1.0d, 1.1d) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference no greater than <0.001>. + Expected a difference no greater than 0.001. expected: 1 actual: 1.1 """); @@ -647,7 +647,7 @@ public async Task DoubleAreNotEqual_InterpolatedString_SameValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreNotEqual(1.0d, 1.1d) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference greater than <0.2>. + Expected a difference greater than 0.2. notExpected: 1 actual: 1.1 """); @@ -824,7 +824,7 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif Action action = () => Assert.AreEqual(5.0f, 2.0f, 2.0f); // difference is 3. Delta is 2 action.Should().Throw().WithMessage("""" Assert.AreEqual(5.0f, 2.0f) failed. - Expected a difference no greater than <2>. + Expected a difference no greater than 2. expected: 5 actual: 2 """"); @@ -835,7 +835,7 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif Action action = () => Assert.AreEqual(2.0f, 5.0f, 2.0f); // difference is -3. Delta is 2 action.Should().Throw().WithMessage("""" Assert.AreEqual(2.0f, 5.0f) failed. - Expected a difference no greater than <2>. + Expected a difference no greater than 2. expected: 2 actual: 5 """"); @@ -852,7 +852,7 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFai Action action = () => Assert.AreEqual(5.0f, float.NaN, 2.0f); action.Should().Throw().WithMessage("""" Assert.AreEqual(5.0f, float.NaN) failed. - Expected a difference no greater than <2>. + Expected a difference no greater than 2. expected: 5 actual: NaN """"); @@ -863,7 +863,7 @@ public void FloatAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFai Action action = () => Assert.AreEqual(float.NaN, 5.0f, 2.0f); action.Should().Throw().WithMessage("""" Assert.AreEqual(float.NaN, 5.0f) failed. - Expected a difference no greater than <2>. + Expected a difference no greater than 2. expected: NaN actual: 5 """"); @@ -1056,7 +1056,7 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual Action action = () => Assert.AreNotEqual(5.0f, 4.0f, 2.0f); // difference is 1. Delta is 2 action.Should().Throw().WithMessage("""" Assert.AreNotEqual(5.0f, 4.0f) failed. - Expected a difference greater than <2>. + Expected a difference greater than 2. notExpected: 5 actual: 4 """"); @@ -1067,7 +1067,7 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual Action action = () => Assert.AreNotEqual(4.0f, 5.0f, 2.0f); // difference is -1. Delta is 2 action.Should().Throw().WithMessage("""" Assert.AreNotEqual(4.0f, 5.0f) failed. - Expected a difference greater than <2>. + Expected a difference greater than 2. notExpected: 4 actual: 5 """"); @@ -1083,7 +1083,7 @@ public void FloatAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFail Action action = () => Assert.AreNotEqual(float.NaN, float.NaN, 2.0f); action.Should().Throw().WithMessage("""" Assert.AreNotEqual(float.NaN, float.NaN) failed. - Expected a difference greater than <2>. + Expected a difference greater than 2. notExpected: NaN actual: NaN """"); @@ -1272,7 +1272,7 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi action.Should().Throw() .WithMessage("""" Assert.AreEqual(5.0d, 2.0d) failed. - Expected a difference no greater than <2>. + Expected a difference no greater than 2. expected: 5 actual: 2 """"); @@ -1284,7 +1284,7 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi action.Should().Throw() .WithMessage("""" Assert.AreEqual(2.0d, 5.0d) failed. - Expected a difference no greater than <2>. + Expected a difference no greater than 2. expected: 2 actual: 5 """"); @@ -1302,7 +1302,7 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFa action.Should().Throw() .WithMessage("""" Assert.AreEqual(5.0d, double.NaN) failed. - Expected a difference no greater than <2>. + Expected a difference no greater than 2. expected: 5 actual: NaN """"); @@ -1314,7 +1314,7 @@ public void DoubleAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFa action.Should().Throw() .WithMessage("""" Assert.AreEqual(double.NaN, 5.0d) failed. - Expected a difference no greater than <2>. + Expected a difference no greater than 2. expected: NaN actual: 5 """"); @@ -1515,7 +1515,7 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua action.Should().Throw() .WithMessage("""" Assert.AreNotEqual(5.0d, 4.0d) failed. - Expected a difference greater than <2>. + Expected a difference greater than 2. notExpected: 5 actual: 4 """"); @@ -1527,7 +1527,7 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua action.Should().Throw() .WithMessage("""" Assert.AreNotEqual(4.0d, 5.0d) failed. - Expected a difference greater than <2>. + Expected a difference greater than 2. notExpected: 4 actual: 5 """"); @@ -1544,7 +1544,7 @@ public void DoubleAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFai action.Should().Throw() .WithMessage("""" Assert.AreNotEqual(double.NaN, double.NaN) failed. - Expected a difference greater than <2>. + Expected a difference greater than 2. notExpected: NaN actual: NaN """"); From 08fb47e45e20effcad287cae331df50aa42548b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 13:59:42 +0100 Subject: [PATCH 32/58] Fix trailing newlines in test files --- .../Assertions/AssertTests.AreEqualTests.cs | 2 +- .../Assertions/AssertTests.IsExactInstanceOfTypeTests.cs | 2 +- .../Assertions/AssertTests.IsInstanceOfTypeTests.cs | 2 +- .../TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs | 2 +- .../Assertions/AssertTests.IsTrueTests.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index 0efc43a99b..f3a18ed85e 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index 4faff3036d..31e13fed75 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index fb4cb96077..d6331aa7e5 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index 687b444fd6..fa03d261c0 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs index 3a623744c0..38c78faccc 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; From 7f4294e071b590ebe3de32fde8b863bcbc2224eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 18:16:43 +0100 Subject: [PATCH 33/58] Materialize non-ICollection enumerables at assertion boundary to prevent multiple enumeration Address review feedback: collection assertion methods (Contains, DoesNotContain, HasCount) now snapshot non-ICollection enumerables into a List before checking, ensuring the error message displays the same values the assertion actually tested. FormatCollectionParameter retains a safety-net guard for non-ICollection types. Added non-regression test with a non-deterministic iterator that yields different values on re-enumeration to prove the fix. --- .../Assertions/Assert.Contains.cs | 69 +++++++++++------- .../TestFramework/Assertions/Assert.Count.cs | 8 ++- .../TestFramework/Assertions/Assert.cs | 23 ++++++ .../Assertions/AssertTests.cs | 72 ++++++++++++++----- 4 files changed, 128 insertions(+), 44 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs index dc00f50e92..c2b07a811e 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs @@ -268,9 +268,12 @@ public static T ContainsSingle(Func predicate, IEnumerable collec /// public static void Contains(T expected, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(expected))] string expectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - if (!collection.Contains(expected)) + // Materialize non-ICollection enumerables to prevent multiple enumeration + // that could yield different results or fail on second pass. + ICollection snapshot = collection as ICollection ?? new List(collection); + if (!snapshot.Contains(expected)) { - ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, collection); + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, snapshot); } } @@ -292,7 +295,10 @@ public static void Contains(object? expected, IEnumerable collection, string? me { CheckParameterNotNull(collection, "Assert.Contains", "collection"); - foreach (object? item in collection) + // Materialize non-ICollection enumerables to prevent multiple enumeration. + ICollection snapshot = collection as ICollection ?? collection.Cast().ToList(); + + foreach (object? item in snapshot) { if (object.Equals(item, expected)) { @@ -300,7 +306,7 @@ public static void Contains(object? expected, IEnumerable collection, string? me } } - ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, collection); + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, snapshot); } /// @@ -321,9 +327,10 @@ public static void Contains(object? expected, IEnumerable collection, string? me /// public static void Contains(T expected, IEnumerable collection, IEqualityComparer comparer, string? message = "", [CallerArgumentExpression(nameof(expected))] string expectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - if (!collection.Contains(expected, comparer)) + ICollection snapshot = collection as ICollection ?? new List(collection); + if (!snapshot.Contains(expected, comparer)) { - ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, collection); + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, snapshot); } } @@ -347,7 +354,9 @@ public static void Contains(object? expected, IEnumerable collection, IEqualityC CheckParameterNotNull(collection, "Assert.Contains", "collection"); CheckParameterNotNull(comparer, "Assert.Contains", "comparer"); - foreach (object? item in collection) + ICollection snapshot = collection as ICollection ?? collection.Cast().ToList(); + + foreach (object? item in snapshot) { if (comparer.Equals(item, expected)) { @@ -355,7 +364,7 @@ public static void Contains(object? expected, IEnumerable collection, IEqualityC } } - ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, collection); + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, snapshot); } /// @@ -375,9 +384,10 @@ public static void Contains(object? expected, IEnumerable collection, IEqualityC /// public static void Contains(Func predicate, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(predicate))] string predicateExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - if (!collection.Any(predicate)) + ICollection snapshot = collection as ICollection ?? new List(collection); + if (!snapshot.Any(predicate)) { - ThrowAssertContainsPredicateFailed(message, predicateExpression, collectionExpression, collection); + ThrowAssertContainsPredicateFailed(message, predicateExpression, collectionExpression, snapshot); } } @@ -400,7 +410,9 @@ public static void Contains(Func predicate, IEnumerable collectio CheckParameterNotNull(collection, "Assert.Contains", "collection"); CheckParameterNotNull(predicate, "Assert.Contains", "predicate"); - foreach (object? item in collection) + ICollection snapshot = collection as ICollection ?? collection.Cast().ToList(); + + foreach (object? item in snapshot) { if (predicate(item)) { @@ -408,7 +420,7 @@ public static void Contains(Func predicate, IEnumerable collectio } } - ThrowAssertContainsPredicateFailed(message, predicateExpression, collectionExpression, collection); + ThrowAssertContainsPredicateFailed(message, predicateExpression, collectionExpression, snapshot); } /// @@ -505,9 +517,10 @@ public static void Contains(string substring, string value, StringComparison com /// public static void DoesNotContain(T notExpected, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(notExpected))] string notExpectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - if (collection.Contains(notExpected)) + ICollection snapshot = collection as ICollection ?? new List(collection); + if (snapshot.Contains(notExpected)) { - ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, collection); + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, snapshot); } } @@ -529,11 +542,13 @@ public static void DoesNotContain(object? notExpected, IEnumerable collection, s { CheckParameterNotNull(collection, "Assert.DoesNotContain", "collection"); - foreach (object? item in collection) + ICollection snapshot = collection as ICollection ?? collection.Cast().ToList(); + + foreach (object? item in snapshot) { if (object.Equals(notExpected, item)) { - ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, collection); + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, snapshot); } } } @@ -556,9 +571,10 @@ public static void DoesNotContain(object? notExpected, IEnumerable collection, s /// public static void DoesNotContain(T notExpected, IEnumerable collection, IEqualityComparer comparer, string? message = "", [CallerArgumentExpression(nameof(notExpected))] string notExpectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - if (collection.Contains(notExpected, comparer)) + ICollection snapshot = collection as ICollection ?? new List(collection); + if (snapshot.Contains(notExpected, comparer)) { - ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, collection); + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, snapshot); } } @@ -582,11 +598,13 @@ public static void DoesNotContain(object? notExpected, IEnumerable collection, I CheckParameterNotNull(collection, "Assert.DoesNotContain", "collection"); CheckParameterNotNull(comparer, "Assert.DoesNotContain", "comparer"); - foreach (object? item in collection) + ICollection snapshot = collection as ICollection ?? collection.Cast().ToList(); + + foreach (object? item in snapshot) { if (comparer.Equals(item, notExpected)) { - ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, collection); + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, snapshot); } } } @@ -608,9 +626,10 @@ public static void DoesNotContain(object? notExpected, IEnumerable collection, I /// public static void DoesNotContain(Func predicate, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(predicate))] string predicateExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - if (collection.Any(predicate)) + ICollection snapshot = collection as ICollection ?? new List(collection); + if (snapshot.Any(predicate)) { - ThrowAssertDoesNotContainPredicateFailed(message, predicateExpression, collectionExpression, collection); + ThrowAssertDoesNotContainPredicateFailed(message, predicateExpression, collectionExpression, snapshot); } } @@ -633,11 +652,13 @@ public static void DoesNotContain(Func predicate, IEnumerable col CheckParameterNotNull(collection, "Assert.DoesNotContain", "collection"); CheckParameterNotNull(predicate, "Assert.DoesNotContain", "predicate"); - foreach (object? item in collection) + ICollection snapshot = collection as ICollection ?? collection.Cast().ToList(); + + foreach (object? item in snapshot) { if (predicate(item)) { - ThrowAssertDoesNotContainPredicateFailed(message, predicateExpression, collectionExpression, collection); + ThrowAssertDoesNotContainPredicateFailed(message, predicateExpression, collectionExpression, snapshot); } } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs index 04b1cd5c32..4caa57a8dd 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs @@ -319,13 +319,15 @@ public static void IsEmpty(IEnumerable collection, string? message = "", [Caller private static void HasCount(string assertionName, int expected, IEnumerable collection, string? message, string collectionExpression) { - int actualCount = collection.Count(); - if (actualCount == expected) + // Materialize non-ICollection enumerables to prevent multiple enumeration + // that could yield different results or fail on second pass. + ICollection snapshot = collection as ICollection ?? new List(collection); + if (snapshot.Count == expected) { return; } - ThrowAssertCountFailed(assertionName, expected, actualCount, collection, message, collectionExpression); + ThrowAssertCountFailed(assertionName, expected, snapshot.Count, snapshot, message, collectionExpression); } private static void HasCount(string assertionName, int expected, IEnumerable collection, string? message, string collectionExpression) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index ae68de4a27..d2b8811c8f 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -161,6 +161,18 @@ internal static string FormatType(Type type) return $"<{typeName}>"; } + internal static string FormatValueWithType(object value) + { + string formattedValue = FormatValue(value); + string formattedType = FormatType(value.GetType()); + + // When FormatValue already returned the type name (e.g. ), + // don't repeat it. + return formattedValue == formattedType + ? formattedValue + : $"{formattedValue} ({formattedType})"; + } + internal static string TruncateExpression(string expression, int maxLength = 100) => expression.Length <= maxLength ? expression @@ -307,9 +319,20 @@ internal static string FormatExpressionParameter(string paramName, string expres /// /// Formats a collection parameter line showing a preview of the collection elements. + /// Callers must ensure the collection is safe to enumerate (e.g. materialized via + /// snapshot at the assertion boundary). Non-ICollection enumerables are shown as their + /// type name as a safety net. /// internal static string FormatCollectionParameter(string expression, IEnumerable collection) { + // Safety net: callers should materialize non-ICollection enumerables before + // reaching here, but if they don't, fall back to the type name rather than + // risk re-enumerating a non-deterministic or exhausted enumerator. + if (collection is not ICollection) + { + return $"{Environment.NewLine} collection: {FormatType(collection.GetType())}"; + } + string preview = FormatCollectionPreview(collection); return $"{Environment.NewLine} collection: {preview}"; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index ff0a3fb711..3c71c2609c 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -31,7 +31,7 @@ public void ObsoleteEqualsMethodThrowsAssertFailedException() Action act = () => Assert.Equals("test", "test"); #pragma warning restore CS0618 // Type or member is obsolete act.Should().Throw() - .WithMessage("*Assert.Equals should not be used for Assertions*"); + .WithMessage("Assert.Fail failed. Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead."); } public void ObsoleteReferenceEqualsMethodThrowsAssertFailedException() @@ -41,7 +41,7 @@ public void ObsoleteReferenceEqualsMethodThrowsAssertFailedException() Action act = () => Assert.ReferenceEquals(obj, obj); #pragma warning restore CS0618 // Type or member is obsolete act.Should().Throw() - .WithMessage("*Assert.ReferenceEquals should not be used for Assertions*"); + .WithMessage("Assert.Fail failed. Assert.ReferenceEquals should not be used for Assertions. Please use Assert.AreSame & overloads instead."); } #endif #endregion @@ -79,7 +79,7 @@ public void FormatValue_WhenStringExceedsMaxLength_ShouldTruncateWithEllipsis() Action action = () => Assert.IsNull(longValue); action.Should().Throw() .WithMessage($""" - Assert.IsNull(*) failed. + Assert.IsNull(longValue) failed. Expected value to be null. value: {expectedValue} """); @@ -93,7 +93,7 @@ public void FormatValue_WhenStringIsWithinMaxLength_ShouldNotTruncate() Action action = () => Assert.IsNull(value); action.Should().Throw() .WithMessage($""" - Assert.IsNull(*) failed. + Assert.IsNull(value) failed. Expected value to be null. value: {expectedFullValue} """); @@ -108,7 +108,7 @@ public void FormatValue_WhenCustomToStringExceedsMaxLength_ShouldTruncate() Action action = () => Assert.IsNull(obj); action.Should().Throw() .WithMessage($""" - Assert.IsNull(*) failed. + Assert.IsNull(obj) failed. Expected value to be null. value: {expectedValue} """); @@ -122,7 +122,7 @@ public void TruncateExpression_WhenExpressionExceeds100Chars_ShouldShowEllipsis( Action action = () => Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull(*) failed. + Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected a non-null value. value: null """); @@ -139,7 +139,7 @@ public void FormatValue_WhenValueContainsNewlines_ShouldEscapeThem() Action action = () => Assert.IsNull(obj); action.Should().Throw() .WithMessage(""" - Assert.IsNull(*) failed. + Assert.IsNull(obj) failed. Expected value to be null. value: line1\r\nline2\nline3 """); @@ -152,7 +152,7 @@ public void FormatValue_WhenStringContainsNewlines_ShouldEscapeThem() Action action = () => Assert.IsNull(value); action.Should().Throw() .WithMessage(""" - Assert.IsNull(*) failed. + Assert.IsNull(value) failed. Expected value to be null. value: "hello\nworld" """); @@ -169,7 +169,7 @@ public void FormatValue_WhenValueIsCollection_ShouldShowPreview() Action action = () => Assert.IsNull(collection); action.Should().Throw() .WithMessage(""" - Assert.IsNull(*) failed. + Assert.IsNull(collection) failed. Expected value to be null. value: [1, 2, 3] """); @@ -190,7 +190,7 @@ public void FormatCollectionPreview_WhenTotalStringLengthExceeds256_ShouldTrunca Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() .WithMessage($""" - Assert.Contains(*) failed. + Assert.Contains("not-there", collection) failed. Expected collection to contain the specified item. collection: ["{new string('a', 30)}", "{new string('b', 30)}", "{new string('c', 30)}", "{new string('d', 30)}", "{new string('e', 30)}", "{new string('f', 30)}", "{new string('g', 30)}", ... 13 more] """); @@ -205,9 +205,9 @@ public void FormatCollectionPreview_WhenElementToStringExceeds50_ShouldTruncateE Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() .WithMessage($""" - Assert.Contains(*) failed. + Assert.Contains("not-there", collection) failed. Expected collection to contain the specified item. - collection*[{expectedFirstElement}, "short"] + collection: [{expectedFirstElement}, "short"] """); } @@ -220,7 +220,7 @@ public void FormatCollectionPreview_WhenCollectionContainsNestedCollections_Shou Action action = () => Assert.IsNull(outer); action.Should().Throw() .WithMessage(""" - Assert.IsNull(*) failed. + Assert.IsNull(outer) failed. Expected value to be null. value: [[1, 2], [3, 4]] """); @@ -244,7 +244,7 @@ public void FormatCollectionPreview_WhenNestedCollectionIsLarge_ShouldTruncateIn Action action = () => Assert.IsNull(outer); action.Should().Throw() .WithMessage(""" - Assert.IsNull(*) failed. + Assert.IsNull(outer) failed. Expected value to be null. value: [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 35 more]] """); @@ -257,9 +257,9 @@ public void FormatCollectionPreview_WhenElementContainsNewlines_ShouldEscapeThem Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() .WithMessage(""" - Assert.Contains(*) failed. + Assert.Contains("not-there", collection) failed. Expected collection to contain the specified item. - collection*["line1\nline2", "ok"] + collection: ["line1\nline2", "ok"] """); } @@ -270,12 +270,50 @@ public void FormatCollectionPreview_WhenSingleElement_ShouldShowSingularForm() Action action = () => Assert.Contains(99, collection); action.Should().Throw() .WithMessage(""" - Assert.Contains(*) failed. + Assert.Contains(99, collection) failed. Expected collection to contain the specified item. collection: [42] """); } + public void FormatCollectionParameter_WhenNonICollectionEnumerable_ShouldNotReEnumerate() + { + // This enumerable yields different results on each enumeration. + // The assertion materializes the enumerable once at the boundary, + // so both the assertion check and the error message use the same snapshot. + int callCount = 0; + IEnumerable NonDeterministicEnumerable() + { + callCount++; + if (callCount == 1) + { + // First (and only) enumeration: materialized by Assert.Contains + yield return 1; + yield return 2; + yield return 3; + } + else + { + // If re-enumerated, yields completely different values + yield return 99; + yield return 100; + } + } + + IEnumerable collection = NonDeterministicEnumerable(); + Action action = () => Assert.Contains(42, collection); + action.Should().Throw() + .WithMessage(""" + Assert.Contains(42, collection) failed. + Expected collection to contain the specified item. + collection: [1, 2, 3] + """); + + // The enumerable should have been enumerated exactly once (materialized at assertion boundary). + // If this were 2, the error message could show [99, 100] instead of [1, 2, 3]. + callCount.Should().Be(1); + } + #endregion } From 26f5c025641e334935a02f76dedb7dfb61934245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 18:47:56 +0100 Subject: [PATCH 34/58] WIP: In-progress assertion changes before refactor --- .../Assertions/Assert.AreEqual.cs | 4 +-- .../Assert.IsExactInstanceOfType.cs | 29 +++++++++++-------- .../Assertions/Assert.IsInstanceOfType.cs | 29 +++++++++++-------- .../TestFramework/Assertions/Assert.IsNull.cs | 16 +++++++--- .../Assertions/AssertTests.AreEqualTests.cs | 2 +- .../AssertTests.IsExactInstanceOfTypeTests.cs | 22 +++++++++++++- .../AssertTests.IsInstanceOfTypeTests.cs | 22 +++++++++++++- .../Assertions/AssertTests.IsNull.cs | 22 +++++++------- .../Assertions/AssertTests.cs | 27 ++++++----------- 9 files changed, 110 insertions(+), 63 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 2231f6f275..8e82c574b8 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -612,8 +612,8 @@ private static void ThrowAssertAreEqualFailed(object? expected, object? actual, { message += Environment.NewLine + FrameworkMessages.AreEqualFailNew; message += FormatAlignedParameters( - (nameof(expected), $"{FormatValue(expected)} ({FormatType(expected.GetType())})"), - (nameof(actual), $"{FormatValue(actual)} ({FormatType(actual.GetType())})")); + (nameof(expected), FormatValueWithType(expected)), + (nameof(actual), FormatValueWithType(actual))); } else if (expected is string expectedString && actual is string actualString) { diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs index 5a2d344902..4c22ee086e 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs @@ -324,16 +324,20 @@ private static void ThrowAssertIsExactInstanceOfTypeFailed(object? value, Type? { string callSite = FormatCallSite("Assert.IsExactInstanceOfType", (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - if (expectedType is not null && value is not null) - { - message += Environment.NewLine + FrameworkMessages.IsExactInstanceOfTypeFailNew; - } + message += Environment.NewLine + FrameworkMessages.IsExactInstanceOfTypeFailNew; message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - if (expectedType is not null && value is not null) + if (expectedType is null) { - message += Environment.NewLine + $" expectedType: {FormatType(expectedType)}" - + Environment.NewLine + $" actualType: {FormatType(value.GetType())}"; + message += Environment.NewLine + " expectedType: (null)"; + } + else + { + message += Environment.NewLine + $" expectedType: {FormatType(expectedType)}"; + if (value is not null) + { + message += Environment.NewLine + $" actualType: {FormatType(value.GetType())}"; + } } ThrowAssertFailed(callSite, message); @@ -403,13 +407,14 @@ private static void ThrowAssertIsNotExactInstanceOfTypeFailed(object? value, Typ { string callSite = FormatCallSite("Assert.IsNotExactInstanceOfType", (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - if (wrongType is not null) - { - message += Environment.NewLine + FrameworkMessages.IsNotExactInstanceOfTypeFailNew; - } + message += Environment.NewLine + FrameworkMessages.IsNotExactInstanceOfTypeFailNew; message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - if (wrongType is not null) + if (wrongType is null) + { + message += Environment.NewLine + " wrongType: (null)"; + } + else { message += Environment.NewLine + $" wrongType: {FormatType(wrongType)}" + Environment.NewLine + $" actualType: {FormatType(value!.GetType())}"; diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 6626f2dda2..ff3faba408 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -331,16 +331,20 @@ private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expec { string callSite = FormatCallSite("Assert.IsInstanceOfType", (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - if (expectedType is not null && value is not null) - { - message += Environment.NewLine + FrameworkMessages.IsInstanceOfTypeFailNew; - } + message += Environment.NewLine + FrameworkMessages.IsInstanceOfTypeFailNew; message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - if (expectedType is not null && value is not null) + if (expectedType is null) { - message += Environment.NewLine + $" expectedType: {FormatType(expectedType)}" - + Environment.NewLine + $" actualType: {FormatType(value.GetType())}"; + message += Environment.NewLine + " expectedType: (null)"; + } + else + { + message += Environment.NewLine + $" expectedType: {FormatType(expectedType)}"; + if (value is not null) + { + message += Environment.NewLine + $" actualType: {FormatType(value.GetType())}"; + } } ThrowAssertFailed(callSite, message); @@ -412,13 +416,14 @@ private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wr { string callSite = FormatCallSite("Assert.IsNotInstanceOfType", (nameof(value), valueExpression)); string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - if (wrongType is not null) - { - message += Environment.NewLine + FrameworkMessages.IsNotInstanceOfTypeFailNew; - } + message += Environment.NewLine + FrameworkMessages.IsNotInstanceOfTypeFailNew; message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); - if (wrongType is not null) + if (wrongType is null) + { + message += Environment.NewLine + " wrongType: (null)"; + } + else { message += Environment.NewLine + $" wrongType: {FormatType(wrongType)}" + Environment.NewLine + $" actualType: {FormatType(value!.GetType())}"; diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 4b447ea7de..12c9b24844 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -162,8 +162,12 @@ public static void IsNull(object? value, string? message = "", [CallerArgumentEx private static void ThrowAssertIsNullFailed(object? value, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsNull", (nameof(value), valueExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.IsNullFailNew; + string message = FrameworkMessages.IsNullFailNew; + if (!string.IsNullOrEmpty(userMessage)) + { + message += Environment.NewLine + userMessage; + } + message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); ThrowAssertFailed(callSite, message); } @@ -208,8 +212,12 @@ public static void IsNotNull([NotNull] object? value, string? message = "", [Cal private static void ThrowAssertIsNotNullFailed(string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsNotNull", ("value", valueExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.IsNotNullFailNew; + string message = FrameworkMessages.IsNotNullFailNew; + if (!string.IsNullOrEmpty(userMessage)) + { + message += Environment.NewLine + userMessage; + } + message += Environment.NewLine + FormatParameter("value", valueExpression, null); ThrowAssertFailed(callSite, message); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index f3a18ed85e..59da63b0fb 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -374,7 +374,7 @@ public void AreEqualTwoObjectsDifferentTypeShouldFail() .WithMessage(""" Assert.AreEqual(new object(), 1) failed. Expected values to be equal. - expected: () + expected: actual: 1 () """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index 31e13fed75..574255890e 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -14,7 +14,9 @@ public void ExactInstanceOfTypeShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(null) failed. +Expected value to be exactly of the specified type. value: null + expectedType: """); } @@ -24,7 +26,9 @@ public void ExactInstanceOfTypeShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) failed. +Expected value to be exactly of the specified type. value: 5 + expectedType: (null) """); } @@ -82,7 +86,9 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(null) failed. User-provided message +Expected value to be exactly of the specified type. value: null + expectedType: """); } @@ -92,7 +98,9 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) failed. User-provided message +Expected value to be exactly of the specified type. value: 5 + expectedType: (null) """); } @@ -120,7 +128,9 @@ public async Task ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenValue (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsExactInstanceOfType(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected value to be exactly of the specified type. value: null + expectedType: """); o.WasToStringCalled.Should().BeTrue(); } @@ -132,7 +142,9 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull( action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls +Expected value to be exactly of the specified type. value: 5 + expectedType: (null) """); o.WasToStringCalled.Should().BeTrue(); } @@ -164,7 +176,13 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldPassWhenTypeIsCorre public void ExactInstanceNotOfTypeShouldFailWhenTypeIsNull() { Action action = () => Assert.IsNotExactInstanceOfType(5, null); - action.Should().Throw(); + action.Should().Throw() + .WithMessage(""" +Assert.IsNotExactInstanceOfType(5) failed. +Value should not be exactly of the specified type. + value: 5 + wrongType: (null) +"""); } public void ExactInstanceNotOfTypeShouldPassOnWrongInstance() => Assert.IsNotExactInstanceOfType(5L, typeof(int)); @@ -197,7 +215,9 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(null) failed. +Expected value to be exactly of the specified type. value: null + expectedType: """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index d6331aa7e5..6ed354ad5a 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -14,7 +14,9 @@ public void InstanceOfTypeShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(null) failed. + Expected value to be of the specified type. value: null + expectedType: """); } @@ -24,7 +26,9 @@ public void InstanceOfTypeShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) failed. + Expected value to be of the specified type. value: 5 + expectedType: (null) """); } @@ -51,7 +55,9 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(null) failed. User-provided message + Expected value to be of the specified type. value: null + expectedType: """); } @@ -61,7 +67,9 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) failed. User-provided message + Expected value to be of the specified type. value: 5 + expectedType: (null) """); } @@ -89,7 +97,9 @@ public async Task InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNul (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsInstanceOfType(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Expected value to be of the specified type. value: null + expectedType: """); o.WasToStringCalled.Should().BeTrue(); } @@ -101,7 +111,9 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls + Expected value to be of the specified type. value: 5 + expectedType: (null) """); o.WasToStringCalled.Should().BeTrue(); } @@ -133,7 +145,13 @@ public void InstanceOfType_WithInterpolatedString_ShouldPassWhenTypeIsCorrect() public void InstanceNotOfTypeShouldFailWhenTypeIsNull() { Action action = () => Assert.IsNotInstanceOfType(5, null); - action.Should().Throw(); + action.Should().Throw() + .WithMessage(""" + Assert.IsNotInstanceOfType(5) failed. + Value should not be of the specified type. + value: 5 + wrongType: (null) + """); } public void InstanceNotOfTypeShouldPassOnWrongInstance() => Assert.IsNotInstanceOfType(5L, typeof(int)); @@ -146,7 +164,9 @@ public void IsInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(null) failed. + Expected value to be of the specified type. value: null + expectedType: """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index fa03d261c0..00c8d21a12 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -17,8 +17,7 @@ public void IsNull_PassNonNull_ShouldFail() Action action = () => Assert.IsNull(new object()); action.Should().Throw() .WithMessage(""" - Assert.IsNull(new object()) failed. - Expected value to be null. + Assert.IsNull(new object()) failed. Expected value to be null. value: """); } @@ -31,8 +30,8 @@ public void IsNull_StringMessage_PassNonNull_ShouldFail() Action action = () => Assert.IsNull(new object(), "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsNull(new object()) failed. User-provided message - Expected value to be null. + Assert.IsNull(new object()) failed. Expected value to be null. + User-provided message value: """); } @@ -51,8 +50,8 @@ public async Task IsNull_InterpolatedString_PassNonNull_ShouldFail() Func action = async () => Assert.IsNull(new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNull(new object()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected value to be null. + Assert.IsNull(new object()) failed. Expected value to be null. + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* value: """); o.WasToStringCalled.Should().BeTrue(); @@ -86,8 +85,7 @@ public void IsNotNull_PassNull_ShouldFail() Action action = () => Assert.IsNotNull(null); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull(null) failed. - Expected a non-null value. + Assert.IsNotNull(null) failed. Expected a non-null value. value: null """); } @@ -97,8 +95,8 @@ public void IsNotNull_StringMessage_PassNonNull_ShouldFail() Action action = () => Assert.IsNotNull(null, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull(null) failed. User-provided message - Expected a non-null value. + Assert.IsNotNull(null) failed. Expected a non-null value. + User-provided message value: null """); } @@ -110,8 +108,8 @@ public async Task IsNotNull_InterpolatedString_PassNonNull_ShouldFail() Func action = async () => Assert.IsNotNull(null, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNotNull(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a non-null value. + Assert.IsNotNull(null) failed. Expected a non-null value. + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* value: null """); o.WasToStringCalled.Should().BeTrue(); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index 3c71c2609c..5c35229752 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -79,8 +79,7 @@ public void FormatValue_WhenStringExceedsMaxLength_ShouldTruncateWithEllipsis() Action action = () => Assert.IsNull(longValue); action.Should().Throw() .WithMessage($""" - Assert.IsNull(longValue) failed. - Expected value to be null. + Assert.IsNull(longValue) failed. Expected value to be null. value: {expectedValue} """); } @@ -93,8 +92,7 @@ public void FormatValue_WhenStringIsWithinMaxLength_ShouldNotTruncate() Action action = () => Assert.IsNull(value); action.Should().Throw() .WithMessage($""" - Assert.IsNull(value) failed. - Expected value to be null. + Assert.IsNull(value) failed. Expected value to be null. value: {expectedFullValue} """); } @@ -108,8 +106,7 @@ public void FormatValue_WhenCustomToStringExceedsMaxLength_ShouldTruncate() Action action = () => Assert.IsNull(obj); action.Should().Throw() .WithMessage($""" - Assert.IsNull(obj) failed. - Expected value to be null. + Assert.IsNull(obj) failed. Expected value to be null. value: {expectedValue} """); } @@ -122,8 +119,7 @@ public void TruncateExpression_WhenExpressionExceeds100Chars_ShouldShowEllipsis( Action action = () => Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. - Expected a non-null value. + Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected a non-null value. value: null """); } @@ -139,8 +135,7 @@ public void FormatValue_WhenValueContainsNewlines_ShouldEscapeThem() Action action = () => Assert.IsNull(obj); action.Should().Throw() .WithMessage(""" - Assert.IsNull(obj) failed. - Expected value to be null. + Assert.IsNull(obj) failed. Expected value to be null. value: line1\r\nline2\nline3 """); } @@ -152,8 +147,7 @@ public void FormatValue_WhenStringContainsNewlines_ShouldEscapeThem() Action action = () => Assert.IsNull(value); action.Should().Throw() .WithMessage(""" - Assert.IsNull(value) failed. - Expected value to be null. + Assert.IsNull(value) failed. Expected value to be null. value: "hello\nworld" """); } @@ -169,8 +163,7 @@ public void FormatValue_WhenValueIsCollection_ShouldShowPreview() Action action = () => Assert.IsNull(collection); action.Should().Throw() .WithMessage(""" - Assert.IsNull(collection) failed. - Expected value to be null. + Assert.IsNull(collection) failed. Expected value to be null. value: [1, 2, 3] """); } @@ -220,8 +213,7 @@ public void FormatCollectionPreview_WhenCollectionContainsNestedCollections_Shou Action action = () => Assert.IsNull(outer); action.Should().Throw() .WithMessage(""" - Assert.IsNull(outer) failed. - Expected value to be null. + Assert.IsNull(outer) failed. Expected value to be null. value: [[1, 2], [3, 4]] """); } @@ -244,8 +236,7 @@ public void FormatCollectionPreview_WhenNestedCollectionIsLarge_ShouldTruncateIn Action action = () => Assert.IsNull(outer); action.Should().Throw() .WithMessage(""" - Assert.IsNull(outer) failed. - Expected value to be null. + Assert.IsNull(outer) failed. Expected value to be null. value: [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 35 more]] """); } From 99b49228d51be17fef0da9aed3b0ba6ef8061db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 19:45:50 +0100 Subject: [PATCH 35/58] Refactor assertion error messages with structured format - Drop 'failed.' from assertion error first line - Move user message to end with 'User message:' label - Use consistent 'Expected...' voice across all assertions - Use human-friendly parameter labels (e.g. 'lower bound' not 'lowerBound') - Make relational assertion messages precise with embedded values - Align parameters consistently using FormatAlignedParameters - Remove redundant 'value: null' from IsNotNull - Update resource strings for voice consistency --- .../Assertions/Assert.AreEqual.cs | 38 +-- .../Assertions/Assert.AreSame.cs | 13 +- .../Assertions/Assert.Contains.cs | 39 ++-- .../TestFramework/Assertions/Assert.Count.cs | 13 +- .../Assertions/Assert.EndsWith.cs | 12 +- .../TestFramework/Assertions/Assert.Fail.cs | 2 +- .../Assertions/Assert.IComparable.cs | 32 +-- .../Assert.IsExactInstanceOfType.cs | 20 +- .../Assertions/Assert.IsInstanceOfType.cs | 20 +- .../TestFramework/Assertions/Assert.IsNull.cs | 13 +- .../TestFramework/Assertions/Assert.IsTrue.cs | 8 +- .../Assertions/Assert.Matches.cs | 8 +- .../Assertions/Assert.StartsWith.cs | 12 +- .../Assertions/Assert.ThrowsException.cs | 28 +-- .../TestFramework/Assertions/Assert.cs | 22 +- .../Resources/FrameworkMessages.resx | 16 +- .../Resources/xlf/FrameworkMessages.cs.xlf | 32 +-- .../Resources/xlf/FrameworkMessages.de.xlf | 32 +-- .../Resources/xlf/FrameworkMessages.es.xlf | 32 +-- .../Resources/xlf/FrameworkMessages.fr.xlf | 32 +-- .../Resources/xlf/FrameworkMessages.it.xlf | 32 +-- .../Resources/xlf/FrameworkMessages.ja.xlf | 32 +-- .../Resources/xlf/FrameworkMessages.ko.xlf | 32 +-- .../Resources/xlf/FrameworkMessages.pl.xlf | 32 +-- .../Resources/xlf/FrameworkMessages.pt-BR.xlf | 32 +-- .../Resources/xlf/FrameworkMessages.ru.xlf | 32 +-- .../Resources/xlf/FrameworkMessages.tr.xlf | 32 +-- .../xlf/FrameworkMessages.zh-Hans.xlf | 32 +-- .../xlf/FrameworkMessages.zh-Hant.xlf | 32 +-- .../Assertions/AssertTests.AreEqualTests.cs | 216 ++++++++++-------- .../Assertions/AssertTests.AreSame.cs | 60 ++--- .../Assertions/AssertTests.Contains.cs | 141 +++++++----- .../Assertions/AssertTests.EndsWith.cs | 55 ++--- .../AssertTests.IComparableTests.cs | 142 ++++++------ .../AssertTests.IsExactInstanceOfTypeTests.cs | 146 ++++++------ .../Assertions/AssertTests.IsInRange.cs | 140 +++++------- .../AssertTests.IsInstanceOfTypeTests.cs | 106 +++++---- .../Assertions/AssertTests.IsNull.cs | 29 +-- .../Assertions/AssertTests.IsTrueTests.cs | 52 +++-- .../Assertions/AssertTests.Items.cs | 55 +++-- .../Assertions/AssertTests.MatchesRegex.cs | 16 +- .../Assertions/AssertTests.StartsWith.cs | 55 ++--- .../AssertTests.ThrowsExceptionTests.cs | 64 +++--- .../Assertions/AssertTests.cs | 42 ++-- .../Assertions/CollectionAssertTests.cs | 10 +- .../Assertions/StringAssertTests.cs | 12 +- 46 files changed, 1074 insertions(+), 979 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 8e82c574b8..a628ec5e9b 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -534,7 +534,7 @@ private static string FormatStringComparisonMessage(string? expected, string? ac // Handle null cases if (expected is null || actual is null) { - string message = userMessage; + string message = FrameworkMessages.AreEqualFailNew; message += FormatAlignedParameters( (nameof(expected), FormatValue(expected)), (nameof(actual), FormatValue(actual))); @@ -599,36 +599,39 @@ private static string FormatStringDifferenceMessage(string expected, string actu string formattedUserMessage = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; - return formattedUserMessage + Environment.NewLine + lengthInfo + Environment.NewLine + expectedLine + Environment.NewLine + actualLine + Environment.NewLine + " " + new string('-', adjustedCaretPosition - 2) + "^"; + string result = lengthInfo + Environment.NewLine + expectedLine + Environment.NewLine + actualLine + Environment.NewLine + " " + new string('-', adjustedCaretPosition - 2) + "^"; + return string.IsNullOrEmpty(formattedUserMessage) ? result : result + Environment.NewLine + "User message: " + formattedUserMessage; } [DoesNotReturn] private static void ThrowAssertAreEqualFailed(object? expected, object? actual, string? userMessage, string expectedExpression, string actualExpression) { string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + string message; if (actual is not null && expected is not null && !actual.GetType().Equals(expected.GetType())) { - message += Environment.NewLine + FrameworkMessages.AreEqualFailNew; + message = FrameworkMessages.AreEqualFailNew; message += FormatAlignedParameters( (nameof(expected), FormatValueWithType(expected)), (nameof(actual), FormatValueWithType(actual))); } else if (expected is string expectedString && actual is string actualString) { - message = FormatStringComparisonMessage(expectedString, actualString, message); + message = FormatStringComparisonMessage(expectedString, actualString, string.Empty); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); return; } else { - message += Environment.NewLine + FrameworkMessages.AreEqualFailNew; + message = FrameworkMessages.AreEqualFailNew; message += FormatAlignedParameters( (nameof(expected), FormatValue(expected)), (nameof(actual), FormatValue(actual))); } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -637,11 +640,11 @@ private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, where T : struct, IConvertible { string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreEqualDeltaNoGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); + string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreEqualDeltaNoGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); message += FormatAlignedParameters( (nameof(expected), FormatValue(expected)), (nameof(actual), FormatValue(actual))); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -649,12 +652,12 @@ private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, private static void ThrowAssertAreEqualFailed(string? expected, string? actual, bool ignoreCase, CultureInfo culture, string? userMessage, string expectedExpression, string actualExpression) { string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; + string message; // If the user requested to match case, and the difference between expected/actual is casing only, then we use a different message. if (!ignoreCase && CompareInternal(expected, actual, ignoreCase: true, culture) == 0) { - message += Environment.NewLine + FrameworkMessages.AreEqualCaseDiffersMsg; + message = FrameworkMessages.AreEqualCaseDiffersMsg; message += FormatAlignedParameters( (nameof(expected), FormatValue(expected)), (nameof(actual), FormatValue(actual))); @@ -662,9 +665,10 @@ private static void ThrowAssertAreEqualFailed(string? expected, string? actual, else { // Use enhanced string comparison for string-specific failures - message = FormatStringComparisonMessage(expected, actual, message); + message = FormatStringComparisonMessage(expected, actual, string.Empty); } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -1179,11 +1183,11 @@ private static void ThrowAssertAreNotEqualFailed(T notExpected, T actual, T d where T : struct, IConvertible { string callSite = FormatCallSite("Assert.AreNotEqual", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreNotEqualDeltaGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); + string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreNotEqualDeltaGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); message += FormatAlignedParameters( - (nameof(notExpected), FormatValue(notExpected)), + ("not expected", FormatValue(notExpected)), (nameof(actual), FormatValue(actual))); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -1385,11 +1389,11 @@ private static bool AreNotEqualFailing(T? notExpected, T? actual, IEqualityCo private static void ThrowAssertAreNotEqualFailed(object? notExpected, object? actual, string? userMessage, string notExpectedExpression, string actualExpression) { string callSite = FormatCallSite("Assert.AreNotEqual", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.AreNotEqualFailNew; + string message = FrameworkMessages.AreNotEqualFailNew; message += FormatAlignedParameters( - (nameof(notExpected), FormatValue(notExpected)), + ("not expected", FormatValue(notExpected)), (nameof(actual), FormatValue(actual))); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index b85e4b1dbf..3c9841e27c 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -189,7 +189,6 @@ private static bool IsAreSameFailing(T? expected, T? actual) private static void ThrowAssertAreSameFailed(T? expected, T? actual, string? userMessage, string expectedExpression, string actualExpression) { string callSite = FormatCallSite("Assert.AreSame", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; // When both values have the same string representation, include hash codes // to help the user understand they are different object instances. @@ -203,20 +202,22 @@ private static void ThrowAssertAreSameFailed(T? expected, T? actual, string? ? actualFormatted + $" (Hash={RuntimeHelpers.GetHashCode(actual!)})" : actualFormatted; + string message; // If value types, add diagnostic hint before parameter details if (expected is ValueType && actual is ValueType) { - message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreSameGivenValues, string.Empty).TrimEnd(); + message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreSameGivenValues, string.Empty).TrimEnd(); } else { - message += Environment.NewLine + FrameworkMessages.AreSameFailNew; + message = FrameworkMessages.AreSameFailNew; } message += FormatAlignedParameters( (nameof(expected), expectedValue), (nameof(actual), actualValue)); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -272,11 +273,11 @@ private static bool IsAreNotSameFailing(T? notExpected, T? actual) private static void ThrowAssertAreNotSameFailed(T? notExpected, T? actual, string? userMessage, string notExpectedExpression, string actualExpression) { string callSite = FormatCallSite("Assert.AreNotSame", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.AreNotSameFailNew; + string message = FrameworkMessages.AreNotSameFailNew; message += FormatAlignedParameters( - (nameof(notExpected), FormatValue(notExpected)), + ("not expected", FormatValue(notExpected)), (nameof(actual), FormatValue(actual))); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs index c2b07a811e..2c3e04319c 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs @@ -781,8 +781,8 @@ public static void IsInRange(T minValue, T maxValue, T value, string? message private static void ThrowAssertSingleMatchFailed(int actualCount, string? userMessage, string predicateExpression, string collectionExpression) { string callSite = FormatCallSite("Assert.ContainsSingle", ("predicate", predicateExpression), ("collection", collectionExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleMatchFailNew, actualCount); + string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleMatchFailNew, actualCount); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -790,8 +790,8 @@ private static void ThrowAssertSingleMatchFailed(int actualCount, string? userMe private static void ThrowAssertContainsSingleFailed(int actualCount, string? userMessage, string collectionExpression) { string callSite = FormatCallSite("Assert.ContainsSingle", ("collection", collectionExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleFailNew, actualCount); + string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleFailNew, actualCount); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -799,13 +799,13 @@ private static void ThrowAssertContainsSingleFailed(int actualCount, string? use private static void ThrowAssertContainsItemFailed(string? userMessage, string expectedExpression, string collectionExpression, IEnumerable? collectionValue = null) { string callSite = FormatCallSite("Assert.Contains", ("expected", expectedExpression), ("collection", collectionExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.ContainsItemFailNew; + string message = FrameworkMessages.ContainsItemFailNew; if (collectionValue is not null) { message += FormatCollectionParameter(collectionExpression, collectionValue); } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -813,13 +813,13 @@ private static void ThrowAssertContainsItemFailed(string? userMessage, string ex private static void ThrowAssertContainsPredicateFailed(string? userMessage, string predicateExpression, string collectionExpression, IEnumerable? collectionValue = null) { string callSite = FormatCallSite("Assert.Contains", ("predicate", predicateExpression), ("collection", collectionExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.ContainsPredicateFailNew; + string message = FrameworkMessages.ContainsPredicateFailNew; if (collectionValue is not null) { message += FormatCollectionParameter(collectionExpression, collectionValue); } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -827,13 +827,13 @@ private static void ThrowAssertContainsPredicateFailed(string? userMessage, stri private static void ThrowAssertDoesNotContainItemFailed(string? userMessage, string notExpectedExpression, string collectionExpression, IEnumerable? collectionValue = null) { string callSite = FormatCallSite("Assert.DoesNotContain", ("notExpected", notExpectedExpression), ("collection", collectionExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.DoesNotContainItemFailNew; + string message = FrameworkMessages.DoesNotContainItemFailNew; if (collectionValue is not null) { message += FormatCollectionParameter(collectionExpression, collectionValue); } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -841,13 +841,13 @@ private static void ThrowAssertDoesNotContainItemFailed(string? userMessage, str private static void ThrowAssertDoesNotContainPredicateFailed(string? userMessage, string predicateExpression, string collectionExpression, IEnumerable? collectionValue = null) { string callSite = FormatCallSite("Assert.DoesNotContain", ("predicate", predicateExpression), ("collection", collectionExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.DoesNotContainPredicateFailNew; + string message = FrameworkMessages.DoesNotContainPredicateFailNew; if (collectionValue is not null) { message += FormatCollectionParameter(collectionExpression, collectionValue); } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -855,11 +855,11 @@ private static void ThrowAssertDoesNotContainPredicateFailed(string? userMessage private static void ThrowAssertStringContainsFailed(string value, string substring, string? userMessage, string substringExpression, string valueExpression) { string callSite = FormatCallSite("Assert.Contains", (nameof(substring), substringExpression), (nameof(value), valueExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.ContainsStringFailNew; + string message = FrameworkMessages.ContainsStringFailNew; message += FormatAlignedParameters( (nameof(substring), FormatValue(substring)), (nameof(value), FormatValue(value))); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -867,11 +867,11 @@ private static void ThrowAssertStringContainsFailed(string value, string substri private static void ThrowAssertStringDoesNotContainFailed(string value, string substring, string? userMessage, string substringExpression, string valueExpression) { string callSite = FormatCallSite("Assert.DoesNotContain", (nameof(substring), substringExpression), (nameof(value), valueExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.DoesNotContainStringFailNew; + string message = FrameworkMessages.DoesNotContainStringFailNew; message += FormatAlignedParameters( (nameof(substring), FormatValue(substring)), (nameof(value), FormatValue(value))); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -879,12 +879,11 @@ private static void ThrowAssertStringDoesNotContainFailed(string value, string s private static void ThrowAssertIsInRangeFailed(T value, T minValue, T maxValue, string? userMessage, string minValueExpression, string maxValueExpression, string valueExpression) { string callSite = FormatCallSite("Assert.IsInRange", (nameof(value), valueExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.IsInRangeFailNew; + string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsInRangeFailNew, FormatValue(value), FormatValue(minValue), FormatValue(maxValue)); message += FormatAlignedParameters( - (nameof(minValue), FormatValue(minValue)), - (nameof(maxValue), FormatValue(maxValue)), + ("range", $"[{FormatValue(minValue)}, {FormatValue(maxValue)}]"), (nameof(value), FormatValue(value))); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs index 4caa57a8dd..159e6134b8 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs @@ -337,11 +337,12 @@ private static void HasCount(string assertionName, int expected, IEnumerable col private static void ThrowAssertCountFailed(string assertionName, int expectedCount, int actualCount, IEnumerable collection, string? userMessage, string collectionExpression) { string callSite = FormatCallSite($"Assert.{assertionName}", ("collection", collectionExpression)); - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - msg += Environment.NewLine + FrameworkMessages.HasCountFailNew; + string msg = FrameworkMessages.HasCountFailNew; msg += FormatCollectionParameter(collectionExpression, collection); - msg += $"{Environment.NewLine} expectedCount: {expectedCount}"; - msg += $"{Environment.NewLine} actualCount: {actualCount}"; + msg += FormatAlignedParameters( + ("expected count", expectedCount.ToString(CultureInfo.InvariantCulture)), + ("actual count", actualCount.ToString(CultureInfo.InvariantCulture))); + msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -349,8 +350,8 @@ private static void ThrowAssertCountFailed(string assertionName, int expectedCou private static void ThrowAssertIsNotEmptyFailed(string? userMessage, string collectionExpression) { string callSite = FormatCallSite("Assert.IsNotEmpty", ("collection", collectionExpression)); - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - msg += Environment.NewLine + FrameworkMessages.IsNotEmptyFailNew; + string msg = FrameworkMessages.IsNotEmptyFailNew; + msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs b/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs index 1b1bc6ef7f..5aec763303 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs @@ -77,11 +77,11 @@ public static void EndsWith([NotNull] string? expectedSuffix, [NotNull] string? if (!value.EndsWith(expectedSuffix, comparisonType)) { string callSite = FormatCallSite("Assert.EndsWith", (nameof(expectedSuffix), expectedSuffixExpression), (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; - msg += Environment.NewLine + FrameworkMessages.EndsWithFailNew; + string msg = FrameworkMessages.EndsWithFailNew; msg += FormatAlignedParameters( - (nameof(expectedSuffix), FormatValue(expectedSuffix)), + ("expected suffix", FormatValue(expectedSuffix)), (nameof(value), FormatValue(value))); + msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } } @@ -155,11 +155,11 @@ public static void DoesNotEndWith([NotNull] string? notExpectedSuffix, [NotNull] if (value.EndsWith(notExpectedSuffix, comparisonType)) { string callSite = FormatCallSite("Assert.DoesNotEndWith", (nameof(notExpectedSuffix), notExpectedSuffixExpression), (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; - msg += Environment.NewLine + FrameworkMessages.DoesNotEndWithFailNew; + string msg = FrameworkMessages.DoesNotEndWithFailNew; msg += FormatAlignedParameters( - (nameof(notExpectedSuffix), FormatValue(notExpectedSuffix)), + ("unwanted suffix", FormatValue(notExpectedSuffix)), (nameof(value), FormatValue(value))); + msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Fail.cs b/src/TestFramework/TestFramework/Assertions/Assert.Fail.cs index 3a3a4ebd24..80df01ea55 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Fail.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Fail.cs @@ -22,5 +22,5 @@ public sealed partial class Assert /// [DoesNotReturn] public static void Fail(string message = "") - => ThrowAssertFailed("Assert.Fail", BuildUserMessage(message)); + => ThrowAssertFailed("Assert.Fail", string.IsNullOrEmpty(message) ? null : message); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs b/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs index 5767ee98a4..8154f57ace 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs @@ -292,11 +292,11 @@ public static void IsNegative(T value, string? message = "", [CallerArgumentE private static void ThrowAssertIsGreaterThanFailed(T lowerBound, T value, string? userMessage, string lowerBoundExpression, string valueExpression) { string callSite = FormatCallSite("Assert.IsGreaterThan", (nameof(lowerBound), lowerBoundExpression), (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - msg += Environment.NewLine + FrameworkMessages.IsGreaterThanFailNew; + string msg = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsGreaterThanFailNew, FormatValue(value), FormatValue(lowerBound)); msg += FormatAlignedParameters( - (nameof(lowerBound), FormatValue(lowerBound)), + ("lower bound", FormatValue(lowerBound)), (nameof(value), FormatValue(value))); + msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -304,11 +304,11 @@ private static void ThrowAssertIsGreaterThanFailed(T lowerBound, T value, str private static void ThrowAssertIsGreaterThanOrEqualToFailed(T lowerBound, T value, string? userMessage, string lowerBoundExpression, string valueExpression) { string callSite = FormatCallSite("Assert.IsGreaterThanOrEqualTo", (nameof(lowerBound), lowerBoundExpression), (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - msg += Environment.NewLine + FrameworkMessages.IsGreaterThanOrEqualToFailNew; + string msg = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsGreaterThanOrEqualToFailNew, FormatValue(value), FormatValue(lowerBound)); msg += FormatAlignedParameters( - (nameof(lowerBound), FormatValue(lowerBound)), + ("lower bound", FormatValue(lowerBound)), (nameof(value), FormatValue(value))); + msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -316,11 +316,11 @@ private static void ThrowAssertIsGreaterThanOrEqualToFailed(T lowerBound, T v private static void ThrowAssertIsLessThanFailed(T upperBound, T value, string? userMessage, string upperBoundExpression, string valueExpression) { string callSite = FormatCallSite("Assert.IsLessThan", (nameof(upperBound), upperBoundExpression), (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - msg += Environment.NewLine + FrameworkMessages.IsLessThanFailNew; + string msg = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsLessThanFailNew, FormatValue(value), FormatValue(upperBound)); msg += FormatAlignedParameters( - (nameof(upperBound), FormatValue(upperBound)), + ("upper bound", FormatValue(upperBound)), (nameof(value), FormatValue(value))); + msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -328,11 +328,11 @@ private static void ThrowAssertIsLessThanFailed(T upperBound, T value, string private static void ThrowAssertIsLessThanOrEqualToFailed(T upperBound, T value, string? userMessage, string upperBoundExpression, string valueExpression) { string callSite = FormatCallSite("Assert.IsLessThanOrEqualTo", (nameof(upperBound), upperBoundExpression), (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - msg += Environment.NewLine + FrameworkMessages.IsLessThanOrEqualToFailNew; + string msg = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsLessThanOrEqualToFailNew, FormatValue(value), FormatValue(upperBound)); msg += FormatAlignedParameters( - (nameof(upperBound), FormatValue(upperBound)), + ("upper bound", FormatValue(upperBound)), (nameof(value), FormatValue(value))); + msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -340,9 +340,9 @@ private static void ThrowAssertIsLessThanOrEqualToFailed(T upperBound, T valu private static void ThrowAssertIsPositiveFailed(T value, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsPositive", (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - msg += Environment.NewLine + FrameworkMessages.IsPositiveFailNew; + string msg = FrameworkMessages.IsPositiveFailNew; msg += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -350,9 +350,9 @@ private static void ThrowAssertIsPositiveFailed(T value, string? userMessage, private static void ThrowAssertIsNegativeFailed(T value, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsNegative", (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - msg += Environment.NewLine + FrameworkMessages.IsNegativeFailNew; + string msg = FrameworkMessages.IsNegativeFailNew; msg += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs index 4c22ee086e..a9b2083e57 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs @@ -323,23 +323,23 @@ private static bool IsExactInstanceOfTypeFailing([NotNullWhen(false)] object? va private static void ThrowAssertIsExactInstanceOfTypeFailed(object? value, Type? expectedType, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsExactInstanceOfType", (nameof(value), valueExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.IsExactInstanceOfTypeFailNew; + string message = FrameworkMessages.IsExactInstanceOfTypeFailNew; message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (expectedType is null) { - message += Environment.NewLine + " expectedType: (null)"; + message += Environment.NewLine + " expected type: (null)"; } else { - message += Environment.NewLine + $" expectedType: {FormatType(expectedType)}"; + message += Environment.NewLine + $" expected type: {FormatType(expectedType)}"; if (value is not null) { - message += Environment.NewLine + $" actualType: {FormatType(value.GetType())}"; + message += Environment.NewLine + $" actual type: {FormatType(value.GetType())}"; } } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -406,20 +406,20 @@ private static bool IsNotExactInstanceOfTypeFailing(object? value, [NotNullWhen( private static void ThrowAssertIsNotExactInstanceOfTypeFailed(object? value, Type? wrongType, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsNotExactInstanceOfType", (nameof(value), valueExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.IsNotExactInstanceOfTypeFailNew; + string message = FrameworkMessages.IsNotExactInstanceOfTypeFailNew; message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (wrongType is null) { - message += Environment.NewLine + " wrongType: (null)"; + message += Environment.NewLine + " wrong type: (null)"; } else { - message += Environment.NewLine + $" wrongType: {FormatType(wrongType)}" - + Environment.NewLine + $" actualType: {FormatType(value!.GetType())}"; + message += Environment.NewLine + $" wrong type: {FormatType(wrongType)}" + + Environment.NewLine + $" actual type: {FormatType(value!.GetType())}"; } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index ff3faba408..de54c60168 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -330,23 +330,23 @@ private static bool IsInstanceOfTypeFailing([NotNullWhen(false)] object? value, private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expectedType, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsInstanceOfType", (nameof(value), valueExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.IsInstanceOfTypeFailNew; + string message = FrameworkMessages.IsInstanceOfTypeFailNew; message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (expectedType is null) { - message += Environment.NewLine + " expectedType: (null)"; + message += Environment.NewLine + " expected type: (null)"; } else { - message += Environment.NewLine + $" expectedType: {FormatType(expectedType)}"; + message += Environment.NewLine + $" expected type: {FormatType(expectedType)}"; if (value is not null) { - message += Environment.NewLine + $" actualType: {FormatType(value.GetType())}"; + message += Environment.NewLine + $" actual type: {FormatType(value.GetType())}"; } } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -415,20 +415,20 @@ private static bool IsNotInstanceOfTypeFailing(object? value, [NotNullWhen(false private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wrongType, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsNotInstanceOfType", (nameof(value), valueExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.IsNotInstanceOfTypeFailNew; + string message = FrameworkMessages.IsNotInstanceOfTypeFailNew; message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (wrongType is null) { - message += Environment.NewLine + " wrongType: (null)"; + message += Environment.NewLine + " wrong type: (null)"; } else { - message += Environment.NewLine + $" wrongType: {FormatType(wrongType)}" - + Environment.NewLine + $" actualType: {FormatType(value!.GetType())}"; + message += Environment.NewLine + $" wrong type: {FormatType(wrongType)}" + + Environment.NewLine + $" actual type: {FormatType(value!.GetType())}"; } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 12c9b24844..3a8f0cbe7a 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -163,12 +163,8 @@ private static void ThrowAssertIsNullFailed(object? value, string? userMessage, { string callSite = FormatCallSite("Assert.IsNull", (nameof(value), valueExpression)); string message = FrameworkMessages.IsNullFailNew; - if (!string.IsNullOrEmpty(userMessage)) - { - message += Environment.NewLine + userMessage; - } - message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -213,12 +209,7 @@ private static void ThrowAssertIsNotNullFailed(string? userMessage, string value { string callSite = FormatCallSite("Assert.IsNotNull", ("value", valueExpression)); string message = FrameworkMessages.IsNotNullFailNew; - if (!string.IsNullOrEmpty(userMessage)) - { - message += Environment.NewLine + userMessage; - } - - message += Environment.NewLine + FormatParameter("value", valueExpression, null); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 1ea772f961..18ba993561 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -163,9 +163,9 @@ private static bool IsTrueFailing(bool? condition) private static void ThrowAssertIsTrueFailed(bool? condition, string? userMessage, string conditionExpression) { string callSite = FormatCallSite("Assert.IsTrue", (nameof(condition), conditionExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.IsTrueFailNew; + string message = FrameworkMessages.IsTrueFailNew; message += Environment.NewLine + FormatParameter(nameof(condition), conditionExpression, condition); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -208,9 +208,9 @@ private static bool IsFalseFailing(bool? condition) private static void ThrowAssertIsFalseFailed(bool? condition, string? userMessage, string conditionExpression) { string callSite = FormatCallSite("Assert.IsFalse", (nameof(condition), conditionExpression)); - string message = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage!; - message += Environment.NewLine + FrameworkMessages.IsFalseFailNew; + string message = FrameworkMessages.IsFalseFailNew; message += Environment.NewLine + FormatParameter(nameof(condition), conditionExpression, condition); + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs b/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs index ce2f23fe09..f2eff640ef 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs @@ -45,11 +45,11 @@ public static void MatchesRegex([NotNull] Regex? pattern, [NotNull] string? valu if (!pattern.IsMatch(value)) { string callSite = FormatCallSite("Assert.MatchesRegex", (nameof(pattern), patternExpression), (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; - msg += Environment.NewLine + FrameworkMessages.MatchesRegexFailNew; + string msg = FrameworkMessages.MatchesRegexFailNew; msg += FormatAlignedParameters( (nameof(pattern), FormatValue(pattern)), (nameof(value), FormatValue(value))); + msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } } @@ -125,11 +125,11 @@ public static void DoesNotMatchRegex([NotNull] Regex? pattern, [NotNull] string? if (pattern.IsMatch(value)) { string callSite = FormatCallSite("Assert.DoesNotMatchRegex", (nameof(pattern), patternExpression), (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; - msg += Environment.NewLine + FrameworkMessages.DoesNotMatchRegexFailNew; + string msg = FrameworkMessages.DoesNotMatchRegexFailNew; msg += FormatAlignedParameters( (nameof(pattern), FormatValue(pattern)), (nameof(value), FormatValue(value))); + msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs b/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs index 47f94e657e..2695d15ae1 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs @@ -77,11 +77,11 @@ public static void StartsWith([NotNull] string? expectedPrefix, [NotNull] string if (!value.StartsWith(expectedPrefix, comparisonType)) { string callSite = FormatCallSite("Assert.StartsWith", (nameof(expectedPrefix), expectedPrefixExpression), (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; - msg += Environment.NewLine + FrameworkMessages.StartsWithFailNew; + string msg = FrameworkMessages.StartsWithFailNew; msg += FormatAlignedParameters( - (nameof(expectedPrefix), FormatValue(expectedPrefix)), + ("expected prefix", FormatValue(expectedPrefix)), (nameof(value), FormatValue(value))); + msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } } @@ -153,11 +153,11 @@ public static void DoesNotStartWith([NotNull] string? notExpectedPrefix, [NotNul if (value.StartsWith(notExpectedPrefix, comparisonType)) { string callSite = FormatCallSite("Assert.DoesNotStartWith", (nameof(notExpectedPrefix), notExpectedPrefixExpression), (nameof(value), valueExpression)); - string msg = string.IsNullOrEmpty(message) ? string.Empty : message!; - msg += Environment.NewLine + FrameworkMessages.DoesNotStartWithFailNew; + string msg = FrameworkMessages.DoesNotStartWithFailNew; msg += FormatAlignedParameters( - (nameof(notExpectedPrefix), FormatValue(notExpectedPrefix)), + ("unwanted prefix", FormatValue(notExpectedPrefix)), (nameof(value), FormatValue(value))); + msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs index 482f274ebd..e4b2151484 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs @@ -530,11 +530,11 @@ private static async Task IsThrowsAsyncFailingAsync { - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; - msg += Environment.NewLine + FrameworkMessages.WrongExceptionThrownNew; + string msg = FrameworkMessages.WrongExceptionThrownNew; msg += FormatExpressionParameter(nameof(action), actionExpr); - msg += Environment.NewLine + $" expectedExceptionType: {FormatType(typeof(TException))}"; - msg += Environment.NewLine + $" actualExceptionType: {FormatType(ex.GetType())}"; + msg += Environment.NewLine + $" expected exception type: {FormatType(typeof(TException))}"; + msg += Environment.NewLine + $" actual exception type: {FormatType(ex.GetType())}"; + msg = AppendUserMessage(msg, string.IsNullOrEmpty(userMessage) ? null : userMessage); ThrowAssertFailed("Assert." + assertMethodName, msg); }, ex); } @@ -542,10 +542,10 @@ private static async Task IsThrowsAsyncFailingAsync { - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; - msg += Environment.NewLine + FrameworkMessages.NoExceptionThrownNew; + string msg = FrameworkMessages.NoExceptionThrownNew; msg += FormatExpressionParameter(nameof(action), actionExpr); - msg += Environment.NewLine + $" expectedExceptionType: {FormatType(typeof(TException))}"; + msg += Environment.NewLine + $" expected exception type: {FormatType(typeof(TException))}"; + msg = AppendUserMessage(msg, string.IsNullOrEmpty(userMessage) ? null : userMessage); ThrowAssertFailed("Assert." + assertMethodName, msg); }, null); } @@ -568,11 +568,11 @@ private static ThrowsExceptionState IsThrowsFailing(Action action, b : ThrowsExceptionState.CreateFailingState( (userMessage, actionExpr) => { - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; - msg += Environment.NewLine + FrameworkMessages.WrongExceptionThrownNew; + string msg = FrameworkMessages.WrongExceptionThrownNew; msg += FormatExpressionParameter(nameof(action), actionExpr); - msg += Environment.NewLine + $" expectedExceptionType: {FormatType(typeof(TException))}"; - msg += Environment.NewLine + $" actualExceptionType: {FormatType(ex.GetType())}"; + msg += Environment.NewLine + $" expected exception type: {FormatType(typeof(TException))}"; + msg += Environment.NewLine + $" actual exception type: {FormatType(ex.GetType())}"; + msg = AppendUserMessage(msg, string.IsNullOrEmpty(userMessage) ? null : userMessage); ThrowAssertFailed("Assert." + assertMethodName, msg); }, ex); } @@ -580,10 +580,10 @@ private static ThrowsExceptionState IsThrowsFailing(Action action, b return ThrowsExceptionState.CreateFailingState( failAction: (userMessage, actionExpr) => { - string msg = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; - msg += Environment.NewLine + FrameworkMessages.NoExceptionThrownNew; + string msg = FrameworkMessages.NoExceptionThrownNew; msg += FormatExpressionParameter(nameof(action), actionExpr); - msg += Environment.NewLine + $" expectedExceptionType: {FormatType(typeof(TException))}"; + msg += Environment.NewLine + $" expected exception type: {FormatType(typeof(TException))}"; + msg = AppendUserMessage(msg, string.IsNullOrEmpty(userMessage) ? null : userMessage); ThrowAssertFailed("Assert." + assertMethodName, msg); }, null); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index d2b8811c8f..f65bcb9571 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -50,16 +50,9 @@ internal static void ThrowAssertFailed(string assertionName, string? message) } } - string formattedMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AssertionFailed, assertionName, message); - - // When there's no user message (message starts with newline for parameter details), - // the format produces a trailing space before the newline ("failed. \\r\\n"). - // Remove it to avoid trailing whitespace on the first line while preserving localization. - if (message is not null && message.StartsWith(Environment.NewLine, StringComparison.Ordinal)) - { - string prefix = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AssertionFailed, assertionName, string.Empty); - formattedMessage = prefix.TrimEnd() + message; - } + string formattedMessage = string.IsNullOrEmpty(message) + ? assertionName + : assertionName + Environment.NewLine + message; throw new AssertFailedException(formattedMessage); } @@ -306,6 +299,15 @@ internal static string FormatParameter(string paramName, string expression, T return $" {paramName}: {formattedValue}"; } + /// + /// Appends the user-provided message to the end of a failure message. + /// Returns the message unchanged if userMessage is null or empty. + /// + internal static string AppendUserMessage(string message, string? userMessage) + => string.IsNullOrEmpty(userMessage) + ? message + : message + Environment.NewLine + "User message: " + userMessage; + /// /// Formats a parameter line showing only the expression (no value). /// Used for parameters like predicates and actions where the diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index bd7318bbc9..7650bb8e77 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -340,10 +340,10 @@ Actual: {2} Expected collection to have the specified number of items. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. Wrong exception type was thrown. @@ -379,25 +379,25 @@ Actual: {2} Expected value to be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. Expected value to be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. Expected a positive value. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index a229fece41..659dc3a41c 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -257,18 +257,18 @@ Skutečnost: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Skutečnost: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Skutečnost: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index ab3f60c972..c6433cb9f2 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -257,18 +257,18 @@ Tatsächlich: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Tatsächlich: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Tatsächlich: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index 3763d9fb75..bfd4307c9a 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -257,18 +257,18 @@ Real: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Real: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Real: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index 03a0d4f808..054e7d9b3b 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -257,18 +257,18 @@ Réel : {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Réel : {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Réel : {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index 7e12682ae4..2dcb6cccf7 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -257,18 +257,18 @@ Effettivo: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Effettivo: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Effettivo: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index 138c1af1bc..4ce118216d 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -257,18 +257,18 @@ Actual: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Actual: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Actual: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index ae11d31c37..4560c3d2c5 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -257,18 +257,18 @@ Actual: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Actual: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Actual: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index 85a600b21e..eaea87216d 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -257,18 +257,18 @@ Rzeczywiste: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Rzeczywiste: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Rzeczywiste: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index f625c93b62..7b5b0c96d4 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -257,18 +257,18 @@ Real: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Real: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Real: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index 742f1cfb95..b611f41218 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -257,18 +257,18 @@ Actual: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Actual: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Actual: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index c22762c18b..fa0113d718 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -257,18 +257,18 @@ Gerçekte olan: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Gerçekte olan: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Gerçekte olan: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index 0f22457021..ff23039f5a 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -257,18 +257,18 @@ Actual: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Actual: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Actual: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index 743d50c404..976dec8119 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -257,18 +257,18 @@ Actual: {2} - Expected value to be greater than the specified bound. - Expected value to be greater than the specified bound. + Expected value ({0}) to be greater than {1}. + Expected value ({0}) to be greater than {1}. - Expected value to be greater than or equal to the specified bound. - Expected value to be greater than or equal to the specified bound. + Expected value ({0}) to be greater than or equal to {1}. + Expected value ({0}) to be greater than or equal to {1}. - Value is not within the expected range. - Value is not within the expected range. + Expected value ({0}) to be in range [{1}, {2}]. + Expected value ({0}) to be in range [{1}, {2}]. @@ -282,13 +282,13 @@ Actual: {2} - Expected value to be less than the specified bound. - Expected value to be less than the specified bound. + Expected value ({0}) to be less than {1}. + Expected value ({0}) to be less than {1}. - Expected value to be less than or equal to the specified bound. - Expected value to be less than or equal to the specified bound. + Expected value ({0}) to be less than or equal to {1}. + Expected value ({0}) to be less than or equal to {1}. @@ -302,18 +302,18 @@ Actual: {2} - Expected collection to contain any item but it is empty. - Expected collection to contain any item but it is empty. + Expected collection to not be empty. + Expected collection to not be empty. - Value should not be exactly of the specified type. - Value should not be exactly of the specified type. + Expected value to not be exactly the specified type. + Expected value to not be exactly the specified type. - Value should not be of the specified type. - Value should not be of the specified type. + Expected value to not be an instance of the specified type. + Expected value to not be an instance of the specified type. diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index 59da63b0fb..d36e8df807 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -20,10 +20,11 @@ public void AreNotEqualShouldFailWhenNotEqualTypeWithMessage() Action action = () => Assert.AreNotEqual(1, 1, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(1, 1) failed. A Message + Assert.AreNotEqual(1, 1) Expected values to differ. - notExpected: 1 - actual: 1 + not expected: 1 + actual: 1 + User message: A Message """); } @@ -38,10 +39,11 @@ public void AreNotEqualShouldFailWhenNotEqualStringWithMessage() Action action = () => Assert.AreNotEqual("A", "A", "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual("A", "A") failed. A Message + Assert.AreNotEqual("A", "A") Expected values to differ. - notExpected: "A" - actual: "A" + not expected: "A" + actual: "A" + User message: A Message """); } @@ -63,10 +65,11 @@ public void AreNotEqualShouldFailWhenNotEqualIntWithMessage() Action action = () => Assert.AreNotEqual(1, 1, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(1, 1) failed. A Message + Assert.AreNotEqual(1, 1) Expected values to differ. - notExpected: 1 - actual: 1 + not expected: 1 + actual: 1 + User message: A Message """); } @@ -81,10 +84,11 @@ public void AreNotEqualShouldFailWhenNotEqualLongWithMessage() Action action = () => Assert.AreNotEqual(1L, 1L, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(1L, 1L) failed. A Message + Assert.AreNotEqual(1L, 1L) Expected values to differ. - notExpected: 1 - actual: 1 + not expected: 1 + actual: 1 + User message: A Message """); } @@ -105,10 +109,11 @@ public void AreNotEqualShouldFailWhenNotEqualDecimalWithMessage() Action action = () => Assert.AreNotEqual(0.1M, 0.1M, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(0.1M, 0.1M) failed. A Message + Assert.AreNotEqual(0.1M, 0.1M) Expected values to differ. - notExpected: 0.1 - actual: 0.1 + not expected: 0.1 + actual: 0.1 + User message: A Message """); } @@ -129,10 +134,11 @@ public void AreNotEqualShouldFailWhenNotEqualDoubleWithMessage() Action action = () => Assert.AreNotEqual(0.1, 0.1, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(0.1, 0.1) failed. A Message + Assert.AreNotEqual(0.1, 0.1) Expected values to differ. - notExpected: 0.1 - actual: 0.1 + not expected: 0.1 + actual: 0.1 + User message: A Message """); } @@ -153,10 +159,11 @@ public void AreNotEqualShouldFailWhenFloatDoubleWithMessage() Action action = () => Assert.AreNotEqual(100E-2, 100E-2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(100E-2, 100E-2) failed. A Message + Assert.AreNotEqual(100E-2, 100E-2) Expected values to differ. - notExpected: 1 - actual: 1 + not expected: 1 + actual: 1 + User message: A Message """); } @@ -177,10 +184,11 @@ public void AreEqualShouldFailWhenNotEqualTypeWithMessage() Action action = () => Assert.AreEqual(null, "string", "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(null, "string") failed. A Message + Assert.AreEqual(null, "string") Expected values to be equal. expected: null actual: "string" + User message: A Message """); } @@ -215,7 +223,7 @@ public void AreEqual_WithEnglishCultureAndDoesNotIgnoreCase_Throws() Action action = () => Assert.AreEqual(expected, actual, false, englishCulture); action.Should().Throw() .WithMessage("""" - Assert.AreEqual(expected, actual) failed. + Assert.AreEqual(expected, actual) Case differs. expected: "i" actual: "I" @@ -257,10 +265,11 @@ public void AreEqualShouldFailWhenNotEqualIntWithMessage() Action action = () => Assert.AreEqual(1, 2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(1, 2) failed. A Message + Assert.AreEqual(1, 2) Expected values to be equal. expected: 1 actual: 2 + User message: A Message """); } @@ -275,10 +284,11 @@ public void AreEqualShouldFailWhenNotEqualLongWithMessage() Action action = () => Assert.AreEqual(1L, 2L, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(1L, 2L) failed. A Message + Assert.AreEqual(1L, 2L) Expected values to be equal. expected: 1 actual: 2 + User message: A Message """); } @@ -299,10 +309,11 @@ public void AreEqualShouldFailWhenNotEqualDoubleWithMessage() Action action = () => Assert.AreEqual(0.1, 0.2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(0.1, 0.2) failed. A Message + Assert.AreEqual(0.1, 0.2) Expected values to be equal. expected: 0.1 actual: 0.2 + User message: A Message """); } @@ -324,10 +335,11 @@ public void AreEqualShouldFailWhenNotEqualDecimalWithMessage() Action action = () => Assert.AreEqual(0.1M, 0.2M, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(0.1M, 0.2M) failed. A Message + Assert.AreEqual(0.1M, 0.2M) Expected values to be equal. expected: 0.1 actual: 0.2 + User message: A Message """); } @@ -348,10 +360,11 @@ public void AreEqualShouldFailWhenFloatDoubleWithMessage() Action action = () => Assert.AreEqual(100E-2, 200E-2, "A Message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(100E-2, 200E-2) failed. A Message + Assert.AreEqual(100E-2, 200E-2) Expected values to be equal. expected: 1 actual: 2 + User message: A Message """); } @@ -372,7 +385,7 @@ public void AreEqualTwoObjectsDifferentTypeShouldFail() Action action = () => Assert.AreEqual(new object(), 1); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(new object(), 1) failed. + Assert.AreEqual(new object(), 1) Expected values to be equal. expected: actual: 1 () @@ -448,10 +461,11 @@ public async Task GenericAreEqual_InterpolatedString_DifferentValues_ShouldFail( Func action = async () => Assert.AreEqual(0, 1, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(0, 1) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(0, 1) Expected values to be equal. expected: 0 actual: 1 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -470,10 +484,11 @@ public async Task GenericAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(0, 0, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(0, 0) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(0, 0) Expected values to differ. - notExpected: 0 - actual: 0 + not expected: 0 + actual: 0 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -492,10 +507,11 @@ public async Task FloatAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1.0f, 1.1f, 0.001f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(1.0f, 1.1f) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(1.0f, 1.1f) Expected a difference no greater than 0.001. expected: 1 actual: 1.1 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -514,10 +530,11 @@ public async Task FloatAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0f, 1.1f, 0.2f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(1.0f, 1.1f) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(1.0f, 1.1f) Expected a difference greater than 0.2. - notExpected: 1 - actual: 1.1 + not expected: 1 + actual: 1.1 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -536,10 +553,11 @@ public async Task DecimalAreEqual_InterpolatedString_DifferentValues_ShouldFail( Func action = async () => Assert.AreEqual(1.0m, 1.1m, 0.001m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(1.0m, 1.1m) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(1.0m, 1.1m) Expected a difference no greater than 0.001. expected: 1.0 actual: 1.1 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -558,10 +576,11 @@ public async Task DecimalAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0m, 1.1m, 0.2m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(1.0m, 1.1m) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(1.0m, 1.1m) Expected a difference greater than 0.2. - notExpected: 1.0 - actual: 1.1 + not expected: 1.0 + actual: 1.1 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -580,10 +599,11 @@ public async Task LongAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1L, 2L, 0L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(1L, 2L) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(1L, 2L) Expected a difference no greater than 0. expected: 1 actual: 2 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -602,10 +622,11 @@ public async Task LongAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1L, 2L, 1L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(1L, 2L) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(1L, 2L) Expected a difference greater than 1. - notExpected: 1 - actual: 2 + not expected: 1 + actual: 2 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -624,10 +645,11 @@ public async Task DoubleAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1.0d, 1.1d, 0.001d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(1.0d, 1.1d) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreEqual(1.0d, 1.1d) Expected a difference no greater than 0.001. expected: 1 actual: 1.1 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -646,10 +668,11 @@ public async Task DoubleAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0d, 1.1d, 0.2d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(1.0d, 1.1d) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotEqual(1.0d, 1.1d) Expected a difference greater than 0.2. - notExpected: 1 - actual: 1.1 + not expected: 1 + actual: 1.1 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -823,7 +846,7 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif { Action action = () => Assert.AreEqual(5.0f, 2.0f, 2.0f); // difference is 3. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreEqual(5.0f, 2.0f) failed. + Assert.AreEqual(5.0f, 2.0f) Expected a difference no greater than 2. expected: 5 actual: 2 @@ -834,7 +857,7 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif { Action action = () => Assert.AreEqual(2.0f, 5.0f, 2.0f); // difference is -3. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreEqual(2.0f, 5.0f) failed. + Assert.AreEqual(2.0f, 5.0f) Expected a difference no greater than 2. expected: 2 actual: 5 @@ -851,7 +874,7 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFai { Action action = () => Assert.AreEqual(5.0f, float.NaN, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreEqual(5.0f, float.NaN) failed. + Assert.AreEqual(5.0f, float.NaN) Expected a difference no greater than 2. expected: 5 actual: NaN @@ -862,7 +885,7 @@ public void FloatAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFai { Action action = () => Assert.AreEqual(float.NaN, 5.0f, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreEqual(float.NaN, 5.0f) failed. + Assert.AreEqual(float.NaN, 5.0f) Expected a difference no greater than 2. expected: NaN actual: 5 @@ -1055,10 +1078,10 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual { Action action = () => Assert.AreNotEqual(5.0f, 4.0f, 2.0f); // difference is 1. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreNotEqual(5.0f, 4.0f) failed. + Assert.AreNotEqual(5.0f, 4.0f) Expected a difference greater than 2. - notExpected: 5 - actual: 4 + not expected: 5 + actual: 4 """"); } @@ -1066,10 +1089,10 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual { Action action = () => Assert.AreNotEqual(4.0f, 5.0f, 2.0f); // difference is -1. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreNotEqual(4.0f, 5.0f) failed. + Assert.AreNotEqual(4.0f, 5.0f) Expected a difference greater than 2. - notExpected: 4 - actual: 5 + not expected: 4 + actual: 5 """"); } @@ -1082,10 +1105,10 @@ public void FloatAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFail { Action action = () => Assert.AreNotEqual(float.NaN, float.NaN, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreNotEqual(float.NaN, float.NaN) failed. + Assert.AreNotEqual(float.NaN, float.NaN) Expected a difference greater than 2. - notExpected: NaN - actual: NaN + not expected: NaN + actual: NaN """"); } @@ -1271,7 +1294,7 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi Action action = () => Assert.AreEqual(5.0d, 2.0d, 2.0d); // difference is 3. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreEqual(5.0d, 2.0d) failed. + Assert.AreEqual(5.0d, 2.0d) Expected a difference no greater than 2. expected: 5 actual: 2 @@ -1283,7 +1306,7 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi Action action = () => Assert.AreEqual(2.0d, 5.0d, 2.0d); // difference is -3. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreEqual(2.0d, 5.0d) failed. + Assert.AreEqual(2.0d, 5.0d) Expected a difference no greater than 2. expected: 2 actual: 5 @@ -1301,7 +1324,7 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFa Action action = () => Assert.AreEqual(5.0d, double.NaN, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreEqual(5.0d, double.NaN) failed. + Assert.AreEqual(5.0d, double.NaN) Expected a difference no greater than 2. expected: 5 actual: NaN @@ -1313,7 +1336,7 @@ public void DoubleAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFa Action action = () => Assert.AreEqual(double.NaN, 5.0d, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreEqual(double.NaN, 5.0d) failed. + Assert.AreEqual(double.NaN, 5.0d) Expected a difference no greater than 2. expected: NaN actual: 5 @@ -1514,10 +1537,10 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua Action action = () => Assert.AreNotEqual(5.0d, 4.0d, 2.0d); // difference is 1. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual(5.0d, 4.0d) failed. + Assert.AreNotEqual(5.0d, 4.0d) Expected a difference greater than 2. - notExpected: 5 - actual: 4 + not expected: 5 + actual: 4 """"); } @@ -1526,10 +1549,10 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua Action action = () => Assert.AreNotEqual(4.0d, 5.0d, 2.0d); // difference is -1. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual(4.0d, 5.0d) failed. + Assert.AreNotEqual(4.0d, 5.0d) Expected a difference greater than 2. - notExpected: 4 - actual: 5 + not expected: 4 + actual: 5 """"); } @@ -1543,10 +1566,10 @@ public void DoubleAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFai Action action = () => Assert.AreNotEqual(double.NaN, double.NaN, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual(double.NaN, double.NaN) failed. + Assert.AreNotEqual(double.NaN, double.NaN) Expected a difference greater than 2. - notExpected: NaN - actual: NaN + not expected: NaN + actual: NaN """"); } @@ -1606,7 +1629,7 @@ public void AreEqualStringDifferenceAtBeginning() Action action = () => Assert.AreEqual("baaa", "aaaa"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual("baaa", "aaaa") failed. + Assert.AreEqual("baaa", "aaaa") String lengths are both 4 but differ at index 0. expected: "baaa" actual: "aaaa" @@ -1619,7 +1642,7 @@ public void AreEqualStringDifferenceAtEnd() Action action = () => Assert.AreEqual("aaaa", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual("aaaa", "aaab") failed. + Assert.AreEqual("aaaa", "aaab") String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" @@ -1632,7 +1655,7 @@ public void AreEqualStringWithSpecialCharactersShouldEscape() Action action = () => Assert.AreEqual("aa\ta", "aa a"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual("aa\ta", "aa a") failed. + Assert.AreEqual("aa\ta", "aa a") String lengths are both 4 but differ at index 2. expected: "aa␉a" actual: "aa a" @@ -1648,7 +1671,7 @@ public void AreEqualLongStringsShouldTruncateAndShowContext() Action action = () => Assert.AreEqual(expected, actual); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(expected, actual) failed. + Assert.AreEqual(expected, actual) String lengths are both 201 but differ at index 100. expected: "...aaaaaaaaaaaaaaaaaabcccccccccccccccc..." actual: "...aaaaaaaaaaaaaaaaaadcccccccccccccccc..." @@ -1661,7 +1684,7 @@ public void AreEqualStringWithCultureShouldUseEnhancedMessage() Action action = () => Assert.AreEqual("aaaa", "aaab", false, CultureInfo.InvariantCulture); action.Should().Throw() .WithMessage(""" - Assert.AreEqual("aaaa", "aaab") failed. + Assert.AreEqual("aaaa", "aaab") String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" @@ -1674,7 +1697,7 @@ public void AreEqualStringWithDifferentLength() Action action = () => Assert.AreEqual("aaaa", "aaa"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual("aaaa", "aaa") failed. + Assert.AreEqual("aaaa", "aaa") Expected string length 4 but was 3. expected: "aaaa" actual: "aaa" @@ -1687,7 +1710,7 @@ public void AreEqualShorterExpectedString() Action action = () => Assert.AreEqual("aaa", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual("aaa", "aaab") failed. + Assert.AreEqual("aaa", "aaab") Expected string length 3 but was 4. expected: "aaa" actual: "aaab" @@ -1700,11 +1723,12 @@ public void AreEqualStringWithUserMessage() Action action = () => Assert.AreEqual("aaaa", "aaab", "My custom message"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual("aaaa", "aaab") failed. My custom message + Assert.AreEqual("aaaa", "aaab") String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" --------------^ + User message: My custom message """); } @@ -1713,7 +1737,7 @@ public void AreEqualStringWithEmojis() Action action = () => Assert.AreEqual("??", "aaab"); action.Should().Throw() .WithMessage(""" - Assert.AreEqual("??", "aaab") failed. + Assert.AreEqual("??", "aaab") Expected string length 2 but was 4. expected: "??" actual: "aaab" @@ -1935,7 +1959,7 @@ public void AreEqual_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreEqual(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 2); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 2) failed. + Assert.AreEqual(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 2) Expected values to be equal. expected: 1 actual: 2 @@ -1950,7 +1974,7 @@ public void AreEqual_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreEqual(expected, actual); action.Should().Throw() .WithMessage($""" - Assert.AreEqual(expected, actual) failed. + Assert.AreEqual(expected, actual) Expected values to be equal. expected: {new string('L', 256)}... 44 more actual: {new string('L', 256)}... 44 more @@ -1965,7 +1989,7 @@ public void AreEqual_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreEqual(expected, actual); action.Should().Throw() .WithMessage(""" - Assert.AreEqual(expected, actual) failed. + Assert.AreEqual(expected, actual) Expected values to be equal. expected: line1\r\nline2\nline3 actual: line1\r\nline2\nline3 @@ -1979,10 +2003,10 @@ public void AreNotEqual_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreNotEqual(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 1); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 1) failed. + Assert.AreNotEqual(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 1) Expected values to differ. - notExpected: 1 - actual: 1 + not expected: 1 + actual: 1 """); } @@ -1993,10 +2017,10 @@ public void AreNotEqual_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreNotEqual(obj, obj); action.Should().Throw() .WithMessage($""" - Assert.AreNotEqual(obj, obj) failed. + Assert.AreNotEqual(obj, obj) Expected values to differ. - notExpected: {new string('L', 256)}... 44 more - actual: {new string('L', 256)}... 44 more + not expected: {new string('L', 256)}... 44 more + actual: {new string('L', 256)}... 44 more """); } @@ -2007,10 +2031,10 @@ public void AreNotEqual_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreNotEqual(obj, obj); action.Should().Throw() .WithMessage(""" - Assert.AreNotEqual(obj, obj) failed. + Assert.AreNotEqual(obj, obj) Expected values to differ. - notExpected: line1\r\nline2\nline3 - actual: line1\r\nline2\nline3 + not expected: line1\r\nline2\nline3 + actual: line1\r\nline2\nline3 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index 773564ded3..21dc12fd7b 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -17,7 +17,7 @@ public void AreSame_PassDifferentObject_ShouldFail() { Action action = () => Assert.AreSame(new object(), new object()); action.Should().Throw().WithMessage(""" - Assert.AreSame(new object(), new object()) failed. + Assert.AreSame(new object(), new object()) Expected references to be the same. expected: (Hash=*) actual: (Hash=*) @@ -34,10 +34,11 @@ public void AreSame_StringMessage_PassDifferentObject_ShouldFail() { Action action = () => Assert.AreSame(new object(), new object(), "User-provided message"); action.Should().Throw().WithMessage(""" - Assert.AreSame(new object(), new object()) failed. User-provided message + Assert.AreSame(new object(), new object()) Expected references to be the same. expected: (Hash=*) actual: (Hash=*) + User message: User-provided message """); } @@ -54,10 +55,11 @@ public async Task AreSame_InterpolatedString_PassDifferentObject_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreSame(new object(), new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()).WithMessage(""" - Assert.AreSame(new object(), new object()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreSame(new object(), new object()) Expected references to be the same. expected: (Hash=*) actual: (Hash=*) + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -69,7 +71,7 @@ public void AreSame_BothAreValueTypes_ShouldFailWithSpecializedMessage() { Action action = () => Assert.AreSame(1, 1); action.Should().Throw().WithMessage(""" - Assert.AreSame(1, 1) failed. + Assert.AreSame(1, 1) Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) actual: 1 (Hash=*) @@ -80,10 +82,11 @@ public void AreSame_StringMessage_BothAreValueTypes_ShouldFailWithSpecializedMes { Action action = () => Assert.AreSame(1, 1, "User-provided message"); action.Should().Throw().WithMessage(""" - Assert.AreSame(1, 1) failed. User-provided message + Assert.AreSame(1, 1) Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) actual: 1 (Hash=*) + User message: User-provided message """); } @@ -91,10 +94,11 @@ public void AreSame_InterpolatedString_BothAreValueTypes_ShouldFailWithSpecializ { Action action = () => Assert.AreSame(1, 1, $"User-provided message {new object().GetType()}"); action.Should().Throw().WithMessage(""" - Assert.AreSame(1, 1) failed. User-provided message System.Object + Assert.AreSame(1, 1) Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) actual: 1 (Hash=*) + User message: User-provided message System.Object """); } @@ -103,10 +107,10 @@ public void AreNotSame_PassSameObject_ShouldFail() object o = new(); Action action = () => Assert.AreNotSame(o, o); action.Should().Throw().WithMessage(""" - Assert.AreNotSame(o, o) failed. + Assert.AreNotSame(o, o) Expected references to be different. - notExpected: - actual: + not expected: + actual: """); } @@ -118,10 +122,11 @@ public void AreNotSame_StringMessage_PassSameObject_ShouldFail() object o = new(); Action action = () => Assert.AreNotSame(o, o, "User-provided message"); action.Should().Throw().WithMessage(""" - Assert.AreNotSame(o, o) failed. User-provided message + Assert.AreNotSame(o, o) Expected references to be different. - notExpected: - actual: + not expected: + actual: + User message: User-provided message """); } @@ -138,10 +143,11 @@ public async Task AreNotSame_InterpolatedString_PassSameObject_ShouldFail() DateTime dateTime = DateTime.Now; Func action = async () => Assert.AreNotSame(o, o, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()).WithMessage(""" - Assert.AreNotSame(o, o) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.AreNotSame(o, o) Expected references to be different. - notExpected: DummyClassTrackingToStringCalls - actual: DummyClassTrackingToStringCalls + not expected: DummyClassTrackingToStringCalls + actual: DummyClassTrackingToStringCalls + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -155,7 +161,7 @@ public void AreSame_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreSame(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, new object()); action.Should().Throw() .WithMessage(""" - Assert.AreSame(aVeryLongVariableNameThatExceedsOneHundredCharacte..., new object()) failed. + Assert.AreSame(aVeryLongVariableNameThatExceedsOneHundredCharacte..., new object()) Expected references to be the same. expected: (Hash=*) actual: (Hash=*) @@ -167,7 +173,7 @@ public void AreSame_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreSame(new ObjectWithLongToString(), new ObjectWithLongToString()); action.Should().Throw() .WithMessage($""" - Assert.AreSame(new ObjectWithLongToString(), new ObjectWithLongToString()) failed. + Assert.AreSame(new ObjectWithLongToString(), new ObjectWithLongToString()) Expected references to be the same. expected: {new string('L', 256)}... 44 more (Hash=*) actual: {new string('L', 256)}... 44 more (Hash=*) @@ -179,7 +185,7 @@ public void AreSame_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreSame(new ObjectWithNewlineToString(), new ObjectWithNewlineToString()); action.Should().Throw() .WithMessage(""" - Assert.AreSame(new ObjectWithNewlineToString(), new ObjectWithNewlineToString()) failed. + Assert.AreSame(new ObjectWithNewlineToString(), new ObjectWithNewlineToString()) Expected references to be the same. expected: line1\r\nline2\nline3 (Hash=*) actual: line1\r\nline2\nline3 (Hash=*) @@ -193,10 +199,10 @@ public void AreNotSame_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.AreNotSame(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.AreNotSame(aVeryLongVariableNameThatExceedsOneHundredCharacte..., aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.AreNotSame(aVeryLongVariableNameThatExceedsOneHundredCharacte..., aVeryLongVariableNameThatExceedsOneHundredCharacte...) Expected references to be different. - notExpected: - actual: + not expected: + actual: """); } @@ -207,10 +213,10 @@ public void AreNotSame_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.AreNotSame(obj, obj); action.Should().Throw() .WithMessage($""" - Assert.AreNotSame(obj, obj) failed. + Assert.AreNotSame(obj, obj) Expected references to be different. - notExpected: {new string('L', 256)}... 44 more - actual: {new string('L', 256)}... 44 more + not expected: {new string('L', 256)}... 44 more + actual: {new string('L', 256)}... 44 more """); } @@ -221,10 +227,10 @@ public void AreNotSame_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.AreNotSame(obj, obj); action.Should().Throw() .WithMessage(""" - Assert.AreNotSame(obj, obj) failed. + Assert.AreNotSame(obj, obj) Expected references to be different. - notExpected: line1\r\nline2\nline3 - actual: line1\r\nline2\nline3 + not expected: line1\r\nline2\nline3 + actual: line1\r\nline2\nline3 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index 9ef32a3d48..f4c864c991 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -339,7 +339,7 @@ public void ContainsSingle_InterpolatedHandler_WithMultipleElements_ThrowsExcept // Assert action.Should().Throw().WithMessage(""" - Assert.ContainsSingle(collection) failed. + Assert.ContainsSingle(collection) Expected collection to contain exactly one item but found 3 item(s). """); } @@ -372,7 +372,7 @@ public void ContainsSingle_InNonGenericCollection_NoMessage_WithEmptyCollection_ // Assert action.Should().Throw().WithMessage(""" - Assert.ContainsSingle(collection) failed. + Assert.ContainsSingle(collection) Expected collection to contain exactly one item but found 0 item(s). """); } @@ -390,8 +390,9 @@ public void ContainsSingle_InNonGenericCollection_AssertCustomMessage_WithEmptyC // Assert action.Should().Throw().WithMessage(""" - Assert.ContainsSingle(collection) failed. my custom message + Assert.ContainsSingle(collection) Expected collection to contain exactly one item but found 0 item(s). + User message: my custom message """); } #endregion @@ -427,8 +428,9 @@ public void Contains_ValueExpected_ItemDoesNotExist_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(20, collection) failed. Item 20 not found + Assert.Contains(20, collection) Expected collection to contain the specified item.* + User message: Item 20 not found """); } @@ -446,8 +448,9 @@ public void Contains_InNonGenericCollection_ValueExpected_ItemDoesNotExist_Throw // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(expected, collection) failed. Item 20 not found + Assert.Contains(expected, collection) Expected collection to contain the specified item.* + User message: Item 20 not found """); } @@ -495,8 +498,9 @@ public void Contains_InNonGenericCollection_NullableValueExpected_ItemDoesNotExi // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(expected, collection) failed. Item not found + Assert.Contains(expected, collection) Expected collection to contain the specified item.* + User message: Item not found """); } @@ -547,8 +551,9 @@ public void Contains_WithComparer_ItemDoesNotExist_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains("cherry", collection) failed. Missing cherry + Assert.Contains("cherry", collection) Expected collection to contain the specified item.* + User message: Missing cherry """); } @@ -596,8 +601,9 @@ public void Contains_Predicate_NoItemMatches_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(IsEven, collection) failed. No even number found + Assert.Contains(IsEven, collection) Expected at least one item to match the predicate.* + User message: No even number found """); } @@ -615,8 +621,9 @@ public void Contains_InNonGenericCollection_Predicate_NoItemMatches_ThrowsExcept // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(IsEven, collection) failed. No even number found + Assert.Contains(IsEven, collection) Expected at least one item to match the predicate.* + User message: No even number found """); } @@ -651,10 +658,11 @@ public void Contains_StringVersion_SubstringNotPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(substring, value) failed. Missing substring + Assert.Contains(substring, value) String does not contain the expected substring. substring: "lazy" value: "The quick brown fox" + User message: Missing substring """); } @@ -681,7 +689,7 @@ public void Contains_InNonGenericCollection_NullCollection_ThrowsException() Action action = () => Assert.Contains(1, collection); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. The parameter 'collection' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.Contains\nThe parameter 'collection' is invalid. The value cannot be null."); } /// @@ -698,7 +706,7 @@ public void Contains_InNonGenericCollection_WithComparer_NullCollection_ThrowsEx Action action = () => Assert.Contains(1, collection, comparer); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. The parameter 'collection' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.Contains\nThe parameter 'collection' is invalid. The value cannot be null."); } /// @@ -732,7 +740,7 @@ public void Contains_InNonGenericCollection_WithComparer_ItemDoesNotExist_Throws // Assert action.Should().Throw().WithMessage(""" - Assert.Contains("banana", collection) failed. + Assert.Contains("banana", collection) Expected collection to contain the specified item.* """); } @@ -750,7 +758,7 @@ public void Contains_InNonGenericCollection_Predicate_NullCollection_ThrowsExcep Action action = () => Assert.Contains(Predicate, collection); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. The parameter 'collection' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.Contains\nThe parameter 'collection' is invalid. The value cannot be null."); // Local functions static bool Predicate(object? x) => x is int i && i > 5; @@ -770,7 +778,7 @@ public void Contains_InNonGenericCollection_NullPredicate_ThrowsException() Action action = () => Assert.Contains(predicate, collection); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. The parameter 'predicate' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.Contains\nThe parameter 'predicate' is invalid. The value cannot be null."); } /// @@ -802,7 +810,7 @@ public void Contains_String_NullSubstring_ThrowsException() Action action = () => Assert.Contains(substring, value); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. The parameter 'substring' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.Contains\nThe parameter 'substring' is invalid. The value cannot be null."); } /// @@ -819,7 +827,7 @@ public void Contains_String_NullValue_ThrowsException() Action action = () => Assert.Contains(substring, value); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. The parameter 'value' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.Contains\nThe parameter 'value' is invalid. The value cannot be null."); } /// @@ -836,7 +844,7 @@ public void Contains_String_BothNull_ThrowsException() Action action = () => Assert.Contains(substring, value); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. The parameter 'value' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.Contains\nThe parameter 'value' is invalid. The value cannot be null."); } /// @@ -870,7 +878,7 @@ public void Contains_String_EmptyValue_WithNonEmptySubstring_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.Contains(substring, value) failed. + Assert.Contains(substring, value) String does not contain the expected substring. substring: "test" value: "" @@ -908,7 +916,7 @@ public void Contains_String_WithComparison_NullSubstring_ThrowsException() Action action = () => Assert.Contains(substring, value, StringComparison.OrdinalIgnoreCase); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. The parameter 'substring' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.Contains\nThe parameter 'substring' is invalid. The value cannot be null."); } /// @@ -925,7 +933,7 @@ public void Contains_String_WithComparison_NullValue_ThrowsException() Action action = () => Assert.Contains(substring, value, StringComparison.OrdinalIgnoreCase); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. The parameter 'value' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.Contains\nThe parameter 'value' is invalid. The value cannot be null."); } /// @@ -942,7 +950,7 @@ public void Contains_InNonGenericCollection_WithComparer_NullComparer_ThrowsExce Action action = () => Assert.Contains("apple", collection, comparer); // Assert - action.Should().Throw().WithMessage("Assert.Contains failed. The parameter 'comparer' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.Contains\nThe parameter 'comparer' is invalid. The value cannot be null."); } #endregion @@ -978,8 +986,9 @@ public void DoesNotContain_ValueExpected_ItemPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(10, collection) failed. Item 10 should not be found + Assert.DoesNotContain(10, collection) Expected collection to not contain the specified item.* + User message: Item 10 should not be found """); } @@ -1012,9 +1021,10 @@ public void DoesNotContain_InNonGenericCollection_ValueExpected_ItemPresent_Thro // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(10, collection) failed. Item 10 should not be found + Assert.DoesNotContain(10, collection) Expected collection to not contain the specified item. collection: [5, 10, 15, "a"] + User message: Item 10 should not be found """); } @@ -1065,8 +1075,9 @@ public void DoesNotContain_WithComparer_ItemPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain("APPLE", collection) failed. Unexpected "APPLE" + Assert.DoesNotContain("APPLE", collection) Expected collection to not contain the specified item.* + User message: Unexpected "APPLE" """); } @@ -1085,8 +1096,9 @@ public void DoesNotContain_InNonGenericCollection_WithComparer_ItemPresent_Throw // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain("APPLE", collection) failed. APPLE + Assert.DoesNotContain("APPLE", collection) Expected collection to not contain the specified item.* + User message: APPLE """); } @@ -1134,8 +1146,9 @@ public void DoesNotContain_Predicate_AtLeastOneItemMatches_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(IsEven, collection) failed. An even number exists + Assert.DoesNotContain(IsEven, collection) Expected no items to match the predicate.* + User message: An even number exists """); } @@ -1153,8 +1166,9 @@ public void DoesNotContain_InNonGenericCollection_Predicate_AtLeastOneItemMatche // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(IsEven, collection) failed. An even number exists + Assert.DoesNotContain(IsEven, collection) Expected no items to match the predicate.* + User message: An even number exists """); } @@ -1189,10 +1203,11 @@ public void DoesNotContain_StringVersion_SubstringPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(substring, value) failed. Unexpected substring + Assert.DoesNotContain(substring, value) String contains the unexpected substring. substring: "brown" value: "The quick brown fox" + User message: Unexpected substring """); } @@ -1229,10 +1244,11 @@ public void DoesNotContain_StringWithComparisonAndMessage_SubstringPresent_Throw // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(substring, value) failed. Found unexpected substring + Assert.DoesNotContain(substring, value) String contains the unexpected substring. substring: "BROWN" value: "The quick brown fox" + User message: Found unexpected substring """); } @@ -1267,7 +1283,7 @@ public void DoesNotContain_StringSimpleOverload_SubstringPresent_ThrowsException // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(substring, value) failed. + Assert.DoesNotContain(substring, value) String contains the unexpected substring. substring: "brown" value: "The quick brown fox" @@ -1305,10 +1321,11 @@ public void DoesNotContain_StringWithMessageOnly_SubstringPresent_ThrowsExceptio // Assert action.Should().Throw().WithMessage(""" - Assert.DoesNotContain(substring, value) failed. Found unexpected substring + Assert.DoesNotContain(substring, value) String contains the unexpected substring. substring: "brown" value: "The quick brown fox" + User message: Found unexpected substring """); } @@ -1325,7 +1342,7 @@ public void DoesNotContain_InNonGenericCollection_NullCollection_ThrowsException Action action = () => Assert.DoesNotContain(1, collection); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. The parameter 'collection' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.DoesNotContain\nThe parameter 'collection' is invalid. The value cannot be null."); } /// @@ -1342,7 +1359,7 @@ public void DoesNotContain_InNonGenericCollection_WithComparer_NullCollection_Th Action action = () => Assert.DoesNotContain(1, collection, comparer); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. The parameter 'collection' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.DoesNotContain\nThe parameter 'collection' is invalid. The value cannot be null."); } /// @@ -1359,7 +1376,7 @@ public void DoesNotContain_InNonGenericCollection_WithComparer_NullComparer_Thro Action action = () => Assert.DoesNotContain("cherry", collection, comparer); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. The parameter 'comparer' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.DoesNotContain\nThe parameter 'comparer' is invalid. The value cannot be null."); } /// @@ -1375,7 +1392,7 @@ public void DoesNotContain_InNonGenericCollection_Predicate_NullCollection_Throw Action action = () => Assert.DoesNotContain(Predicate, collection); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. The parameter 'collection' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.DoesNotContain\nThe parameter 'collection' is invalid. The value cannot be null."); // Local functions static bool Predicate(object? x) => x is int i && i > 5; @@ -1395,7 +1412,7 @@ public void DoesNotContain_InNonGenericCollection_NullPredicate_ThrowsException( Action action = () => Assert.DoesNotContain(predicate, collection); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. The parameter 'predicate' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.DoesNotContain\nThe parameter 'predicate' is invalid. The value cannot be null."); } /// @@ -1412,7 +1429,7 @@ public void DoesNotContain_String_NullSubstring_ThrowsException() Action action = () => Assert.DoesNotContain(substring, value); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. The parameter 'substring' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.DoesNotContain\nThe parameter 'substring' is invalid. The value cannot be null."); } /// @@ -1429,7 +1446,7 @@ public void DoesNotContain_String_NullValue_ThrowsException() Action action = () => Assert.DoesNotContain(substring, value); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. The parameter 'value' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.DoesNotContain\nThe parameter 'value' is invalid. The value cannot be null."); } /// @@ -1446,7 +1463,7 @@ public void DoesNotContain_String_WithComparison_NullSubstring_ThrowsException() Action action = () => Assert.DoesNotContain(substring, value, StringComparison.OrdinalIgnoreCase); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. The parameter 'substring' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.DoesNotContain\nThe parameter 'substring' is invalid. The value cannot be null."); } /// @@ -1463,7 +1480,7 @@ public void DoesNotContain_String_WithComparison_NullValue_ThrowsException() Action action = () => Assert.DoesNotContain(substring, value, StringComparison.OrdinalIgnoreCase); // Assert - action.Should().Throw().WithMessage("Assert.DoesNotContain failed. The parameter 'value' is invalid. The value cannot be null."); + action.Should().Throw().WithMessage("Assert.DoesNotContain\nThe parameter 'value' is invalid. The value cannot be null."); } private static bool IsEven(int x) => x % 2 == 0; @@ -1553,7 +1570,7 @@ public void ContainsSinglePredicate_NoItemMatches_ThrowsException() // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x % 2 == 0, collection) failed. + Assert.ContainsSingle(x => x % 2 == 0, collection) Expected exactly one item to match the predicate but found 0 item(s). """); } @@ -1573,7 +1590,7 @@ public void ContainsSinglePredicate_InNonGenericCollection_NoItemMatches_ThrowsE // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) failed. + Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) Expected exactly one item to match the predicate but found 0 item(s). """); } @@ -1593,7 +1610,7 @@ public void ContainsSinglePredicate_MultipleItemsMatch_ThrowsException() // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x % 2 == 0, collection) failed. + Assert.ContainsSingle(x => x % 2 == 0, collection) Expected exactly one item to match the predicate but found 4 item(s). """); } @@ -1613,7 +1630,7 @@ public void ContainsSinglePredicate_InNonGenericCollection_MultipleItemsMatch_Th // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) failed. + Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) Expected exactly one item to match the predicate but found 2 item(s). """); } @@ -1633,8 +1650,9 @@ public void ContainsSinglePredicate_WithMessage_NoItemMatches_ThrowsException() // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x % 2 == 0, collection) failed. No even numbers found in collection with 3 items + Assert.ContainsSingle(x => x % 2 == 0, collection) Expected exactly one item to match the predicate but found 0 item(s). + User message: No even numbers found in collection with 3 items """); } @@ -1653,8 +1671,9 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_NoItemMat // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) failed. No even numbers found in collection with 3 items + Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) Expected exactly one item to match the predicate but found 0 item(s). + User message: No even numbers found in collection with 3 items """); } @@ -1673,8 +1692,9 @@ public void ContainsSinglePredicate_WithMessage_MultipleItemsMatch_ThrowsExcepti // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x % 2 == 0, collection) failed. Too many even numbers found: 3 + Assert.ContainsSingle(x => x % 2 == 0, collection) Expected exactly one item to match the predicate but found 3 item(s). + User message: Too many even numbers found: 3 """); } @@ -1693,8 +1713,9 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_MultipleI // Assert action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) failed. Too many even numbers found: 2 + Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) Expected exactly one item to match the predicate but found 2 item(s). + User message: Too many even numbers found: 2 """); } @@ -1788,7 +1809,7 @@ public void Contains_ItemNotFound_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.Contains(5, collection) failed. + Assert.Contains(5, collection) Expected collection to contain the specified item.* collection: [1, 2, 3] """); @@ -1808,7 +1829,7 @@ public void Contains_InNonGenericCollection_ItemNotFound_ShowsSpecificErrorMessa // Assert action.Should().Throw() .WithMessage(""" - Assert.Contains(5, collection) failed. + Assert.Contains(5, collection) Expected collection to contain the specified item.* collection: [1, 2, 3] """); @@ -1828,7 +1849,7 @@ public void Contains_PredicateNotMatched_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.Contains(x => x % 2 == 0, collection) failed. + Assert.Contains(x => x % 2 == 0, collection) Expected at least one item to match the predicate.* collection: [1, 3, 5] """); @@ -1848,7 +1869,7 @@ public void DoesNotContain_ItemFound_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain(2, collection) failed. + Assert.DoesNotContain(2, collection) Expected collection to not contain the specified item.* collection: [1, 2, 3] """); @@ -1868,7 +1889,7 @@ public void DoesNotContain_PredicateMatched_ShowsSpecificErrorMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain(x => x % 2 == 0, collection) failed. + Assert.DoesNotContain(x => x % 2 == 0, collection) Expected no items to match the predicate.* collection: [1, 2, 3] """); @@ -1925,7 +1946,7 @@ public void Contains_String_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.Contains("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.Contains("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.Contains("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) String does not contain the expected substring. substring: "world" value: "hello" @@ -1939,7 +1960,7 @@ public void Contains_String_WithLongValue_ShouldTruncateValue() Action action = () => Assert.Contains("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.Contains("world", longValue) failed. + Assert.Contains("world", longValue) String does not contain the expected substring. substring: "world" value: "{new string('x', 255)}... 46 more @@ -1951,7 +1972,7 @@ public void Contains_String_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.Contains("world", "hello\r\nfoo"); action.Should().Throw() .WithMessage(""" - Assert.Contains("world", "hello\r\nfoo") failed. + Assert.Contains("world", "hello\r\nfoo") String does not contain the expected substring. substring: "world" value: "hello\r\nfoo" @@ -1965,7 +1986,7 @@ public void DoesNotContain_String_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotContain("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.DoesNotContain("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) String contains the unexpected substring. substring: "hello" value: "hello world" @@ -1979,7 +2000,7 @@ public void DoesNotContain_String_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotContain("hello", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotContain("hello", longValue) failed. + Assert.DoesNotContain("hello", longValue) String contains the unexpected substring. substring: "hello" value: "hello{new string('x', 250)}... 51 more @@ -1991,7 +2012,7 @@ public void DoesNotContain_String_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotContain("hello", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotContain("hello", "hello\r\nworld") failed. + Assert.DoesNotContain("hello", "hello\r\nworld") String contains the unexpected substring. substring: "hello" value: "hello\r\nworld" diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs index 537ec66b74..f8541f560f 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs @@ -17,10 +17,10 @@ public void EndsWith_WhenValueDoesNotEndWithSuffix_ShouldFail() Action action = () => Assert.EndsWith("hello", "world"); action.Should().Throw() .WithMessage(""" - Assert.EndsWith("hello", "world") failed. + Assert.EndsWith("hello", "world") String does not end with expected suffix. - expectedSuffix: "hello" - value: "world" + expected suffix: "hello" + value: "world" """); } @@ -29,10 +29,11 @@ public void EndsWith_WithMessage_WhenValueDoesNotEndWithSuffix_ShouldFail() Action action = () => Assert.EndsWith("hello", "world", "User message"); action.Should().Throw() .WithMessage(""" - Assert.EndsWith("hello", "world") failed. User message + Assert.EndsWith("hello", "world") String does not end with expected suffix. - expectedSuffix: "hello" - value: "world" + expected suffix: "hello" + value: "world" + User message: User message """); } @@ -44,10 +45,10 @@ public void DoesNotEndWith_WhenValueEndsWithSuffix_ShouldFail() Action action = () => Assert.DoesNotEndWith("world", "hello world"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotEndWith("world", "hello world") failed. + Assert.DoesNotEndWith("world", "hello world") String ends with unexpected suffix. - notExpectedSuffix: "world" - value: "hello world" + unwanted suffix: "world" + value: "hello world" """); } @@ -62,10 +63,10 @@ public void EndsWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.EndsWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.EndsWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.EndsWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) String does not end with expected suffix. - expectedSuffix: "hello" - value: "hello world" + expected suffix: "hello" + value: "hello world" """); } @@ -76,10 +77,10 @@ public void EndsWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.EndsWith("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.EndsWith("world", longValue) failed. + Assert.EndsWith("world", longValue) String does not end with expected suffix. - expectedSuffix: "world" - value: "{new string('x', 255)}... 46 more + expected suffix: "world" + value: "{new string('x', 255)}... 46 more """); } @@ -88,10 +89,10 @@ public void EndsWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.EndsWith("world", "hello\r\nfoo"); action.Should().Throw() .WithMessage(""" - Assert.EndsWith("world", "hello\r\nfoo") failed. + Assert.EndsWith("world", "hello\r\nfoo") String does not end with expected suffix. - expectedSuffix: "world" - value: "hello\r\nfoo" + expected suffix: "world" + value: "hello\r\nfoo" """); } @@ -102,10 +103,10 @@ public void DoesNotEndWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotEndWith("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotEndWith("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.DoesNotEndWith("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) String ends with unexpected suffix. - notExpectedSuffix: "world" - value: "hello world" + unwanted suffix: "world" + value: "hello world" """); } @@ -116,10 +117,10 @@ public void DoesNotEndWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotEndWith("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotEndWith("world", longValue) failed. + Assert.DoesNotEndWith("world", longValue) String ends with unexpected suffix. - notExpectedSuffix: "world" - value: "{new string('x', 255)}... 51 more + unwanted suffix: "world" + value: "{new string('x', 255)}... 51 more """); } @@ -128,10 +129,10 @@ public void DoesNotEndWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotEndWith("world", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotEndWith("world", "hello\r\nworld") failed. + Assert.DoesNotEndWith("world", "hello\r\nworld") String ends with unexpected suffix. - notExpectedSuffix: "world" - value: "hello\r\nworld" + unwanted suffix: "world" + value: "hello\r\nworld" """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs index d8d25a1e32..e86251bd15 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs @@ -43,10 +43,11 @@ public void IsGreaterThanShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThan(10, 5) failed. A Message - Expected value to be greater than the specified bound. - lowerBound: 10 - value: 5 + Assert.IsGreaterThan(10, 5) + Expected value (5) to be greater than 10. + lower bound: 10 + value: 5 + User message: A Message """); } @@ -92,10 +93,11 @@ public void IsGreaterThanOrEqualToShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThanOrEqualTo(10, 5) failed. A Message - Expected value to be greater than or equal to the specified bound. - lowerBound: 10 - value: 5 + Assert.IsGreaterThanOrEqualTo(10, 5) + Expected value (5) to be greater than or equal to 10. + lower bound: 10 + value: 5 + User message: A Message """); } @@ -141,10 +143,11 @@ public void IsLessThanShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsLessThan(5, 10) failed. A Message - Expected value to be less than the specified bound. - upperBound: 5 - value: 10 + Assert.IsLessThan(5, 10) + Expected value (10) to be less than 5. + upper bound: 5 + value: 10 + User message: A Message """); } @@ -190,10 +193,11 @@ public void IsLessThanOrEqualToShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsLessThanOrEqualTo(5, 10) failed. A Message - Expected value to be less than or equal to the specified bound. - upperBound: 5 - value: 10 + Assert.IsLessThanOrEqualTo(5, 10) + Expected value (10) to be less than or equal to 5. + upper bound: 5 + value: 10 + User message: A Message """); } @@ -254,9 +258,10 @@ public void IsPositiveShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsPositive(-5) failed. A Message + Assert.IsPositive(-5) Expected a positive value. value: -5 + User message: A Message """); } @@ -323,9 +328,10 @@ public void IsNegativeShouldThrowWithMessage() // Assert action.Should().Throw() .WithMessage(""" - Assert.IsNegative(5) failed. A Message + Assert.IsNegative(5) Expected a negative value. value: 5 + User message: A Message """); } @@ -352,10 +358,10 @@ public void IsGreaterThan_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsGreaterThan(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 5); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThan(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 5) failed. - Expected value to be greater than the specified bound. - lowerBound: 10 - value: 5 + Assert.IsGreaterThan(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 5) + Expected value (5) to be greater than 10. + lower bound: 10 + value: 5 """); } @@ -367,10 +373,10 @@ public void IsGreaterThan_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsGreaterThan(lowerBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsGreaterThan(lowerBound, value) failed. - Expected value to be greater than the specified bound. - lowerBound: {new string('V', 256)}... 44 more - value: {new string('V', 256)}... 44 more + Assert.IsGreaterThan(lowerBound, value) + Expected value ({new string('V', 256)}... 44 more) to be greater than {new string('V', 256)}... 44 more. + lower bound: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -382,10 +388,10 @@ public void IsGreaterThan_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsGreaterThan(lowerBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThan(lowerBound, value) failed. - Expected value to be greater than the specified bound. - lowerBound: line1\r\nline2 - value: line1\r\nline2 + Assert.IsGreaterThan(lowerBound, value) + Expected value (line1\r\nline2) to be greater than line1\r\nline2. + lower bound: line1\r\nline2 + value: line1\r\nline2 """); } @@ -396,10 +402,10 @@ public void IsGreaterThanOrEqualTo_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsGreaterThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 5); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 5) failed. - Expected value to be greater than or equal to the specified bound. - lowerBound: 10 - value: 5 + Assert.IsGreaterThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 5) + Expected value (5) to be greater than or equal to 10. + lower bound: 10 + value: 5 """); } @@ -411,10 +417,10 @@ public void IsGreaterThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsGreaterThanOrEqualTo(lowerBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsGreaterThanOrEqualTo(lowerBound, value) failed. - Expected value to be greater than or equal to the specified bound. - lowerBound: {new string('V', 256)}... 44 more - value: {new string('V', 256)}... 44 more + Assert.IsGreaterThanOrEqualTo(lowerBound, value) + Expected value ({new string('V', 256)}... 44 more) to be greater than or equal to {new string('V', 256)}... 44 more. + lower bound: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -426,10 +432,10 @@ public void IsGreaterThanOrEqualTo_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsGreaterThanOrEqualTo(lowerBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsGreaterThanOrEqualTo(lowerBound, value) failed. - Expected value to be greater than or equal to the specified bound. - lowerBound: line1\r\nline2 - value: line1\r\nline2 + Assert.IsGreaterThanOrEqualTo(lowerBound, value) + Expected value (line1\r\nline2) to be greater than or equal to line1\r\nline2. + lower bound: line1\r\nline2 + value: line1\r\nline2 """); } @@ -440,10 +446,10 @@ public void IsLessThan_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsLessThan(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 10); action.Should().Throw() .WithMessage(""" - Assert.IsLessThan(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 10) failed. - Expected value to be less than the specified bound. - upperBound: 5 - value: 10 + Assert.IsLessThan(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 10) + Expected value (10) to be less than 5. + upper bound: 5 + value: 10 """); } @@ -455,10 +461,10 @@ public void IsLessThan_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsLessThan(upperBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsLessThan(upperBound, value) failed. - Expected value to be less than the specified bound. - upperBound: {new string('V', 256)}... 44 more - value: {new string('V', 256)}... 44 more + Assert.IsLessThan(upperBound, value) + Expected value ({new string('V', 256)}... 44 more) to be less than {new string('V', 256)}... 44 more. + upper bound: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -470,10 +476,10 @@ public void IsLessThan_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsLessThan(upperBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsLessThan(upperBound, value) failed. - Expected value to be less than the specified bound. - upperBound: line1\r\nline2 - value: line1\r\nline2 + Assert.IsLessThan(upperBound, value) + Expected value (line1\r\nline2) to be less than line1\r\nline2. + upper bound: line1\r\nline2 + value: line1\r\nline2 """); } @@ -484,10 +490,10 @@ public void IsLessThanOrEqualTo_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsLessThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, 10); action.Should().Throw() .WithMessage(""" - Assert.IsLessThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 10) failed. - Expected value to be less than or equal to the specified bound. - upperBound: 5 - value: 10 + Assert.IsLessThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 10) + Expected value (10) to be less than or equal to 5. + upper bound: 5 + value: 10 """); } @@ -499,10 +505,10 @@ public void IsLessThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsLessThanOrEqualTo(upperBound, value); action.Should().Throw() .WithMessage($""" - Assert.IsLessThanOrEqualTo(upperBound, value) failed. - Expected value to be less than or equal to the specified bound. - upperBound: {new string('V', 256)}... 44 more - value: {new string('V', 256)}... 44 more + Assert.IsLessThanOrEqualTo(upperBound, value) + Expected value ({new string('V', 256)}... 44 more) to be less than or equal to {new string('V', 256)}... 44 more. + upper bound: {new string('V', 256)}... 44 more + value: {new string('V', 256)}... 44 more """); } @@ -514,10 +520,10 @@ public void IsLessThanOrEqualTo_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsLessThanOrEqualTo(upperBound, value); action.Should().Throw() .WithMessage(""" - Assert.IsLessThanOrEqualTo(upperBound, value) failed. - Expected value to be less than or equal to the specified bound. - upperBound: line1\r\nline2 - value: line1\r\nline2 + Assert.IsLessThanOrEqualTo(upperBound, value) + Expected value (line1\r\nline2) to be less than or equal to line1\r\nline2. + upper bound: line1\r\nline2 + value: line1\r\nline2 """); } @@ -528,7 +534,7 @@ public void IsPositive_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsPositive(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsPositive(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.IsPositive(aVeryLongVariableNameThatExceedsOneHundredCharacte...) Expected a positive value. value: -5 """); @@ -541,7 +547,7 @@ public void IsNegative_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsNegative(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsNegative(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.IsNegative(aVeryLongVariableNameThatExceedsOneHundredCharacte...) Expected a negative value. value: 5 """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index 574255890e..c9c459fab4 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -13,10 +13,10 @@ public void ExactInstanceOfTypeShouldFailWhenValueIsNull() Action action = () => Assert.IsExactInstanceOfType(null, typeof(AssertTests)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(null) failed. +Assert.IsExactInstanceOfType(null) Expected value to be exactly of the specified type. value: null - expectedType: + expected type: """); } @@ -25,10 +25,10 @@ public void ExactInstanceOfTypeShouldFailWhenTypeIsNull() Action action = () => Assert.IsExactInstanceOfType(5, null); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(5) failed. +Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expectedType: (null) + expected type: (null) """); } @@ -37,11 +37,11 @@ public void ExactInstanceOfTypeShouldFailWhenTypeIsMismatched() Action action = () => Assert.IsExactInstanceOfType(5, typeof(string)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(5) failed. +Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expectedType: - actualType: + expected type: + actual type: """); } @@ -52,11 +52,11 @@ public void ExactInstanceOfTypeShouldFailOnHigherInstance() Action action = () => Assert.IsExactInstanceOfType(5, typeof(object)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(5) failed. +Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expectedType: - actualType: + expected type: + actual type: """); } @@ -66,11 +66,11 @@ public void ExactInstanceOfTypeShouldFailOnDerivedType() Action action = () => Assert.IsExactInstanceOfType(x, typeof(Stream)); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(x) failed. +Assert.IsExactInstanceOfType(x) Expected value to be exactly of the specified type. value: - expectedType: - actualType: + expected type: + actual type: """); } @@ -85,10 +85,11 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() Action action = () => Assert.IsExactInstanceOfType(null, typeof(AssertTests), "User-provided message"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(null) failed. User-provided message +Assert.IsExactInstanceOfType(null) Expected value to be exactly of the specified type. value: null - expectedType: + expected type: +User message: User-provided message """); } @@ -97,10 +98,11 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() Action action = () => Assert.IsExactInstanceOfType(5, null, "User-provided message"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(5) failed. User-provided message +Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expectedType: (null) + expected type: (null) +User message: User-provided message """); } @@ -109,11 +111,12 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched Action action = () => Assert.IsExactInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(5) failed. User-provided message +Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expectedType: - actualType: + expected type: + actual type: +User message: User-provided message """); } @@ -127,10 +130,11 @@ public async Task ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenValue Func action = async () => Assert.IsExactInstanceOfType(null, typeof(AssertTests), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsExactInstanceOfType(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsExactInstanceOfType(null) Expected value to be exactly of the specified type. value: null - expectedType: + expected type: + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -141,10 +145,11 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull( Action action = () => Assert.IsExactInstanceOfType(5, null, $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls +Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expectedType: (null) + expected type: (null) +User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); } @@ -155,11 +160,12 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMisma Action action = () => Assert.IsExactInstanceOfType(5, typeof(string), $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls +Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expectedType: - actualType: + expected type: + actual type: +User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); } @@ -178,10 +184,10 @@ public void ExactInstanceNotOfTypeShouldFailWhenTypeIsNull() Action action = () => Assert.IsNotExactInstanceOfType(5, null); action.Should().Throw() .WithMessage(""" -Assert.IsNotExactInstanceOfType(5) failed. -Value should not be exactly of the specified type. +Assert.IsNotExactInstanceOfType(5) +Expected value to not be exactly the specified type. value: 5 - wrongType: (null) + wrong type: (null) """); } @@ -201,11 +207,11 @@ public void ExactInstanceNotOfTypeShouldFailOnExactType() Action action = () => Assert.IsNotExactInstanceOfType(x, typeof(MemoryStream)); action.Should().Throw() .WithMessage(""" -Assert.IsNotExactInstanceOfType(x) failed. -Value should not be exactly of the specified type. +Assert.IsNotExactInstanceOfType(x) +Expected value to not be exactly the specified type. value: - wrongType: - actualType: + wrong type: + actual type: """); } @@ -214,10 +220,10 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() Action action = () => Assert.IsExactInstanceOfType(null); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(null) failed. +Assert.IsExactInstanceOfType(null) Expected value to be exactly of the specified type. value: null - expectedType: + expected type: """); } @@ -226,11 +232,11 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() Action action = () => Assert.IsExactInstanceOfType(5); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(5) failed. +Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expectedType: - actualType: + expected type: + actual type: """); } @@ -240,11 +246,11 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenDerivedType_Fails() Action action = () => Assert.IsExactInstanceOfType(x); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(x) failed. +Assert.IsExactInstanceOfType(x) Expected value to be exactly of the specified type. value: - expectedType: - actualType: + expected type: + actual type: """); } @@ -268,11 +274,11 @@ public void IsExactInstanceOfTypeUsingGenericType_OnHigherInstance_Fails() Action action = () => Assert.IsExactInstanceOfType(5); action.Should().Throw() .WithMessage(""" -Assert.IsExactInstanceOfType(5) failed. +Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expectedType: - actualType: + expected type: + actual type: """); } @@ -301,11 +307,11 @@ public void IsNotExactInstanceOfTypeUsingGenericType_OnExactType_Fails() Action action = () => Assert.IsNotExactInstanceOfType(x); action.Should().Throw() .WithMessage(""" -Assert.IsNotExactInstanceOfType(x) failed. -Value should not be exactly of the specified type. +Assert.IsNotExactInstanceOfType(x) +Expected value to not be exactly the specified type. value: - wrongType: - actualType: + wrong type: + actual type: """); } @@ -388,11 +394,11 @@ public void IsExactInstanceOfType_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.IsExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) Expected value to be exactly of the specified type. value: "hello" - expectedType: - actualType: + expected type: + actual type: """); } @@ -403,11 +409,11 @@ public void IsExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsExactInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage($""" - Assert.IsExactInstanceOfType(obj) failed. + Assert.IsExactInstanceOfType(obj) Expected value to be exactly of the specified type. value: {new string('L', 256)}... 44 more - expectedType: - actualType: + expected type: + actual type: """); } @@ -418,11 +424,11 @@ public void IsExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsExactInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsExactInstanceOfType(obj) failed. + Assert.IsExactInstanceOfType(obj) Expected value to be exactly of the specified type. value: line1\r\nline2\nline3 - expectedType: - actualType: + expected type: + actual type: """); } @@ -433,11 +439,11 @@ public void IsNotExactInstanceOfType_WithLongExpression_ShouldTruncateExpression Action action = () => Assert.IsNotExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(string)); action.Should().Throw() .WithMessage(""" - Assert.IsNotExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. - Value should not be exactly of the specified type. + Assert.IsNotExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) + Expected value to not be exactly the specified type. value: "hello" - wrongType: - actualType: + wrong type: + actual type: """); } @@ -448,11 +454,11 @@ public void IsNotExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsNotExactInstanceOfType(obj, typeof(ObjectWithLongToString)); action.Should().Throw() .WithMessage($""" - Assert.IsNotExactInstanceOfType(obj) failed. - Value should not be exactly of the specified type. + Assert.IsNotExactInstanceOfType(obj) + Expected value to not be exactly the specified type. value: {new string('L', 256)}... 44 more - wrongType: - actualType: + wrong type: + actual type: """); } @@ -463,11 +469,11 @@ public void IsNotExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines( Action action = () => Assert.IsNotExactInstanceOfType(obj, typeof(ObjectWithNewlineToString)); action.Should().Throw() .WithMessage(""" - Assert.IsNotExactInstanceOfType(obj) failed. - Value should not be exactly of the specified type. + Assert.IsNotExactInstanceOfType(obj) + Expected value to not be exactly the specified type. value: line1\r\nline2\nline3 - wrongType: - actualType: + wrong type: + actual type: """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index b511a61536..2cbc74ecaa 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -58,11 +58,10 @@ public void IsInRange_WithValueBelowRange_ThrowsAssertFailedException() Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().Throw() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: 5 - maxValue: 10 - value: 3 + Assert.IsInRange(value) + Expected value (3) to be in range [5, 10]. + range: [5, 10] + value: 3 """); } @@ -77,11 +76,10 @@ public void IsInRange_WithValueAboveRange_ThrowsAssertFailedException() Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().Throw() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: 1 - maxValue: 5 - value: 8 + Assert.IsInRange(value) + Expected value (8) to be in range [1, 5]. + range: [1, 5] + value: 8 """); } @@ -99,11 +97,11 @@ public void IsInRange_WithCustomMessage_IncludesCustomMessage() // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(value) failed. Custom error message - Value is not within the expected range. - minValue: 1 - maxValue: 5 - value: 10 + Assert.IsInRange(value) + Expected value (10) to be in range [1, 5]. + range: [1, 5] + value: 10 + User message: Custom error message """); } @@ -120,11 +118,10 @@ public void IsInRange_WithDoubleValues_WorksCorrectly() Action action = () => Assert.IsInRange(minValue, maxValue, valueOutOfRange); action.Should().Throw() .WithMessage(""" - Assert.IsInRange(valueOutOfRange) failed. - Value is not within the expected range. - minValue: 1.5 - maxValue: 5.5 - value: 6 + Assert.IsInRange(valueOutOfRange) + Expected value (6) to be in range [1.5, 5.5]. + range: [1.5, 5.5] + value: 6 """); } @@ -142,7 +139,7 @@ public void IsInRange_WithDateTimeValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .WithMessage("Assert.IsInRange(valueOutOfRange) failed.*Value is not within the expected range*"); + .WithMessage("Assert.IsInRange(valueOutOfRange)*Expected value*to be in range*"); } public void IsInRange_WithCharValues_WorksCorrectly() @@ -159,7 +156,7 @@ public void IsInRange_WithCharValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .WithMessage("Assert.IsInRange(valueOutOfRange) failed.*Value is not within the expected range*"); + .WithMessage("Assert.IsInRange(valueOutOfRange)*Expected value*to be in range*"); } public void IsInRange_WithNullMessage_DoesNotThrow() @@ -219,11 +216,10 @@ public void IsInRange_WithAllNegativeValuesBelowRange_ThrowsAssertFailedExceptio // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: -10 - maxValue: -5 - value: -12 + Assert.IsInRange(value) + Expected value (-12) to be in range [-10, -5]. + range: [-10, -5] + value: -12 """); } @@ -240,11 +236,10 @@ public void IsInRange_WithAllNegativeValuesAboveRange_ThrowsAssertFailedExceptio // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: -10 - maxValue: -5 - value: -3 + Assert.IsInRange(value) + Expected value (-3) to be in range [-10, -5]. + range: [-10, -5] + value: -3 """); } @@ -294,11 +289,10 @@ public void IsInRange_WithRangeSpanningNegativeToPositive_ValueBelowRange_Throws // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: -5 - maxValue: 5 - value: -7 + Assert.IsInRange(value) + Expected value (-7) to be in range [-5, 5]. + range: [-5, 5] + value: -7 """); } @@ -315,11 +309,10 @@ public void IsInRange_WithRangeSpanningNegativeToPositive_ValueAboveRange_Throws // Assert action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: -5 - maxValue: 5 - value: 7 + Assert.IsInRange(value) + Expected value (7) to be in range [-5, 5]. + range: [-5, 5] + value: 7 """); } @@ -370,11 +363,10 @@ public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsSmaller Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: 5 - maxValue: 5 - value: 4 + Assert.IsInRange(value) + Expected value (4) to be in range [5, 5]. + range: [5, 5] + value: 4 """); } @@ -388,11 +380,10 @@ public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsLarger( Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: 5 - maxValue: 5 - value: 6 + Assert.IsInRange(value) + Expected value (6) to be in range [5, 5]. + range: [5, 5] + value: 6 """); } @@ -417,11 +408,10 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsSmall Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: 5 - maxValue: 5 - value: 4 + Assert.IsInRange(value) + Expected value (4) to be in range [5, 5]. + range: [5, 5] + value: 4 """); } @@ -435,11 +425,10 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsLarge Action action = () => Assert.IsInRange(minValue, maxValue, value); action.Should().ThrowExactly() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: 5 - maxValue: 5 - value: 6 + Assert.IsInRange(value) + Expected value (6) to be in range [5, 5]. + range: [5, 5] + value: 6 """); } @@ -454,11 +443,10 @@ public void IsInRange_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsInRange(1, 10, aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsInRange(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. - Value is not within the expected range. - minValue: 1 - maxValue: 10 - value: 20 + Assert.IsInRange(aVeryLongVariableNameThatExceedsOneHundredCharacte...) + Expected value (20) to be in range [1, 10]. + range: [1, 10] + value: 20 """); } @@ -471,11 +459,10 @@ public void IsInRange_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsInRange(min, max, value); action.Should().Throw() .WithMessage($""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: {new string('R', 256)}... 44 more - maxValue: {new string('R', 256)}... 44 more - value: {new string('R', 256)}... 44 more + Assert.IsInRange(value) + Expected value ({new string('R', 256)}... 44 more) to be in range [{new string('R', 256)}... 44 more, {new string('R', 256)}... 44 more]. + range: [{new string('R', 256)}... 44 more, {new string('R', 256)}... 44 more] + value: {new string('R', 256)}... 44 more """); } @@ -488,11 +475,10 @@ public void IsInRange_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsInRange(min, max, value); action.Should().Throw() .WithMessage(""" - Assert.IsInRange(value) failed. - Value is not within the expected range. - minValue: line1\r\nline2 - maxValue: line1\r\nline2 - value: line1\r\nline2 + Assert.IsInRange(value) + Expected value (line1\r\nline2) to be in range [line1\r\nline2, line1\r\nline2]. + range: [line1\r\nline2, line1\r\nline2] + value: line1\r\nline2 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 6ed354ad5a..23e8c2b40a 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -13,10 +13,10 @@ public void InstanceOfTypeShouldFailWhenValueIsNull() Action action = () => Assert.IsInstanceOfType(null, typeof(AssertTests)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(null) failed. + Assert.IsInstanceOfType(null) Expected value to be of the specified type. value: null - expectedType: + expected type: """); } @@ -25,10 +25,10 @@ public void InstanceOfTypeShouldFailWhenTypeIsNull() Action action = () => Assert.IsInstanceOfType(5, null); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(5) failed. + Assert.IsInstanceOfType(5) Expected value to be of the specified type. value: 5 - expectedType: (null) + expected type: (null) """); } @@ -37,11 +37,11 @@ public void InstanceOfTypeShouldFailWhenTypeIsMismatched() Action action = () => Assert.IsInstanceOfType(5, typeof(string)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(5) failed. + Assert.IsInstanceOfType(5) Expected value to be of the specified type. value: 5 - expectedType: - actualType: + expected type: + actual type: """); } @@ -54,10 +54,11 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() Action action = () => Assert.IsInstanceOfType(null, typeof(AssertTests), "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(null) failed. User-provided message + Assert.IsInstanceOfType(null) Expected value to be of the specified type. value: null - expectedType: + expected type: + User message: User-provided message """); } @@ -66,10 +67,11 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() Action action = () => Assert.IsInstanceOfType(5, null, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(5) failed. User-provided message + Assert.IsInstanceOfType(5) Expected value to be of the specified type. value: 5 - expectedType: (null) + expected type: (null) + User message: User-provided message """); } @@ -78,11 +80,12 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() Action action = () => Assert.IsInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(5) failed. User-provided message + Assert.IsInstanceOfType(5) Expected value to be of the specified type. value: 5 - expectedType: - actualType: + expected type: + actual type: + User message: User-provided message """); } @@ -96,10 +99,11 @@ public async Task InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNul Func action = async () => Assert.IsInstanceOfType(null, typeof(AssertTests), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsInstanceOfType(null) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsInstanceOfType(null) Expected value to be of the specified type. value: null - expectedType: + expected type: + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -110,10 +114,11 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull() Action action = () => Assert.IsInstanceOfType(5, null, $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls + Assert.IsInstanceOfType(5) Expected value to be of the specified type. value: 5 - expectedType: (null) + expected type: (null) + User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); } @@ -124,11 +129,12 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMismatched Action action = () => Assert.IsInstanceOfType(5, typeof(string), $"User-provided message {o}"); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(5) failed. User-provided message DummyClassTrackingToStringCalls + Assert.IsInstanceOfType(5) Expected value to be of the specified type. value: 5 - expectedType: - actualType: + expected type: + actual type: + User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); } @@ -147,10 +153,10 @@ public void InstanceNotOfTypeShouldFailWhenTypeIsNull() Action action = () => Assert.IsNotInstanceOfType(5, null); action.Should().Throw() .WithMessage(""" - Assert.IsNotInstanceOfType(5) failed. - Value should not be of the specified type. + Assert.IsNotInstanceOfType(5) + Expected value to not be an instance of the specified type. value: 5 - wrongType: (null) + wrong type: (null) """); } @@ -163,10 +169,10 @@ public void IsInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() Action action = () => Assert.IsInstanceOfType(null); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(null) failed. + Assert.IsInstanceOfType(null) Expected value to be of the specified type. value: null - expectedType: + expected type: """); } @@ -175,11 +181,11 @@ public void IsInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() Action action = () => Assert.IsInstanceOfType(5); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(5) failed. + Assert.IsInstanceOfType(5) Expected value to be of the specified type. value: 5 - expectedType: - actualType: + expected type: + actual type: """); } @@ -304,11 +310,11 @@ public void IsInstanceOfType_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.IsInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) Expected value to be of the specified type. value: "hello" - expectedType: - actualType: + expected type: + actual type: """); } @@ -319,11 +325,11 @@ public void IsInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage($""" - Assert.IsInstanceOfType(obj) failed. + Assert.IsInstanceOfType(obj) Expected value to be of the specified type. value: {new string('L', 256)}... 44 more - expectedType: - actualType: + expected type: + actual type: """); } @@ -334,11 +340,11 @@ public void IsInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsInstanceOfType(obj, typeof(int)); action.Should().Throw() .WithMessage(""" - Assert.IsInstanceOfType(obj) failed. + Assert.IsInstanceOfType(obj) Expected value to be of the specified type. value: line1\r\nline2\nline3 - expectedType: - actualType: + expected type: + actual type: """); } @@ -349,11 +355,11 @@ public void IsNotInstanceOfType_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsNotInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ, typeof(string)); action.Should().Throw() .WithMessage(""" - Assert.IsNotInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. - Value should not be of the specified type. + Assert.IsNotInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) + Expected value to not be an instance of the specified type. value: "hello" - wrongType: - actualType: + wrong type: + actual type: """); } @@ -364,11 +370,11 @@ public void IsNotInstanceOfType_WithLongToStringValue_ShouldTruncateValue() Action action = () => Assert.IsNotInstanceOfType(obj, typeof(ObjectWithLongToString)); action.Should().Throw() .WithMessage($""" - Assert.IsNotInstanceOfType(obj) failed. - Value should not be of the specified type. + Assert.IsNotInstanceOfType(obj) + Expected value to not be an instance of the specified type. value: {new string('L', 256)}... 44 more - wrongType: - actualType: + wrong type: + actual type: """); } @@ -379,11 +385,11 @@ public void IsNotInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() Action action = () => Assert.IsNotInstanceOfType(obj, typeof(ObjectWithNewlineToString)); action.Should().Throw() .WithMessage(""" - Assert.IsNotInstanceOfType(obj) failed. - Value should not be of the specified type. + Assert.IsNotInstanceOfType(obj) + Expected value to not be an instance of the specified type. value: line1\r\nline2\nline3 - wrongType: - actualType: + wrong type: + actual type: """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index 00c8d21a12..b96d09a4f0 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -17,7 +17,8 @@ public void IsNull_PassNonNull_ShouldFail() Action action = () => Assert.IsNull(new object()); action.Should().Throw() .WithMessage(""" - Assert.IsNull(new object()) failed. Expected value to be null. + Assert.IsNull(new object()) + Expected value to be null. value: """); } @@ -30,9 +31,10 @@ public void IsNull_StringMessage_PassNonNull_ShouldFail() Action action = () => Assert.IsNull(new object(), "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsNull(new object()) failed. Expected value to be null. - User-provided message + Assert.IsNull(new object()) + Expected value to be null. value: + User message: User-provided message """); } @@ -50,9 +52,10 @@ public async Task IsNull_InterpolatedString_PassNonNull_ShouldFail() Func action = async () => Assert.IsNull(new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNull(new object()) failed. Expected value to be null. - User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsNull(new object()) + Expected value to be null. value: + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -85,8 +88,8 @@ public void IsNotNull_PassNull_ShouldFail() Action action = () => Assert.IsNotNull(null); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull(null) failed. Expected a non-null value. - value: null + Assert.IsNotNull(null) + Expected a non-null value. """); } @@ -95,9 +98,9 @@ public void IsNotNull_StringMessage_PassNonNull_ShouldFail() Action action = () => Assert.IsNotNull(null, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull(null) failed. Expected a non-null value. - User-provided message - value: null + Assert.IsNotNull(null) + Expected a non-null value. + User message: User-provided message """); } @@ -108,9 +111,9 @@ public async Task IsNotNull_InterpolatedString_PassNonNull_ShouldFail() Func action = async () => Assert.IsNotNull(null, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNotNull(null) failed. Expected a non-null value. - User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - value: null + Assert.IsNotNull(null) + Expected a non-null value. + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs index 38c78faccc..db8f3fae11 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs @@ -13,7 +13,7 @@ public void IsFalseNullableBooleanShouldFailWithNull() Action action = () => Assert.IsFalse(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(nullBool) failed. + Assert.IsFalse(nullBool) Expected condition to be false. condition: null """); @@ -25,7 +25,7 @@ public void IsFalseNullableBooleanShouldFailWithTrue() Action action = () => Assert.IsFalse(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(nullBool) failed. + Assert.IsFalse(nullBool) Expected condition to be false. condition: True """); @@ -42,7 +42,7 @@ public void IsFalseBooleanShouldFailWithTrue() Action action = () => Assert.IsFalse(true); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(true) failed. + Assert.IsFalse(true) Expected condition to be false. condition: True """); @@ -57,9 +57,10 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithNull() Action action = () => Assert.IsFalse(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(nullBool) failed. User-provided message + Assert.IsFalse(nullBool) Expected condition to be false. condition: null + User message: User-provided message """); } @@ -69,9 +70,10 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithTrue() Action action = () => Assert.IsFalse(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(nullBool) failed. User-provided message + Assert.IsFalse(nullBool) Expected condition to be false. condition: True + User message: User-provided message """); } @@ -86,9 +88,10 @@ public void IsFalseBooleanStringMessageShouldFailWithTrue() Action action = () => Assert.IsFalse(true, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(true) failed. User-provided message + Assert.IsFalse(true) Expected condition to be false. condition: True + User message: User-provided message """); } @@ -103,9 +106,10 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithN Func action = async () => Assert.IsFalse(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsFalse(nullBool) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsFalse(nullBool) Expected condition to be false. condition: null + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -117,9 +121,10 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithT Func action = async () => Assert.IsFalse(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsFalse(nullBool) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsFalse(nullBool) Expected condition to be false. condition: True + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -136,9 +141,10 @@ public async Task IsFalseBooleanInterpolatedStringMessageShouldFailWithTrue() Func action = async () => Assert.IsFalse(true, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsFalse(true) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsFalse(true) Expected condition to be false. condition: True + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -151,7 +157,7 @@ public void IsTrueNullableBooleanShouldFailWithNull() Action action = () => Assert.IsTrue(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(nullBool) failed. + Assert.IsTrue(nullBool) Expected condition to be true. condition: null """); @@ -163,7 +169,7 @@ public void IsTrueNullableBooleanShouldFailWithFalse() Action action = () => Assert.IsTrue(nullBool); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(nullBool) failed. + Assert.IsTrue(nullBool) Expected condition to be true. condition: False """); @@ -180,7 +186,7 @@ public void IsTrueBooleanShouldFailWithFalse() Action action = () => Assert.IsTrue(false); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(false) failed. + Assert.IsTrue(false) Expected condition to be true. condition: False """); @@ -195,9 +201,10 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithNull() Action action = () => Assert.IsTrue(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(nullBool) failed. User-provided message + Assert.IsTrue(nullBool) Expected condition to be true. condition: null + User message: User-provided message """); } @@ -207,9 +214,10 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithFalse() Action action = () => Assert.IsTrue(nullBool, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(nullBool) failed. User-provided message + Assert.IsTrue(nullBool) Expected condition to be true. condition: False + User message: User-provided message """); } @@ -224,9 +232,10 @@ public void IsTrueBooleanStringMessageShouldFailWithFalse() Action action = () => Assert.IsTrue(false, "User-provided message"); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(false) failed. User-provided message + Assert.IsTrue(false) Expected condition to be true. condition: False + User message: User-provided message """); } @@ -241,9 +250,10 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithNu Func action = async () => Assert.IsTrue(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsTrue(nullBool) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsTrue(nullBool) Expected condition to be true. condition: null + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -255,9 +265,10 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithFa Func action = async () => Assert.IsTrue(nullBool, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsTrue(nullBool) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsTrue(nullBool) Expected condition to be true. condition: False + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -274,9 +285,10 @@ public async Task IsTrueBooleanInterpolatedStringMessageShouldFailWithFalse() Func action = async () => Assert.IsTrue(false, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsTrue(false) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsTrue(false) Expected condition to be true. condition: False + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -292,7 +304,7 @@ public void IsTrue_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsTrue(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsTrue(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.IsTrue(aVeryLongVariableNameThatExceedsOneHundredCharacte...) Expected condition to be true. condition: False """); @@ -305,7 +317,7 @@ public void IsFalse_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.IsFalse(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsFalse(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.IsFalse(aVeryLongVariableNameThatExceedsOneHundredCharacte...) Expected condition to be false. condition: True """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs index dbcd8018f3..5155d2c2dc 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs @@ -26,11 +26,11 @@ public void Count_WhenCountIsNotSame_ShouldFail() Action action = () => Assert.HasCount(3, collection); action.Should().Throw() .WithMessage(""" - Assert.HasCount(collection) failed. + Assert.HasCount(collection) Expected collection to have the specified number of items. collection: [1] - expectedCount: 3 - actualCount: 1 + expected count: 3 + actual count: 1 """); } @@ -41,11 +41,12 @@ public async Task Count_InterpolatedString_WhenCountIsNotSame_ShouldFail() Func action = async () => Assert.HasCount(1, Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.HasCount(Array.Empty()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.HasCount(Array.Empty()) Expected collection to have the specified number of items. collection: [] - expectedCount: 1 - actualCount: 0 + expected count: 1 + actual count: 0 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -66,11 +67,11 @@ public void NotAny_WhenNotEmpty_ShouldFail() Action action = () => Assert.IsEmpty(collection); action.Should().Throw() .WithMessage(""" - Assert.IsEmpty(collection) failed. + Assert.IsEmpty(collection) Expected collection to have the specified number of items. collection: [1] - expectedCount: 0 - actualCount: 1 + expected count: 0 + actual count: 1 """); } @@ -82,11 +83,12 @@ public async Task NotAny_InterpolatedString_WhenNotEmpty_ShouldFail() Func action = async () => Assert.IsEmpty(collection, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsEmpty(collection) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.IsEmpty(collection) Expected collection to have the specified number of items. collection: [1] - expectedCount: 0 - actualCount: 1 + expected count: 0 + actual count: 1 + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -111,7 +113,7 @@ public void Single_WhenNoItems_ShouldFail() Action action = () => Assert.ContainsSingle(Array.Empty()); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(Array.Empty()) failed. + Assert.ContainsSingle(Array.Empty()) Expected collection to contain exactly one item but found 0 item(s). """); } @@ -121,7 +123,7 @@ public void Single_WhenMultipleItems_ShouldFail() Action action = () => Assert.ContainsSingle([1, 2, 3]); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle([1, 2, 3]) failed. + Assert.ContainsSingle([1, 2, 3]) Expected collection to contain exactly one item but found 3 item(s). """); } @@ -133,8 +135,9 @@ public async Task Single_InterpolatedString_WhenNoItem_ShouldFail() Func action = async () => Assert.ContainsSingle(Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.ContainsSingle(Array.Empty()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.ContainsSingle(Array.Empty()) Expected collection to contain exactly one item but found 0 item(s). + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -146,8 +149,9 @@ public async Task Single_InterpolatedString_WhenMultipleItems_ShouldFail() Func action = async () => Assert.ContainsSingle([1, 2, 3], $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.ContainsSingle([1, 2, 3]) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* + Assert.ContainsSingle([1, 2, 3]) Expected collection to contain exactly one item but found 3 item(s). + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -174,7 +178,7 @@ public void SinglePredicate_WhenNoItemMatches_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x % 2 == 0, collection) failed. + Assert.ContainsSingle(x => x % 2 == 0, collection) Expected exactly one item to match the predicate but found 0 item(s). """); } @@ -185,7 +189,7 @@ public void SinglePredicate_WhenMultipleItemsMatch_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x % 2 == 0, collection) failed. + Assert.ContainsSingle(x => x % 2 == 0, collection) Expected exactly one item to match the predicate but found 3 item(s). """); } @@ -196,8 +200,9 @@ public void SinglePredicate_Message_WhenNoItemMatches_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection, "No even numbers found: test"); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x % 2 == 0, collection) failed. No even numbers found: test + Assert.ContainsSingle(x => x % 2 == 0, collection) Expected exactly one item to match the predicate but found 0 item(s). + User message: No even numbers found: test """); } @@ -207,8 +212,9 @@ public void SinglePredicate_Message_WhenMultipleItemsMatch_ShouldFail() Action action = () => Assert.ContainsSingle(x => x % 2 == 0, collection, "Too many even numbers: test"); action.Should().Throw() .WithMessage(""" - Assert.ContainsSingle(x => x % 2 == 0, collection) failed. Too many even numbers: test + Assert.ContainsSingle(x => x % 2 == 0, collection) Expected exactly one item to match the predicate but found 3 item(s). + User message: Too many even numbers: test """); } @@ -243,8 +249,8 @@ public void Any_WhenNoItem_ShouldFail() Action action = () => Assert.IsNotEmpty(Array.Empty()); action.Should().Throw() .WithMessage(""" - Assert.IsNotEmpty(Array.Empty()) failed. - Expected collection to contain any item but it is empty. + Assert.IsNotEmpty(Array.Empty()) + Expected collection to not be empty. """); } @@ -255,8 +261,9 @@ public async Task Any_InterpolatedString_WhenNoItem_ShouldFail() Func action = async () => Assert.IsNotEmpty(Array.Empty(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.IsNotEmpty(Array.Empty()) failed. User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected collection to contain any item but it is empty. + Assert.IsNotEmpty(Array.Empty()) + Expected collection to not be empty. + User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs index 209e3d5c45..8bc0c0df35 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs @@ -17,7 +17,7 @@ public void MatchesRegex_WhenValueDoesNotMatchPattern_ShouldFail() Action action = () => Assert.MatchesRegex(@"\d+", "abc"); action.Should().Throw() .WithMessage(""" - Assert.MatchesRegex(@"\d+", "abc") failed. + Assert.MatchesRegex(@"\d+", "abc") String does not match expected pattern. pattern: \d+ value: "abc" @@ -32,7 +32,7 @@ public void DoesNotMatchRegex_WhenValueMatchesPattern_ShouldFail() Action action = () => Assert.DoesNotMatchRegex(@"\d+", "abc123"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotMatchRegex(@"\d+", "abc123") failed. + Assert.DoesNotMatchRegex(@"\d+", "abc123") String matches pattern but should not. pattern: \d+ value: "abc123" @@ -50,7 +50,7 @@ public void MatchesRegex_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.MatchesRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.MatchesRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.MatchesRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharacte...) String does not match expected pattern. pattern: \d+ value: "hello" @@ -64,7 +64,7 @@ public void MatchesRegex_WithLongValue_ShouldTruncateValue() Action action = () => Assert.MatchesRegex(@"\d+", longValue); action.Should().Throw() .WithMessage($""" - Assert.MatchesRegex(@"\d+", longValue) failed. + Assert.MatchesRegex(@"\d+", longValue) String does not match expected pattern. pattern: \d+ value: "{new string('x', 255)}... 46 more @@ -76,7 +76,7 @@ public void MatchesRegex_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.MatchesRegex(@"^\d+$", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.MatchesRegex(@"^\d+$", "hello\r\nworld") failed. + Assert.MatchesRegex(@"^\d+$", "hello\r\nworld") String does not match expected pattern. pattern: ^\d+$ value: "hello\r\nworld" @@ -90,7 +90,7 @@ public void DoesNotMatchRegex_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotMatchRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotMatchRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.DoesNotMatchRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharacte...) String matches pattern but should not. pattern: \d+ value: "abc123" @@ -104,7 +104,7 @@ public void DoesNotMatchRegex_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotMatchRegex(@"\d+", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotMatchRegex(@"\d+", longValue) failed. + Assert.DoesNotMatchRegex(@"\d+", longValue) String matches pattern but should not. pattern: \d+ value: "{new string('1', 255)}... 46 more @@ -116,7 +116,7 @@ public void DoesNotMatchRegex_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotMatchRegex(@"hello", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotMatchRegex(@"hello", "hello\r\nworld") failed. + Assert.DoesNotMatchRegex(@"hello", "hello\r\nworld") String matches pattern but should not. pattern: hello value: "hello\r\nworld" diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs index 537d61df61..32a3bd2f26 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs @@ -17,10 +17,10 @@ public void StartsWith_WhenValueDoesNotStartWithPrefix_ShouldFail() Action action = () => Assert.StartsWith("world", "hello"); action.Should().Throw() .WithMessage(""" - Assert.StartsWith("world", "hello") failed. + Assert.StartsWith("world", "hello") String does not start with expected prefix. - expectedPrefix: "world" - value: "hello" + expected prefix: "world" + value: "hello" """); } @@ -29,10 +29,11 @@ public void StartsWith_WithMessage_WhenValueDoesNotStartWithPrefix_ShouldFail() Action action = () => Assert.StartsWith("world", "hello", "User message"); action.Should().Throw() .WithMessage(""" - Assert.StartsWith("world", "hello") failed. User message + Assert.StartsWith("world", "hello") String does not start with expected prefix. - expectedPrefix: "world" - value: "hello" + expected prefix: "world" + value: "hello" + User message: User message """); } @@ -44,10 +45,10 @@ public void DoesNotStartWith_WhenValueStartsWithPrefix_ShouldFail() Action action = () => Assert.DoesNotStartWith("hello", "hello world"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotStartWith("hello", "hello world") failed. + Assert.DoesNotStartWith("hello", "hello world") String starts with unexpected prefix. - notExpectedPrefix: "hello" - value: "hello world" + unwanted prefix: "hello" + value: "hello world" """); } @@ -62,10 +63,10 @@ public void StartsWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.StartsWith("world", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.StartsWith("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.StartsWith("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) String does not start with expected prefix. - expectedPrefix: "world" - value: "hello world" + expected prefix: "world" + value: "hello world" """); } @@ -76,10 +77,10 @@ public void StartsWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.StartsWith("world", longValue); action.Should().Throw() .WithMessage($""" - Assert.StartsWith("world", longValue) failed. + Assert.StartsWith("world", longValue) String does not start with expected prefix. - expectedPrefix: "world" - value: "{new string('x', 255)}... 46 more + expected prefix: "world" + value: "{new string('x', 255)}... 46 more """); } @@ -88,10 +89,10 @@ public void StartsWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.StartsWith("world", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.StartsWith("world", "hello\r\nworld") failed. + Assert.StartsWith("world", "hello\r\nworld") String does not start with expected prefix. - expectedPrefix: "world" - value: "hello\r\nworld" + expected prefix: "world" + value: "hello\r\nworld" """); } @@ -102,10 +103,10 @@ public void DoesNotStartWith_WithLongExpression_ShouldTruncateExpression() Action action = () => Assert.DoesNotStartWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.DoesNotStartWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. + Assert.DoesNotStartWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) String starts with unexpected prefix. - notExpectedPrefix: "hello" - value: "hello world" + unwanted prefix: "hello" + value: "hello world" """); } @@ -116,10 +117,10 @@ public void DoesNotStartWith_WithLongValue_ShouldTruncateValue() Action action = () => Assert.DoesNotStartWith("hello", longValue); action.Should().Throw() .WithMessage($""" - Assert.DoesNotStartWith("hello", longValue) failed. + Assert.DoesNotStartWith("hello", longValue) String starts with unexpected prefix. - notExpectedPrefix: "hello" - value: "hello{new string('x', 250)}... 51 more + unwanted prefix: "hello" + value: "hello{new string('x', 250)}... 51 more """); } @@ -128,10 +129,10 @@ public void DoesNotStartWith_WithNewlineInValue_ShouldEscapeNewlines() Action action = () => Assert.DoesNotStartWith("hello", "hello\r\nworld"); action.Should().Throw() .WithMessage(""" - Assert.DoesNotStartWith("hello", "hello\r\nworld") failed. + Assert.DoesNotStartWith("hello", "hello\r\nworld") String starts with unexpected prefix. - notExpectedPrefix: "hello" - value: "hello\r\nworld" + unwanted prefix: "hello" + value: "hello\r\nworld" """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs index 615f92712e..05d8f2fa1d 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -13,7 +13,7 @@ public void ThrowAssertFailedDoesNotThrowIfMessageContainsInvalidStringFormatCom { Action action = () => Assert.ThrowAssertFailed("name", "{"); action.Should().Throw() - .WithMessage("*name failed. {*"); + .WithMessage("name\n{"); } #endregion @@ -71,11 +71,11 @@ public void ThrowsAsync_WhenExceptionIsNotExpectedType_ShouldThrow() action.Should().Throw() .WithInnerException() .WithMessage(""" - Assert.ThrowsAsync failed. + Assert.ThrowsAsync Wrong exception type was thrown. action: () => throw new Exception() - expectedExceptionType: - actualExceptionType: + expected exception type: + actual exception type: """); } @@ -86,11 +86,11 @@ public void ThrowsExactlyAsync_WhenExceptionIsDerivedFromExpectedType_ShouldThro action.Should().Throw() .WithInnerException() .WithMessage(""" - Assert.ThrowsExactlyAsync failed. + Assert.ThrowsExactlyAsync Wrong exception type was thrown. action: () => throw new ArgumentNullException() - expectedExceptionType: - actualExceptionType: + expected exception type: + actual exception type: """); } @@ -118,10 +118,11 @@ public void Throws_WithMessageBuilder_FailsBecauseNoException() }); action.Should().Throw() .WithMessage(""" - Assert.Throws failed. message constructed via builder. + Assert.Throws No exception was thrown. action: () => { } - expectedExceptionType: + expected exception type: + User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -140,11 +141,12 @@ public void Throws_WithMessageBuilder_FailsBecauseTypeMismatch() }); action.Should().Throw() .WithMessage(""" - Assert.Throws failed. message constructed via builder. + Assert.Throws Wrong exception type was thrown. action: () => throw new ArgumentOutOfRangeException("MyParamNameHere") - expectedExceptionType: - actualExceptionType: + expected exception type: + actual exception type: + User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -176,10 +178,11 @@ public void ThrowsExactly_WithMessageBuilder_FailsBecauseNoException() }); action.Should().Throw() .WithMessage(""" - Assert.ThrowsExactly failed. message constructed via builder. + Assert.ThrowsExactly No exception was thrown. action: () => { } - expectedExceptionType: + expected exception type: + User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -198,11 +201,12 @@ public void ThrowsExactly_WithMessageBuilder_FailsBecauseTypeMismatch() }); action.Should().Throw() .WithMessage(""" - Assert.ThrowsExactly failed. message constructed via builder. + Assert.ThrowsExactly Wrong exception type was thrown. action: () => throw new ArgumentOutOfRangeException("MyParamNameHere") - expectedExceptionType: - actualExceptionType: + expected exception type: + actual exception type: + User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -234,10 +238,11 @@ public async Task ThrowsAsync_WithMessageBuilder_FailsBecauseNoException() }); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.ThrowsAsync failed. message constructed via builder. + Assert.ThrowsAsync No exception was thrown. action: () => Task.CompletedTask - expectedExceptionType: + expected exception type: + User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -256,11 +261,12 @@ public async Task ThrowsAsync_WithMessageBuilder_FailsBecauseTypeMismatch() }); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.ThrowsAsync failed. message constructed via builder. + Assert.ThrowsAsync Wrong exception type was thrown. action: () => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere")) - expectedExceptionType: - actualExceptionType: + expected exception type: + actual exception type: + User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -292,10 +298,11 @@ public async Task ThrowsExactlyAsync_WithMessageBuilder_FailsBecauseNoException( }); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.ThrowsExactlyAsync failed. message constructed via builder. + Assert.ThrowsExactlyAsync No exception was thrown. action: () => Task.CompletedTask - expectedExceptionType: + expected exception type: + User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -314,11 +321,12 @@ public async Task ThrowsExactlyAsync_WithMessageBuilder_FailsBecauseTypeMismatch }); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.ThrowsExactlyAsync failed. message constructed via builder. + Assert.ThrowsExactlyAsync Wrong exception type was thrown. action: () => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere")) - expectedExceptionType: - actualExceptionType: + expected exception type: + actual exception type: + User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index 5c35229752..a7866cf4e6 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -31,7 +31,7 @@ public void ObsoleteEqualsMethodThrowsAssertFailedException() Action act = () => Assert.Equals("test", "test"); #pragma warning restore CS0618 // Type or member is obsolete act.Should().Throw() - .WithMessage("Assert.Fail failed. Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead."); + .WithMessage("Assert.Fail\nAssert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead."); } public void ObsoleteReferenceEqualsMethodThrowsAssertFailedException() @@ -41,7 +41,7 @@ public void ObsoleteReferenceEqualsMethodThrowsAssertFailedException() Action act = () => Assert.ReferenceEquals(obj, obj); #pragma warning restore CS0618 // Type or member is obsolete act.Should().Throw() - .WithMessage("Assert.Fail failed. Assert.ReferenceEquals should not be used for Assertions. Please use Assert.AreSame & overloads instead."); + .WithMessage("Assert.Fail\nAssert.ReferenceEquals should not be used for Assertions. Please use Assert.AreSame & overloads instead."); } #endif #endregion @@ -79,7 +79,8 @@ public void FormatValue_WhenStringExceedsMaxLength_ShouldTruncateWithEllipsis() Action action = () => Assert.IsNull(longValue); action.Should().Throw() .WithMessage($""" - Assert.IsNull(longValue) failed. Expected value to be null. + Assert.IsNull(longValue) + Expected value to be null. value: {expectedValue} """); } @@ -92,7 +93,8 @@ public void FormatValue_WhenStringIsWithinMaxLength_ShouldNotTruncate() Action action = () => Assert.IsNull(value); action.Should().Throw() .WithMessage($""" - Assert.IsNull(value) failed. Expected value to be null. + Assert.IsNull(value) + Expected value to be null. value: {expectedFullValue} """); } @@ -106,7 +108,8 @@ public void FormatValue_WhenCustomToStringExceedsMaxLength_ShouldTruncate() Action action = () => Assert.IsNull(obj); action.Should().Throw() .WithMessage($""" - Assert.IsNull(obj) failed. Expected value to be null. + Assert.IsNull(obj) + Expected value to be null. value: {expectedValue} """); } @@ -119,8 +122,8 @@ public void TruncateExpression_WhenExpressionExceeds100Chars_ShouldShowEllipsis( Action action = () => Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharactersInLengthToTestTruncationBehaviorOfExpressionDisplayXYZ); action.Should().Throw() .WithMessage(""" - Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharacte...) failed. Expected a non-null value. - value: null + Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharacte...) + Expected a non-null value. """); } @@ -135,7 +138,8 @@ public void FormatValue_WhenValueContainsNewlines_ShouldEscapeThem() Action action = () => Assert.IsNull(obj); action.Should().Throw() .WithMessage(""" - Assert.IsNull(obj) failed. Expected value to be null. + Assert.IsNull(obj) + Expected value to be null. value: line1\r\nline2\nline3 """); } @@ -147,7 +151,8 @@ public void FormatValue_WhenStringContainsNewlines_ShouldEscapeThem() Action action = () => Assert.IsNull(value); action.Should().Throw() .WithMessage(""" - Assert.IsNull(value) failed. Expected value to be null. + Assert.IsNull(value) + Expected value to be null. value: "hello\nworld" """); } @@ -163,7 +168,8 @@ public void FormatValue_WhenValueIsCollection_ShouldShowPreview() Action action = () => Assert.IsNull(collection); action.Should().Throw() .WithMessage(""" - Assert.IsNull(collection) failed. Expected value to be null. + Assert.IsNull(collection) + Expected value to be null. value: [1, 2, 3] """); } @@ -183,7 +189,7 @@ public void FormatCollectionPreview_WhenTotalStringLengthExceeds256_ShouldTrunca Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() .WithMessage($""" - Assert.Contains("not-there", collection) failed. + Assert.Contains("not-there", collection) Expected collection to contain the specified item. collection: ["{new string('a', 30)}", "{new string('b', 30)}", "{new string('c', 30)}", "{new string('d', 30)}", "{new string('e', 30)}", "{new string('f', 30)}", "{new string('g', 30)}", ... 13 more] """); @@ -198,7 +204,7 @@ public void FormatCollectionPreview_WhenElementToStringExceeds50_ShouldTruncateE Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() .WithMessage($""" - Assert.Contains("not-there", collection) failed. + Assert.Contains("not-there", collection) Expected collection to contain the specified item. collection: [{expectedFirstElement}, "short"] """); @@ -213,7 +219,8 @@ public void FormatCollectionPreview_WhenCollectionContainsNestedCollections_Shou Action action = () => Assert.IsNull(outer); action.Should().Throw() .WithMessage(""" - Assert.IsNull(outer) failed. Expected value to be null. + Assert.IsNull(outer) + Expected value to be null. value: [[1, 2], [3, 4]] """); } @@ -236,7 +243,8 @@ public void FormatCollectionPreview_WhenNestedCollectionIsLarge_ShouldTruncateIn Action action = () => Assert.IsNull(outer); action.Should().Throw() .WithMessage(""" - Assert.IsNull(outer) failed. Expected value to be null. + Assert.IsNull(outer) + Expected value to be null. value: [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 35 more]] """); } @@ -248,7 +256,7 @@ public void FormatCollectionPreview_WhenElementContainsNewlines_ShouldEscapeThem Action action = () => Assert.Contains("not-there", collection); action.Should().Throw() .WithMessage(""" - Assert.Contains("not-there", collection) failed. + Assert.Contains("not-there", collection) Expected collection to contain the specified item. collection: ["line1\nline2", "ok"] """); @@ -261,7 +269,7 @@ public void FormatCollectionPreview_WhenSingleElement_ShouldShowSingularForm() Action action = () => Assert.Contains(99, collection); action.Should().Throw() .WithMessage(""" - Assert.Contains(99, collection) failed. + Assert.Contains(99, collection) Expected collection to contain the specified item. collection: [42] """); @@ -295,7 +303,7 @@ IEnumerable NonDeterministicEnumerable() Action action = () => Assert.Contains(42, collection); action.Should().Throw() .WithMessage(""" - Assert.Contains(42, collection) failed. + Assert.Contains(42, collection) Expected collection to contain the specified item. collection: [1, 2, 3] """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs index 6e351151dd..cf7e9d4a8d 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs @@ -103,7 +103,7 @@ public void CollectionAssertIsSubsetOf_ReturnedSubsetValueMessage_ThrowException Action action = () => CollectionAssert.IsSubsetOf(collection, superset); // Assert - action.Should().Throw().WithMessage("CollectionAssert.IsSubsetOf failed. Element(s) is/are not present in the collection."); + action.Should().Throw().WithMessage("CollectionAssert.IsSubsetOf\nElement(s) is/are not present in the collection."); } public void CollectionAssertIsSubsetOf_WithMessage_ReturnedSubsetValueMessage_ThrowExceptionMessage() @@ -116,7 +116,7 @@ public void CollectionAssertIsSubsetOf_WithMessage_ReturnedSubsetValueMessage_Th Action action = () => CollectionAssert.IsSubsetOf(collection, superset, "message"); // Assert - action.Should().Throw().WithMessage("CollectionAssert.IsSubsetOf failed. Element(s) is/are not present in the collection. message"); + action.Should().Throw().WithMessage("CollectionAssert.IsSubsetOf\nElement(s) is/are not present in the collection. message"); } public void CollectionAssertIsNotSubsetOfNullabilityPostConditions() @@ -398,7 +398,8 @@ public void CollectionAssertAreEqualWithoutUserMessage_FailsWithGoodMessage() Action action = () => CollectionAssert.AreEqual(new[] { 1, 2, 3 }, new[] { 1, 5, 3 }); action.Should().Throw() .WithMessage(""" - CollectionAssert.AreEqual failed. Element at index 1 do not match. + CollectionAssert.AreEqual + Element at index 1 do not match. Expected: 2 Actual: 5 """); @@ -410,7 +411,8 @@ public void CollectionAssertAreEqualWithUserMessage_FailsWithGoodMessage() action.Should().Throw() .WithMessage( """ - CollectionAssert.AreEqual failed. User-provided message. Element at index 1 do not match. + CollectionAssert.AreEqual + User-provided message. Element at index 1 do not match. Expected: 2 Actual: 5 """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/StringAssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/StringAssertTests.cs index 662bd5f742..cecc5236d6 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/StringAssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/StringAssertTests.cs @@ -19,7 +19,7 @@ public void StringAssertContains() string notInString = "I'm not in the string above"; Action action = () => StringAssert.Contains(actual, notInString); action.Should().Throw() - .And.Message.Should().Contain("StringAssert.Contains failed"); + .And.Message.Should().StartWith("StringAssert.Contains"); } public void StringAssertStartsWith() @@ -28,7 +28,7 @@ public void StringAssertStartsWith() string notInString = "I'm not in the string above"; Action action = () => StringAssert.StartsWith(actual, notInString); action.Should().Throw() - .And.Message.Should().Contain("StringAssert.StartsWith failed"); + .And.Message.Should().StartWith("StringAssert.StartsWith"); } public void StringAssertEndsWith() @@ -37,7 +37,7 @@ public void StringAssertEndsWith() string notInString = "I'm not in the string above"; Action action = () => StringAssert.EndsWith(actual, notInString); action.Should().Throw() - .And.Message.Should().Contain("StringAssert.EndsWith failed"); + .And.Message.Should().StartWith("StringAssert.EndsWith"); } public void StringAssertDoesNotMatch() @@ -46,7 +46,7 @@ public void StringAssertDoesNotMatch() Regex doesMatch = new("quick brown fox"); Action action = () => StringAssert.DoesNotMatch(actual, doesMatch); action.Should().Throw() - .And.Message.Should().Contain("StringAssert.DoesNotMatch failed"); + .And.Message.Should().StartWith("StringAssert.DoesNotMatch"); } public void StringAssertContainsIgnoreCase_DoesNotThrow() @@ -75,7 +75,7 @@ public void StringAssertContainsDoesNotThrowFormatException() { Action action = () => StringAssert.Contains(":-{", "x"); action.Should().Throw() - .And.Message.Should().Contain("StringAssert.Contains failed"); + .And.Message.Should().StartWith("StringAssert.Contains"); } // See https://github.com/dotnet/sdk/issues/25373 @@ -83,7 +83,7 @@ public void StringAssertContainsDoesNotThrowFormatExceptionWithArguments() { Action action = () => StringAssert.Contains("{", "x", "message"); action.Should().Throw() - .And.Message.Should().Contain("StringAssert.Contains failed"); + .And.Message.Should().StartWith("StringAssert.Contains"); } public void StringAssertContainsNullabilitiesPostConditions() From edc1aa14334b99d5250b659c297a243e3c11e7e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 21:44:00 +0100 Subject: [PATCH 36/58] Add C# numeric type suffixes to FormatValue display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Append type-disambiguating suffixes to numeric values in assertion error messages: long→L, ulong→UL, uint→U, float→f, decimal→m. int and double are left unsuffixed as they are the default types. --- .../TestFramework/Assertions/Assert.cs | 20 +++++- .../Assertions/AssertTests.AreEqualTests.cs | 68 +++++++++---------- .../Assertions/AssertTests.AreSame.cs | 2 +- .../Assertions/AssertTests.EndsWith.cs | 2 +- .../AssertTests.IComparableTests.cs | 2 +- .../Assertions/AssertTests.IsInRange.cs | 12 ++-- .../Assertions/AssertTests.MatchesRegex.cs | 2 +- .../Assertions/AssertTests.StartsWith.cs | 2 +- 8 files changed, 64 insertions(+), 46 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index f65bcb9571..dd6cd9cb8d 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -126,7 +126,9 @@ internal static string FormatValue(T? value, int maxLength = 256) if (type.IsPrimitive || value is decimal or DateTime or DateTimeOffset or TimeSpan or Guid or Enum) { - return EscapeNewlines(Truncate(value.ToString() ?? string.Empty, maxLength)); + string formatted = EscapeNewlines(Truncate(value.ToString() ?? string.Empty, maxLength)); + string suffix = GetNumericTypeSuffix(value); + return suffix.Length > 0 ? formatted + suffix : formatted; } MethodInfo? toStringMethod = type.GetMethod(nameof(ToString), BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null); @@ -148,6 +150,22 @@ internal static string FormatValue(T? value, int maxLength = 256) return FormatType(type); } + /// + /// Returns the C# literal suffix for numeric types where the type + /// is not the default for its category (int for integers, double for + /// floating-point). Returns empty string for int, double, and + /// non-numeric types. + /// + private static string GetNumericTypeSuffix(T value) => value switch + { + long => "L", + ulong => "UL", + uint => "U", + float => "f", + decimal => "m", + _ => string.Empty, + }; + internal static string FormatType(Type type) { string typeName = type.FullName ?? type.Name; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index d36e8df807..4c05c97acb 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -86,8 +86,8 @@ public void AreNotEqualShouldFailWhenNotEqualLongWithMessage() .WithMessage(""" Assert.AreNotEqual(1L, 1L) Expected values to differ. - not expected: 1 - actual: 1 + not expected: 1L + actual: 1L User message: A Message """); } @@ -111,8 +111,8 @@ public void AreNotEqualShouldFailWhenNotEqualDecimalWithMessage() .WithMessage(""" Assert.AreNotEqual(0.1M, 0.1M) Expected values to differ. - not expected: 0.1 - actual: 0.1 + not expected: 0.1m + actual: 0.1m User message: A Message """); } @@ -286,8 +286,8 @@ public void AreEqualShouldFailWhenNotEqualLongWithMessage() .WithMessage(""" Assert.AreEqual(1L, 2L) Expected values to be equal. - expected: 1 - actual: 2 + expected: 1L + actual: 2L User message: A Message """); } @@ -337,8 +337,8 @@ public void AreEqualShouldFailWhenNotEqualDecimalWithMessage() .WithMessage(""" Assert.AreEqual(0.1M, 0.2M) Expected values to be equal. - expected: 0.1 - actual: 0.2 + expected: 0.1m + actual: 0.2m User message: A Message """); } @@ -509,8 +509,8 @@ public async Task FloatAreEqual_InterpolatedString_DifferentValues_ShouldFail() .WithMessage(""" Assert.AreEqual(1.0f, 1.1f) Expected a difference no greater than 0.001. - expected: 1 - actual: 1.1 + expected: 1f + actual: 1.1f User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); @@ -532,8 +532,8 @@ public async Task FloatAreNotEqual_InterpolatedString_SameValues_ShouldFail() .WithMessage(""" Assert.AreNotEqual(1.0f, 1.1f) Expected a difference greater than 0.2. - not expected: 1 - actual: 1.1 + not expected: 1f + actual: 1.1f User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); @@ -555,8 +555,8 @@ public async Task DecimalAreEqual_InterpolatedString_DifferentValues_ShouldFail( .WithMessage(""" Assert.AreEqual(1.0m, 1.1m) Expected a difference no greater than 0.001. - expected: 1.0 - actual: 1.1 + expected: 1.0m + actual: 1.1m User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); @@ -578,8 +578,8 @@ public async Task DecimalAreNotEqual_InterpolatedString_SameValues_ShouldFail() .WithMessage(""" Assert.AreNotEqual(1.0m, 1.1m) Expected a difference greater than 0.2. - not expected: 1.0 - actual: 1.1 + not expected: 1.0m + actual: 1.1m User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); @@ -601,8 +601,8 @@ public async Task LongAreEqual_InterpolatedString_DifferentValues_ShouldFail() .WithMessage(""" Assert.AreEqual(1L, 2L) Expected a difference no greater than 0. - expected: 1 - actual: 2 + expected: 1L + actual: 2L User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); @@ -624,8 +624,8 @@ public async Task LongAreNotEqual_InterpolatedString_SameValues_ShouldFail() .WithMessage(""" Assert.AreNotEqual(1L, 2L) Expected a difference greater than 1. - not expected: 1 - actual: 2 + not expected: 1L + actual: 2L User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); @@ -848,8 +848,8 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif action.Should().Throw().WithMessage("""" Assert.AreEqual(5.0f, 2.0f) Expected a difference no greater than 2. - expected: 5 - actual: 2 + expected: 5f + actual: 2f """"); } @@ -859,8 +859,8 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif action.Should().Throw().WithMessage("""" Assert.AreEqual(2.0f, 5.0f) Expected a difference no greater than 2. - expected: 2 - actual: 5 + expected: 2f + actual: 5f """"); } @@ -876,8 +876,8 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFai action.Should().Throw().WithMessage("""" Assert.AreEqual(5.0f, float.NaN) Expected a difference no greater than 2. - expected: 5 - actual: NaN + expected: 5f + actual: NaNf """"); } @@ -887,8 +887,8 @@ public void FloatAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFai action.Should().Throw().WithMessage("""" Assert.AreEqual(float.NaN, 5.0f) Expected a difference no greater than 2. - expected: NaN - actual: 5 + expected: NaNf + actual: 5f """"); } @@ -1080,8 +1080,8 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual action.Should().Throw().WithMessage("""" Assert.AreNotEqual(5.0f, 4.0f) Expected a difference greater than 2. - not expected: 5 - actual: 4 + not expected: 5f + actual: 4f """"); } @@ -1091,8 +1091,8 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual action.Should().Throw().WithMessage("""" Assert.AreNotEqual(4.0f, 5.0f) Expected a difference greater than 2. - not expected: 4 - actual: 5 + not expected: 4f + actual: 5f """"); } @@ -1107,8 +1107,8 @@ public void FloatAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFail action.Should().Throw().WithMessage("""" Assert.AreNotEqual(float.NaN, float.NaN) Expected a difference greater than 2. - not expected: NaN - actual: NaN + not expected: NaNf + actual: NaNf """"); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index 21dc12fd7b..3edaa57be9 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs index f8541f560f..3f6ac4b560 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs index e86251bd15..520bc95e11 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index 2cbc74ecaa..41a6a6890a 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -409,9 +409,9 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsSmall action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (4) to be in range [5, 5]. - range: [5, 5] - value: 4 + Expected value (4f) to be in range [5f, 5f]. + range: [5f, 5f] + value: 4f """); } @@ -426,9 +426,9 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsLarge action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (6) to be in range [5, 5]. - range: [5, 5] - value: 6 + Expected value (6f) to be in range [5f, 5f]. + range: [5f, 5f] + value: 6f """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs index 8bc0c0df35..8bb4b0f9d1 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs index 32a3bd2f26..890c18e6b4 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; From 6aad990bda71b42cde9499e73e3b184592a2d695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 21:53:03 +0100 Subject: [PATCH 37/58] Improve assertion messages: drop parens, specific counts, collection display - Drop parentheses around values in relational messages: 'Expected value (5) to be greater than 10' -> 'Expected value 5 to be greater than 10' - Make HasCount message specific with embedded values: 'Expected collection to have the specified number of items.' -> 'Expected collection to have 3 item(s) but found 1.' - Display collection in ContainsSingle failure messages --- .../Assertions/Assert.Contains.cs | 22 +++++++++---- .../TestFramework/Assertions/Assert.Count.cs | 2 +- .../Resources/FrameworkMessages.resx | 12 +++---- .../Assertions/AssertTests.Contains.cs | 2 ++ .../AssertTests.IComparableTests.cs | 32 +++++++++---------- .../Assertions/AssertTests.IsInRange.cs | 30 ++++++++--------- .../Assertions/AssertTests.Items.cs | 12 ++++--- 7 files changed, 64 insertions(+), 48 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs index 2c3e04319c..9ab35793ed 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs @@ -178,11 +178,11 @@ public static T ContainsSingle(Func predicate, IEnumerable collec if (string.IsNullOrEmpty(predicateExpression)) { - ThrowAssertContainsSingleFailed(matchCount, message, collectionExpression); + ThrowAssertContainsSingleFailed(matchCount, message, collectionExpression, collection); } else { - ThrowAssertSingleMatchFailed(matchCount, message, predicateExpression, collectionExpression); + ThrowAssertSingleMatchFailed(matchCount, message, predicateExpression, collectionExpression, collection); } // Unreachable code but compiler cannot work it out @@ -237,11 +237,11 @@ public static T ContainsSingle(Func predicate, IEnumerable collec if (string.IsNullOrEmpty(predicateExpression)) { - ThrowAssertContainsSingleFailed(matchCount, message, collectionExpression); + ThrowAssertContainsSingleFailed(matchCount, message, collectionExpression, collection); } else { - ThrowAssertSingleMatchFailed(matchCount, message, predicateExpression, collectionExpression); + ThrowAssertSingleMatchFailed(matchCount, message, predicateExpression, collectionExpression, collection); } return default; @@ -778,19 +778,29 @@ public static void IsInRange(T minValue, T maxValue, T value, string? message #endregion // IsInRange [DoesNotReturn] - private static void ThrowAssertSingleMatchFailed(int actualCount, string? userMessage, string predicateExpression, string collectionExpression) + private static void ThrowAssertSingleMatchFailed(int actualCount, string? userMessage, string predicateExpression, string collectionExpression, IEnumerable? collectionValue = null) { string callSite = FormatCallSite("Assert.ContainsSingle", ("predicate", predicateExpression), ("collection", collectionExpression)); string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleMatchFailNew, actualCount); + if (collectionValue is not null) + { + message += FormatCollectionParameter(collectionExpression, collectionValue); + } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } [DoesNotReturn] - private static void ThrowAssertContainsSingleFailed(int actualCount, string? userMessage, string collectionExpression) + private static void ThrowAssertContainsSingleFailed(int actualCount, string? userMessage, string collectionExpression, IEnumerable? collectionValue = null) { string callSite = FormatCallSite("Assert.ContainsSingle", ("collection", collectionExpression)); string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleFailNew, actualCount); + if (collectionValue is not null) + { + message += FormatCollectionParameter(collectionExpression, collectionValue); + } + message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs index 159e6134b8..47cf7483ea 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs @@ -337,7 +337,7 @@ private static void HasCount(string assertionName, int expected, IEnumerable col private static void ThrowAssertCountFailed(string assertionName, int expectedCount, int actualCount, IEnumerable collection, string? userMessage, string collectionExpression) { string callSite = FormatCallSite($"Assert.{assertionName}", ("collection", collectionExpression)); - string msg = FrameworkMessages.HasCountFailNew; + string msg = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.HasCountFailNew, expectedCount, actualCount); msg += FormatCollectionParameter(collectionExpression, collection); msg += FormatAlignedParameters( ("expected count", expectedCount.ToString(CultureInfo.InvariantCulture)), diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index 7650bb8e77..2548500697 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -337,13 +337,13 @@ Actual: {2} Expected collection to contain exactly one item but found {0} item(s). - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. Expected collection to not be empty. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. Wrong exception type was thrown. @@ -388,16 +388,16 @@ Actual: {2} Expected value to not be exactly the specified type. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. Expected a positive value. diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index f4c864c991..9a52a6cd82 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -374,6 +374,7 @@ public void ContainsSingle_InNonGenericCollection_NoMessage_WithEmptyCollection_ action.Should().Throw().WithMessage(""" Assert.ContainsSingle(collection) Expected collection to contain exactly one item but found 0 item(s). + collection: [] """); } @@ -392,6 +393,7 @@ public void ContainsSingle_InNonGenericCollection_AssertCustomMessage_WithEmptyC action.Should().Throw().WithMessage(""" Assert.ContainsSingle(collection) Expected collection to contain exactly one item but found 0 item(s). + collection: [] User message: my custom message """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs index 520bc95e11..463672f75f 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs @@ -44,7 +44,7 @@ public void IsGreaterThanShouldThrowWithMessage() action.Should().Throw() .WithMessage(""" Assert.IsGreaterThan(10, 5) - Expected value (5) to be greater than 10. + Expected value 5 to be greater than 10. lower bound: 10 value: 5 User message: A Message @@ -94,7 +94,7 @@ public void IsGreaterThanOrEqualToShouldThrowWithMessage() action.Should().Throw() .WithMessage(""" Assert.IsGreaterThanOrEqualTo(10, 5) - Expected value (5) to be greater than or equal to 10. + Expected value 5 to be greater than or equal to 10. lower bound: 10 value: 5 User message: A Message @@ -144,7 +144,7 @@ public void IsLessThanShouldThrowWithMessage() action.Should().Throw() .WithMessage(""" Assert.IsLessThan(5, 10) - Expected value (10) to be less than 5. + Expected value 10 to be less than 5. upper bound: 5 value: 10 User message: A Message @@ -194,7 +194,7 @@ public void IsLessThanOrEqualToShouldThrowWithMessage() action.Should().Throw() .WithMessage(""" Assert.IsLessThanOrEqualTo(5, 10) - Expected value (10) to be less than or equal to 5. + Expected value 10 to be less than or equal to 5. upper bound: 5 value: 10 User message: A Message @@ -359,7 +359,7 @@ public void IsGreaterThan_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.IsGreaterThan(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 5) - Expected value (5) to be greater than 10. + Expected value 5 to be greater than 10. lower bound: 10 value: 5 """); @@ -374,7 +374,7 @@ public void IsGreaterThan_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.IsGreaterThan(lowerBound, value) - Expected value ({new string('V', 256)}... 44 more) to be greater than {new string('V', 256)}... 44 more. + Expected value {new string('V', 256)}... 44 more to be greater than {new string('V', 256)}... 44 more. lower bound: {new string('V', 256)}... 44 more value: {new string('V', 256)}... 44 more """); @@ -389,7 +389,7 @@ public void IsGreaterThan_WithNewlineInToString_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.IsGreaterThan(lowerBound, value) - Expected value (line1\r\nline2) to be greater than line1\r\nline2. + Expected value line1\r\nline2 to be greater than line1\r\nline2. lower bound: line1\r\nline2 value: line1\r\nline2 """); @@ -403,7 +403,7 @@ public void IsGreaterThanOrEqualTo_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.IsGreaterThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 5) - Expected value (5) to be greater than or equal to 10. + Expected value 5 to be greater than or equal to 10. lower bound: 10 value: 5 """); @@ -418,7 +418,7 @@ public void IsGreaterThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.IsGreaterThanOrEqualTo(lowerBound, value) - Expected value ({new string('V', 256)}... 44 more) to be greater than or equal to {new string('V', 256)}... 44 more. + Expected value {new string('V', 256)}... 44 more to be greater than or equal to {new string('V', 256)}... 44 more. lower bound: {new string('V', 256)}... 44 more value: {new string('V', 256)}... 44 more """); @@ -433,7 +433,7 @@ public void IsGreaterThanOrEqualTo_WithNewlineInToString_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.IsGreaterThanOrEqualTo(lowerBound, value) - Expected value (line1\r\nline2) to be greater than or equal to line1\r\nline2. + Expected value line1\r\nline2 to be greater than or equal to line1\r\nline2. lower bound: line1\r\nline2 value: line1\r\nline2 """); @@ -447,7 +447,7 @@ public void IsLessThan_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.IsLessThan(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 10) - Expected value (10) to be less than 5. + Expected value 10 to be less than 5. upper bound: 5 value: 10 """); @@ -462,7 +462,7 @@ public void IsLessThan_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.IsLessThan(upperBound, value) - Expected value ({new string('V', 256)}... 44 more) to be less than {new string('V', 256)}... 44 more. + Expected value {new string('V', 256)}... 44 more to be less than {new string('V', 256)}... 44 more. upper bound: {new string('V', 256)}... 44 more value: {new string('V', 256)}... 44 more """); @@ -477,7 +477,7 @@ public void IsLessThan_WithNewlineInToString_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.IsLessThan(upperBound, value) - Expected value (line1\r\nline2) to be less than line1\r\nline2. + Expected value line1\r\nline2 to be less than line1\r\nline2. upper bound: line1\r\nline2 value: line1\r\nline2 """); @@ -491,7 +491,7 @@ public void IsLessThanOrEqualTo_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.IsLessThanOrEqualTo(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 10) - Expected value (10) to be less than or equal to 5. + Expected value 10 to be less than or equal to 5. upper bound: 5 value: 10 """); @@ -506,7 +506,7 @@ public void IsLessThanOrEqualTo_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.IsLessThanOrEqualTo(upperBound, value) - Expected value ({new string('V', 256)}... 44 more) to be less than or equal to {new string('V', 256)}... 44 more. + Expected value {new string('V', 256)}... 44 more to be less than or equal to {new string('V', 256)}... 44 more. upper bound: {new string('V', 256)}... 44 more value: {new string('V', 256)}... 44 more """); @@ -521,7 +521,7 @@ public void IsLessThanOrEqualTo_WithNewlineInToString_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.IsLessThanOrEqualTo(upperBound, value) - Expected value (line1\r\nline2) to be less than or equal to line1\r\nline2. + Expected value line1\r\nline2 to be less than or equal to line1\r\nline2. upper bound: line1\r\nline2 value: line1\r\nline2 """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index 41a6a6890a..99f3f864e9 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -59,7 +59,7 @@ public void IsInRange_WithValueBelowRange_ThrowsAssertFailedException() action.Should().Throw() .WithMessage(""" Assert.IsInRange(value) - Expected value (3) to be in range [5, 10]. + Expected value 3 to be in range [5, 10]. range: [5, 10] value: 3 """); @@ -77,7 +77,7 @@ public void IsInRange_WithValueAboveRange_ThrowsAssertFailedException() action.Should().Throw() .WithMessage(""" Assert.IsInRange(value) - Expected value (8) to be in range [1, 5]. + Expected value 8 to be in range [1, 5]. range: [1, 5] value: 8 """); @@ -98,7 +98,7 @@ public void IsInRange_WithCustomMessage_IncludesCustomMessage() action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (10) to be in range [1, 5]. + Expected value 10 to be in range [1, 5]. range: [1, 5] value: 10 User message: Custom error message @@ -119,7 +119,7 @@ public void IsInRange_WithDoubleValues_WorksCorrectly() action.Should().Throw() .WithMessage(""" Assert.IsInRange(valueOutOfRange) - Expected value (6) to be in range [1.5, 5.5]. + Expected value 6 to be in range [1.5, 5.5]. range: [1.5, 5.5] value: 6 """); @@ -217,7 +217,7 @@ public void IsInRange_WithAllNegativeValuesBelowRange_ThrowsAssertFailedExceptio action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (-12) to be in range [-10, -5]. + Expected value -12 to be in range [-10, -5]. range: [-10, -5] value: -12 """); @@ -237,7 +237,7 @@ public void IsInRange_WithAllNegativeValuesAboveRange_ThrowsAssertFailedExceptio action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (-3) to be in range [-10, -5]. + Expected value -3 to be in range [-10, -5]. range: [-10, -5] value: -3 """); @@ -290,7 +290,7 @@ public void IsInRange_WithRangeSpanningNegativeToPositive_ValueBelowRange_Throws action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (-7) to be in range [-5, 5]. + Expected value -7 to be in range [-5, 5]. range: [-5, 5] value: -7 """); @@ -310,7 +310,7 @@ public void IsInRange_WithRangeSpanningNegativeToPositive_ValueAboveRange_Throws action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (7) to be in range [-5, 5]. + Expected value 7 to be in range [-5, 5]. range: [-5, 5] value: 7 """); @@ -364,7 +364,7 @@ public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsSmaller action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (4) to be in range [5, 5]. + Expected value 4 to be in range [5, 5]. range: [5, 5] value: 4 """); @@ -381,7 +381,7 @@ public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldFailIfValueIsLarger( action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (6) to be in range [5, 5]. + Expected value 6 to be in range [5, 5]. range: [5, 5] value: 6 """); @@ -409,7 +409,7 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsSmall action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (4f) to be in range [5f, 5f]. + Expected value 4f to be in range [5f, 5f]. range: [5f, 5f] value: 4f """); @@ -426,7 +426,7 @@ public void IsInRange_WithMaxValueEqualToMinValue_Float_ShouldFailIfValueIsLarge action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) - Expected value (6f) to be in range [5f, 5f]. + Expected value 6f to be in range [5f, 5f]. range: [5f, 5f] value: 6f """); @@ -444,7 +444,7 @@ public void IsInRange_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.IsInRange(aVeryLongVariableNameThatExceedsOneHundredCharacte...) - Expected value (20) to be in range [1, 10]. + Expected value 20 to be in range [1, 10]. range: [1, 10] value: 20 """); @@ -460,7 +460,7 @@ public void IsInRange_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.IsInRange(value) - Expected value ({new string('R', 256)}... 44 more) to be in range [{new string('R', 256)}... 44 more, {new string('R', 256)}... 44 more]. + Expected value {new string('R', 256)}... 44 more to be in range [{new string('R', 256)}... 44 more, {new string('R', 256)}... 44 more]. range: [{new string('R', 256)}... 44 more, {new string('R', 256)}... 44 more] value: {new string('R', 256)}... 44 more """); @@ -476,7 +476,7 @@ public void IsInRange_WithNewlineInToString_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.IsInRange(value) - Expected value (line1\r\nline2) to be in range [line1\r\nline2, line1\r\nline2]. + Expected value line1\r\nline2 to be in range [line1\r\nline2, line1\r\nline2]. range: [line1\r\nline2, line1\r\nline2] value: line1\r\nline2 """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs index 5155d2c2dc..267f20b33e 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs @@ -27,7 +27,7 @@ public void Count_WhenCountIsNotSame_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.HasCount(collection) - Expected collection to have the specified number of items. + Expected collection to have 3 item(s) but found 1. collection: [1] expected count: 3 actual count: 1 @@ -42,7 +42,7 @@ public async Task Count_InterpolatedString_WhenCountIsNotSame_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.HasCount(Array.Empty()) - Expected collection to have the specified number of items. + Expected collection to have 1 item(s) but found 0. collection: [] expected count: 1 actual count: 0 @@ -68,7 +68,7 @@ public void NotAny_WhenNotEmpty_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.IsEmpty(collection) - Expected collection to have the specified number of items. + Expected collection to have 0 item(s) but found 1. collection: [1] expected count: 0 actual count: 1 @@ -84,7 +84,7 @@ public async Task NotAny_InterpolatedString_WhenNotEmpty_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsEmpty(collection) - Expected collection to have the specified number of items. + Expected collection to have 0 item(s) but found 1. collection: [1] expected count: 0 actual count: 1 @@ -115,6 +115,7 @@ public void Single_WhenNoItems_ShouldFail() .WithMessage(""" Assert.ContainsSingle(Array.Empty()) Expected collection to contain exactly one item but found 0 item(s). + collection: [] """); } @@ -125,6 +126,7 @@ public void Single_WhenMultipleItems_ShouldFail() .WithMessage(""" Assert.ContainsSingle([1, 2, 3]) Expected collection to contain exactly one item but found 3 item(s). + collection: [1, 2, 3] """); } @@ -137,6 +139,7 @@ public async Task Single_InterpolatedString_WhenNoItem_ShouldFail() .WithMessage(""" Assert.ContainsSingle(Array.Empty()) Expected collection to contain exactly one item but found 0 item(s). + collection: [] User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); @@ -151,6 +154,7 @@ public async Task Single_InterpolatedString_WhenMultipleItems_ShouldFail() .WithMessage(""" Assert.ContainsSingle([1, 2, 3]) Expected collection to contain exactly one item but found 3 item(s). + collection: [1, 2, 3] User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); From 1332f3597a1519dc32f2f4200fb711c6d1561824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 21:57:26 +0100 Subject: [PATCH 38/58] Drop parentheses from null type display: (null) -> null --- .../Assertions/Assert.IsExactInstanceOfType.cs | 4 ++-- .../Assertions/Assert.IsInstanceOfType.cs | 4 ++-- .../AssertTests.IsExactInstanceOfTypeTests.cs | 17 +++++------------ .../AssertTests.IsInstanceOfTypeTests.cs | 17 +++++------------ 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs index a9b2083e57..2efc1b279b 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs @@ -328,7 +328,7 @@ private static void ThrowAssertIsExactInstanceOfTypeFailed(object? value, Type? message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (expectedType is null) { - message += Environment.NewLine + " expected type: (null)"; + message += Environment.NewLine + " expected type: null"; } else { @@ -411,7 +411,7 @@ private static void ThrowAssertIsNotExactInstanceOfTypeFailed(object? value, Typ message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (wrongType is null) { - message += Environment.NewLine + " wrong type: (null)"; + message += Environment.NewLine + " wrong type: null"; } else { diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index de54c60168..56b2189c0c 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -335,7 +335,7 @@ private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expec message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (expectedType is null) { - message += Environment.NewLine + " expected type: (null)"; + message += Environment.NewLine + " expected type: null"; } else { @@ -420,7 +420,7 @@ private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wr message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (wrongType is null) { - message += Environment.NewLine + " wrong type: (null)"; + message += Environment.NewLine + " wrong type: null"; } else { diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index c9c459fab4..03f3d3fb27 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -28,11 +28,8 @@ public void ExactInstanceOfTypeShouldFailWhenTypeIsNull() Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expected type: (null) -"""); - } - - public void ExactInstanceOfTypeShouldFailWhenTypeIsMismatched() + expected type: null +""); { Action action = () => Assert.IsExactInstanceOfType(5, typeof(string)); action.Should().Throw() @@ -101,12 +98,8 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expected type: (null) + expected type: null User message: User-provided message -"""); - } - - public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() { Action action = () => Assert.IsExactInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() @@ -148,7 +141,7 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull( Assert.IsExactInstanceOfType(5) Expected value to be exactly of the specified type. value: 5 - expected type: (null) + expected type: null User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); @@ -187,7 +180,7 @@ public void ExactInstanceNotOfTypeShouldFailWhenTypeIsNull() Assert.IsNotExactInstanceOfType(5) Expected value to not be exactly the specified type. value: 5 - wrong type: (null) + wrong type: null """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 23e8c2b40a..417cb872e7 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -28,11 +28,8 @@ public void InstanceOfTypeShouldFailWhenTypeIsNull() Assert.IsInstanceOfType(5) Expected value to be of the specified type. value: 5 - expected type: (null) - """); - } - - public void InstanceOfTypeShouldFailWhenTypeIsMismatched() + expected type: null + ""); { Action action = () => Assert.IsInstanceOfType(5, typeof(string)); action.Should().Throw() @@ -70,12 +67,8 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() Assert.IsInstanceOfType(5) Expected value to be of the specified type. value: 5 - expected type: (null) + expected type: null User message: User-provided message - """); - } - - public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() { Action action = () => Assert.IsInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() @@ -117,7 +110,7 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull() Assert.IsInstanceOfType(5) Expected value to be of the specified type. value: 5 - expected type: (null) + expected type: null User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); @@ -156,7 +149,7 @@ public void InstanceNotOfTypeShouldFailWhenTypeIsNull() Assert.IsNotInstanceOfType(5) Expected value to not be an instance of the specified type. value: 5 - wrong type: (null) + wrong type: null """); } From c6efa3eb8338f204edb3ab749cdf7740b2b3dafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 19 Mar 2026 22:21:01 +0100 Subject: [PATCH 39/58] Improve InstanceOfType messages: embed type in sentence, combine value+type - IsInstanceOfType: 'Expected value to be an instance of .' with 'value: 5 ()' on one line - IsExactInstanceOfType: 'Expected value to be exactly .' - Remove redundant separate 'expected type:' and 'actual type:' lines - IsNot variants: 'Expected value to not be [an instance of|exactly] .' - Null type edge case preserved with fallback lines --- .../Assert.IsExactInstanceOfType.cs | 21 ++-- .../Assertions/Assert.IsInstanceOfType.cs | 21 ++-- .../Resources/FrameworkMessages.resx | 8 +- .../AssertTests.IsExactInstanceOfTypeTests.cs | 117 +++++++----------- .../AssertTests.IsInstanceOfTypeTests.cs | 89 ++++++------- 5 files changed, 104 insertions(+), 152 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs index 2efc1b279b..3b6f56aaaf 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs @@ -323,20 +323,18 @@ private static bool IsExactInstanceOfTypeFailing([NotNullWhen(false)] object? va private static void ThrowAssertIsExactInstanceOfTypeFailed(object? value, Type? expectedType, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsExactInstanceOfType", (nameof(value), valueExpression)); - string message = FrameworkMessages.IsExactInstanceOfTypeFailNew; + string message; - message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (expectedType is null) { + message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsExactInstanceOfTypeFailNew, "null"); + message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); message += Environment.NewLine + " expected type: null"; } else { - message += Environment.NewLine + $" expected type: {FormatType(expectedType)}"; - if (value is not null) - { - message += Environment.NewLine + $" actual type: {FormatType(value.GetType())}"; - } + message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsExactInstanceOfTypeFailNew, FormatType(expectedType)); + message += Environment.NewLine + $" value: {(value is null ? "null" : FormatValueWithType(value))}"; } message = AppendUserMessage(message, userMessage); @@ -406,17 +404,18 @@ private static bool IsNotExactInstanceOfTypeFailing(object? value, [NotNullWhen( private static void ThrowAssertIsNotExactInstanceOfTypeFailed(object? value, Type? wrongType, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsNotExactInstanceOfType", (nameof(value), valueExpression)); - string message = FrameworkMessages.IsNotExactInstanceOfTypeFailNew; + string message; - message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (wrongType is null) { + message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsNotExactInstanceOfTypeFailNew, "null"); + message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); message += Environment.NewLine + " wrong type: null"; } else { - message += Environment.NewLine + $" wrong type: {FormatType(wrongType)}" - + Environment.NewLine + $" actual type: {FormatType(value!.GetType())}"; + message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsNotExactInstanceOfTypeFailNew, FormatType(wrongType)); + message += Environment.NewLine + $" value: {FormatValueWithType(value!)}"; } message = AppendUserMessage(message, userMessage); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 56b2189c0c..220ed86a54 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -330,20 +330,18 @@ private static bool IsInstanceOfTypeFailing([NotNullWhen(false)] object? value, private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expectedType, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsInstanceOfType", (nameof(value), valueExpression)); - string message = FrameworkMessages.IsInstanceOfTypeFailNew; + string message; - message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (expectedType is null) { + message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsInstanceOfTypeFailNew, "null"); + message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); message += Environment.NewLine + " expected type: null"; } else { - message += Environment.NewLine + $" expected type: {FormatType(expectedType)}"; - if (value is not null) - { - message += Environment.NewLine + $" actual type: {FormatType(value.GetType())}"; - } + message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsInstanceOfTypeFailNew, FormatType(expectedType)); + message += Environment.NewLine + $" value: {(value is null ? "null" : FormatValueWithType(value))}"; } message = AppendUserMessage(message, userMessage); @@ -415,17 +413,18 @@ private static bool IsNotInstanceOfTypeFailing(object? value, [NotNullWhen(false private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wrongType, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsNotInstanceOfType", (nameof(value), valueExpression)); - string message = FrameworkMessages.IsNotInstanceOfTypeFailNew; + string message; - message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); if (wrongType is null) { + message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsNotInstanceOfTypeFailNew, "null"); + message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); message += Environment.NewLine + " wrong type: null"; } else { - message += Environment.NewLine + $" wrong type: {FormatType(wrongType)}" - + Environment.NewLine + $" actual type: {FormatType(value!.GetType())}"; + message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsNotInstanceOfTypeFailNew, FormatType(wrongType)); + message += Environment.NewLine + $" value: {FormatValueWithType(value!)}"; } message = AppendUserMessage(message, userMessage); diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index 2548500697..c6aeab5604 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -376,16 +376,16 @@ Actual: {2} Expected a non-null value. - Expected value to be of the specified type. + Expected value to be an instance of {0}. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. Expected value {0} to be greater than {1}. diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index 03f3d3fb27..a5e857d400 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -14,9 +14,8 @@ public void ExactInstanceOfTypeShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(null) -Expected value to be exactly of the specified type. +Expected value to be exactly . value: null - expected type: """); } @@ -26,19 +25,20 @@ public void ExactInstanceOfTypeShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) -Expected value to be exactly of the specified type. +Expected value to be exactly null. value: 5 expected type: null -""); +"""); + } + + public void ExactInstanceOfTypeShouldFailWhenTypeIsMismatched() { Action action = () => Assert.IsExactInstanceOfType(5, typeof(string)); action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) -Expected value to be exactly of the specified type. - value: 5 - expected type: - actual type: +Expected value to be exactly . + value: 5 () """); } @@ -50,10 +50,8 @@ public void ExactInstanceOfTypeShouldFailOnHigherInstance() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) -Expected value to be exactly of the specified type. - value: 5 - expected type: - actual type: +Expected value to be exactly . + value: 5 () """); } @@ -64,10 +62,8 @@ public void ExactInstanceOfTypeShouldFailOnDerivedType() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(x) -Expected value to be exactly of the specified type. +Expected value to be exactly . value: - expected type: - actual type: """); } @@ -83,9 +79,8 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(null) -Expected value to be exactly of the specified type. +Expected value to be exactly . value: null - expected type: User message: User-provided message """); } @@ -96,19 +91,21 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) -Expected value to be exactly of the specified type. +Expected value to be exactly null. value: 5 expected type: null User message: User-provided message +"""); + } + + public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() { Action action = () => Assert.IsExactInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) -Expected value to be exactly of the specified type. - value: 5 - expected type: - actual type: +Expected value to be exactly . + value: 5 () User message: User-provided message """); } @@ -124,9 +121,8 @@ public async Task ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenValue (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsExactInstanceOfType(null) - Expected value to be exactly of the specified type. + Expected value to be exactly . value: null - expected type: User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); @@ -139,7 +135,7 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull( action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) -Expected value to be exactly of the specified type. +Expected value to be exactly null. value: 5 expected type: null User message: User-provided message DummyClassTrackingToStringCalls @@ -154,10 +150,8 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMisma action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) -Expected value to be exactly of the specified type. - value: 5 - expected type: - actual type: +Expected value to be exactly . + value: 5 () User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); @@ -178,7 +172,7 @@ public void ExactInstanceNotOfTypeShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsNotExactInstanceOfType(5) -Expected value to not be exactly the specified type. +Expected value to not be exactly null. value: 5 wrong type: null """); @@ -201,10 +195,8 @@ public void ExactInstanceNotOfTypeShouldFailOnExactType() action.Should().Throw() .WithMessage(""" Assert.IsNotExactInstanceOfType(x) -Expected value to not be exactly the specified type. +Expected value to not be exactly . value: - wrong type: - actual type: """); } @@ -214,9 +206,8 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(null) -Expected value to be exactly of the specified type. +Expected value to be exactly . value: null - expected type: """); } @@ -226,10 +217,8 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) -Expected value to be exactly of the specified type. - value: 5 - expected type: - actual type: +Expected value to be exactly . + value: 5 () """); } @@ -240,10 +229,8 @@ public void IsExactInstanceOfTypeUsingGenericType_WhenDerivedType_Fails() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(x) -Expected value to be exactly of the specified type. +Expected value to be exactly . value: - expected type: - actual type: """); } @@ -268,10 +255,8 @@ public void IsExactInstanceOfTypeUsingGenericType_OnHigherInstance_Fails() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) -Expected value to be exactly of the specified type. - value: 5 - expected type: - actual type: +Expected value to be exactly . + value: 5 () """); } @@ -301,10 +286,8 @@ public void IsNotExactInstanceOfTypeUsingGenericType_OnExactType_Fails() action.Should().Throw() .WithMessage(""" Assert.IsNotExactInstanceOfType(x) -Expected value to not be exactly the specified type. +Expected value to not be exactly . value: - wrong type: - actual type: """); } @@ -388,10 +371,8 @@ public void IsExactInstanceOfType_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) - Expected value to be exactly of the specified type. - value: "hello" - expected type: - actual type: + Expected value to be exactly . + value: "hello" () """); } @@ -403,10 +384,8 @@ public void IsExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.IsExactInstanceOfType(obj) - Expected value to be exactly of the specified type. - value: {new string('L', 256)}... 44 more - expected type: - actual type: + Expected value to be exactly . + value: {new string('L', 256)}... 44 more () """); } @@ -418,10 +397,8 @@ public void IsExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(obj) - Expected value to be exactly of the specified type. - value: line1\r\nline2\nline3 - expected type: - actual type: + Expected value to be exactly . + value: line1\r\nline2\nline3 () """); } @@ -433,10 +410,8 @@ public void IsNotExactInstanceOfType_WithLongExpression_ShouldTruncateExpression action.Should().Throw() .WithMessage(""" Assert.IsNotExactInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) - Expected value to not be exactly the specified type. - value: "hello" - wrong type: - actual type: + Expected value to not be exactly . + value: "hello" () """); } @@ -448,10 +423,8 @@ public void IsNotExactInstanceOfType_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.IsNotExactInstanceOfType(obj) - Expected value to not be exactly the specified type. - value: {new string('L', 256)}... 44 more - wrong type: - actual type: + Expected value to not be exactly . + value: {new string('L', 256)}... 44 more () """); } @@ -463,10 +436,8 @@ public void IsNotExactInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines( action.Should().Throw() .WithMessage(""" Assert.IsNotExactInstanceOfType(obj) - Expected value to not be exactly the specified type. - value: line1\r\nline2\nline3 - wrong type: - actual type: + Expected value to not be exactly . + value: line1\r\nline2\nline3 () """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 417cb872e7..d627e79935 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -14,9 +14,8 @@ public void InstanceOfTypeShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(null) - Expected value to be of the specified type. + Expected value to be an instance of . value: null - expected type: """); } @@ -26,19 +25,20 @@ public void InstanceOfTypeShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) - Expected value to be of the specified type. + Expected value to be an instance of null. value: 5 expected type: null - ""); + """); + } + + public void InstanceOfTypeShouldFailWhenTypeIsMismatched() { Action action = () => Assert.IsInstanceOfType(5, typeof(string)); action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) - Expected value to be of the specified type. - value: 5 - expected type: - actual type: + Expected value to be an instance of . + value: 5 () """); } @@ -52,9 +52,8 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(null) - Expected value to be of the specified type. + Expected value to be an instance of . value: null - expected type: User message: User-provided message """); } @@ -65,19 +64,21 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) - Expected value to be of the specified type. + Expected value to be an instance of null. value: 5 expected type: null User message: User-provided message + """); + } + + public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() { Action action = () => Assert.IsInstanceOfType(5, typeof(string), "User-provided message"); action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) - Expected value to be of the specified type. - value: 5 - expected type: - actual type: + Expected value to be an instance of . + value: 5 () User message: User-provided message """); } @@ -93,9 +94,8 @@ public async Task InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNul (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsInstanceOfType(null) - Expected value to be of the specified type. + Expected value to be an instance of . value: null - expected type: User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); @@ -108,7 +108,7 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) - Expected value to be of the specified type. + Expected value to be an instance of null. value: 5 expected type: null User message: User-provided message DummyClassTrackingToStringCalls @@ -123,10 +123,8 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMismatched action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) - Expected value to be of the specified type. - value: 5 - expected type: - actual type: + Expected value to be an instance of . + value: 5 () User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); @@ -147,7 +145,7 @@ public void InstanceNotOfTypeShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsNotInstanceOfType(5) - Expected value to not be an instance of the specified type. + Expected value to not be an instance of null. value: 5 wrong type: null """); @@ -163,9 +161,8 @@ public void IsInstanceOfTypeUsingGenericType_WhenValueIsNull_Fails() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(null) - Expected value to be of the specified type. + Expected value to be an instance of . value: null - expected type: """); } @@ -175,10 +172,8 @@ public void IsInstanceOfTypeUsingGenericType_WhenTypeMismatch_Fails() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) - Expected value to be of the specified type. - value: 5 - expected type: - actual type: + Expected value to be an instance of . + value: 5 () """); } @@ -304,10 +299,8 @@ public void IsInstanceOfType_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) - Expected value to be of the specified type. - value: "hello" - expected type: - actual type: + Expected value to be an instance of . + value: "hello" () """); } @@ -319,10 +312,8 @@ public void IsInstanceOfType_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.IsInstanceOfType(obj) - Expected value to be of the specified type. - value: {new string('L', 256)}... 44 more - expected type: - actual type: + Expected value to be an instance of . + value: {new string('L', 256)}... 44 more () """); } @@ -334,10 +325,8 @@ public void IsInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(obj) - Expected value to be of the specified type. - value: line1\r\nline2\nline3 - expected type: - actual type: + Expected value to be an instance of . + value: line1\r\nline2\nline3 () """); } @@ -349,10 +338,8 @@ public void IsNotInstanceOfType_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.IsNotInstanceOfType(aVeryLongVariableNameThatExceedsOneHundredCharacte...) - Expected value to not be an instance of the specified type. - value: "hello" - wrong type: - actual type: + Expected value to not be an instance of . + value: "hello" () """); } @@ -364,10 +351,8 @@ public void IsNotInstanceOfType_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.IsNotInstanceOfType(obj) - Expected value to not be an instance of the specified type. - value: {new string('L', 256)}... 44 more - wrong type: - actual type: + Expected value to not be an instance of . + value: {new string('L', 256)}... 44 more () """); } @@ -379,10 +364,8 @@ public void IsNotInstanceOfType_WithNewlineInToString_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.IsNotInstanceOfType(obj) - Expected value to not be an instance of the specified type. - value: line1\r\nline2\nline3 - wrong type: - actual type: + Expected value to not be an instance of . + value: line1\r\nline2\nline3 () """); } From d8e4572e5a94d9ce1f2a006a15461b867b15059e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 20 Mar 2026 08:51:22 +0100 Subject: [PATCH 40/58] Add equality hint to AreSame and show hash in AreNotSame - AreSame failures now show 'Objects are equal.' or 'Objects are not equal.' to help diagnose whether the issue is reference sharing vs wrong value - AreNotSame failures now show hash codes to confirm same instance - Equality check is guarded against Equals() throwing --- .../Assertions/Assert.AreSame.cs | 35 ++++++++++++++-- .../Assertions/AssertTests.AreSame.cs | 42 ++++++++----------- 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index 3c9841e27c..a25ba3d650 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -210,7 +210,24 @@ private static void ThrowAssertAreSameFailed(T? expected, T? actual, string? } else { - message = FrameworkMessages.AreSameFailNew; + // Check equality to give a diagnostic hint about whether the objects are equal + // even though they are different references. + string equalityHint = string.Empty; + if (expected is not null && actual is not null) + { + try + { + equalityHint = expected.Equals(actual) + ? " Objects are equal." + : " Objects are not equal."; + } + catch (Exception) + { + // If Equals throws, skip the hint. + } + } + + message = FrameworkMessages.AreSameFailNew + equalityHint; } message += FormatAlignedParameters( @@ -274,9 +291,21 @@ private static void ThrowAssertAreNotSameFailed(T? notExpected, T? actual, st { string callSite = FormatCallSite("Assert.AreNotSame", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression)); string message = FrameworkMessages.AreNotSameFailNew; + + string notExpectedFormatted = FormatValue(notExpected); + string actualFormatted = FormatValue(actual); + + // Since AreNotSame failed, both references point to the same object. + // Show the hash to confirm it's one instance. + if (notExpected is not null) + { + notExpectedFormatted += $" (Hash={RuntimeHelpers.GetHashCode(notExpected!)})"; + actualFormatted += $" (Hash={RuntimeHelpers.GetHashCode(actual!)})"; + } + message += FormatAlignedParameters( - ("not expected", FormatValue(notExpected)), - (nameof(actual), FormatValue(actual))); + ("not expected", notExpectedFormatted), + (nameof(actual), actualFormatted)); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index 3edaa57be9..7624e69966 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -18,13 +18,10 @@ public void AreSame_PassDifferentObject_ShouldFail() Action action = () => Assert.AreSame(new object(), new object()); action.Should().Throw().WithMessage(""" Assert.AreSame(new object(), new object()) - Expected references to be the same. + Expected references to be the same. Objects are not equal. expected: (Hash=*) actual: (Hash=*) """); - } - - public void AreSame_StringMessage_PassSameObject_ShouldPass() { object o = new(); Assert.AreSame(o, o, "User-provided message"); @@ -35,14 +32,11 @@ public void AreSame_StringMessage_PassDifferentObject_ShouldFail() Action action = () => Assert.AreSame(new object(), new object(), "User-provided message"); action.Should().Throw().WithMessage(""" Assert.AreSame(new object(), new object()) - Expected references to be the same. + Expected references to be the same. Objects are not equal. expected: (Hash=*) actual: (Hash=*) User message: User-provided message """); - } - - public void AreSame_InterpolatedString_PassSameObject_ShouldPass() { DummyClassTrackingToStringCalls o = new(); Assert.AreSame(o, o, $"User-provided message: {o}"); @@ -56,7 +50,7 @@ public async Task AreSame_InterpolatedString_PassDifferentObject_ShouldFail() Func action = async () => Assert.AreSame(new object(), new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()).WithMessage(""" Assert.AreSame(new object(), new object()) - Expected references to be the same. + Expected references to be the same. Objects are not equal. expected: (Hash=*) actual: (Hash=*) User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* @@ -109,8 +103,8 @@ public void AreNotSame_PassSameObject_ShouldFail() action.Should().Throw().WithMessage(""" Assert.AreNotSame(o, o) Expected references to be different. - not expected: - actual: + not expected: (Hash=*) + actual: (Hash=*) """); } @@ -124,8 +118,8 @@ public void AreNotSame_StringMessage_PassSameObject_ShouldFail() action.Should().Throw().WithMessage(""" Assert.AreNotSame(o, o) Expected references to be different. - not expected: - actual: + not expected: (Hash=*) + actual: (Hash=*) User message: User-provided message """); } @@ -145,8 +139,8 @@ public async Task AreNotSame_InterpolatedString_PassSameObject_ShouldFail() (await action.Should().ThrowAsync()).WithMessage(""" Assert.AreNotSame(o, o) Expected references to be different. - not expected: DummyClassTrackingToStringCalls - actual: DummyClassTrackingToStringCalls + not expected: DummyClassTrackingToStringCalls (Hash=*) + actual: DummyClassTrackingToStringCalls (Hash=*) User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); @@ -162,7 +156,7 @@ public void AreSame_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.AreSame(aVeryLongVariableNameThatExceedsOneHundredCharacte..., new object()) - Expected references to be the same. + Expected references to be the same. Objects are not equal. expected: (Hash=*) actual: (Hash=*) """); @@ -174,7 +168,7 @@ public void AreSame_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.AreSame(new ObjectWithLongToString(), new ObjectWithLongToString()) - Expected references to be the same. + Expected references to be the same. Objects are not equal. expected: {new string('L', 256)}... 44 more (Hash=*) actual: {new string('L', 256)}... 44 more (Hash=*) """); @@ -186,7 +180,7 @@ public void AreSame_WithNewlineInToString_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.AreSame(new ObjectWithNewlineToString(), new ObjectWithNewlineToString()) - Expected references to be the same. + Expected references to be the same. Objects are not equal. expected: line1\r\nline2\nline3 (Hash=*) actual: line1\r\nline2\nline3 (Hash=*) """); @@ -201,8 +195,8 @@ public void AreNotSame_WithLongExpression_ShouldTruncateExpression() .WithMessage(""" Assert.AreNotSame(aVeryLongVariableNameThatExceedsOneHundredCharacte..., aVeryLongVariableNameThatExceedsOneHundredCharacte...) Expected references to be different. - not expected: - actual: + not expected: (Hash=*) + actual: (Hash=*) """); } @@ -215,8 +209,8 @@ public void AreNotSame_WithLongToStringValue_ShouldTruncateValue() .WithMessage($""" Assert.AreNotSame(obj, obj) Expected references to be different. - not expected: {new string('L', 256)}... 44 more - actual: {new string('L', 256)}... 44 more + not expected: {new string('L', 256)}... 44 more (Hash=*) + actual: {new string('L', 256)}... 44 more (Hash=*) """); } @@ -229,8 +223,8 @@ public void AreNotSame_WithNewlineInToString_ShouldEscapeNewlines() .WithMessage(""" Assert.AreNotSame(obj, obj) Expected references to be different. - not expected: line1\r\nline2\nline3 - actual: line1\r\nline2\nline3 + not expected: line1\r\nline2\nline3 (Hash=*) + actual: line1\r\nline2\nline3 (Hash=*) """); } From 7065af5c116e8653813fb76772005371ebe7f1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 20 Mar 2026 10:37:52 +0100 Subject: [PATCH 41/58] Move user message before explanation, drop 'User message:' prefix User message now appears right after the call-site line, before the assertion explanation and parameter details. The 'User message:' prefix is removed - position alone distinguishes it. --- .../Assertions/Assert.AreEqual.cs | 2 +- .../TestFramework/Assertions/Assert.cs | 4 +- .../Assertions/AssertTests.AreEqualTests.cs | 48 +++++++++---------- .../Assertions/AssertTests.AreSame.cs | 16 +++---- .../Assertions/AssertTests.Contains.cs | 42 ++++++++-------- .../Assertions/AssertTests.EndsWith.cs | 2 +- .../AssertTests.IComparableTests.cs | 12 ++--- .../AssertTests.IsExactInstanceOfTypeTests.cs | 12 ++--- .../Assertions/AssertTests.IsInRange.cs | 2 +- .../AssertTests.IsInstanceOfTypeTests.cs | 12 ++--- .../Assertions/AssertTests.IsNull.cs | 8 ++-- .../Assertions/AssertTests.IsTrueTests.cs | 24 +++++----- .../Assertions/AssertTests.Items.cs | 14 +++--- .../Assertions/AssertTests.StartsWith.cs | 2 +- .../AssertTests.ThrowsExceptionTests.cs | 16 +++---- 15 files changed, 108 insertions(+), 108 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index a628ec5e9b..2697d38b7f 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -600,7 +600,7 @@ private static string FormatStringDifferenceMessage(string expected, string actu string formattedUserMessage = string.IsNullOrEmpty(userMessage) ? string.Empty : userMessage; string result = lengthInfo + Environment.NewLine + expectedLine + Environment.NewLine + actualLine + Environment.NewLine + " " + new string('-', adjustedCaretPosition - 2) + "^"; - return string.IsNullOrEmpty(formattedUserMessage) ? result : result + Environment.NewLine + "User message: " + formattedUserMessage; + return string.IsNullOrEmpty(formattedUserMessage) ? result : formattedUserMessage + Environment.NewLine + result; } [DoesNotReturn] diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index dd6cd9cb8d..1ea6554298 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -318,13 +318,13 @@ internal static string FormatParameter(string paramName, string expression, T } /// - /// Appends the user-provided message to the end of a failure message. + /// Prepends the user-provided message before the assertion explanation. /// Returns the message unchanged if userMessage is null or empty. /// internal static string AppendUserMessage(string message, string? userMessage) => string.IsNullOrEmpty(userMessage) ? message - : message + Environment.NewLine + "User message: " + userMessage; + : userMessage + Environment.NewLine + message; /// /// Formats a parameter line showing only the expression (no value). diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index 4c05c97acb..cfc0c9b4d6 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -21,10 +21,10 @@ public void AreNotEqualShouldFailWhenNotEqualTypeWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreNotEqual(1, 1) + A Message Expected values to differ. not expected: 1 actual: 1 - User message: A Message """); } @@ -40,10 +40,10 @@ public void AreNotEqualShouldFailWhenNotEqualStringWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreNotEqual("A", "A") + A Message Expected values to differ. not expected: "A" actual: "A" - User message: A Message """); } @@ -66,10 +66,10 @@ public void AreNotEqualShouldFailWhenNotEqualIntWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreNotEqual(1, 1) + A Message Expected values to differ. not expected: 1 actual: 1 - User message: A Message """); } @@ -85,10 +85,10 @@ public void AreNotEqualShouldFailWhenNotEqualLongWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreNotEqual(1L, 1L) + A Message Expected values to differ. not expected: 1L actual: 1L - User message: A Message """); } @@ -110,10 +110,10 @@ public void AreNotEqualShouldFailWhenNotEqualDecimalWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreNotEqual(0.1M, 0.1M) + A Message Expected values to differ. not expected: 0.1m actual: 0.1m - User message: A Message """); } @@ -135,10 +135,10 @@ public void AreNotEqualShouldFailWhenNotEqualDoubleWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreNotEqual(0.1, 0.1) + A Message Expected values to differ. not expected: 0.1 actual: 0.1 - User message: A Message """); } @@ -160,10 +160,10 @@ public void AreNotEqualShouldFailWhenFloatDoubleWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreNotEqual(100E-2, 100E-2) + A Message Expected values to differ. not expected: 1 actual: 1 - User message: A Message """); } @@ -185,10 +185,10 @@ public void AreEqualShouldFailWhenNotEqualTypeWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreEqual(null, "string") + A Message Expected values to be equal. expected: null actual: "string" - User message: A Message """); } @@ -266,10 +266,10 @@ public void AreEqualShouldFailWhenNotEqualIntWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreEqual(1, 2) + A Message Expected values to be equal. expected: 1 actual: 2 - User message: A Message """); } @@ -285,10 +285,10 @@ public void AreEqualShouldFailWhenNotEqualLongWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreEqual(1L, 2L) + A Message Expected values to be equal. expected: 1L actual: 2L - User message: A Message """); } @@ -310,10 +310,10 @@ public void AreEqualShouldFailWhenNotEqualDoubleWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreEqual(0.1, 0.2) + A Message Expected values to be equal. expected: 0.1 actual: 0.2 - User message: A Message """); } @@ -336,10 +336,10 @@ public void AreEqualShouldFailWhenNotEqualDecimalWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreEqual(0.1M, 0.2M) + A Message Expected values to be equal. expected: 0.1m actual: 0.2m - User message: A Message """); } @@ -361,10 +361,10 @@ public void AreEqualShouldFailWhenFloatDoubleWithMessage() action.Should().Throw() .WithMessage(""" Assert.AreEqual(100E-2, 200E-2) + A Message Expected values to be equal. expected: 1 actual: 2 - User message: A Message """); } @@ -462,10 +462,10 @@ public async Task GenericAreEqual_InterpolatedString_DifferentValues_ShouldFail( (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreEqual(0, 1) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected values to be equal. expected: 0 actual: 1 - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -485,10 +485,10 @@ public async Task GenericAreNotEqual_InterpolatedString_SameValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreNotEqual(0, 0) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected values to differ. not expected: 0 actual: 0 - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -508,10 +508,10 @@ public async Task FloatAreEqual_InterpolatedString_DifferentValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreEqual(1.0f, 1.1f) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than 0.001. expected: 1f actual: 1.1f - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -531,10 +531,10 @@ public async Task FloatAreNotEqual_InterpolatedString_SameValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreNotEqual(1.0f, 1.1f) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than 0.2. not expected: 1f actual: 1.1f - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -554,10 +554,10 @@ public async Task DecimalAreEqual_InterpolatedString_DifferentValues_ShouldFail( (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreEqual(1.0m, 1.1m) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than 0.001. expected: 1.0m actual: 1.1m - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -577,10 +577,10 @@ public async Task DecimalAreNotEqual_InterpolatedString_SameValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreNotEqual(1.0m, 1.1m) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than 0.2. not expected: 1.0m actual: 1.1m - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -600,10 +600,10 @@ public async Task LongAreEqual_InterpolatedString_DifferentValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreEqual(1L, 2L) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than 0. expected: 1L actual: 2L - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -623,10 +623,10 @@ public async Task LongAreNotEqual_InterpolatedString_SameValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreNotEqual(1L, 2L) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than 1. not expected: 1L actual: 2L - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -646,10 +646,10 @@ public async Task DoubleAreEqual_InterpolatedString_DifferentValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreEqual(1.0d, 1.1d) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference no greater than 0.001. expected: 1 actual: 1.1 - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -669,10 +669,10 @@ public async Task DoubleAreNotEqual_InterpolatedString_SameValues_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.AreNotEqual(1.0d, 1.1d) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a difference greater than 0.2. not expected: 1 actual: 1.1 - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -1724,11 +1724,11 @@ public void AreEqualStringWithUserMessage() action.Should().Throw() .WithMessage(""" Assert.AreEqual("aaaa", "aaab") + My custom message String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" --------------^ - User message: My custom message """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index 7624e69966..b5c1bb5e2d 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -32,10 +32,10 @@ public void AreSame_StringMessage_PassDifferentObject_ShouldFail() Action action = () => Assert.AreSame(new object(), new object(), "User-provided message"); action.Should().Throw().WithMessage(""" Assert.AreSame(new object(), new object()) + User-provided message Expected references to be the same. Objects are not equal. expected: (Hash=*) actual: (Hash=*) - User message: User-provided message """); { DummyClassTrackingToStringCalls o = new(); @@ -50,10 +50,10 @@ public async Task AreSame_InterpolatedString_PassDifferentObject_ShouldFail() Func action = async () => Assert.AreSame(new object(), new object(), $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()).WithMessage(""" Assert.AreSame(new object(), new object()) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected references to be the same. Objects are not equal. expected: (Hash=*) actual: (Hash=*) - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -77,10 +77,10 @@ public void AreSame_StringMessage_BothAreValueTypes_ShouldFailWithSpecializedMes Action action = () => Assert.AreSame(1, 1, "User-provided message"); action.Should().Throw().WithMessage(""" Assert.AreSame(1, 1) + User-provided message Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) actual: 1 (Hash=*) - User message: User-provided message """); } @@ -89,10 +89,10 @@ public void AreSame_InterpolatedString_BothAreValueTypes_ShouldFailWithSpecializ Action action = () => Assert.AreSame(1, 1, $"User-provided message {new object().GetType()}"); action.Should().Throw().WithMessage(""" Assert.AreSame(1, 1) + User-provided message System.Object Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). expected: 1 (Hash=*) actual: 1 (Hash=*) - User message: User-provided message System.Object """); } @@ -117,10 +117,10 @@ public void AreNotSame_StringMessage_PassSameObject_ShouldFail() Action action = () => Assert.AreNotSame(o, o, "User-provided message"); action.Should().Throw().WithMessage(""" Assert.AreNotSame(o, o) + User-provided message Expected references to be different. not expected: (Hash=*) actual: (Hash=*) - User message: User-provided message """); } @@ -138,10 +138,10 @@ public async Task AreNotSame_InterpolatedString_PassSameObject_ShouldFail() Func action = async () => Assert.AreNotSame(o, o, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()).WithMessage(""" Assert.AreNotSame(o, o) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected references to be different. not expected: DummyClassTrackingToStringCalls (Hash=*) actual: DummyClassTrackingToStringCalls (Hash=*) - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -195,8 +195,8 @@ public void AreNotSame_WithLongExpression_ShouldTruncateExpression() .WithMessage(""" Assert.AreNotSame(aVeryLongVariableNameThatExceedsOneHundredCharacte..., aVeryLongVariableNameThatExceedsOneHundredCharacte...) Expected references to be different. - not expected: (Hash=*) - actual: (Hash=*) + not expected: (Hash=*) + actual: (Hash=*) """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index 9a52a6cd82..87f655ce57 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -392,9 +392,9 @@ public void ContainsSingle_InNonGenericCollection_AssertCustomMessage_WithEmptyC // Assert action.Should().Throw().WithMessage(""" Assert.ContainsSingle(collection) + my custom message Expected collection to contain exactly one item but found 0 item(s). collection: [] - User message: my custom message """); } #endregion @@ -431,8 +431,8 @@ public void Contains_ValueExpected_ItemDoesNotExist_ThrowsException() // Assert action.Should().Throw().WithMessage(""" Assert.Contains(20, collection) + Item 20 not found Expected collection to contain the specified item.* - User message: Item 20 not found """); } @@ -451,8 +451,8 @@ public void Contains_InNonGenericCollection_ValueExpected_ItemDoesNotExist_Throw // Assert action.Should().Throw().WithMessage(""" Assert.Contains(expected, collection) + Item 20 not found Expected collection to contain the specified item.* - User message: Item 20 not found """); } @@ -501,8 +501,8 @@ public void Contains_InNonGenericCollection_NullableValueExpected_ItemDoesNotExi // Assert action.Should().Throw().WithMessage(""" Assert.Contains(expected, collection) + Item not found Expected collection to contain the specified item.* - User message: Item not found """); } @@ -554,8 +554,8 @@ public void Contains_WithComparer_ItemDoesNotExist_ThrowsException() // Assert action.Should().Throw().WithMessage(""" Assert.Contains("cherry", collection) + Missing cherry Expected collection to contain the specified item.* - User message: Missing cherry """); } @@ -604,8 +604,8 @@ public void Contains_Predicate_NoItemMatches_ThrowsException() // Assert action.Should().Throw().WithMessage(""" Assert.Contains(IsEven, collection) + No even number found Expected at least one item to match the predicate.* - User message: No even number found """); } @@ -624,8 +624,8 @@ public void Contains_InNonGenericCollection_Predicate_NoItemMatches_ThrowsExcept // Assert action.Should().Throw().WithMessage(""" Assert.Contains(IsEven, collection) + No even number found Expected at least one item to match the predicate.* - User message: No even number found """); } @@ -661,10 +661,10 @@ public void Contains_StringVersion_SubstringNotPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" Assert.Contains(substring, value) + Missing substring String does not contain the expected substring. substring: "lazy" value: "The quick brown fox" - User message: Missing substring """); } @@ -989,8 +989,8 @@ public void DoesNotContain_ValueExpected_ItemPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" Assert.DoesNotContain(10, collection) + Item 10 should not be found Expected collection to not contain the specified item.* - User message: Item 10 should not be found """); } @@ -1024,9 +1024,9 @@ public void DoesNotContain_InNonGenericCollection_ValueExpected_ItemPresent_Thro // Assert action.Should().Throw().WithMessage(""" Assert.DoesNotContain(10, collection) + Item 10 should not be found Expected collection to not contain the specified item. collection: [5, 10, 15, "a"] - User message: Item 10 should not be found """); } @@ -1078,8 +1078,8 @@ public void DoesNotContain_WithComparer_ItemPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" Assert.DoesNotContain("APPLE", collection) + Unexpected "APPLE" Expected collection to not contain the specified item.* - User message: Unexpected "APPLE" """); } @@ -1099,8 +1099,8 @@ public void DoesNotContain_InNonGenericCollection_WithComparer_ItemPresent_Throw // Assert action.Should().Throw().WithMessage(""" Assert.DoesNotContain("APPLE", collection) + APPLE Expected collection to not contain the specified item.* - User message: APPLE """); } @@ -1149,8 +1149,8 @@ public void DoesNotContain_Predicate_AtLeastOneItemMatches_ThrowsException() // Assert action.Should().Throw().WithMessage(""" Assert.DoesNotContain(IsEven, collection) + An even number exists Expected no items to match the predicate.* - User message: An even number exists """); } @@ -1169,8 +1169,8 @@ public void DoesNotContain_InNonGenericCollection_Predicate_AtLeastOneItemMatche // Assert action.Should().Throw().WithMessage(""" Assert.DoesNotContain(IsEven, collection) + An even number exists Expected no items to match the predicate.* - User message: An even number exists """); } @@ -1206,10 +1206,10 @@ public void DoesNotContain_StringVersion_SubstringPresent_ThrowsException() // Assert action.Should().Throw().WithMessage(""" Assert.DoesNotContain(substring, value) + Unexpected substring String contains the unexpected substring. substring: "brown" value: "The quick brown fox" - User message: Unexpected substring """); } @@ -1247,10 +1247,10 @@ public void DoesNotContain_StringWithComparisonAndMessage_SubstringPresent_Throw // Assert action.Should().Throw().WithMessage(""" Assert.DoesNotContain(substring, value) + Found unexpected substring String contains the unexpected substring. substring: "BROWN" value: "The quick brown fox" - User message: Found unexpected substring """); } @@ -1324,10 +1324,10 @@ public void DoesNotContain_StringWithMessageOnly_SubstringPresent_ThrowsExceptio // Assert action.Should().Throw().WithMessage(""" Assert.DoesNotContain(substring, value) + Found unexpected substring String contains the unexpected substring. substring: "brown" value: "The quick brown fox" - User message: Found unexpected substring """); } @@ -1653,8 +1653,8 @@ public void ContainsSinglePredicate_WithMessage_NoItemMatches_ThrowsException() action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) + No even numbers found in collection with 3 items Expected exactly one item to match the predicate but found 0 item(s). - User message: No even numbers found in collection with 3 items """); } @@ -1674,8 +1674,8 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_NoItemMat action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) + No even numbers found in collection with 3 items Expected exactly one item to match the predicate but found 0 item(s). - User message: No even numbers found in collection with 3 items """); } @@ -1695,8 +1695,8 @@ public void ContainsSinglePredicate_WithMessage_MultipleItemsMatch_ThrowsExcepti action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) + Too many even numbers found: 3 Expected exactly one item to match the predicate but found 3 item(s). - User message: Too many even numbers found: 3 """); } @@ -1716,8 +1716,8 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_MultipleI action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) + Too many even numbers found: 2 Expected exactly one item to match the predicate but found 2 item(s). - User message: Too many even numbers found: 2 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs index 3f6ac4b560..9b0a689d51 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs @@ -30,10 +30,10 @@ public void EndsWith_WithMessage_WhenValueDoesNotEndWithSuffix_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.EndsWith("hello", "world") + User message String does not end with expected suffix. expected suffix: "hello" value: "world" - User message: User message """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs index 463672f75f..681aee2b72 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs @@ -44,10 +44,10 @@ public void IsGreaterThanShouldThrowWithMessage() action.Should().Throw() .WithMessage(""" Assert.IsGreaterThan(10, 5) + A Message Expected value 5 to be greater than 10. lower bound: 10 value: 5 - User message: A Message """); } @@ -94,10 +94,10 @@ public void IsGreaterThanOrEqualToShouldThrowWithMessage() action.Should().Throw() .WithMessage(""" Assert.IsGreaterThanOrEqualTo(10, 5) + A Message Expected value 5 to be greater than or equal to 10. lower bound: 10 value: 5 - User message: A Message """); } @@ -144,10 +144,10 @@ public void IsLessThanShouldThrowWithMessage() action.Should().Throw() .WithMessage(""" Assert.IsLessThan(5, 10) + A Message Expected value 10 to be less than 5. upper bound: 5 value: 10 - User message: A Message """); } @@ -194,10 +194,10 @@ public void IsLessThanOrEqualToShouldThrowWithMessage() action.Should().Throw() .WithMessage(""" Assert.IsLessThanOrEqualTo(5, 10) + A Message Expected value 10 to be less than or equal to 5. upper bound: 5 value: 10 - User message: A Message """); } @@ -259,9 +259,9 @@ public void IsPositiveShouldThrowWithMessage() action.Should().Throw() .WithMessage(""" Assert.IsPositive(-5) + A Message Expected a positive value. value: -5 - User message: A Message """); } @@ -329,9 +329,9 @@ public void IsNegativeShouldThrowWithMessage() action.Should().Throw() .WithMessage(""" Assert.IsNegative(5) + A Message Expected a negative value. value: 5 - User message: A Message """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs index a5e857d400..3823ad00f3 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsExactInstanceOfTypeTests.cs @@ -79,9 +79,9 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(null) +User-provided message Expected value to be exactly . value: null -User message: User-provided message """); } @@ -91,10 +91,10 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) +User-provided message Expected value to be exactly null. value: 5 expected type: null -User message: User-provided message """); } @@ -104,9 +104,9 @@ public void ExactInstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) +User-provided message Expected value to be exactly . value: 5 () -User message: User-provided message """); } @@ -121,9 +121,9 @@ public async Task ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenValue (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsExactInstanceOfType(null) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected value to be exactly . value: null - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -135,10 +135,10 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull( action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) +User-provided message DummyClassTrackingToStringCalls Expected value to be exactly null. value: 5 expected type: null -User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); } @@ -150,9 +150,9 @@ public void ExactInstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMisma action.Should().Throw() .WithMessage(""" Assert.IsExactInstanceOfType(5) +User-provided message DummyClassTrackingToStringCalls Expected value to be exactly . value: 5 () -User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index 99f3f864e9..d2b5655da8 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -98,10 +98,10 @@ public void IsInRange_WithCustomMessage_IncludesCustomMessage() action.Should().ThrowExactly() .WithMessage(""" Assert.IsInRange(value) + Custom error message Expected value 10 to be in range [1, 5]. range: [1, 5] value: 10 - User message: Custom error message """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index d627e79935..84ef7ecbd3 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -52,9 +52,9 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenValueIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(null) + User-provided message Expected value to be an instance of . value: null - User message: User-provided message """); } @@ -64,10 +64,10 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) + User-provided message Expected value to be an instance of null. value: 5 expected type: null - User message: User-provided message """); } @@ -77,9 +77,9 @@ public void InstanceOfType_WithStringMessage_ShouldFailWhenTypeIsMismatched() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) + User-provided message Expected value to be an instance of . value: 5 () - User message: User-provided message """); } @@ -94,9 +94,9 @@ public async Task InstanceOfType_WithInterpolatedString_ShouldFailWhenValueIsNul (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsInstanceOfType(null) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected value to be an instance of . value: null - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -108,10 +108,10 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsNull() action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) + User-provided message DummyClassTrackingToStringCalls Expected value to be an instance of null. value: 5 expected type: null - User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); } @@ -123,9 +123,9 @@ public void InstanceOfType_WithInterpolatedString_ShouldFailWhenTypeIsMismatched action.Should().Throw() .WithMessage(""" Assert.IsInstanceOfType(5) + User-provided message DummyClassTrackingToStringCalls Expected value to be an instance of . value: 5 () - User message: User-provided message DummyClassTrackingToStringCalls """); o.WasToStringCalled.Should().BeTrue(); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index b96d09a4f0..d0e850ce71 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -32,9 +32,9 @@ public void IsNull_StringMessage_PassNonNull_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.IsNull(new object()) + User-provided message Expected value to be null. value: - User message: User-provided message """); } @@ -53,9 +53,9 @@ public async Task IsNull_InterpolatedString_PassNonNull_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsNull(new object()) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected value to be null. value: - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -99,8 +99,8 @@ public void IsNotNull_StringMessage_PassNonNull_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.IsNotNull(null) + User-provided message Expected a non-null value. - User message: User-provided message """); } @@ -112,8 +112,8 @@ public async Task IsNotNull_InterpolatedString_PassNonNull_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsNotNull(null) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected a non-null value. - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs index db8f3fae11..0d74c076e1 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsTrueTests.cs @@ -58,9 +58,9 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithNull() action.Should().Throw() .WithMessage(""" Assert.IsFalse(nullBool) + User-provided message Expected condition to be false. condition: null - User message: User-provided message """); } @@ -71,9 +71,9 @@ public void IsFalseNullableBooleanStringMessageShouldFailWithTrue() action.Should().Throw() .WithMessage(""" Assert.IsFalse(nullBool) + User-provided message Expected condition to be false. condition: True - User message: User-provided message """); } @@ -89,9 +89,9 @@ public void IsFalseBooleanStringMessageShouldFailWithTrue() action.Should().Throw() .WithMessage(""" Assert.IsFalse(true) + User-provided message Expected condition to be false. condition: True - User message: User-provided message """); } @@ -107,9 +107,9 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithN (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsFalse(nullBool) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be false. condition: null - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -122,9 +122,9 @@ public async Task IsFalseNullableBooleanInterpolatedStringMessageShouldFailWithT (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsFalse(nullBool) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be false. condition: True - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -142,9 +142,9 @@ public async Task IsFalseBooleanInterpolatedStringMessageShouldFailWithTrue() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsFalse(true) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be false. condition: True - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -202,9 +202,9 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithNull() action.Should().Throw() .WithMessage(""" Assert.IsTrue(nullBool) + User-provided message Expected condition to be true. condition: null - User message: User-provided message """); } @@ -215,9 +215,9 @@ public void IsTrueNullableBooleanStringMessageShouldFailWithFalse() action.Should().Throw() .WithMessage(""" Assert.IsTrue(nullBool) + User-provided message Expected condition to be true. condition: False - User message: User-provided message """); } @@ -233,9 +233,9 @@ public void IsTrueBooleanStringMessageShouldFailWithFalse() action.Should().Throw() .WithMessage(""" Assert.IsTrue(false) + User-provided message Expected condition to be true. condition: False - User message: User-provided message """); } @@ -251,9 +251,9 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithNu (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsTrue(nullBool) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be true. condition: null - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -266,9 +266,9 @@ public async Task IsTrueNullableBooleanInterpolatedStringMessageShouldFailWithFa (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsTrue(nullBool) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be true. condition: False - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } @@ -286,9 +286,9 @@ public async Task IsTrueBooleanInterpolatedStringMessageShouldFailWithFalse() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsTrue(false) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected condition to be true. condition: False - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs index 267f20b33e..3ddb12930a 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs @@ -42,11 +42,11 @@ public async Task Count_InterpolatedString_WhenCountIsNotSame_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.HasCount(Array.Empty()) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to have 1 item(s) but found 0. collection: [] expected count: 1 actual count: 0 - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -84,11 +84,11 @@ public async Task NotAny_InterpolatedString_WhenNotEmpty_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsEmpty(collection) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to have 0 item(s) but found 1. collection: [1] expected count: 0 actual count: 1 - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -138,9 +138,9 @@ public async Task Single_InterpolatedString_WhenNoItem_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.ContainsSingle(Array.Empty()) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to contain exactly one item but found 0 item(s). collection: [] - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -153,9 +153,9 @@ public async Task Single_InterpolatedString_WhenMultipleItems_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.ContainsSingle([1, 2, 3]) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to contain exactly one item but found 3 item(s). collection: [1, 2, 3] - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } @@ -205,8 +205,8 @@ public void SinglePredicate_Message_WhenNoItemMatches_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) + No even numbers found: test Expected exactly one item to match the predicate but found 0 item(s). - User message: No even numbers found: test """); } @@ -217,8 +217,8 @@ public void SinglePredicate_Message_WhenMultipleItemsMatch_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) + Too many even numbers: test Expected exactly one item to match the predicate but found 3 item(s). - User message: Too many even numbers: test """); } @@ -266,8 +266,8 @@ public async Task Any_InterpolatedString_WhenNoItem_ShouldFail() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.IsNotEmpty(Array.Empty()) + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* Expected collection to not be empty. - User message: User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* """); o.WasToStringCalled.Should().BeTrue(); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs index 890c18e6b4..8517f018c5 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs @@ -30,10 +30,10 @@ public void StartsWith_WithMessage_WhenValueDoesNotStartWithPrefix_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.StartsWith("world", "hello") + User message String does not start with expected prefix. expected prefix: "world" value: "hello" - User message: User message """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs index 05d8f2fa1d..3c61bd3971 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs @@ -119,10 +119,10 @@ public void Throws_WithMessageBuilder_FailsBecauseNoException() action.Should().Throw() .WithMessage(""" Assert.Throws + message constructed via builder. No exception was thrown. action: () => { } expected exception type: - User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -142,11 +142,11 @@ public void Throws_WithMessageBuilder_FailsBecauseTypeMismatch() action.Should().Throw() .WithMessage(""" Assert.Throws + message constructed via builder. Wrong exception type was thrown. action: () => throw new ArgumentOutOfRangeException("MyParamNameHere") expected exception type: actual exception type: - User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -179,10 +179,10 @@ public void ThrowsExactly_WithMessageBuilder_FailsBecauseNoException() action.Should().Throw() .WithMessage(""" Assert.ThrowsExactly + message constructed via builder. No exception was thrown. action: () => { } expected exception type: - User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -202,11 +202,11 @@ public void ThrowsExactly_WithMessageBuilder_FailsBecauseTypeMismatch() action.Should().Throw() .WithMessage(""" Assert.ThrowsExactly + message constructed via builder. Wrong exception type was thrown. action: () => throw new ArgumentOutOfRangeException("MyParamNameHere") expected exception type: actual exception type: - User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -239,10 +239,10 @@ public async Task ThrowsAsync_WithMessageBuilder_FailsBecauseNoException() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.ThrowsAsync + message constructed via builder. No exception was thrown. action: () => Task.CompletedTask expected exception type: - User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -262,11 +262,11 @@ public async Task ThrowsAsync_WithMessageBuilder_FailsBecauseTypeMismatch() (await action.Should().ThrowAsync()) .WithMessage(""" Assert.ThrowsAsync + message constructed via builder. Wrong exception type was thrown. action: () => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere")) expected exception type: actual exception type: - User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -299,10 +299,10 @@ public async Task ThrowsExactlyAsync_WithMessageBuilder_FailsBecauseNoException( (await action.Should().ThrowAsync()) .WithMessage(""" Assert.ThrowsExactlyAsync + message constructed via builder. No exception was thrown. action: () => Task.CompletedTask expected exception type: - User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); @@ -322,11 +322,11 @@ public async Task ThrowsExactlyAsync_WithMessageBuilder_FailsBecauseTypeMismatch (await action.Should().ThrowAsync()) .WithMessage(""" Assert.ThrowsExactlyAsync + message constructed via builder. Wrong exception type was thrown. action: () => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere")) expected exception type: actual exception type: - User message: message constructed via builder. """); wasBuilderCalled.Should().BeTrue(); From 25e7447931527fa7b63de4bcacb6610be7a3fdd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 20 Mar 2026 11:12:08 +0100 Subject: [PATCH 42/58] Replace wildcard patterns with precise expected messages in IsInRange tests --- .../Assertions/AssertTests.IsInRange.cs | 14 ++++++++++++-- .../AssertTests.IsInstanceOfTypeTests.cs | 9 ++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index d2b5655da8..bf5e83a93c 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -139,7 +139,12 @@ public void IsInRange_WithDateTimeValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .WithMessage("Assert.IsInRange(valueOutOfRange)*Expected value*to be in range*"); + .WithMessage($""" + Assert.IsInRange(valueOutOfRange) + Expected value {valueOutOfRange} to be in range [{minValue}, {maxValue}]. + range: [{minValue}, {maxValue}] + value: {valueOutOfRange} + """); } public void IsInRange_WithCharValues_WorksCorrectly() @@ -156,7 +161,12 @@ public void IsInRange_WithCharValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .WithMessage("Assert.IsInRange(valueOutOfRange)*Expected value*to be in range*"); + .WithMessage(""" + Assert.IsInRange(valueOutOfRange) + Expected value a to be in range [A, Z]. + range: [A, Z] + value: a + """); } public void IsInRange_WithNullMessage_DoesNotThrow() diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 84ef7ecbd3..7e1307bb15 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -207,11 +207,14 @@ public void IsInstanceOfTypeUsingGenericTypeWithOutParameter_OnHigherInstance_Do instance.Should().BeSameAs(testInstance); } - public void IsNotInstanceOfTypeUsingGenericType_WhenValueIsNull_DoesNotThrow() => Assert.IsNotInstanceOfType(null); + public void IsNotInstanceOfTypeUsingGenericType_WhenValueIsNull_DoesNotThrow() + => Assert.IsNotInstanceOfType(null); - public void IsNotInstanceOfType_OnWrongInstanceUsingGenericType_DoesNotThrow() => Assert.IsNotInstanceOfType(5L); + public void IsNotInstanceOfType_OnWrongInstanceUsingGenericType_DoesNotThrow() + => Assert.IsNotInstanceOfType(5L); - public void IsNotInstanceOfTypeUsingGenericType_OnSubInstance_DoesNotThrow() => Assert.IsNotInstanceOfType(new object()); + public void IsNotInstanceOfTypeUsingGenericType_OnSubInstance_DoesNotThrow() + => Assert.IsNotInstanceOfType(new object()); public void IsInstanceOfType_WhenNonNullNullableValue_LearnNonNull() { From 370e8ac204d22698032d6d429cc9e58d47b58065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 20 Mar 2026 18:32:09 +0100 Subject: [PATCH 43/58] Unify assertion failure messages with structured format - Converge all assertion messages to 'Expected [subject] to [verb phrase].' style - Add ellipsis (...) to callsite for overloads with omitted params (delta, culture) - Show delta, ignoreCase, culture as structured parameters - Rework CollectionAssert to use AppendUserMessage + FormatAlignedParameters - Rework StringAssert to use new structured format - Rework Assert.That to strip lambda wrapper and generate expression-aware messages (comparisons, bool members, negation, StartsWith/Contains/All/Any) - Update all test assertions to verify full messages --- .../Assertions/Assert.AreEqual.cs | 16 +- .../TestFramework/Assertions/Assert.That.cs | 113 ++++++- .../Assertions/CollectionAssert.cs | 151 ++++----- .../TestFramework/Assertions/StringAssert.cs | 45 ++- .../Resources/FrameworkMessages.resx | 50 ++- .../Resources/xlf/FrameworkMessages.cs.xlf | 154 +++++----- .../Resources/xlf/FrameworkMessages.de.xlf | 154 +++++----- .../Resources/xlf/FrameworkMessages.es.xlf | 154 +++++----- .../Resources/xlf/FrameworkMessages.fr.xlf | 154 +++++----- .../Resources/xlf/FrameworkMessages.it.xlf | 154 +++++----- .../Resources/xlf/FrameworkMessages.ja.xlf | 154 +++++----- .../Resources/xlf/FrameworkMessages.ko.xlf | 154 +++++----- .../Resources/xlf/FrameworkMessages.pl.xlf | 154 +++++----- .../Resources/xlf/FrameworkMessages.pt-BR.xlf | 154 +++++----- .../Resources/xlf/FrameworkMessages.ru.xlf | 154 +++++----- .../Resources/xlf/FrameworkMessages.tr.xlf | 154 +++++----- .../xlf/FrameworkMessages.zh-Hans.xlf | 154 +++++----- .../xlf/FrameworkMessages.zh-Hant.xlf | 154 +++++----- .../Assertions/AssertTests.AreEqualTests.cs | 140 +++++---- .../Assertions/AssertTests.Contains.cs | 26 +- .../Assertions/AssertTests.EndsWith.cs | 20 +- .../AssertTests.IComparableTests.cs | 10 +- .../Assertions/AssertTests.IsNull.cs | 8 +- .../Assertions/AssertTests.MatchesRegex.cs | 18 +- .../Assertions/AssertTests.StartsWith.cs | 20 +- .../Assertions/AssertTests.That.cs | 289 +++++++++--------- .../AssertTests.ThrowsExceptionTests.cs | 22 +- .../Assertions/AssertTests.cs | 4 +- .../Assertions/CollectionAssertTests.cs | 107 +++++-- .../Assertions/StringAssertTests.cs | 43 ++- 30 files changed, 1621 insertions(+), 1463 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index 2697d38b7f..d513d6b6d9 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -639,11 +639,12 @@ private static void ThrowAssertAreEqualFailed(object? expected, object? actual, private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, string? userMessage, string expectedExpression, string actualExpression) where T : struct, IConvertible { - string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); + string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression), ("...", "...")); string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreEqualDeltaNoGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); message += FormatAlignedParameters( (nameof(expected), FormatValue(expected)), - (nameof(actual), FormatValue(actual))); + (nameof(actual), FormatValue(actual)), + (nameof(delta), FormatValue(delta))); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -651,7 +652,7 @@ private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, [DoesNotReturn] private static void ThrowAssertAreEqualFailed(string? expected, string? actual, bool ignoreCase, CultureInfo culture, string? userMessage, string expectedExpression, string actualExpression) { - string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); + string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression), ("...", "...")); string message; // If the user requested to match case, and the difference between expected/actual is casing only, then we use a different message. @@ -660,7 +661,9 @@ private static void ThrowAssertAreEqualFailed(string? expected, string? actual, message = FrameworkMessages.AreEqualCaseDiffersMsg; message += FormatAlignedParameters( (nameof(expected), FormatValue(expected)), - (nameof(actual), FormatValue(actual))); + (nameof(actual), FormatValue(actual)), + ("ignore case", ignoreCase.ToString()), + (nameof(culture), culture.Name)); } else { @@ -1182,11 +1185,12 @@ private static bool AreNotEqualFailing(double notExpected, double actual, double private static void ThrowAssertAreNotEqualFailed(T notExpected, T actual, T delta, string? userMessage, string notExpectedExpression, string actualExpression) where T : struct, IConvertible { - string callSite = FormatCallSite("Assert.AreNotEqual", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression)); + string callSite = FormatCallSite("Assert.AreNotEqual", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression), ("...", "...")); string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreNotEqualDeltaGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); message += FormatAlignedParameters( ("not expected", FormatValue(notExpected)), - (nameof(actual), FormatValue(actual))); + (nameof(actual), FormatValue(actual)), + (nameof(delta), FormatValue(delta))); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.That.cs b/src/TestFramework/TestFramework/Assertions/Assert.That.cs index e13c803967..6807ecb025 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.That.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.That.cs @@ -36,23 +36,118 @@ public static void That(Expression> condition, string? message = null return; } - var sb = new StringBuilder(); string expressionText = conditionExpression ?? throw new ArgumentNullException(nameof(conditionExpression)); - sb.AppendLine(string.Format(CultureInfo.InvariantCulture, FrameworkMessages.AssertThatFailedFormat, expressionText)); - if (!string.IsNullOrWhiteSpace(message)) - { - sb.AppendLine(string.Format(CultureInfo.InvariantCulture, FrameworkMessages.AssertThatMessageFormat, message)); - } + + // Strip the lambda wrapper "() => " since CallerArgumentExpression captures + // the full argument including the lambda syntax, but the user only cares about + // the condition expression itself. + string displayExpression = expressionText.StartsWith("() => ", StringComparison.Ordinal) + ? expressionText.Substring(6) + : expressionText; + + string callSite = $"Assert.That({Assert.TruncateExpression(displayExpression)})"; + string msg = BuildExpressionAwareMessage(condition.Body); string details = ExtractDetails(condition.Body); if (!string.IsNullOrWhiteSpace(details)) { - sb.AppendLine(FrameworkMessages.AssertThatDetailsPrefix); - sb.AppendLine(details); + msg += Environment.NewLine + details.TrimEnd(); } - throw new AssertFailedException(sb.ToString().TrimEnd()); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed(callSite, msg); + } + } + + private static string BuildExpressionAwareMessage(Expression body) + { + switch (body) + { + // Binary comparisons: x == y, x != y, x > y, etc. + case BinaryExpression binary when body.NodeType + is ExpressionType.Equal + or ExpressionType.NotEqual + or ExpressionType.GreaterThan + or ExpressionType.GreaterThanOrEqual + or ExpressionType.LessThan + or ExpressionType.LessThanOrEqual: + return BuildComparisonMessage(binary); + + // Negation: !flag, !condition + case UnaryExpression unary when body.NodeType == ExpressionType.Not + && unary.Operand is not MethodCallExpression: + string innerName = GetCleanMemberName(unary.Operand); + return $"Expected {innerName} to be false."; + + // Method calls: text.StartsWith("x"), list.Contains(item), etc. + case MethodCallExpression methodCall: + return BuildMethodCallMessage(methodCall); + + // Bool member access: user.IsActive, flag + case MemberExpression: + string memberName = GetCleanMemberName(body); + return $"Expected {memberName} to be true."; + + default: + return FrameworkMessages.IsTrueFailNew; + } + } + + private static string BuildComparisonMessage(BinaryExpression binary) + { + string leftValue = TryEvaluateFormatted(binary.Left); + string rightValue = TryEvaluateFormatted(binary.Right); + + return binary.NodeType switch + { + ExpressionType.Equal => $"Expected {leftValue} to equal {rightValue}.", + ExpressionType.NotEqual => $"Expected {leftValue} to not equal {rightValue}.", + ExpressionType.GreaterThan => $"Expected {leftValue} to be greater than {rightValue}.", + ExpressionType.GreaterThanOrEqual => $"Expected {leftValue} to be greater than or equal to {rightValue}.", + ExpressionType.LessThan => $"Expected {leftValue} to be less than {rightValue}.", + ExpressionType.LessThanOrEqual => $"Expected {leftValue} to be less than or equal to {rightValue}.", + _ => FrameworkMessages.IsTrueFailNew, + }; + } + + private static string BuildMethodCallMessage(MethodCallExpression methodCall) + { + string methodName = methodCall.Method.Name; + + return methodName switch + { + "StartsWith" => FrameworkMessages.StartsWithFailNew, + "EndsWith" => FrameworkMessages.EndsWithFailNew, + nameof(string.Contains) => BuildContainsMessage(methodCall), + "All" => "Expected all elements to match the predicate.", + "Any" => FrameworkMessages.ContainsPredicateFailNew, + _ => FrameworkMessages.IsTrueFailNew, + }; + } + + private static string BuildContainsMessage(MethodCallExpression methodCall) + { + // string.Contains vs collection.Contains + if (methodCall.Object is not null + && methodCall.Object.Type == typeof(string)) + { + return FrameworkMessages.ContainsStringFailNew; + } + + return FrameworkMessages.ContainsItemFailNew; + } + + private static string TryEvaluateFormatted(Expression expr) + { + try + { + object? value = Expression.Lambda(expr).Compile().DynamicInvoke(); + return FormatValue(value); + } + catch + { + return GetCleanMemberName(expr); } } diff --git a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs index c8f37e098b..c009cbc8ae 100644 --- a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs +++ b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs @@ -79,7 +79,9 @@ public static void Contains([NotNull] ICollection? collection, object? element, } } - Assert.ThrowAssertFailed("CollectionAssert.Contains", Assert.BuildUserMessage(message)); + string msg = FrameworkMessages.ContainsItemFailNew; + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.Contains", msg); } /// @@ -126,7 +128,9 @@ public static void DoesNotContain([NotNull] ICollection? collection, object? ele { if (object.Equals(current, element)) { - Assert.ThrowAssertFailed("CollectionAssert.DoesNotContain", Assert.BuildUserMessage(message)); + string msg = FrameworkMessages.DoesNotContainItemFailNew; + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.DoesNotContain", msg); } } } @@ -165,7 +169,9 @@ public static void AllItemsAreNotNull([NotNull] ICollection? collection, string? { if (current == null) { - Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreNotNull", Assert.BuildUserMessage(message)); + string msg = FrameworkMessages.IsNotNullFailNew; + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreNotNull", msg); } } } @@ -204,8 +210,6 @@ public static void AllItemsAreUnique([NotNull] ICollection? collection, string? { Assert.CheckParameterNotNull(collection, "CollectionAssert.AllItemsAreUnique", "collection"); - message = Assert.ReplaceNulls(message); - bool foundNull = false; Dictionary table = []; foreach (object? current in collection) @@ -219,28 +223,22 @@ public static void AllItemsAreUnique([NotNull] ICollection? collection, string? else { // Found a second occurrence of null. - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AllItemsAreUniqueFailMsg, - userMessage, - FrameworkMessages.Common_NullInMessages); - - Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreUnique", finalMessage); + string msg = FrameworkMessages.AllItemsAreUniqueFailMsg; + msg += Assert.FormatAlignedParameters( + ("duplicate", FrameworkMessages.Common_NullInMessages)); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreUnique", msg); } } else { if (!table.TryAdd(current, true)) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.AllItemsAreUniqueFailMsg, - userMessage, - Assert.ReplaceNulls(current)); - - Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreUnique", finalMessage); + string msg = FrameworkMessages.AllItemsAreUniqueFailMsg; + msg += Assert.FormatAlignedParameters( + ("duplicate", Assert.ReplaceNulls(current))); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreUnique", msg); } } } @@ -297,18 +295,10 @@ public static void IsSubsetOf([NotNull] ICollection? subset, [NotNull] ICollecti Tuple> isSubsetValue = IsSubsetOfHelper(subset, superset); if (!isSubsetValue.Item1) { - string returnedSubsetValueMessage = string.Join(", ", isSubsetValue.Item2.Select(item => Convert.ToString(item, CultureInfo.InvariantCulture))); - - returnedSubsetValueMessage = string.Format(CultureInfo.InvariantCulture, FrameworkMessages.ReturnedSubsetValueMessage, returnedSubsetValueMessage); - string userMessage = Assert.BuildUserMessage(message); - if (string.IsNullOrEmpty(userMessage)) - { - Assert.ThrowAssertFailed("CollectionAssert.IsSubsetOf", returnedSubsetValueMessage); - } - else - { - Assert.ThrowAssertFailed("CollectionAssert.IsSubsetOf", $"{returnedSubsetValueMessage} {userMessage}"); - } + string missingElements = string.Join(", ", isSubsetValue.Item2.Select(item => Convert.ToString(item, CultureInfo.InvariantCulture))); + string msg = string.Format(CultureInfo.InvariantCulture, FrameworkMessages.ReturnedSubsetValueMessage, missingElements); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.IsSubsetOf", msg); } } @@ -357,7 +347,9 @@ public static void IsNotSubsetOf([NotNull] ICollection? subset, [NotNull] IColle Tuple> isSubsetValue = IsSubsetOfHelper(subset, superset); if (isSubsetValue.Item1) { - Assert.ThrowAssertFailed("CollectionAssert.IsNotSubsetOf", Assert.BuildUserMessage(message)); + string msg = FrameworkMessages.BothSameElements; + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.IsNotSubsetOf", msg); } } @@ -476,7 +468,9 @@ public static void AreEquivalent( // Check whether one is null while the other is not. if (expected == null != (actual == null)) { - Assert.ThrowAssertFailed("CollectionAssert.AreEquivalent", Assert.BuildUserMessage(message)); + string msg = FrameworkMessages.AreEqualFailNew; + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.AreEquivalent", msg); } // If the references are the same or both collections are null, they are equivalent. @@ -493,14 +487,12 @@ public static void AreEquivalent( // Check whether the element counts are different. if (expectedCollectionCount != actualCollectionCount) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.ElementNumbersDontMatch, - userMessage, - expectedCollectionCount, - actualCollectionCount); - Assert.ThrowAssertFailed("CollectionAssert.AreEquivalent", finalMessage); + string msg = FrameworkMessages.ElementNumbersDontMatch; + msg += Assert.FormatAlignedParameters( + ("expected count", expectedCollectionCount.ToString(CultureInfo.CurrentCulture)), + ("actual count", actualCollectionCount.ToString(CultureInfo.CurrentCulture))); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.AreEquivalent", msg); } // If both collections are empty, they are equivalent. @@ -512,15 +504,13 @@ public static void AreEquivalent( // Search for a mismatched element. if (FindMismatchedElement(expected, actual, comparer, out int expectedCount, out int actualCount, out object? mismatchedElement)) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.ActualHasMismatchedElements, - userMessage, - expectedCount.ToString(CultureInfo.CurrentCulture.NumberFormat), - Assert.ReplaceNulls(mismatchedElement), - actualCount.ToString(CultureInfo.CurrentCulture.NumberFormat)); - Assert.ThrowAssertFailed("CollectionAssert.AreEquivalent", finalMessage); + string msg = FrameworkMessages.ActualHasMismatchedElements; + msg += Assert.FormatAlignedParameters( + ("element", Assert.ReplaceNulls(mismatchedElement)), + ("expected occurrences", expectedCount.ToString(CultureInfo.CurrentCulture)), + ("actual occurrences", actualCount.ToString(CultureInfo.CurrentCulture))); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.AreEquivalent", msg); } // All the elements and counts matched. @@ -649,12 +639,9 @@ public static void AreNotEquivalent( // are equivalent. object.ReferenceEquals will handle case where both are null. if (object.ReferenceEquals(notExpected, actual)) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.BothCollectionsSameReference, - userMessage); - Assert.ThrowAssertFailed("CollectionAssert.AreNotEquivalent", finalMessage); + string msg = FrameworkMessages.BothCollectionsSameReference; + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.AreNotEquivalent", msg); } DebugEx.Assert(actual is not null, "actual is not null here"); @@ -671,23 +658,17 @@ public static void AreNotEquivalent( // If both collections are empty, they are equivalent. if (notExpectedCount == 0) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.BothCollectionsEmpty, - userMessage); - Assert.ThrowAssertFailed("CollectionAssert.AreNotEquivalent", finalMessage); + string msg = FrameworkMessages.BothCollectionsEmpty; + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.AreNotEquivalent", msg); } // Search for a mismatched element. if (!FindMismatchedElement(notExpected, actual, comparer, out _, out _, out _)) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.BothSameElements, - userMessage); - Assert.ThrowAssertFailed("CollectionAssert.AreNotEquivalent", finalMessage); + string msg = FrameworkMessages.BothSameElements; + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.AreNotEquivalent", msg); } } @@ -748,15 +729,15 @@ public static void AllItemsAreInstancesOfType( if (element?.GetType() is { } elementType && !expectedType.IsAssignableFrom(elementType)) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format( + string msg = string.Format( CultureInfo.CurrentCulture, FrameworkMessages.ElementTypesAtIndexDontMatch, - userMessage, - i, - expectedType.ToString(), - element.GetType().ToString()); - Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreInstancesOfType", finalMessage); + i); + msg += Assert.FormatAlignedParameters( + ("expected type", Assert.FormatType(expectedType)), + ("actual type", Assert.FormatType(element.GetType()))); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreInstancesOfType", msg); } i++; @@ -1181,7 +1162,7 @@ private static bool AreCollectionsEqual(ICollection? expected, ICollection? actu Assert.CheckParameterNotNull(comparer, "Assert.AreCollectionsEqual", "comparer"); if (object.ReferenceEquals(expected, actual)) { - reason = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.BothCollectionsSameReference, string.Empty); + reason = FrameworkMessages.BothCollectionsSameReference; return true; } @@ -1229,9 +1210,10 @@ private static bool CompareIEnumerable(IEnumerable? expected, IEnumerable? actua reason = string.Format( CultureInfo.CurrentCulture, FrameworkMessages.ElementsAtIndexDontMatch, - position, - Assert.ReplaceNulls(curExpected), - Assert.ReplaceNulls(curActual)); + position) + + Assert.FormatAlignedParameters( + ("expected", Assert.ReplaceNulls(curExpected)), + ("actual", Assert.ReplaceNulls(curActual))); return false; } } @@ -1250,12 +1232,7 @@ private static bool CompareIEnumerable(IEnumerable? expected, IEnumerable? actua private static string ConstructFinalMessage( string reason, string? message) - { - string userMessage = Assert.BuildUserMessage(message); - return userMessage.Length == 0 - ? reason - : string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CollectionEqualReason, userMessage, reason); - } + => Assert.AppendUserMessage(reason, message); /// /// compares the objects using object.Equals. diff --git a/src/TestFramework/TestFramework/Assertions/StringAssert.cs b/src/TestFramework/TestFramework/Assertions/StringAssert.cs index b2e36625ec..21401abd64 100644 --- a/src/TestFramework/TestFramework/Assertions/StringAssert.cs +++ b/src/TestFramework/TestFramework/Assertions/StringAssert.cs @@ -120,9 +120,12 @@ public static void Contains([NotNull] string? value, [NotNull] string? substring Assert.CheckParameterNotNull(substring, "StringAssert.Contains", "substring"); if (value.IndexOf(substring, comparisonType) < 0) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsFail, value, substring, userMessage); - Assert.ThrowAssertFailed("StringAssert.Contains", finalMessage); + string msg = FrameworkMessages.ContainsStringFailNew; + msg += Assert.FormatAlignedParameters( + (nameof(substring), Assert.FormatValue(substring)), + (nameof(value), Assert.FormatValue(value))); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("StringAssert.Contains", msg); } } @@ -217,9 +220,12 @@ public static void StartsWith([NotNull] string? value, [NotNull] string? substri Assert.CheckParameterNotNull(substring, "StringAssert.StartsWith", "substring"); if (!value.StartsWith(substring, comparisonType)) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.StartsWithFail, value, substring, userMessage); - Assert.ThrowAssertFailed("StringAssert.StartsWith", finalMessage); + string msg = FrameworkMessages.StartsWithFailNew; + msg += Assert.FormatAlignedParameters( + ("expected prefix", Assert.FormatValue(substring)), + (nameof(value), Assert.FormatValue(value))); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("StringAssert.StartsWith", msg); } } @@ -314,9 +320,12 @@ public static void EndsWith([NotNull] string? value, [NotNull] string? substring Assert.CheckParameterNotNull(substring, "StringAssert.EndsWith", "substring"); if (!value.EndsWith(substring, comparisonType)) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.EndsWithFail, value, substring, userMessage); - Assert.ThrowAssertFailed("StringAssert.EndsWith", finalMessage); + string msg = FrameworkMessages.EndsWithFailNew; + msg += Assert.FormatAlignedParameters( + ("expected suffix", Assert.FormatValue(substring)), + (nameof(value), Assert.FormatValue(value))); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("StringAssert.EndsWith", msg); } } @@ -369,9 +378,12 @@ public static void Matches([NotNull] string? value, [NotNull] Regex? pattern, st if (!pattern.IsMatch(value)) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsMatchFail, value, pattern, userMessage); - Assert.ThrowAssertFailed("StringAssert.Matches", finalMessage); + string msg = FrameworkMessages.MatchesRegexFailNew; + msg += Assert.FormatAlignedParameters( + (nameof(pattern), Assert.FormatValue(pattern)), + (nameof(value), Assert.FormatValue(value))); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("StringAssert.Matches", msg); } } @@ -420,9 +432,12 @@ public static void DoesNotMatch([NotNull] string? value, [NotNull] Regex? patter if (pattern.IsMatch(value)) { - string userMessage = Assert.BuildUserMessage(message); - string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsNotMatchFail, value, pattern, userMessage); - Assert.ThrowAssertFailed("StringAssert.DoesNotMatch", finalMessage); + string msg = FrameworkMessages.DoesNotMatchRegexFailNew; + msg += Assert.FormatAlignedParameters( + (nameof(pattern), Assert.FormatValue(pattern)), + (nameof(value), Assert.FormatValue(value))); + msg = Assert.AppendUserMessage(msg, message); + Assert.ThrowAssertFailed("StringAssert.DoesNotMatch", msg); } } diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index c6aeab5604..47dac2648c 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -121,10 +121,10 @@ Access string has invalid syntax. - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} + Expected collections to have matching element occurrences. - Duplicate item found:<{1}>. {0} + Expected all items to be unique. String lengths are both {0} but differ at index {1}. @@ -136,16 +136,16 @@ Do not pass value types to AreSame(). Values converted to Object will never be the same. Consider using AreEqual(). {0} - Both collections are empty. {0} + Both collections are empty. Both collection contain same elements. - Both collection references point to the same collection object. {0} + Both collection references point to the same collection object. - Both collections contain the same elements. {0} + Both collections contain the same elements. {0}. {1} @@ -154,15 +154,13 @@ String '{0}' does not contain string '{1}'. {2}. - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} + Expected the same number of elements in the collections. - Element at index {0} do not match. -Expected: {1} -Actual: {2} + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} + Element at index {0} is not of the expected type. String '{0}' does not end with string '{1}'. {2} @@ -286,31 +284,31 @@ Actual: {2} The maximum value must be greater than or equal to the minimum value. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. Case differs. - String does not start with expected prefix. + Expected string to start with the specified prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. - String does not end with expected suffix. + Expected string to end with the specified suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. - String does not match expected pattern. + Expected string to match the specified pattern. - String matches pattern but should not. + Expected string to not match the specified pattern. Expected collection to contain the specified item. @@ -325,10 +323,10 @@ Actual: {2} Expected no items to match the predicate. - String does not contain the expected substring. + Expected string to contain the specified substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. Expected exactly one item to match the predicate but found {0} item(s). @@ -346,16 +344,16 @@ Actual: {2} Expected value {0} to be in range [{1}, {2}]. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. - No exception was thrown. + Expected an exception to be thrown. Expected values to be equal. - Expected values to differ. + Expected values to not be equal. Expected references to be the same. @@ -373,7 +371,7 @@ Actual: {2} Expected value to be null. - Expected a non-null value. + Expected value to not be null. Expected value to be an instance of {0}. @@ -400,9 +398,9 @@ Actual: {2} Expected value {0} to be less than or equal to {1}. - Expected a positive value. + Expected value to be positive. - Expected a negative value. + Expected value to be negative. \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index 659dc3a41c..2c293ba8ea 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - Očekávaná kolekce obsahuje {1} výskyt(ů) <{2}>. Aktuální kolekce obsahuje {3} výskyt(ů). {0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - Byla nalezena duplicitní položka:<{1}>. {0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - Obě kolekce jsou prázdné. {0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - Obě reference na kolekci odkazují na stejný objekt kolekce. {0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - Obě kolekce obsahují stejné elementy. {0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - Počet elementů v kolekcích nesouhlasí. Očekáváno:<{1}>. Aktuálně:<{2}>.{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - Element v indexu {0} nesouhlasí. -Očekáváno: {1} -Skutečnost: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - Element na indexu {1} není očekávaného typu. Očekávaný typ:<{2}>. Aktuální typ:<{3}>.{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Skutečnost: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Skutečnost: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Skutečnost: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Skutečnost: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Skutečnost: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Skutečnost: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Skutečnost: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Skutečnost: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Skutečnost: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Skutečnost: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Skutečnost: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index c6433cb9f2..b6aec1d1e7 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - Die erwartete Sammlung enthält {1} Vorkommen von <{2}>. Die tatsächliche Sammlung enthält {3} Vorkommen. {0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - Doppeltes Element gefunden: <{1}>. {0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - Beide Sammlungen sind leer. {0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - Beide Sammlungsverweise zeigen auf dasselbe Sammlungsobjekt. {0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - Beide Sammlungen enthalten dieselben Elemente. {0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - Die Anzahl der Elemente in den Sammlungen stimmt nicht überein. Erwartet: <{1}>. Tatsächlich: <{2}>.{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - Das Element bei Index {0} stimmt nicht überein. -Erwartet: {1} -Tatsächlich: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - Das Element bei Index "{1}" weist nicht den erwarteten Typ auf. Erwarteter Typ:<{2}>. Tatsächlicher Typ:<{3}>.{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Tatsächlich: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Tatsächlich: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Tatsächlich: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Tatsächlich: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Tatsächlich: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Tatsächlich: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Tatsächlich: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Tatsächlich: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Tatsächlich: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Tatsächlich: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Tatsächlich: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index bfd4307c9a..49c9f4df3a 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - Apariciones que contiene la colección esperada: {1} de <{2}>. Apariciones que contiene la colección real: {3}. {0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - Se encontró un elemento duplicado:<{1}>. {0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - Ambas colecciones están vacías. {0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - Las referencias de ambas colecciones apuntan al mismo objeto de colección. {0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - Ambas colecciones tienen los mismos elementos. {0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - El número de elementos de las colecciones no coincide. Se esperaba:<{1}>, pero es:<{2}>.{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - El elemento del índice {0} no coincide. -Esperado: {1} -Real: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - El elemento del índice {1} no es del tipo esperado. Tipo esperado:<{2}>, pero es el tipo:<{3}>.{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Real: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Real: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Real: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Real: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Real: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Real: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Real: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Real: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Real: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Real: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Real: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index 054e7d9b3b..7047573f39 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - La collection attendue contient {1} occurrence(s) de <{2}>. La collection réelle contient {3} occurrence(s). {0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - Un élément dupliqué a été trouvé : <{1}>. {0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - Les deux collections sont vides. {0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - Les deux collections Reference pointent vers le même objet Collection. {0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - Les deux collections contiennent les mêmes éléments. {0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - Le nombre d'éléments dans les collections ne correspond pas. Attendu : <{1}>, Réel : <{2}>.{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - L’élément au {0} d’index ne correspond pas. -Attendu : {1} -Réel : {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - L'élément à l'index {1} n'est pas du type attendu. Type attendu : <{2}>, Type réel : <{3}>.{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Réel : {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Réel : {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Réel : {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Réel : {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Réel : {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Réel : {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Réel : {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Réel : {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Réel : {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Réel : {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Réel : {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index 2dcb6cccf7..0085359589 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - La raccolta prevista contiene {1} occorrenza/e di <{2}>. La raccolta effettiva contiene {3} occorrenza/e. {0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - Rilevato elemento duplicato:<{1}>. {0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - Le raccolte sono entrambe vuote. {0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - I riferimenti a raccolte puntano entrambi allo stesso oggetto Collection. {0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - Le raccolte contengono entrambe gli stessi elementi. {0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - Il numero di elementi nelle raccolte non corrisponde. Previsto:<{1}>. Effettivo:<{2}>.{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - L'elemento nell'indice {0} non corrisponde. -Previsto: {1} -Effettivo: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - L'elemento nell'indice {1} non è del tipo previsto. Tipo previsto:<{2}>. Tipo effettivo:<{3}>.{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Effettivo: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Effettivo: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Effettivo: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Effettivo: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Effettivo: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Effettivo: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Effettivo: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Effettivo: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Effettivo: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Effettivo: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Effettivo: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index 4ce118216d..8540130114 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - 予期されたコレクションでは、<{2}> が {1} 回発生します。実際のコレクションでは、{3} 回発生します。{0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - 重複する項目が見つかりました:<{1}>。{0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - 両方のコレクションが空です。{0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - 両方のコレクションの参照が、同じコレクション オブジェクトにポイントしています。{0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - 両方のコレクションが同じ要素を含んでいます。{0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - コレクション内の要素数が一致しません。<{1}> が必要ですが <{2}> が指定されています。{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - インデックス {0} の要素が一致しません。 -予想: {1} -実際: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - インデックス {1} の要素は、必要な型ではありません。<{2}> が必要ですが、<{3}> が指定されています。{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Actual: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Actual: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Actual: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Actual: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Actual: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Actual: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Actual: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Actual: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Actual: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Actual: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Actual: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index 4560c3d2c5..3e0204202b 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - 필요한 컬렉션에 <{2}>은(는) {1}개가 포함되어야 하는데 실제 컬렉션에는 {3}개가 포함되어 있습니다. {0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - 중복된 항목이 있습니다. <{1}>. {0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - 두 컬렉션이 모두 비어 있습니다. {0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - 두 컬렉션 참조가 동일한 컬렉션 개체를 가리킵니다. {0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - 두 컬렉션에 같은 요소가 포함되어 있습니다. {0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - 컬렉션의 요소 수가 일치하지 않습니다. 예상 값: <{1}>. 실제 값: <{2}>.{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - 인덱스 {0}에 있는 요소가 일치하지 않습니다. -예상: {1} -실제: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - 인덱스 {1}에 있는 요소가 필요한 형식이 아닙니다. 필요한 형식: <{2}>, 실제 형식: <{3}>.{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Actual: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Actual: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Actual: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Actual: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Actual: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Actual: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Actual: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Actual: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Actual: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Actual: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Actual: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index eaea87216d..156debe41e 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - Oczekiwana kolekcja zawiera {1} wystąpień <{2}>. Bieżąca kolekcja zawiera {3} wystąpień. {0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - Znaleziono duplikat:<{1}>. {0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - Obie kolekcje są puste. {0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - Odwołania do obu kolekcji wskazują ten sam obiekt kolekcji. {0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - Obie kolekcje zawierają te same elementy. {0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - Nie zgadza się liczba elementów w kolekcji. Oczekiwana:<{1}>. Rzeczywista:<{2}>.{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - Element w indeksie {0} nie jest zgodny. -Oczekiwano: {1} -Rzeczywiste: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - Element o indeksie {1} jest innego typu niż oczekiwano. Oczekiwany typ:<{2}>. Rzeczywisty typ:<{3}>.{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Rzeczywiste: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Rzeczywiste: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Rzeczywiste: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Rzeczywiste: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Rzeczywiste: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Rzeczywiste: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Rzeczywiste: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Rzeczywiste: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Rzeczywiste: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Rzeczywiste: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Rzeczywiste: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index 7b5b0c96d4..27e8086a89 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - A coleção esperada contém {1} ocorrência(s) de <{2}>. A coleção real contém {3} ocorrência(s). {0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - Item duplicado encontrado:<{1}>. {0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - Ambas as coleções estão vazias. {0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - Ambas as referências de coleção apontam para o mesmo objeto de coleção. {0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - Ambas as coleções contêm os mesmos elementos. {0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - O número de elementos nas coleções não coincidem. Esperado:<{1}>. Real:<{2}>.{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - O elemento no índice {0} não corresponde. -Esperado: {1} -Real: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - Elemento de índice {1} não é de tipo esperado. Tipo esperado:<{2}>. Tipo real:<{3}>.{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Real: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Real: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Real: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Real: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Real: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Real: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Real: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Real: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Real: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Real: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Real: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index b611f41218..f0fd6df5e6 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - Ожидаемый набор содержит следующее число событий <{2}>: {1}. Фактический набор содержит число событий: {3}. {0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - Обнаружен совпадающий элемент: <{1}>. {0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - Обе коллекции пусты. {0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - Ссылки в обоих коллекциях указывают на один и тот же объект коллекции. {0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - Обе коллекции содержат одинаковые элементы. {0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - Число элементов в наборе не соответствует ожидаемому. Ожидается: <{1}>. Фактически: <{2}>.{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - Элемент по индексу {0} не совпадает. -Ожидается: {1} -Фактическое значение: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - Тип элемента по индексу {1} не соответствует ожидаемому. Ожидаемый тип: <{2}>. Фактический тип: <{3}>.{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Actual: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Actual: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Actual: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Actual: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Actual: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Actual: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Actual: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Actual: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Actual: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Actual: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Actual: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index fa0113d718..3c4d06cc0c 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - Beklenen koleksiyon {1} <{2}> örneği içerir. Gerçek koleksiyon {3} örnek içerir. {0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - Yinelenen öğe bulundu:<{1}>. {0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - Koleksiyonların her ikisi de boş. {0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - Her iki koleksiyon başvurusu da aynı koleksiyon nesnesine işaret ediyor. {0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - Her iki koleksiyon da aynı öğeleri içeriyor. {0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - Koleksiyonlar içindeki öğe sayıları eşleşmiyor. Beklenen:<{1}>. Gerçek:<{2}>.{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - {0} dizinindeki öğe eşleşmiyor. -Beklenen: {1} -Gerçekte olan: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - {1} dizinindeki öğe, beklenen türde değil. Beklenen tür:<{2}>. Gerçek tür:<{3}>.{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Gerçekte olan: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Gerçekte olan: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Gerçekte olan: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Gerçekte olan: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Gerçekte olan: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Gerçekte olan: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Gerçekte olan: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Gerçekte olan: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Gerçekte olan: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Gerçekte olan: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Gerçekte olan: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index ff23039f5a..b15248bb4c 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - 所需集合包含 <{2}> 的 {1} 个匹配项。实际集合包含 {3} 个匹配项。{0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - 找到了重复项: <{1}>。{0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - 这两个集合都为空。{0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - 这两个集合引用指向同一个集合对象。{0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - 这两个集合包含相同的元素。{0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - 集合中元素的数量不匹配。应为: <{1}>,实际为: <{2}>。{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - 索引 {0} 处的元素不匹配。 -预计值: {1} -实际值: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - 索引 {1} 处的元素不是所需类型。所需类型为: <{2}>,实际类型为: <{3}>。{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Actual: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Actual: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Actual: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Actual: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Actual: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Actual: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Actual: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Actual: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Actual: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Actual: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Actual: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index 976dec8119..a1a9f4185b 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -8,14 +8,14 @@ - The expected collection contains {1} occurrence(s) of <{2}>. The actual collection contains {3} occurrence(s). {0} - 預期在集合中包含 {1} 項 <{2}>,但實際的集合卻有 {3} 項。{0} - + Expected collections to have matching element occurrences. + Expected collections to have matching element occurrences. + - Duplicate item found:<{1}>. {0} - 找到重複的項目: <{1}>。{0} - + Expected all items to be unique. + Expected all items to be unique. + Case differs. @@ -23,8 +23,8 @@ - Expected a difference no greater than {0}. - Expected a difference no greater than {0}. + Expected difference to be no greater than {0}. + Expected difference to be no greater than {0}. @@ -43,13 +43,13 @@ - Expected a difference greater than {0}. - Expected a difference greater than {0}. + Expected difference to be greater than {0}. + Expected difference to be greater than {0}. - Expected values to differ. - Expected values to differ. + Expected values to not be equal. + Expected values to not be equal. @@ -83,9 +83,9 @@ {0} user provided message - Both collections are empty. {0} - 兩個集合皆空白。{0} - + Both collections are empty. + Both collections are empty. + Both collection contain same elements. @@ -93,14 +93,14 @@ - Both collection references point to the same collection object. {0} - 兩個集合參考都指向同一個集合物件。{0} - + Both collection references point to the same collection object. + Both collection references point to the same collection object. + - Both collections contain the same elements. {0} - 兩個集合含有相同的項目。{0} - + Both collections contain the same elements. + Both collections contain the same elements. + {0}. {1} @@ -133,8 +133,8 @@ - String does not contain the expected substring. - String does not contain the expected substring. + Expected string to contain the specified substring. + Expected string to contain the specified substring. @@ -148,8 +148,8 @@ - String contains the unexpected substring. - String contains the unexpected substring. + Expected string to not contain the specified substring. + Expected string to not contain the specified substring. @@ -158,13 +158,13 @@ - String ends with unexpected suffix. - String ends with unexpected suffix. + Expected string to not end with the specified suffix. + Expected string to not end with the specified suffix. - String matches pattern but should not. - String matches pattern but should not. + Expected string to not match the specified pattern. + Expected string to not match the specified pattern. @@ -173,8 +173,8 @@ - String starts with unexpected prefix. - String starts with unexpected prefix. + Expected string to not start with the specified prefix. + Expected string to not start with the specified prefix. @@ -198,23 +198,19 @@ - The number of elements in the collections do not match. Expected:<{1}>. Actual:<{2}>.{0} - 集合中的項目數目不符。預期: <{1}>。實際: <{2}>。{0} - + Expected the same number of elements in the collections. + Expected the same number of elements in the collections. + - Element at index {0} do not match. -Expected: {1} -Actual: {2} - 位於索引 {0} 的項目不符。 -預期為: {1} -實際為: {2} + Element at index {0} do not match. + Element at index {0} do not match. - Element at index {1} is not of expected type. Expected type:<{2}>. Actual type:<{3}>.{0} - 位於索引 {1} 的項目不是預期的類型。預期的類型: <{2}>。實際的類型: <{3}>。{0} - + Element at index {0} is not of the expected type. + Element at index {0} is not of the expected type. + String '{0}' does not end with string '{1}'. {2} @@ -227,13 +223,13 @@ Actual: {2} - String does not end with expected suffix. - String does not end with expected suffix. + Expected string to end with the specified suffix. + Expected string to end with the specified suffix. - Expected collection to have the specified number of items. - Expected collection to have the specified number of items. + Expected collection to have {0} item(s) but found {1}. + Expected collection to have {0} item(s) but found {1}. @@ -247,8 +243,8 @@ Actual: {2} - Expected value to be exactly of the specified type. - Expected value to be exactly of the specified type. + Expected value to be exactly {0}. + Expected value to be exactly {0}. @@ -257,18 +253,18 @@ Actual: {2} - Expected value ({0}) to be greater than {1}. - Expected value ({0}) to be greater than {1}. + Expected value {0} to be greater than {1}. + Expected value {0} to be greater than {1}. - Expected value ({0}) to be greater than or equal to {1}. - Expected value ({0}) to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. + Expected value {0} to be greater than or equal to {1}. - Expected value ({0}) to be in range [{1}, {2}]. - Expected value ({0}) to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. + Expected value {0} to be in range [{1}, {2}]. @@ -277,18 +273,18 @@ Actual: {2} - Expected value to be of the specified type. - Expected value to be of the specified type. + Expected value to be an instance of {0}. + Expected value to be an instance of {0}. - Expected value ({0}) to be less than {1}. - Expected value ({0}) to be less than {1}. + Expected value {0} to be less than {1}. + Expected value {0} to be less than {1}. - Expected value ({0}) to be less than or equal to {1}. - Expected value ({0}) to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. + Expected value {0} to be less than or equal to {1}. @@ -297,8 +293,8 @@ Actual: {2} - Expected a negative value. - Expected a negative value. + Expected value to be negative. + Expected value to be negative. @@ -307,13 +303,13 @@ Actual: {2} - Expected value to not be exactly the specified type. - Expected value to not be exactly the specified type. + Expected value to not be exactly {0}. + Expected value to not be exactly {0}. - Expected value to not be an instance of the specified type. - Expected value to not be an instance of the specified type. + Expected value to not be an instance of {0}. + Expected value to not be an instance of {0}. @@ -322,8 +318,8 @@ Actual: {2} - Expected a non-null value. - Expected a non-null value. + Expected value to not be null. + Expected value to not be null. @@ -332,8 +328,8 @@ Actual: {2} - Expected a positive value. - Expected a positive value. + Expected value to be positive. + Expected value to be positive. @@ -342,13 +338,13 @@ Actual: {2} - String does not match expected pattern. - String does not match expected pattern. + Expected string to match the specified pattern. + Expected string to match the specified pattern. - No exception was thrown. - No exception was thrown. + Expected an exception to be thrown. + Expected an exception to be thrown. @@ -413,8 +409,8 @@ Actual: {2} - String does not start with expected prefix. - String does not start with expected prefix. + Expected string to start with the specified prefix. + Expected string to start with the specified prefix. @@ -478,8 +474,8 @@ Actual: {2} - Wrong exception type was thrown. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. + Expected the specified exception type to be thrown. diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index cfc0c9b4d6..103b9fff0f 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -22,7 +22,7 @@ public void AreNotEqualShouldFailWhenNotEqualTypeWithMessage() .WithMessage(""" Assert.AreNotEqual(1, 1) A Message - Expected values to differ. + Expected values to not be equal. not expected: 1 actual: 1 """); @@ -41,7 +41,7 @@ public void AreNotEqualShouldFailWhenNotEqualStringWithMessage() .WithMessage(""" Assert.AreNotEqual("A", "A") A Message - Expected values to differ. + Expected values to not be equal. not expected: "A" actual: "A" """); @@ -67,7 +67,7 @@ public void AreNotEqualShouldFailWhenNotEqualIntWithMessage() .WithMessage(""" Assert.AreNotEqual(1, 1) A Message - Expected values to differ. + Expected values to not be equal. not expected: 1 actual: 1 """); @@ -86,7 +86,7 @@ public void AreNotEqualShouldFailWhenNotEqualLongWithMessage() .WithMessage(""" Assert.AreNotEqual(1L, 1L) A Message - Expected values to differ. + Expected values to not be equal. not expected: 1L actual: 1L """); @@ -111,7 +111,7 @@ public void AreNotEqualShouldFailWhenNotEqualDecimalWithMessage() .WithMessage(""" Assert.AreNotEqual(0.1M, 0.1M) A Message - Expected values to differ. + Expected values to not be equal. not expected: 0.1m actual: 0.1m """); @@ -136,7 +136,7 @@ public void AreNotEqualShouldFailWhenNotEqualDoubleWithMessage() .WithMessage(""" Assert.AreNotEqual(0.1, 0.1) A Message - Expected values to differ. + Expected values to not be equal. not expected: 0.1 actual: 0.1 """); @@ -161,7 +161,7 @@ public void AreNotEqualShouldFailWhenFloatDoubleWithMessage() .WithMessage(""" Assert.AreNotEqual(100E-2, 100E-2) A Message - Expected values to differ. + Expected values to not be equal. not expected: 1 actual: 1 """); @@ -223,10 +223,12 @@ public void AreEqual_WithEnglishCultureAndDoesNotIgnoreCase_Throws() Action action = () => Assert.AreEqual(expected, actual, false, englishCulture); action.Should().Throw() .WithMessage("""" - Assert.AreEqual(expected, actual) + Assert.AreEqual(expected, actual, ...) Case differs. - expected: "i" - actual: "I" + expected: "i" + actual: "I" + ignore case: False + culture: en-EN """"); } @@ -486,7 +488,7 @@ public async Task GenericAreNotEqual_InterpolatedString_SameValues_ShouldFail() .WithMessage(""" Assert.AreNotEqual(0, 0) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected values to differ. + Expected values to not be equal. not expected: 0 actual: 0 """); @@ -507,11 +509,12 @@ public async Task FloatAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1.0f, 1.1f, 0.001f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(1.0f, 1.1f) + Assert.AreEqual(1.0f, 1.1f, ...) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference no greater than 0.001. + Expected difference to be no greater than 0.001. expected: 1f actual: 1.1f + delta: 0.001f """); o.WasToStringCalled.Should().BeTrue(); } @@ -530,11 +533,12 @@ public async Task FloatAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0f, 1.1f, 0.2f, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(1.0f, 1.1f) + Assert.AreNotEqual(1.0f, 1.1f, ...) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference greater than 0.2. + Expected difference to be greater than 0.2. not expected: 1f actual: 1.1f + delta: 0.2f """); o.WasToStringCalled.Should().BeTrue(); } @@ -553,11 +557,12 @@ public async Task DecimalAreEqual_InterpolatedString_DifferentValues_ShouldFail( Func action = async () => Assert.AreEqual(1.0m, 1.1m, 0.001m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(1.0m, 1.1m) + Assert.AreEqual(1.0m, 1.1m, ...) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference no greater than 0.001. + Expected difference to be no greater than 0.001. expected: 1.0m actual: 1.1m + delta: 0.001m """); o.WasToStringCalled.Should().BeTrue(); } @@ -576,11 +581,12 @@ public async Task DecimalAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0m, 1.1m, 0.2m, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(1.0m, 1.1m) + Assert.AreNotEqual(1.0m, 1.1m, ...) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference greater than 0.2. + Expected difference to be greater than 0.2. not expected: 1.0m actual: 1.1m + delta: 0.2m """); o.WasToStringCalled.Should().BeTrue(); } @@ -599,11 +605,12 @@ public async Task LongAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1L, 2L, 0L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(1L, 2L) + Assert.AreEqual(1L, 2L, ...) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference no greater than 0. + Expected difference to be no greater than 0. expected: 1L actual: 2L + delta: 0L """); o.WasToStringCalled.Should().BeTrue(); } @@ -622,11 +629,12 @@ public async Task LongAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1L, 2L, 1L, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(1L, 2L) + Assert.AreNotEqual(1L, 2L, ...) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference greater than 1. + Expected difference to be greater than 1. not expected: 1L actual: 2L + delta: 1L """); o.WasToStringCalled.Should().BeTrue(); } @@ -645,11 +653,12 @@ public async Task DoubleAreEqual_InterpolatedString_DifferentValues_ShouldFail() Func action = async () => Assert.AreEqual(1.0d, 1.1d, 0.001d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreEqual(1.0d, 1.1d) + Assert.AreEqual(1.0d, 1.1d, ...) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference no greater than 0.001. + Expected difference to be no greater than 0.001. expected: 1 actual: 1.1 + delta: 0.001 """); o.WasToStringCalled.Should().BeTrue(); } @@ -668,11 +677,12 @@ public async Task DoubleAreNotEqual_InterpolatedString_SameValues_ShouldFail() Func action = async () => Assert.AreNotEqual(1.0d, 1.1d, 0.2d, $"User-provided message. {o}, {o,35}, {await GetHelloStringAsync()}, {new DummyIFormattable()}, {dateTime:tt}, {dateTime,5:tt}"); (await action.Should().ThrowAsync()) .WithMessage(""" - Assert.AreNotEqual(1.0d, 1.1d) + Assert.AreNotEqual(1.0d, 1.1d, ...) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a difference greater than 0.2. + Expected difference to be greater than 0.2. not expected: 1 actual: 1.1 + delta: 0.2 """); o.WasToStringCalled.Should().BeTrue(); } @@ -846,10 +856,11 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif { Action action = () => Assert.AreEqual(5.0f, 2.0f, 2.0f); // difference is 3. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreEqual(5.0f, 2.0f) - Expected a difference no greater than 2. + Assert.AreEqual(5.0f, 2.0f, ...) + Expected difference to be no greater than 2. expected: 5f actual: 2f + delta: 2f """"); } @@ -857,10 +868,11 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDif { Action action = () => Assert.AreEqual(2.0f, 5.0f, 2.0f); // difference is -3. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreEqual(2.0f, 5.0f) - Expected a difference no greater than 2. + Assert.AreEqual(2.0f, 5.0f, ...) + Expected difference to be no greater than 2. expected: 2f actual: 5f + delta: 2f """"); } @@ -874,10 +886,11 @@ public void FloatAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFai { Action action = () => Assert.AreEqual(5.0f, float.NaN, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreEqual(5.0f, float.NaN) - Expected a difference no greater than 2. + Assert.AreEqual(5.0f, float.NaN, ...) + Expected difference to be no greater than 2. expected: 5f actual: NaNf + delta: 2f """"); } @@ -885,10 +898,11 @@ public void FloatAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFai { Action action = () => Assert.AreEqual(float.NaN, 5.0f, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreEqual(float.NaN, 5.0f) - Expected a difference no greater than 2. + Assert.AreEqual(float.NaN, 5.0f, ...) + Expected difference to be no greater than 2. expected: NaNf actual: 5f + delta: 2f """"); } @@ -1078,10 +1092,11 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual { Action action = () => Assert.AreNotEqual(5.0f, 4.0f, 2.0f); // difference is 1. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreNotEqual(5.0f, 4.0f) - Expected a difference greater than 2. + Assert.AreNotEqual(5.0f, 4.0f, ...) + Expected difference to be greater than 2. not expected: 5f actual: 4f + delta: 2f """"); } @@ -1089,10 +1104,11 @@ public void FloatAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActual { Action action = () => Assert.AreNotEqual(4.0f, 5.0f, 2.0f); // difference is -1. Delta is 2 action.Should().Throw().WithMessage("""" - Assert.AreNotEqual(4.0f, 5.0f) - Expected a difference greater than 2. + Assert.AreNotEqual(4.0f, 5.0f, ...) + Expected difference to be greater than 2. not expected: 4f actual: 5f + delta: 2f """"); } @@ -1105,10 +1121,11 @@ public void FloatAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFail { Action action = () => Assert.AreNotEqual(float.NaN, float.NaN, 2.0f); action.Should().Throw().WithMessage("""" - Assert.AreNotEqual(float.NaN, float.NaN) - Expected a difference greater than 2. + Assert.AreNotEqual(float.NaN, float.NaN, ...) + Expected difference to be greater than 2. not expected: NaNf actual: NaNf + delta: 2f """"); } @@ -1294,10 +1311,11 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi Action action = () => Assert.AreEqual(5.0d, 2.0d, 2.0d); // difference is 3. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreEqual(5.0d, 2.0d) - Expected a difference no greater than 2. + Assert.AreEqual(5.0d, 2.0d, ...) + Expected difference to be no greater than 2. expected: 5 actual: 2 + delta: 2 """"); } @@ -1306,10 +1324,11 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActualDi Action action = () => Assert.AreEqual(2.0d, 5.0d, 2.0d); // difference is -3. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreEqual(2.0d, 5.0d) - Expected a difference no greater than 2. + Assert.AreEqual(2.0d, 5.0d, ...) + Expected difference to be no greater than 2. expected: 2 actual: 5 + delta: 2 """"); } @@ -1324,10 +1343,11 @@ public void DoubleAreEqual_ExpectedIsNumeric_ActualIsNaN_DeltaIsNumeric_ShouldFa Action action = () => Assert.AreEqual(5.0d, double.NaN, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreEqual(5.0d, double.NaN) - Expected a difference no greater than 2. + Assert.AreEqual(5.0d, double.NaN, ...) + Expected difference to be no greater than 2. expected: 5 actual: NaN + delta: 2 """"); } @@ -1336,10 +1356,11 @@ public void DoubleAreEqual_ExpectedIsNaN_ActualIsNumeric_DeltaIsNumeric_ShouldFa Action action = () => Assert.AreEqual(double.NaN, 5.0d, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreEqual(double.NaN, 5.0d) - Expected a difference no greater than 2. + Assert.AreEqual(double.NaN, 5.0d, ...) + Expected difference to be no greater than 2. expected: NaN actual: 5 + delta: 2 """"); } @@ -1537,10 +1558,11 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua Action action = () => Assert.AreNotEqual(5.0d, 4.0d, 2.0d); // difference is 1. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual(5.0d, 4.0d) - Expected a difference greater than 2. + Assert.AreNotEqual(5.0d, 4.0d, ...) + Expected difference to be greater than 2. not expected: 5 actual: 4 + delta: 2 """"); } @@ -1549,10 +1571,11 @@ public void DoubleAreNotEqual_ExpectedIsNumeric_ActualIsNumeric_ExpectedAndActua Action action = () => Assert.AreNotEqual(4.0d, 5.0d, 2.0d); // difference is -1. Delta is 2 action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual(4.0d, 5.0d) - Expected a difference greater than 2. + Assert.AreNotEqual(4.0d, 5.0d, ...) + Expected difference to be greater than 2. not expected: 4 actual: 5 + delta: 2 """"); } @@ -1566,10 +1589,11 @@ public void DoubleAreNotEqual_ExpectedIsNaN_ActualIsNaN_DeltaIsNumeric_ShouldFai Action action = () => Assert.AreNotEqual(double.NaN, double.NaN, 2.0d); action.Should().Throw() .WithMessage("""" - Assert.AreNotEqual(double.NaN, double.NaN) - Expected a difference greater than 2. + Assert.AreNotEqual(double.NaN, double.NaN, ...) + Expected difference to be greater than 2. not expected: NaN actual: NaN + delta: 2 """"); } @@ -2004,7 +2028,7 @@ public void AreNotEqual_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.AreNotEqual(aVeryLongVariableNameThatExceedsOneHundredCharacte..., 1) - Expected values to differ. + Expected values to not be equal. not expected: 1 actual: 1 """); @@ -2018,7 +2042,7 @@ public void AreNotEqual_WithLongToStringValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.AreNotEqual(obj, obj) - Expected values to differ. + Expected values to not be equal. not expected: {new string('L', 256)}... 44 more actual: {new string('L', 256)}... 44 more """); @@ -2032,7 +2056,7 @@ public void AreNotEqual_WithNewlineInToString_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.AreNotEqual(obj, obj) - Expected values to differ. + Expected values to not be equal. not expected: line1\r\nline2\nline3 actual: line1\r\nline2\nline3 """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index 87f655ce57..ea66b41186 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -662,7 +662,7 @@ public void Contains_StringVersion_SubstringNotPresent_ThrowsException() action.Should().Throw().WithMessage(""" Assert.Contains(substring, value) Missing substring - String does not contain the expected substring. + Expected string to contain the specified substring. substring: "lazy" value: "The quick brown fox" """); @@ -881,7 +881,7 @@ public void Contains_String_EmptyValue_WithNonEmptySubstring_ThrowsException() // Assert action.Should().Throw().WithMessage(""" Assert.Contains(substring, value) - String does not contain the expected substring. + Expected string to contain the specified substring. substring: "test" value: "" """); @@ -1207,7 +1207,7 @@ public void DoesNotContain_StringVersion_SubstringPresent_ThrowsException() action.Should().Throw().WithMessage(""" Assert.DoesNotContain(substring, value) Unexpected substring - String contains the unexpected substring. + Expected string to not contain the specified substring. substring: "brown" value: "The quick brown fox" """); @@ -1248,7 +1248,7 @@ public void DoesNotContain_StringWithComparisonAndMessage_SubstringPresent_Throw action.Should().Throw().WithMessage(""" Assert.DoesNotContain(substring, value) Found unexpected substring - String contains the unexpected substring. + Expected string to not contain the specified substring. substring: "BROWN" value: "The quick brown fox" """); @@ -1286,7 +1286,7 @@ public void DoesNotContain_StringSimpleOverload_SubstringPresent_ThrowsException // Assert action.Should().Throw().WithMessage(""" Assert.DoesNotContain(substring, value) - String contains the unexpected substring. + Expected string to not contain the specified substring. substring: "brown" value: "The quick brown fox" """); @@ -1325,7 +1325,7 @@ public void DoesNotContain_StringWithMessageOnly_SubstringPresent_ThrowsExceptio action.Should().Throw().WithMessage(""" Assert.DoesNotContain(substring, value) Found unexpected substring - String contains the unexpected substring. + Expected string to not contain the specified substring. substring: "brown" value: "The quick brown fox" """); @@ -1949,7 +1949,7 @@ public void Contains_String_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.Contains("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) - String does not contain the expected substring. + Expected string to contain the specified substring. substring: "world" value: "hello" """); @@ -1963,7 +1963,7 @@ public void Contains_String_WithLongValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.Contains("world", longValue) - String does not contain the expected substring. + Expected string to contain the specified substring. substring: "world" value: "{new string('x', 255)}... 46 more """); @@ -1975,7 +1975,7 @@ public void Contains_String_WithNewlineInValue_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.Contains("world", "hello\r\nfoo") - String does not contain the expected substring. + Expected string to contain the specified substring. substring: "world" value: "hello\r\nfoo" """); @@ -1989,7 +1989,7 @@ public void DoesNotContain_String_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.DoesNotContain("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) - String contains the unexpected substring. + Expected string to not contain the specified substring. substring: "hello" value: "hello world" """); @@ -2003,7 +2003,7 @@ public void DoesNotContain_String_WithLongValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.DoesNotContain("hello", longValue) - String contains the unexpected substring. + Expected string to not contain the specified substring. substring: "hello" value: "hello{new string('x', 250)}... 51 more """); @@ -2015,7 +2015,7 @@ public void DoesNotContain_String_WithNewlineInValue_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.DoesNotContain("hello", "hello\r\nworld") - String contains the unexpected substring. + Expected string to not contain the specified substring. substring: "hello" value: "hello\r\nworld" """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs index 9b0a689d51..e7d81b55de 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.EndsWith.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -18,7 +18,7 @@ public void EndsWith_WhenValueDoesNotEndWithSuffix_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.EndsWith("hello", "world") - String does not end with expected suffix. + Expected string to end with the specified suffix. expected suffix: "hello" value: "world" """); @@ -31,7 +31,7 @@ public void EndsWith_WithMessage_WhenValueDoesNotEndWithSuffix_ShouldFail() .WithMessage(""" Assert.EndsWith("hello", "world") User message - String does not end with expected suffix. + Expected string to end with the specified suffix. expected suffix: "hello" value: "world" """); @@ -46,7 +46,7 @@ public void DoesNotEndWith_WhenValueEndsWithSuffix_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.DoesNotEndWith("world", "hello world") - String ends with unexpected suffix. + Expected string to not end with the specified suffix. unwanted suffix: "world" value: "hello world" """); @@ -64,7 +64,7 @@ public void EndsWith_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.EndsWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) - String does not end with expected suffix. + Expected string to end with the specified suffix. expected suffix: "hello" value: "hello world" """); @@ -78,7 +78,7 @@ public void EndsWith_WithLongValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.EndsWith("world", longValue) - String does not end with expected suffix. + Expected string to end with the specified suffix. expected suffix: "world" value: "{new string('x', 255)}... 46 more """); @@ -90,7 +90,7 @@ public void EndsWith_WithNewlineInValue_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.EndsWith("world", "hello\r\nfoo") - String does not end with expected suffix. + Expected string to end with the specified suffix. expected suffix: "world" value: "hello\r\nfoo" """); @@ -104,7 +104,7 @@ public void DoesNotEndWith_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.DoesNotEndWith("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) - String ends with unexpected suffix. + Expected string to not end with the specified suffix. unwanted suffix: "world" value: "hello world" """); @@ -118,7 +118,7 @@ public void DoesNotEndWith_WithLongValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.DoesNotEndWith("world", longValue) - String ends with unexpected suffix. + Expected string to not end with the specified suffix. unwanted suffix: "world" value: "{new string('x', 255)}... 51 more """); @@ -130,7 +130,7 @@ public void DoesNotEndWith_WithNewlineInValue_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.DoesNotEndWith("world", "hello\r\nworld") - String ends with unexpected suffix. + Expected string to not end with the specified suffix. unwanted suffix: "world" value: "hello\r\nworld" """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs index 681aee2b72..2a61f1c1d2 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IComparableTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -260,7 +260,7 @@ public void IsPositiveShouldThrowWithMessage() .WithMessage(""" Assert.IsPositive(-5) A Message - Expected a positive value. + Expected value to be positive. value: -5 """); } @@ -330,7 +330,7 @@ public void IsNegativeShouldThrowWithMessage() .WithMessage(""" Assert.IsNegative(5) A Message - Expected a negative value. + Expected value to be negative. value: 5 """); } @@ -535,7 +535,7 @@ public void IsPositive_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.IsPositive(aVeryLongVariableNameThatExceedsOneHundredCharacte...) - Expected a positive value. + Expected value to be positive. value: -5 """); } @@ -548,7 +548,7 @@ public void IsNegative_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.IsNegative(aVeryLongVariableNameThatExceedsOneHundredCharacte...) - Expected a negative value. + Expected value to be negative. value: 5 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs index d0e850ce71..349d7e002a 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsNull.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -89,7 +89,7 @@ public void IsNotNull_PassNull_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.IsNotNull(null) - Expected a non-null value. + Expected value to not be null. """); } @@ -100,7 +100,7 @@ public void IsNotNull_StringMessage_PassNonNull_ShouldFail() .WithMessage(""" Assert.IsNotNull(null) User-provided message - Expected a non-null value. + Expected value to not be null. """); } @@ -113,7 +113,7 @@ public async Task IsNotNull_InterpolatedString_PassNonNull_ShouldFail() .WithMessage(""" Assert.IsNotNull(null) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected a non-null value. + Expected value to not be null. """); o.WasToStringCalled.Should().BeTrue(); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs index 8bb4b0f9d1..b516a5f4e6 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.MatchesRegex.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -18,7 +18,7 @@ public void MatchesRegex_WhenValueDoesNotMatchPattern_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.MatchesRegex(@"\d+", "abc") - String does not match expected pattern. + Expected string to match the specified pattern. pattern: \d+ value: "abc" """); @@ -33,7 +33,7 @@ public void DoesNotMatchRegex_WhenValueMatchesPattern_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.DoesNotMatchRegex(@"\d+", "abc123") - String matches pattern but should not. + Expected string to not match the specified pattern. pattern: \d+ value: "abc123" """); @@ -51,7 +51,7 @@ public void MatchesRegex_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.MatchesRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharacte...) - String does not match expected pattern. + Expected string to match the specified pattern. pattern: \d+ value: "hello" """); @@ -65,7 +65,7 @@ public void MatchesRegex_WithLongValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.MatchesRegex(@"\d+", longValue) - String does not match expected pattern. + Expected string to match the specified pattern. pattern: \d+ value: "{new string('x', 255)}... 46 more """); @@ -77,7 +77,7 @@ public void MatchesRegex_WithNewlineInValue_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.MatchesRegex(@"^\d+$", "hello\r\nworld") - String does not match expected pattern. + Expected string to match the specified pattern. pattern: ^\d+$ value: "hello\r\nworld" """); @@ -91,7 +91,7 @@ public void DoesNotMatchRegex_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.DoesNotMatchRegex(@"\d+", aVeryLongVariableNameThatExceedsOneHundredCharacte...) - String matches pattern but should not. + Expected string to not match the specified pattern. pattern: \d+ value: "abc123" """); @@ -105,7 +105,7 @@ public void DoesNotMatchRegex_WithLongValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.DoesNotMatchRegex(@"\d+", longValue) - String matches pattern but should not. + Expected string to not match the specified pattern. pattern: \d+ value: "{new string('1', 255)}... 46 more """); @@ -117,7 +117,7 @@ public void DoesNotMatchRegex_WithNewlineInValue_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.DoesNotMatchRegex(@"hello", "hello\r\nworld") - String matches pattern but should not. + Expected string to not match the specified pattern. pattern: hello value: "hello\r\nworld" """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs index 8517f018c5..21f59c04bc 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.StartsWith.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -18,7 +18,7 @@ public void StartsWith_WhenValueDoesNotStartWithPrefix_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.StartsWith("world", "hello") - String does not start with expected prefix. + Expected string to start with the specified prefix. expected prefix: "world" value: "hello" """); @@ -31,7 +31,7 @@ public void StartsWith_WithMessage_WhenValueDoesNotStartWithPrefix_ShouldFail() .WithMessage(""" Assert.StartsWith("world", "hello") User message - String does not start with expected prefix. + Expected string to start with the specified prefix. expected prefix: "world" value: "hello" """); @@ -46,7 +46,7 @@ public void DoesNotStartWith_WhenValueStartsWithPrefix_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.DoesNotStartWith("hello", "hello world") - String starts with unexpected prefix. + Expected string to not start with the specified prefix. unwanted prefix: "hello" value: "hello world" """); @@ -64,7 +64,7 @@ public void StartsWith_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.StartsWith("world", aVeryLongVariableNameThatExceedsOneHundredCharacte...) - String does not start with expected prefix. + Expected string to start with the specified prefix. expected prefix: "world" value: "hello world" """); @@ -78,7 +78,7 @@ public void StartsWith_WithLongValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.StartsWith("world", longValue) - String does not start with expected prefix. + Expected string to start with the specified prefix. expected prefix: "world" value: "{new string('x', 255)}... 46 more """); @@ -90,7 +90,7 @@ public void StartsWith_WithNewlineInValue_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.StartsWith("world", "hello\r\nworld") - String does not start with expected prefix. + Expected string to start with the specified prefix. expected prefix: "world" value: "hello\r\nworld" """); @@ -104,7 +104,7 @@ public void DoesNotStartWith_WithLongExpression_ShouldTruncateExpression() action.Should().Throw() .WithMessage(""" Assert.DoesNotStartWith("hello", aVeryLongVariableNameThatExceedsOneHundredCharacte...) - String starts with unexpected prefix. + Expected string to not start with the specified prefix. unwanted prefix: "hello" value: "hello world" """); @@ -118,7 +118,7 @@ public void DoesNotStartWith_WithLongValue_ShouldTruncateValue() action.Should().Throw() .WithMessage($""" Assert.DoesNotStartWith("hello", longValue) - String starts with unexpected prefix. + Expected string to not start with the specified prefix. unwanted prefix: "hello" value: "hello{new string('x', 250)}... 51 more """); @@ -130,7 +130,7 @@ public void DoesNotStartWith_WithNewlineInValue_ShouldEscapeNewlines() action.Should().Throw() .WithMessage(""" Assert.DoesNotStartWith("hello", "hello\r\nworld") - String starts with unexpected prefix. + Expected string to not start with the specified prefix. unwanted prefix: "hello" value: "hello\r\nworld" """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs index 62297d11df..8950acd89b 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs @@ -31,8 +31,9 @@ public void That_BooleanCondition_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => False) failed. - Message: Boolean condition failed + Assert.That(False) + Boolean condition failed + Expected condition to be true. """); } @@ -45,9 +46,9 @@ public void That_NumericComparison_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => x > 10) failed. - Message: x should be greater than 10 - Details: + Assert.That(x > 10) + x should be greater than 10 + Expected 5 to be greater than 10. x = 5 """); } @@ -61,9 +62,9 @@ public void That_StringEquality_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => s == "world") failed. - Message: String equality failed - Details: + Assert.That(s == "world") + String equality failed + Expected "hello" to equal "world". s = "hello" """); } @@ -77,9 +78,9 @@ public void That_NullString_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => s != null) failed. - Message: String should not be null - Details: + Assert.That(s != null) + String should not be null + Expected null to not equal null. s = null """); } @@ -94,9 +95,9 @@ public void That_CombinedBooleanCondition_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => a && b) failed. - Message: Both should be true - Details: + Assert.That(a && b) + Both should be true + Expected condition to be true. a = True b = False """); @@ -111,9 +112,9 @@ public void That_FormatNestedCollections() action.Should().Throw() .WithMessage( """ - Assert.That(() => nested.Any(arr => arr.Length > 3)) failed. - Message: Check nested arrays - Details: + Assert.That(nested.Any(arr => arr.Length > 3)) + Check nested arrays + Expected at least one item to match the predicate. nested = [[1, 2], [3]] """); } @@ -127,9 +128,9 @@ public void That_PropertyComparison_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => person.Age > 30) failed. - Message: Age should be greater than 30 - Details: + Assert.That(person.Age > 30) + Age should be greater than 30 + Expected 25 to be greater than 30. person.Age = 25 """); } @@ -143,9 +144,9 @@ public void That_MethodCall_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => text.StartsWith("world")) failed. - Message: Text should start with 'world' - Details: + Assert.That(text.StartsWith("world")) + Text should start with 'world' + Expected string to start with the specified prefix. text = "hello" """); } @@ -159,9 +160,9 @@ public void That_ChainedPropertyAccess_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => user.Profile.IsActive) failed. - Message: User profile should be active - Details: + Assert.That(user.Profile.IsActive) + User profile should be active + Expected user.Profile.IsActive to be true. user.Profile.IsActive = False """); } @@ -175,9 +176,9 @@ public void That_ArrayIndexAccess_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => numbers[1] == 5) failed. - Message: Second element should be 5 - Details: + Assert.That(numbers[1] == 5) + Second element should be 5 + Expected 2 to equal 5. numbers[1] = 2 """); } @@ -191,9 +192,9 @@ public void That_NullableComparison_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => nullableValue.HasValue) failed. - Message: Nullable should have value - Details: + Assert.That(nullableValue.HasValue) + Nullable should have value + Expected nullableValue.HasValue to be true. nullableValue.HasValue = False """); } @@ -208,9 +209,9 @@ public void That_OrElseCondition_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => condition1 || condition2) failed. - Message: At least one should be true - Details: + Assert.That(condition1 || condition2) + At least one should be true + Expected condition to be true. condition1 = False condition2 = False """); @@ -227,9 +228,9 @@ public void That_ComplexExpression_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => (x + y) * 2 > z * 3) failed. - Message: Complex calculation should be greater - Details: + Assert.That((x + y) * 2 > z * 3) + Complex calculation should be greater + Expected 30 to be greater than 45. x = 5 y = 10 z = 15 @@ -245,9 +246,9 @@ public void That_LinqExpression_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => numbers.All(n => n > 5)) failed. - Message: All numbers should be greater than 5 - Details: + Assert.That(numbers.All(n => n > 5)) + All numbers should be greater than 5 + Expected all elements to match the predicate. numbers = [1, 2, 3, 4] """); } @@ -261,9 +262,9 @@ public void That_TypeComparison_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => obj is int) failed. - Message: Object should be an integer - Details: + Assert.That(obj is int) + Object should be an integer + Expected condition to be true. obj = "hello" """); } @@ -277,9 +278,9 @@ public void That_NotEqualComparison_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => value != "test") failed. - Message: Value should not be 'test' - Details: + Assert.That(value != "test") + Value should not be 'test' + Expected "test" to not equal "test". value = "test" """); } @@ -295,9 +296,9 @@ public void That_MultipleVariablesInComplexExpression_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => current >= min && current <= max) failed. - Message: Value should be within range - Details: + Assert.That(current >= min && current <= max) + Value should be within range + Expected condition to be true. current = 25 max = 20 min = 10 @@ -313,9 +314,9 @@ public void That_DictionaryAccess_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => dict["key1"] > 15) failed. - Message: Dictionary value should be greater than 15 - Details: + Assert.That(dict["key1"] > 15) + Dictionary value should be greater than 15 + Expected 10 to be greater than 15. dict["key1"] = 10 """); } @@ -329,9 +330,9 @@ public void That_NestedMethodCalls_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => text.Substring(6).StartsWith("Universe")) failed. - Message: Substring should start with 'Universe' - Details: + Assert.That(text.Substring(6).StartsWith("Universe")) + Substring should start with 'Universe' + Expected string to start with the specified prefix. text.Substring(6) = "World" """); } @@ -343,9 +344,9 @@ public void That_StaticPropertyAccess_FailsAsExpected() act.Should().Throw() .WithMessage( $""" - Assert.That(() => DateTime.Now.Year < 2000) failed. - Message: Current year should be before 2000 - Details: + Assert.That(DateTime.Now.Year < 2000) + Current year should be before 2000 + Expected {year} to be less than 2000. DateTime.Now.Year = {year} """); } @@ -359,9 +360,9 @@ public void That_GenericMethodCall_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => list.Contains("d")) failed. - Message: List should contain 'd' - Details: + Assert.That(list.Contains("d")) + List should contain 'd' + Expected collection to contain the specified item. list = ["a", "b", "c"] """); } @@ -377,9 +378,9 @@ public void That_ConditionalExpression_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => (flag ? value1 : value2) > 15) failed. - Message: Conditional result should be greater than 15 - Details: + Assert.That((flag ? value1 : value2) > 15) + Conditional result should be greater than 15 + Expected 5 to be greater than 15. flag = True value1 = 5 value2 = 10 @@ -395,9 +396,9 @@ public void That_ArrayLength_FailsAsExpected() act.Should().Throw() .WithMessage( """ - Assert.That(() => numbers.Length > 10) failed. - Message: Array should have more than 10 elements - Details: + Assert.That(numbers.Length > 10) + Array should have more than 10 elements + Expected 5 to be greater than 10. numbers.Length = 5 """); } @@ -411,8 +412,8 @@ public void That_UnaryExpression_ExtractsVariablesCorrectly() Action action = () => Assert.That(() => !Convert.ToBoolean(value)); action.Should().Throw() .WithMessage(""" - Assert.That(() => !Convert.ToBoolean(value)) failed. - Details: + Assert.That(!Convert.ToBoolean(value)) + Expected condition to be true. value = 5 """); } @@ -426,8 +427,8 @@ public void That_UnaryExpression_WithNegation_ExtractsVariablesCorrectly() Action action = () => Assert.That(() => !flag); action.Should().Throw() .WithMessage(""" - Assert.That(() => !flag) failed. - Details: + Assert.That(!flag) + Expected flag to be false. flag = True """); } @@ -442,8 +443,8 @@ public void That_InvocationExpression_ExtractsVariablesCorrectly() Action action = () => Assert.That(() => predicate(testValue)); action.Should().Throw() .WithMessage(""" - Assert.That(() => predicate(testValue)) failed. - Details: + Assert.That(predicate(testValue)) + Expected condition to be true. testValue = 5 """); } @@ -459,8 +460,8 @@ public void That_InvocationExpression_WithComplexArguments_ExtractsVariablesCorr Action action = () => Assert.That(() => complexFunc(text, expectedLength)); action.Should().Throw() .WithMessage(""" - Assert.That(() => complexFunc(text, expectedLength)) failed. - Details: + Assert.That(complexFunc(text, expectedLength)) + Expected condition to be true. expectedLength = 3 text = "hello" """); @@ -477,8 +478,8 @@ public void That_NewExpression_ExtractsVariablesCorrectly() Action action = () => Assert.That(() => new DateTime(year, month, day) == DateTime.MinValue); action.Should().Throw() .WithMessage($""" - Assert.That(() => new DateTime(year, month, day) == DateTime.MinValue) failed. - Details: + Assert.That(new DateTime(year, month, day) == DateTime.MinValue) + Expected {new DateTime(year, month, day).ToString(CultureInfo.CurrentCulture)} to equal {DateTime.MinValue.ToString(CultureInfo.CurrentCulture)}. DateTime.MinValue = {DateTime.MinValue.ToString(CultureInfo.CurrentCulture)} day = 25 month = 12 @@ -497,8 +498,8 @@ public void That_NewExpression_WithComplexArguments_ExtractsVariablesCorrectly() Action action = () => Assert.That(() => new { Name = firstName + " " + lastName }.Name == "Jane Doe"); action.Should().Throw() .WithMessage(""" - Assert.That(() => new { Name = firstName + " " + lastName }.Name == "Jane Doe") failed. - Details: + Assert.That(new { Name = firstName + " " + lastName }.Name == "Jane Doe") + Expected "John Doe" to equal "Jane Doe". firstName = "John" lastName = "Doe" new { Name = ((firstName + " ") + lastName) }.Name = "John Doe" @@ -516,8 +517,8 @@ public void That_ListInitExpression_ExtractsVariablesCorrectly() Action action = () => Assert.That(() => new List { first, second, third }.Count == 5); action.Should().Throw() .WithMessage(""" - Assert.That(() => new List { first, second, third }.Count == 5) failed. - Details: + Assert.That(new List { first, second, third }.Count == 5) + Expected 3 to equal 5. first = 1 new List { first, second, third }.Count = 3 second = 2 @@ -537,8 +538,8 @@ public void That_ListInitExpression_WithComplexElements_ExtractsVariablesCorrect Action action = () => Assert.That(() => new List { new { Name = name1, Age = age1 }, new { Name = name2, Age = age2 } }.Count == 1); action.Should().Throw() .WithMessage(""" - Assert.That(() => new List { new { Name = name1, Age = age1 }, new { Name = name2, Age = age2 } }.Count == 1) failed. - Details: + Assert.That(new List { new { Name = name1, Age = age1 }, new { Name = name2, Age = age2 } }.Count == 1) + Expected 2 to equal 1. age1 = 25 age2 = 30 name1 = "Alice" @@ -558,8 +559,8 @@ public void That_NewArrayExpression_ExtractsVariablesCorrectly() Action action = () => Assert.That(() => new[] { x, y, z }.Length == 5); action.Should().Throw() .WithMessage(""" - Assert.That(() => new[] { x, y, z }.Length == 5) failed. - Details: + Assert.That(new[] { x, y, z }.Length == 5) + Expected 3 to equal 5. new [] {x, y, z}.Length = 3 x = 10 y = 20 @@ -577,8 +578,8 @@ public void That_NewArrayExpression_WithExpressions_ExtractsVariablesCorrectly() Action action = () => Assert.That(() => new[] { baseValue * multiplier, baseValue + multiplier }.Length == 1); action.Should().Throw() .WithMessage(""" - Assert.That(() => new[] { baseValue * multiplier, baseValue + multiplier }.Length == 1) failed. - Details: + Assert.That(new[] { baseValue * multiplier, baseValue + multiplier }.Length == 1) + Expected 2 to equal 1. baseValue = 3 multiplier = 5 new [] {(baseValue * multiplier), (baseValue + multiplier)}.Length = 2 @@ -596,8 +597,8 @@ public void That_IndexExpression_ExtractsVariablesCorrectly() Action action = () => Assert.That(() => dict[key] == expectedValue); action.Should().Throw() .WithMessage(""" - Assert.That(() => dict[key] == expectedValue) failed. - Details: + Assert.That(dict[key] == expectedValue) + Expected 100 to equal 150. dict[key] = 100 expectedValue = 150 key = "key1" @@ -621,8 +622,8 @@ public void That_IndexExpression_WithMultipleIndices_ExtractsVariablesCorrectly( Action action = () => Assert.That(() => matrix[row, col] == expectedValue); action.Should().Throw() .WithMessage(""" - Assert.That(() => matrix[row, col] == expectedValue) failed. - Details: + Assert.That(matrix[row, col] == expectedValue) + Expected 6 to equal 10. col = 2 expectedValue = 10 matrix[row, col] = 6 @@ -641,8 +642,8 @@ public void That_IndexExpression_WithComplexIndexArguments_ExtractsVariablesCorr Action action = () => Assert.That(() => array[start + offset] == 100); action.Should().Throw() .WithMessage(""" - Assert.That(() => array[start + offset] == 100) failed. - Details: + Assert.That(array[start + offset] == 100) + Expected 40 to equal 100. array[start + offset] = 40 offset = 2 start = 1 @@ -658,9 +659,9 @@ public void That_NonGenericCollection_FormatsCorrectly() Action action = () => Assert.That(() => nonGenericCollection.Count == 10, "Collection should have 10 items"); action.Should().Throw() .WithMessage(""" - Assert.That(() => nonGenericCollection.Count == 10) failed. - Message: Collection should have 10 items - Details: + Assert.That(nonGenericCollection.Count == 10) + Collection should have 10 items + Expected 4 to equal 10. nonGenericCollection.Count = 4 """); } @@ -675,9 +676,9 @@ public void That_NonGenericCollectionInComparison_FormatsCorrectly() Action action = () => Assert.That(() => arrayList.Count == expectedItems.Length, "Collections should have same count"); action.Should().Throw() .WithMessage(""" - Assert.That(() => arrayList.Count == expectedItems.Length) failed. - Message: Collections should have same count - Details: + Assert.That(arrayList.Count == expectedItems.Length) + Collections should have same count + Expected 3 to equal 4. arrayList.Count = 3 expectedItems.Length = 4 """); @@ -692,8 +693,8 @@ public void That_ArrayIndexWithParameterExpression_ExtractsArrayVariable() Action action = () => Assert.That(() => arrayParam[arrayParam.Length - 2] == 999); action.Should().Throw() .WithMessage(""" - Assert.That(() => arrayParam[arrayParam.Length - 2] == 999) failed. - Details: + Assert.That(arrayParam[arrayParam.Length - 2] == 999) + Expected 20 to equal 999. arrayParam.Length = 3 arrayParam[arrayParam.Length - 2] = 20 """); @@ -709,8 +710,8 @@ public void That_WithCapturedVariableConstants_IncludesInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => captured == "wrong_value" && capturedNumber > 50) failed. - Details: + Assert.That(captured == "wrong_value" && capturedNumber > 50) + Expected condition to be true. captured = "captured_value" capturedNumber = 42 """); @@ -725,9 +726,9 @@ public void That_WithStringLiteralsAndCustomMessage_SkipsLiteralInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => testVar == "expected") failed. - Message: Values should match - Details: + Assert.That(testVar == "expected") + Values should match + Expected "actual" to equal "expected". testVar = "actual" """); } @@ -744,8 +745,8 @@ public void That_WithNumericLiterals_SkipsLiteralInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => value == 10 && doubleValue == 2.71 && floatValue == 1.5f && decimalValue == 200.75m) failed. - Details: + Assert.That(value == 10 && doubleValue == 2.71 && floatValue == 1.5f && decimalValue == 200.75m) + Expected condition to be true. decimalValue = 100.50 doubleValue = 3.14 floatValue = 2.5 @@ -763,8 +764,8 @@ public void That_WithBooleanLiterals_SkipsLiteralInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => condition == True) failed. - Details: + Assert.That(condition == True) + Expected False to equal True. condition = False """); } @@ -778,8 +779,8 @@ public void That_WithCharacterLiterals_SkipsLiteralInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => letter == 'b') failed. - Details: + Assert.That(letter == 'b') + Expected a to equal b. letter = a """); } @@ -793,8 +794,8 @@ public void That_WithNullLiterals_SkipsLiteralInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => nullableString == null) failed. - Details: + Assert.That(nullableString == null) + Expected "not null" to equal null. nullableString = "not null" """); } @@ -809,8 +810,8 @@ public void That_WithFuncDelegate_SkipsInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => predicate(value)) failed. - Details: + Assert.That(predicate(value)) + Expected condition to be true. value = -1 """); } @@ -825,8 +826,8 @@ public void That_WithActionDelegate_SkipsInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => shouldExecute && action != null) failed. - Details: + Assert.That(shouldExecute && action != null) + Expected condition to be true. shouldExecute = False """); } @@ -842,8 +843,8 @@ public void That_WithGenericFuncDelegate_SkipsInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => complexFunc(text, threshold)) failed. - Details: + Assert.That(complexFunc(text, threshold)) + Expected condition to be true. text = "hi" threshold = 5 """); @@ -861,8 +862,8 @@ public void That_WithComplexConstantExpression_HandlesCorrectly() act.Should().Throw() .WithMessage(""" - Assert.That(() => dynamicValue.Length == ConstValue && flag == True) failed. - Details: + Assert.That(dynamicValue.Length == ConstValue && flag == True) + Expected condition to be true. dynamicValue.Length = 7 flag = False """); @@ -878,8 +879,8 @@ public void That_WithEmptyStringConstant_SkipsInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => value == "") failed. - Details: + Assert.That(value == "") + Expected "non-empty" to equal "". value = "non-empty" """); } @@ -893,8 +894,8 @@ public void That_WithNegativeNumericLiterals_SkipsInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => positiveValue == -10) failed. - Details: + Assert.That(positiveValue == -10) + Expected 5 to equal -10. positiveValue = 5 """); } @@ -908,8 +909,8 @@ public void That_WithFloatAndDoubleNotation_SkipsInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => value == 2.5d && value != 3.14f) failed. - Details: + Assert.That(value == 2.5d && value != 3.14f) + Expected condition to be true. value = 1 """); } @@ -925,8 +926,8 @@ public void That_WithCapturedVariableNamesContainingKeywords_HandlesCorrectly() act.Should().Throw() .WithMessage(""" - Assert.That(() => @null == null && @true == "true" && @false == 0) failed. - Details: + Assert.That(@null == null && @true == "true" && @false == 0) + Expected condition to be true. false = 1 null = System.Object true = "false" @@ -944,8 +945,8 @@ public void That_WithConstExpressionInIndexAccess_FormatsCorrectly() act.Should().Throw() .WithMessage(""" - Assert.That(() => array[Index] == 5 && array[dynamicIndex] == 10) failed. - Details: + Assert.That(array[Index] == 5 && array[dynamicIndex] == 10) + Expected condition to be true. array[0] = 1 array[dynamicIndex] = 2 dynamicIndex = 1 @@ -962,8 +963,8 @@ public void That_WithMultipleStringLiterals_OnlyIncludesVariables() act.Should().Throw() .WithMessage(""" - Assert.That(() => firstName == "Jane" && lastName == "Smith") failed. - Details: + Assert.That(firstName == "Jane" && lastName == "Smith") + Expected condition to be true. firstName = "John" lastName = "Doe" """); @@ -982,8 +983,8 @@ public void That_WithMixedLiteralsAndVariables_FiltersCorrectly() act.Should().Throw() .WithMessage(""" - Assert.That(() => name == "Admin" && age == 30 && isActive == False && grade == 'A') failed. - Details: + Assert.That(name == "Admin" && age == 30 && isActive == False && grade == 'A') + Expected condition to be true. age = 25 grade = B isActive = True @@ -1001,9 +1002,9 @@ public void That_WithCustomMessageAndLiterals_SkipsLiteralsInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => count > 5 && status == "completed") failed. - Message: Operation should be ready - Details: + Assert.That(count > 5 && status == "completed") + Operation should be ready + Expected condition to be true. count = 3 status = "pending" """); @@ -1019,8 +1020,8 @@ public void That_WithCapturedDecimalLiteral_SkipsInDetails() act.Should().Throw() .WithMessage(""" - Assert.That(() => price + tax == 25.00m) failed. - Details: + Assert.That(price + tax == 25.00m) + Expected 22.49 to equal 25.00. price = 19.99 tax = 2.50 """); @@ -1036,8 +1037,8 @@ public void That_WithNullConstantAndVariable_OnlyIncludesVariable() act.Should().Throw() .WithMessage(""" - Assert.That(() => nullVariable != null && nonNullVariable == null) failed. - Details: + Assert.That(nullVariable != null && nonNullVariable == null) + Expected condition to be true. nonNullVariable = "value" nullVariable = null """); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs index 3c61bd3971..731a0cdfbd 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -72,7 +72,7 @@ public void ThrowsAsync_WhenExceptionIsNotExpectedType_ShouldThrow() .WithInnerException() .WithMessage(""" Assert.ThrowsAsync - Wrong exception type was thrown. + Expected the specified exception type to be thrown. action: () => throw new Exception() expected exception type: actual exception type: @@ -87,7 +87,7 @@ public void ThrowsExactlyAsync_WhenExceptionIsDerivedFromExpectedType_ShouldThro .WithInnerException() .WithMessage(""" Assert.ThrowsExactlyAsync - Wrong exception type was thrown. + Expected the specified exception type to be thrown. action: () => throw new ArgumentNullException() expected exception type: actual exception type: @@ -120,7 +120,7 @@ public void Throws_WithMessageBuilder_FailsBecauseNoException() .WithMessage(""" Assert.Throws message constructed via builder. - No exception was thrown. + Expected an exception to be thrown. action: () => { } expected exception type: """); @@ -143,7 +143,7 @@ public void Throws_WithMessageBuilder_FailsBecauseTypeMismatch() .WithMessage(""" Assert.Throws message constructed via builder. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. action: () => throw new ArgumentOutOfRangeException("MyParamNameHere") expected exception type: actual exception type: @@ -180,7 +180,7 @@ public void ThrowsExactly_WithMessageBuilder_FailsBecauseNoException() .WithMessage(""" Assert.ThrowsExactly message constructed via builder. - No exception was thrown. + Expected an exception to be thrown. action: () => { } expected exception type: """); @@ -203,7 +203,7 @@ public void ThrowsExactly_WithMessageBuilder_FailsBecauseTypeMismatch() .WithMessage(""" Assert.ThrowsExactly message constructed via builder. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. action: () => throw new ArgumentOutOfRangeException("MyParamNameHere") expected exception type: actual exception type: @@ -240,7 +240,7 @@ public async Task ThrowsAsync_WithMessageBuilder_FailsBecauseNoException() .WithMessage(""" Assert.ThrowsAsync message constructed via builder. - No exception was thrown. + Expected an exception to be thrown. action: () => Task.CompletedTask expected exception type: """); @@ -263,7 +263,7 @@ public async Task ThrowsAsync_WithMessageBuilder_FailsBecauseTypeMismatch() .WithMessage(""" Assert.ThrowsAsync message constructed via builder. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. action: () => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere")) expected exception type: actual exception type: @@ -300,7 +300,7 @@ public async Task ThrowsExactlyAsync_WithMessageBuilder_FailsBecauseNoException( .WithMessage(""" Assert.ThrowsExactlyAsync message constructed via builder. - No exception was thrown. + Expected an exception to be thrown. action: () => Task.CompletedTask expected exception type: """); @@ -323,7 +323,7 @@ public async Task ThrowsExactlyAsync_WithMessageBuilder_FailsBecauseTypeMismatch .WithMessage(""" Assert.ThrowsExactlyAsync message constructed via builder. - Wrong exception type was thrown. + Expected the specified exception type to be thrown. action: () => Task.FromException(new ArgumentOutOfRangeException("MyParamNameHere")) expected exception type: actual exception type: diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index a7866cf4e6..9d68d02208 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -123,7 +123,7 @@ public void TruncateExpression_WhenExpressionExceeds100Chars_ShouldShowEllipsis( action.Should().Throw() .WithMessage(""" Assert.IsNotNull(aVeryLongVariableNameThatExceedsOneHundredCharacte...) - Expected a non-null value. + Expected value to not be null. """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs index cf7e9d4a8d..de21db4503 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs @@ -103,7 +103,10 @@ public void CollectionAssertIsSubsetOf_ReturnedSubsetValueMessage_ThrowException Action action = () => CollectionAssert.IsSubsetOf(collection, superset); // Assert - action.Should().Throw().WithMessage("CollectionAssert.IsSubsetOf\nElement(s) is/are not present in the collection."); + action.Should().Throw().WithMessage(""" + CollectionAssert.IsSubsetOf + Element(s) is/are not present in the collection. + """); } public void CollectionAssertIsSubsetOf_WithMessage_ReturnedSubsetValueMessage_ThrowExceptionMessage() @@ -116,7 +119,11 @@ public void CollectionAssertIsSubsetOf_WithMessage_ReturnedSubsetValueMessage_Th Action action = () => CollectionAssert.IsSubsetOf(collection, superset, "message"); // Assert - action.Should().Throw().WithMessage("CollectionAssert.IsSubsetOf\nElement(s) is/are not present in the collection. message"); + action.Should().Throw().WithMessage(""" + CollectionAssert.IsSubsetOf + message + Element(s) is/are not present in the collection. + """); } public void CollectionAssertIsNotSubsetOfNullabilityPostConditions() @@ -176,7 +183,11 @@ public void CollectionAssertAreEqual_WithNestedDiffSizedArrays_Fails() int[][] expected = [[1, 2], [3, 4], [5, 6], [7, 8], [9]]; int[][] actual = [[1, 2], [999, 999, 999, 999, 999], [5, 6], [], [9]]; Action action = () => CollectionAssert.AreEqual(expected, actual); - action.Should().Throw(); + action.Should().Throw() + .WithMessage(""" + CollectionAssert.AreEqual + Different number of elements. + """); } public void CollectionAssertAreEqual_WithCaseSensetiveComparer_Fails() @@ -184,7 +195,13 @@ public void CollectionAssertAreEqual_WithCaseSensetiveComparer_Fails() List expected = ["one", "two"]; List actual = ["ONE", "tWo"]; Action action = () => CollectionAssert.AreEqual(expected, actual, StringComparer.Ordinal); - action.Should().Throw(); + action.Should().Throw() + .WithMessage(""" + CollectionAssert.AreEqual + Element at index 1 do not match. + expected: w + actual: W + """); } public void CollectionAssertAreEqualComparerMessageNullabilityPostConditions() @@ -218,7 +235,13 @@ public void CollectionAssertAreEqual_NotEqualNestedLists_Fails() ICollection? collection2 = GetNotMatchingNestedLists(); Action action = () => CollectionAssert.AreEqual(collection1, collection2); - action.Should().Throw(); + action.Should().Throw() + .WithMessage(""" + CollectionAssert.AreEqual + Element at index 0 do not match. + expected: 4 + actual: 1 + """); } public void CollectionAssertAreEqual_EqualNonICollectionInnerCollection_Passes() @@ -235,7 +258,13 @@ public void CollectionAssertAreEqual_NotEqualNonICollectionInnerCollection_Fails ICollection? collection2 = GetNotMatchingGetNonICollectionInnerCollection(); Action action = () => CollectionAssert.AreEqual(collection1, collection2); - action.Should().Throw(); + action.Should().Throw() + .WithMessage(""" + CollectionAssert.AreEqual + Element at index 0 do not match. + expected: 1 + actual: 6 + """); } public void CollectionAssertAreNotEqual_NotEqualNestedLists_Passes() @@ -251,7 +280,11 @@ public void CollectionAssertAreNotEqual_WithIgnoreCaseComparer_Fails() List expected = ["one", "two"]; List actual = ["ONE", "tWo"]; Action action = () => CollectionAssert.AreNotEqual(expected, actual, StringComparer.OrdinalIgnoreCase); - action.Should().Throw(); + action.Should().Throw() + .WithMessage(""" + CollectionAssert.AreNotEqual + Both collection contain same elements. + """); } public void CollectionAssertAreNotEqual_WithCaseSensitiveComparer_Passes() @@ -267,7 +300,11 @@ public void CollectionAssertAreNotEqual_EqualNestedLists_Fails() ICollection? collection2 = GetNestedLists(); Action action = () => CollectionAssert.AreNotEqual(collection1, collection2); - action.Should().Throw(); + action.Should().Throw() + .WithMessage(""" + CollectionAssert.AreNotEqual + Both collection contain same elements. + """); } public void CollectionAssertAreNotEqual_EqualNonICollectionInnerCollection_Fails() @@ -276,7 +313,11 @@ public void CollectionAssertAreNotEqual_EqualNonICollectionInnerCollection_Fails ICollection? collection2 = GetNonICollectionInnerCollection(); Action action = () => CollectionAssert.AreNotEqual(collection1, collection2); - action.Should().Throw(); + action.Should().Throw() + .WithMessage(""" + CollectionAssert.AreNotEqual + Both collection contain same elements. + """); } public void CollectionAssertAreNotEqual_NotEqualNonICollectionInnerCollection_Passes() @@ -335,7 +376,13 @@ public void CollectionAssertAreEquivalent_FailWhenNotEquivalent_WithMessage() ICollection? collection2 = GetMatchingSuperset(); Action action = () => CollectionAssert.AreEquivalent(collection1, collection2, "message"); action.Should().Throw() - .WithMessage("*message*"); + .WithMessage(""" + CollectionAssert.AreEquivalent + message + Expected the same number of elements in the collections. + expected count: 1 + actual count: 2 + """); } public void CollectionAssertAreEquivalent_WithInsensitiveCaseComparer_DoesNotThrow() @@ -351,7 +398,13 @@ public void CollectionAssertAreEquivalent_FailsWithInsensitiveCaseComparer_WithM ICollection? collection2 = GetLettersCaseMismatchingSuperset(); Action action = () => CollectionAssert.AreEquivalent(collection1?.Cast(), collection2?.Cast(), new CaseInsensitiveEqualityComparer(), "message"); action.Should().Throw() - .WithMessage("*message*"); + .WithMessage(""" + CollectionAssert.AreEquivalent + message + Expected the same number of elements in the collections. + expected count: 1 + actual count: 2 + """); } public void CollectionAssertAreNotEquivalent_SameItemsWithDifferentOrder_DoesNotThrow() @@ -367,7 +420,11 @@ public void CollectionAssertAreNotEquivalent_FailWhenNotEquivalent_WithMessage() ICollection? collection2 = GetMatchingSuperset(); Action action = () => CollectionAssert.AreNotEquivalent(collection1, collection2, "message"); action.Should().Throw() - .WithMessage("*message*"); + .WithMessage(""" + CollectionAssert.AreNotEquivalent + message + Both collections contain the same elements. + """); } public void CollectionAssertAreNotEquivalent_WithInsensitiveCaseComparer_DoesNotThrow() @@ -383,14 +440,22 @@ public void CollectionAssertAreNotEquivalent_FailsWithInsensitiveCaseComparer_Wi ICollection? collection2 = GetLettersCaseMismatchingSuperset(); Action action = () => CollectionAssert.AreNotEquivalent(collection1?.Cast(), collection2?.Cast(), new CaseInsensitiveNotEqualityComparer(), "message"); action.Should().Throw() - .WithMessage("*message*"); + .WithMessage(""" + CollectionAssert.AreNotEquivalent + message + Both collections contain the same elements. + """); } public void CollectionAssertAreNotEquivalent_FailsWithTwoNullsAndComparer_WithMessageAndParams() { Action action = () => CollectionAssert.AreNotEquivalent(null, null, new CaseInsensitiveNotEqualityComparer(), "message format"); action.Should().Throw() - .WithMessage("*message*"); + .WithMessage(""" + CollectionAssert.AreNotEquivalent + message format + Both collection references point to the same collection object. + """); } public void CollectionAssertAreEqualWithoutUserMessage_FailsWithGoodMessage() @@ -400,8 +465,8 @@ public void CollectionAssertAreEqualWithoutUserMessage_FailsWithGoodMessage() .WithMessage(""" CollectionAssert.AreEqual Element at index 1 do not match. - Expected: 2 - Actual: 5 + expected: 2 + actual: 5 """); } @@ -409,12 +474,12 @@ public void CollectionAssertAreEqualWithUserMessage_FailsWithGoodMessage() { Action action = () => CollectionAssert.AreEqual(new[] { 1, 2, 3 }, new[] { 1, 5, 3 }, "User-provided message"); action.Should().Throw() - .WithMessage( - """ + .WithMessage(""" CollectionAssert.AreEqual - User-provided message. Element at index 1 do not match. - Expected: 2 - Actual: 5 + User-provided message + Element at index 1 do not match. + expected: 2 + actual: 5 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/StringAssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/StringAssertTests.cs index cecc5236d6..f0b5d3ef7f 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/StringAssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/StringAssertTests.cs @@ -19,7 +19,12 @@ public void StringAssertContains() string notInString = "I'm not in the string above"; Action action = () => StringAssert.Contains(actual, notInString); action.Should().Throw() - .And.Message.Should().StartWith("StringAssert.Contains"); + .WithMessage(""" + StringAssert.Contains + Expected string to contain the specified substring. + substring: "I'm not in the string above" + value: "The quick brown fox jumps over the lazy dog." + """); } public void StringAssertStartsWith() @@ -28,7 +33,12 @@ public void StringAssertStartsWith() string notInString = "I'm not in the string above"; Action action = () => StringAssert.StartsWith(actual, notInString); action.Should().Throw() - .And.Message.Should().StartWith("StringAssert.StartsWith"); + .WithMessage(""" + StringAssert.StartsWith + Expected string to start with the specified prefix. + expected prefix: "I'm not in the string above" + value: "The quick brown fox jumps over the lazy dog." + """); } public void StringAssertEndsWith() @@ -37,7 +47,12 @@ public void StringAssertEndsWith() string notInString = "I'm not in the string above"; Action action = () => StringAssert.EndsWith(actual, notInString); action.Should().Throw() - .And.Message.Should().StartWith("StringAssert.EndsWith"); + .WithMessage(""" + StringAssert.EndsWith + Expected string to end with the specified suffix. + expected suffix: "I'm not in the string above" + value: "The quick brown fox jumps over the lazy dog." + """); } public void StringAssertDoesNotMatch() @@ -46,7 +61,12 @@ public void StringAssertDoesNotMatch() Regex doesMatch = new("quick brown fox"); Action action = () => StringAssert.DoesNotMatch(actual, doesMatch); action.Should().Throw() - .And.Message.Should().StartWith("StringAssert.DoesNotMatch"); + .WithMessage(""" + StringAssert.DoesNotMatch + Expected string to not match the specified pattern. + pattern: quick brown fox + value: "The quick brown fox jumps over the lazy dog." + """); } public void StringAssertContainsIgnoreCase_DoesNotThrow() @@ -75,7 +95,12 @@ public void StringAssertContainsDoesNotThrowFormatException() { Action action = () => StringAssert.Contains(":-{", "x"); action.Should().Throw() - .And.Message.Should().StartWith("StringAssert.Contains"); + .WithMessage(""" + StringAssert.Contains + Expected string to contain the specified substring. + substring: "x" + value: ":-{" + """); } // See https://github.com/dotnet/sdk/issues/25373 @@ -83,7 +108,13 @@ public void StringAssertContainsDoesNotThrowFormatExceptionWithArguments() { Action action = () => StringAssert.Contains("{", "x", "message"); action.Should().Throw() - .And.Message.Should().StartWith("StringAssert.Contains"); + .WithMessage(""" + StringAssert.Contains + message + Expected string to contain the specified substring. + substring: "x" + value: "{" + """); } public void StringAssertContainsNullabilitiesPostConditions() From a7c777a623722e877d7c1ae784c50718b740975d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 20 Mar 2026 18:49:48 +0100 Subject: [PATCH 44/58] Address code review findings - Fix #1: Replace hardcoded 'Expected all elements...' with AllMatchPredicateFailNew resource - Fix #2: Remove 11 dead resource strings (ContainsFail, StartsWithFail, EndsWithFail, IsMatchFail, IsNotMatchFail, DoesNotEndWithFail, DoesNotStartWithFail, AssertThatFailedFormat, AssertThatMessageFormat, AssertThatDetailsPrefix, CollectionEqualReason) - Fix #3: Replace bare catch with catch (Exception) in TryEvaluateFormatted - Fix #5: Type-check StartsWith/EndsWith/Contains to only match string methods - Fix #6: Add explicit ellipsis sentinel handling in FormatCallSite - Fix #7: Fix grammar 'Both collection contain same elements' -> 'Both collections contain the same elements' --- .../TestFramework/Assertions/Assert.That.cs | 32 +++++---- .../TestFramework/Assertions/Assert.cs | 21 +++++- .../Resources/FrameworkMessages.resx | 40 ++--------- .../Resources/xlf/FrameworkMessages.cs.xlf | 66 +++---------------- .../Resources/xlf/FrameworkMessages.de.xlf | 66 +++---------------- .../Resources/xlf/FrameworkMessages.es.xlf | 66 +++---------------- .../Resources/xlf/FrameworkMessages.fr.xlf | 66 +++---------------- .../Resources/xlf/FrameworkMessages.it.xlf | 66 +++---------------- .../Resources/xlf/FrameworkMessages.ja.xlf | 66 +++---------------- .../Resources/xlf/FrameworkMessages.ko.xlf | 66 +++---------------- .../Resources/xlf/FrameworkMessages.pl.xlf | 66 +++---------------- .../Resources/xlf/FrameworkMessages.pt-BR.xlf | 66 +++---------------- .../Resources/xlf/FrameworkMessages.ru.xlf | 66 +++---------------- .../Resources/xlf/FrameworkMessages.tr.xlf | 66 +++---------------- .../xlf/FrameworkMessages.zh-Hans.xlf | 66 +++---------------- .../xlf/FrameworkMessages.zh-Hant.xlf | 66 +++---------------- .../Assertions/CollectionAssertTests.cs | 6 +- 17 files changed, 144 insertions(+), 813 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.That.cs b/src/TestFramework/TestFramework/Assertions/Assert.That.cs index 6807ecb025..a7b8a072e7 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.That.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.That.cs @@ -115,29 +115,27 @@ private static string BuildMethodCallMessage(MethodCallExpression methodCall) { string methodName = methodCall.Method.Name; + // String-specific methods + if (methodCall.Object is not null && methodCall.Object.Type == typeof(string)) + { + return methodName switch + { + "StartsWith" => FrameworkMessages.StartsWithFailNew, + "EndsWith" => FrameworkMessages.EndsWithFailNew, + nameof(string.Contains) => FrameworkMessages.ContainsStringFailNew, + _ => FrameworkMessages.IsTrueFailNew, + }; + } + return methodName switch { - "StartsWith" => FrameworkMessages.StartsWithFailNew, - "EndsWith" => FrameworkMessages.EndsWithFailNew, - nameof(string.Contains) => BuildContainsMessage(methodCall), - "All" => "Expected all elements to match the predicate.", + nameof(string.Contains) => FrameworkMessages.ContainsItemFailNew, + "All" => FrameworkMessages.AllMatchPredicateFailNew, "Any" => FrameworkMessages.ContainsPredicateFailNew, _ => FrameworkMessages.IsTrueFailNew, }; } - private static string BuildContainsMessage(MethodCallExpression methodCall) - { - // string.Contains vs collection.Contains - if (methodCall.Object is not null - && methodCall.Object.Type == typeof(string)) - { - return FrameworkMessages.ContainsStringFailNew; - } - - return FrameworkMessages.ContainsItemFailNew; - } - private static string TryEvaluateFormatted(Expression expr) { try @@ -145,7 +143,7 @@ private static string TryEvaluateFormatted(Expression expr) object? value = Expression.Lambda(expr).Compile().DynamicInvoke(); return FormatValue(value); } - catch + catch (Exception) { return GetCleanMemberName(expr); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 1ea6554298..6b2f8c42d3 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -450,18 +450,33 @@ internal static string FormatCallSite(string methodName, params (string ParamNam { var sb = new StringBuilder(methodName); sb.Append('('); + bool hasVisibleArgs = false; for (int i = 0; i < args.Length; i++) { - if (i > 0) + string expression = args[i].Expression; + string paramName = args[i].ParamName; + + // Sentinel "..." indicates additional parameters were omitted. + if (paramName == "...") + { + if (hasVisibleArgs) + { + sb.Append(", "); + } + + sb.Append("..."); + continue; + } + + if (hasVisibleArgs) { sb.Append(", "); } - string expression = args[i].Expression; - string paramName = args[i].ParamName; sb.Append(string.IsNullOrEmpty(expression) || expression == paramName ? paramName : TruncateExpression(expression, 50)); + hasVisibleArgs = true; } sb.Append(')'); diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index 47dac2648c..965947311d 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -139,7 +139,7 @@ Both collections are empty. - Both collection contain same elements. + Both collections contain the same elements. Both collection references point to the same collection object. @@ -147,12 +147,6 @@ Both collections contain the same elements. - - {0}. {1} - - - String '{0}' does not contain string '{1}'. {2}. - Expected the same number of elements in the collections. @@ -162,18 +156,9 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - {0} failed. {1} - - String '{0}' does not match pattern '{1}'. {2} - - - String '{0}' matches pattern '{1}'. {2} - The member specified ({0}) could not be found. You might need to regenerate your private accessor, @@ -194,9 +179,6 @@ Different number of elements. - - String '{0}' does not start with string '{1}'. {2} - The property {0} has type {1}; expected type {2}. @@ -239,12 +221,6 @@ Invalid GitHub ticket URL - - String '{0}' ends with string '{1}'. {2} - - - String '{0}' starts with string '{1}'. {2} - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. @@ -266,17 +242,6 @@ The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures. - - Assert.That({0}) failed. - {0} is the user code expression - - - Message: {0} - {0} user provided message - - - Details: - Element(s) <{0}> is/are not present in the collection. @@ -322,6 +287,9 @@ Expected no items to match the predicate. + + Expected all elements to match the predicate. + Expected string to contain the specified substring. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index 2c293ba8ea..9592489ea7 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ Nevkládejte hodnotu typů do AreSame(). Hodnoty převedené do typu Object už nebudou nikdy stejné. Zvažte použití AreEqual(). {0} - - Details: - Podrobnosti: - - - - Assert.That({0}) failed. - Assert.That({0}) se nezdařilo. - {0} is the user code expression - - - Message: {0} - Zpráva: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - Obě kolekce obsahují stejné elementy. - + Both collections contain the same elements. + Obě kolekce obsahují stejné elementy. + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}. {1} - - - - String '{0}' does not contain string '{1}'. {2}. - Řetězec '{0}' neobsahuje řetězec '{1}'. {2}. - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - Řetězec „{0}“ končí řetězcem „{1}“. {2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - Řetězec „{0}“ začíná řetězcem „{1}“. {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - Řetězec „{0}“ nekončí řetězcem „{1}“. {2} - - {0} failed. {1} {0} selhalo. {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - Řetězec „{0}“ neodpovídá vzoru „{1}“. {2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - Řetězec „{0}“ odpovídá vzoru „{1}“. {2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ Elementy <{0}> se v kolekci nenachází. - - String '{0}' does not start with string '{1}'. {2} - Řetězec „{0}“ nezačíná řetězcem „{1}“. {2} - - The property {0} has type {1}; expected type {2}. Vlastnost {0} je typu {1}; očekávaný typ {2}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index b6aec1d1e7..445f8b28ca 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ Übergeben Sie keine Werttypen an AreSame(). In ein Objekt konvertierte Werte sind niemals identisch. Verwenden Sie stattdessen AreEqual(). {0} - - Details: - Details: - - - - Assert.That({0}) failed. - Assert.That({0}) fehlgeschlagen. - {0} is the user code expression - - - Message: {0} - Meldung: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - Beide Sammlungen enthalten dieselben Elemente. - + Both collections contain the same elements. + Beide Sammlungen enthalten dieselben Elemente. + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}. {1} - - - - String '{0}' does not contain string '{1}'. {2}. - Die Zeichenfolge "{0}" enthält nicht die Zeichenfolge "{1}". {2}. - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - Die Zeichenfolge „{0}“ endet mit der Zeichenfolge „{1}“. {2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - Die Zeichenfolge „{0}“ beginnt mit der Zeichenfolge „{1}“. {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - Die Zeichenfolge „{0}“ endet nicht auf die Zeichenfolge „{1}“. {2} - - {0} failed. {1} Fehler bei "{0}". {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - Die Zeichenfolge „{0}“ stimmt nicht mit dem Muster „{1}“ überein. {2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - Die Zeichenfolge „{0}“ stimmt mit dem Muster „{1}“ überein. {2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ Element(e) <{0}> ist/sind in der Auflistung nicht vorhanden. - - String '{0}' does not start with string '{1}'. {2} - Die Zeichenfolge „{0}“ beginnt nicht mit der Zeichenfolge „{1}“. {2} - - The property {0} has type {1}; expected type {2}. Die {0}-Eigenschaft weist den Typ "{1}" auf; Typ "{2}" wird erwartet. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index 49c9f4df3a..96b961aa92 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ No pase tipos de valor a AreSame(). Los valores convertidos a Object no serán nunca iguales. Considere el uso de AreEqual(). {0} - - Details: - Detalles: - - - - Assert.That({0}) failed. - Error de Assert.That({0}). - {0} is the user code expression - - - Message: {0} - Mensaje: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - Ambas colecciones tienen los mismos elementos. - + Both collections contain the same elements. + Ambas colecciones tienen los mismos elementos. + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}. {1} - - - - String '{0}' does not contain string '{1}'. {2}. - La cadena '{0}' no contiene la cadena '{1}'. {2}. - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - La cadena "{0}" termina con la cadena "{1}". {2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - La cadena "{0}" comienza con la cadena "{1}". {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - La cadena "{0}" no termina con la cadena "{1}". {2} - - {0} failed. {1} Error de {0}. {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - La cadena "{0}" no coincide con el patrón "{1}". {2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - La cadena "{0}" coincide con el patrón "{1}". {2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ Los elementos <{0}> no están presentes en la colección. - - String '{0}' does not start with string '{1}'. {2} - La cadena "{0}" no empieza con la cadena "{1}". {2} - - The property {0} has type {1}; expected type {2}. La propiedad {0} tiene el tipo {1}; se esperaba el tipo {2}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index 7047573f39..70d0d6d83a 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ Ne passez pas de types valeur à AreSame(). Les valeurs converties en Object ne seront plus jamais les mêmes. Si possible, utilisez AreEqual(). {0} - - Details: - Détails : - - - - Assert.That({0}) failed. - Désolé, échec de Assert.That({0}). - {0} is the user code expression - - - Message: {0} - Message : {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - Les deux collections contiennent des éléments identiques. - + Both collections contain the same elements. + Les deux collections contiennent des éléments identiques. + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}. {1} - - - - String '{0}' does not contain string '{1}'. {2}. - La chaîne '{0}' ne contient pas la chaîne '{1}'. {2}. - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - La chaîne '{0}' se termine par la chaîne '{1}'. {2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - La chaîne '{0}' commence par la chaîne '{1}'. {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - La chaîne '{0}' ne se termine pas par la chaîne '{1}'. {2} - - {0} failed. {1} Échec de {0}. {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - La chaîne '{0}' ne correspond pas au modèle '{1}'. {2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - La chaîne '{0}' correspond au modèle '{1}'. {2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ L’élément ou les éléments <{0}> n’est ou ne sont pas présent(s) dans la collection. - - String '{0}' does not start with string '{1}'. {2} - La chaîne '{0}' ne commence pas par la chaîne '{1}'. {2} - - The property {0} has type {1}; expected type {2}. La propriété {0} possède le type {1} ; type attendu {2}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index 0085359589..4d258a5234 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ Non passare tipi valore a AreSame(). I valori convertiti in Object non saranno mai uguali. Usare AreEqual(). {0} - - Details: - Dettagli: - - - - Assert.That({0}) failed. - Assert.That({0}) non riuscito. - {0} is the user code expression - - - Message: {0} - Messaggio: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - Le raccolte contengono entrambe gli stessi elementi. - + Both collections contain the same elements. + Le raccolte contengono entrambe gli stessi elementi. + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}. {1} - - - - String '{0}' does not contain string '{1}'. {2}. - La stringa '{0}' non contiene la stringa '{1}'. {2}. - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - La stringa '{0}' termina con la stringa '{1}'. {2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - La stringa '{0}' inizia con la stringa '{1}'. {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - La stringa '{0}' non termina con la stringa '{1}'. {2} - - {0} failed. {1} {0} non riuscita. {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - La stringa '{0}' non corrisponde al criterio '{1}'. {2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - La stringa '{0}' corrisponde al criterio '{1}'. {2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ Gli elementi <{0}> non sono presenti nella raccolta. - - String '{0}' does not start with string '{1}'. {2} - La stringa '{0}' non inizia con la stringa '{1}'. {2} - - The property {0} has type {1}; expected type {2}. Il tipo della proprietà {0} è {1}, ma quello previsto è {2}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index 8540130114..d858e8b746 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ AreSame() には値型を渡すことはできません。オブジェクトに変換された値が同じにはなりません。AreEqual() を使用することを検討してください。{0} - - Details: - 詳細: - - - - Assert.That({0}) failed. - Assert.That({0}) に失敗しました。 - {0} is the user code expression - - - Message: {0} - メッセージ: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - 両方のコレクションが同じ要素を含んでいます。 - + Both collections contain the same elements. + 両方のコレクションが同じ要素を含んでいます。 + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}。{1} - - - - String '{0}' does not contain string '{1}'. {2}. - 文字列 '{0}' は文字列 '{1}' を含んでいません。{2}。 - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - 文字列 '{0}' の末尾は文字列 '{1}' です。{2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - 文字列 '{0}' は文字列 '{1}' で始まります。 {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - 文字列 '{0}' は文字列 '{1}' で終わりません。{2} - - {0} failed. {1} {0} に失敗しました。{1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - 文字列 '{0}' はパターン '{1}' と一致しません。{2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - 文字列 '{0}' はパターン '{1}' と一致します。{2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ 要素 <{0}> がコレクション内に存在しません。 - - String '{0}' does not start with string '{1}'. {2} - 文字列 '{0}' は文字列 '{1}' で始まりません。{2} - - The property {0} has type {1}; expected type {2}. プロパティ {0} は型 {1} を含んでいますが、型 {2} が必要です。 diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index 3e0204202b..70ed44695f 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ AreSame()에 값 형식을 전달하면 안 됩니다. Object로 변환된 값은 동일한 값으로 간주되지 않습니다. AreEqual()을 사용해 보세요. {0} - - Details: - 세부 정보: - - - - Assert.That({0}) failed. - Assert.That({0})이(가) 실패했습니다. - {0} is the user code expression - - - Message: {0} - 메시지: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - 두 컬렉션에 같은 요소가 포함되어 있습니다. - + Both collections contain the same elements. + 두 컬렉션에 같은 요소가 포함되어 있습니다. + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}. {1} - - - - String '{0}' does not contain string '{1}'. {2}. - '{0}' 문자열이 '{1}' 문자열을 포함하지 않습니다. {2} - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - 문자열 '{0}'은 문자열 '{1}'(으)로 끝납니다. {2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - 문자열 '{0}'은 문자열 '{1}'(으)로 시작합니다. {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - '{0}' 문자열이 '{1}' 문자열로 끝나지 않습니다. {2} - - {0} failed. {1} {0}이(가) 실패했습니다. {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - '{0}' 문자열이 '{1}' 패턴과 일치하지 않습니다. {2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - '{0}' 문자열이 '{1}' 패턴과 일치합니다. {2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ 컬렉션에 <{0}> 요소가 없습니다. - - String '{0}' does not start with string '{1}'. {2} - '{0}' 문자열이 '{1}' 문자열로 시작되지 않습니다. {2} - - The property {0} has type {1}; expected type {2}. {0} 속성의 형식은 {2}이어야 하는데 실제로는 {1}입니다. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index 156debe41e..eaaf923f6f 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ Nie przekazuj typów wartości do metody AreSame(). Wartości przekonwertowane na typ Object nigdy nie będą takie same. Rozważ użycie metody AreEqual(). {0} - - Details: - Szczegóły: - - - - Assert.That({0}) failed. - Operacja Assert.That({0}) nie powiodła się. - {0} is the user code expression - - - Message: {0} - Komunikat: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - Obie kolekcje zawierają te same elementy. - + Both collections contain the same elements. + Obie kolekcje zawierają te same elementy. + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}. {1} - - - - String '{0}' does not contain string '{1}'. {2}. - Ciąg „{0}” nie zawiera ciągu „{1}”. {2}. - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - Ciąg „{0}” kończy się ciągiem „{1}”. {2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - Ciąg „{0}” rozpoczyna się od ciągu „{1}”. {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - Ciąg „{0}” nie kończy się ciągiem „{1}”. {2} - - {0} failed. {1} {0} — niepowodzenie. {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - Ciąg „{0}” nie jest zgodny ze wzorcem „{1}”. {2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - Ciąg „{0}” jest zgodny ze wzorcem „{1}”. {2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ Elementy <{0}> nie występują w kolekcji. - - String '{0}' does not start with string '{1}'. {2} - Ciąg „{0}” nie rozpoczyna się od ciągu „{1}”. {2} - - The property {0} has type {1}; expected type {2}. Właściwość {0} jest typu {1}; oczekiwano typu {2}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index 27e8086a89..18b55371e2 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ Não passe tipos de valores para AreSame(). Os valores convertidos para Object nunca serão os mesmos. Considere usar AreEqual(). {0} - - Details: - Detalhes: - - - - Assert.That({0}) failed. - Assert.That({0}) falhou. - {0} is the user code expression - - - Message: {0} - Mensagem: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - Ambas as coleções contêm os mesmos elementos. - + Both collections contain the same elements. + Ambas as coleções contêm os mesmos elementos. + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}. {1} - - - - String '{0}' does not contain string '{1}'. {2}. - A cadeia de caracteres '{0}' não contém a cadeia de caracteres '{1}'. {2}. - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - A cadeia de caracteres “{0}” termina com cadeia de caracteres “{1}”. {2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - A cadeia de caracteres “{0}” começa com a cadeia de caracteres “{1}”. {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - A cadeia de caracteres “{0}” não termina com a cadeia de caracteres “{1}”. {2} - - {0} failed. {1} {0} falhou. {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - A cadeia de caracteres “{0}” não corresponde ao padrão “{1}”. {2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - A cadeia de caracteres “{0}” corresponde ao padrão “{1}”. {2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ O(s) elemento(s) <{0}> não está/estão presente(s) na coleção. - - String '{0}' does not start with string '{1}'. {2} - A cadeia de caracteres “{0}” não começa com a cadeia de caracteres “{1}”. {2} - - The property {0} has type {1}; expected type {2}. A propriedade {0} é do tipo {1}; o tipo esperado era {2}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index f0fd6df5e6..db55e28ead 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ Не передавайте типы значений в функцию AreSame(). Значения, преобразованные в Object, никогда не будут одинаковыми. Попробуйте использовать AreEqual(). {0} - - Details: - Подробности: - - - - Assert.That({0}) failed. - Сбой Assert.That({0}). - {0} is the user code expression - - - Message: {0} - Сообщение: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - Обе коллекции содержат одинаковые элементы. - + Both collections contain the same elements. + Обе коллекции содержат одинаковые элементы. + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}. {1} - - - - String '{0}' does not contain string '{1}'. {2}. - Строка "{0}" не содержит строку "{1}". {2}. - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - Строка "{0}" заканчивается строкой "{1}". {2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - Строка "{0}" начинается со строки "{1}". {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - Строка "{0}" не заканчивается строкой "{1}". {2} - - {0} failed. {1} Сбой {0}. {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - Строка "{0}" не соответствует шаблону "{1}". {2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - Строка "{0}" соответствует шаблону "{1}". {2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ Элементы <{0}> отсутствуют в коллекции. - - String '{0}' does not start with string '{1}'. {2} - Строка "{0}" не начинается со строки "{1}". {2} - - The property {0} has type {1}; expected type {2}. Свойство {0} имеет тип {1}. Ожидается тип {2}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index 3c4d06cc0c..9e98081b26 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ AreSame()'e değer türleri geçirmeyin. Object olarak dönüştürülen değerler asla aynı olamayacak. AreEqual() kullanmayı düşün. {0} - - Details: - Ayrıntılar: - - - - Assert.That({0}) failed. - Assert.That({0}) başarısız oldu. - {0} is the user code expression - - - Message: {0} - İleti: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - Her iki koleksiyon da aynı öğeleri içeriyor. - + Both collections contain the same elements. + Her iki koleksiyon da aynı öğeleri içeriyor. + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}. {1} - - - - String '{0}' does not contain string '{1}'. {2}. - '{0}' dizesi, '{1}' dizesini içermiyor. {2}. - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - '{0}' dizesi '{1}' dizesi ile bitiyor. {2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - '{0}' dizesi '{1}' dizesi ile başlıyor. {2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - '{0}' dizesi, '{1}' dizesi ile sonlanmıyor. {2} - - {0} failed. {1} {0} başarısız. {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - '{0}' dizesi, '{1}' deseni ile eşleşmiyor. {2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - '{0}' dizesi, '{1}' deseni ile eşleşiyor. {2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ Öğe(ler) <{0}> koleksiyonda mevcut değildir. - - String '{0}' does not start with string '{1}'. {2} - '{0}' dizesi, '{1}' dizesi ile başlamıyor. {2} - - The property {0} has type {1}; expected type {2}. {0} özelliği, {1} türüne sahip; beklenen tür {2}. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index b15248bb4c..861b921af1 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ 不要向 AreSame() 传递值类型。转换为 Object 的值将永远不会相等。请考虑使用 AreEqual()。{0} - - Details: - 详细信息: - - - - Assert.That({0}) failed. - Assert.That({0}) 失败。 - {0} is the user code expression - - - Message: {0} - 消息: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - 这两个集合包含相同的元素。 - + Both collections contain the same elements. + 这两个集合包含相同的元素。 + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}。{1} - - - - String '{0}' does not contain string '{1}'. {2}. - 字符串“{0}”不包含字符串“{1}”。{2}。 - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - 字符串 '{0}' 以字符串 '{1}'结尾。{2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - 字符串 '{0}' 以字符串 '{1}' 开头。{2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - 字符串 '{0}' 不以字符串 '{1}' 结尾。{2} - - {0} failed. {1} {0} 失败。{1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - 字符串 '{0}' 与模式 '{1}' 不匹配。{2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - 字符串 '{0}' 与模式 '{1}' 匹配。{2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ 集合中不存在元素 <{0}>。 - - String '{0}' does not start with string '{1}'. {2} - 字符串 '{0}' 不以字符串 '{1}' 开头。{2} - - The property {0} has type {1}; expected type {2}. 属性 {0} 的类型为 {1};类型应为 {2}。 diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index a1a9f4185b..8b42dde962 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -17,6 +17,11 @@ Expected all items to be unique. + + Expected all elements to match the predicate. + Expected all elements to match the predicate. + + Case differs. Case differs. @@ -67,30 +72,15 @@ 不要將實值型別傳遞給 AreSame()。轉換成 Object 的值從此不再一樣。請考慮使用 AreEqual()。{0} - - Details: - 詳細資料: - - - - Assert.That({0}) failed. - Assert.That({0}) 失敗。 - {0} is the user code expression - - - Message: {0} - 訊息: {0} - {0} user provided message - Both collections are empty. Both collections are empty. - Both collection contain same elements. - 兩個集合含有相同的項目。 - + Both collections contain the same elements. + 兩個集合含有相同的項目。 + Both collection references point to the same collection object. @@ -102,16 +92,6 @@ Both collections contain the same elements. - - {0}. {1} - {0}。{1} - - - - String '{0}' does not contain string '{1}'. {2}. - 字串 '{0}' 未包含字串 '{1}'。{2}。 - - Expected collection to contain the specified item. Expected collection to contain the specified item. @@ -152,11 +132,6 @@ Expected string to not contain the specified substring. - - String '{0}' ends with string '{1}'. {2} - 字串 '{0}' 以字串 '{1}' 結尾。{2} - - Expected string to not end with the specified suffix. Expected string to not end with the specified suffix. @@ -167,11 +142,6 @@ Expected string to not match the specified pattern. - - String '{0}' starts with string '{1}'. {2} - 字串 '{0}' 以字串 '{1}' 開頭。{2} - - Expected string to not start with the specified prefix. Expected string to not start with the specified prefix. @@ -212,11 +182,6 @@ Element at index {0} is not of the expected type. - - String '{0}' does not end with string '{1}'. {2} - 字串 '{0}' 不是以字串 '{1}' 結尾。{2} - - {0} failed. {1} {0} 失敗。 {1} @@ -287,11 +252,6 @@ Expected value {0} to be less than or equal to {1}. - - String '{0}' does not match pattern '{1}'. {2} - 字串 '{0}' 與模式 '{1}' 不符。{2} - - Expected value to be negative. Expected value to be negative. @@ -312,11 +272,6 @@ Expected value to not be an instance of {0}. - - String '{0}' matches pattern '{1}'. {2} - 字串 '{0}' 與模式 '{1}' 相符。{2} - - Expected value to not be null. Expected value to not be null. @@ -388,11 +343,6 @@ 集合中不存在元素 <{0}>。 - - String '{0}' does not start with string '{1}'. {2} - 字串 '{0}' 不是以字串 '{1}' 開頭。{2} - - The property {0} has type {1}; expected type {2}. 屬性 {0} 具有類型 {1}; 預期為類型 {2}。 diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs index de21db4503..1c78467066 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs @@ -283,7 +283,7 @@ public void CollectionAssertAreNotEqual_WithIgnoreCaseComparer_Fails() action.Should().Throw() .WithMessage(""" CollectionAssert.AreNotEqual - Both collection contain same elements. + Both collections contain the same elements. """); } @@ -303,7 +303,7 @@ public void CollectionAssertAreNotEqual_EqualNestedLists_Fails() action.Should().Throw() .WithMessage(""" CollectionAssert.AreNotEqual - Both collection contain same elements. + Both collections contain the same elements. """); } @@ -316,7 +316,7 @@ public void CollectionAssertAreNotEqual_EqualNonICollectionInnerCollection_Fails action.Should().Throw() .WithMessage(""" CollectionAssert.AreNotEqual - Both collection contain same elements. + Both collections contain the same elements. """); } From e797b5d427c770a64bc041613af641103a4404ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 23 Mar 2026 11:30:27 +0100 Subject: [PATCH 45/58] Fix broken AreSame test methods with missing closing braces and method signatures --- .../Assertions/AssertTests.AreSame.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs index b5c1bb5e2d..01e30da363 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreSame.cs @@ -22,6 +22,9 @@ Expected references to be the same. Objects are not equal. expected: (Hash=*) actual: (Hash=*) """); + } + + public void AreSame_StringMessage_PassSameObject_ShouldPass() { object o = new(); Assert.AreSame(o, o, "User-provided message"); @@ -37,6 +40,9 @@ Expected references to be the same. Objects are not equal. expected: (Hash=*) actual: (Hash=*) """); + } + + public void AreSame_InterpolatedString_PassSameObject_ShouldPass() { DummyClassTrackingToStringCalls o = new(); Assert.AreSame(o, o, $"User-provided message: {o}"); From 7972e96d075fbc51064392d5c564010fbbffaa2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 23 Mar 2026 14:15:33 +0100 Subject: [PATCH 46/58] Fix all Build.cmd errors - Fix IDE0028/IDE0306: Use collection expression [.. collection] instead of new List(collection) - Fix IDE0046: Simplify if-return to conditional expression in BuildMethodCallMessage - Fix IDE0051: Remove unused private methods (IsExpressionRedundant, TryExtractStringLiteralContent, IsExpressionMoreSpecificNumericLiteral, FormatParameterWithValue, FormatParameterWithExpressionCheck) - Fix SA1028/IDE0055: Remove trailing whitespace in IsInstanceOfTypeTests.cs - Fix CS8137/CS8179: Replace ValueTuple params with StringPair struct to support net462 (no System.ValueTuple dependency) - Fix AreSame.cs: Restore missing method signatures and closing braces --- .../Assertions/Assert.AreEqual.cs | 46 +++--- .../Assertions/Assert.AreSame.cs | 12 +- .../Assertions/Assert.Contains.cs | 42 ++--- .../TestFramework/Assertions/Assert.Count.cs | 10 +- .../Assertions/Assert.EndsWith.cs | 12 +- .../Assertions/Assert.IComparable.cs | 28 ++-- .../Assert.IsExactInstanceOfType.cs | 4 +- .../Assertions/Assert.IsInstanceOfType.cs | 4 +- .../TestFramework/Assertions/Assert.IsNull.cs | 4 +- .../TestFramework/Assertions/Assert.IsTrue.cs | 4 +- .../Assertions/Assert.Matches.cs | 12 +- .../Assertions/Assert.StartsWith.cs | 12 +- .../TestFramework/Assertions/Assert.That.cs | 21 ++- .../TestFramework/Assertions/Assert.cs | 146 +++--------------- .../Assertions/CollectionAssert.cs | 22 +-- .../TestFramework/Assertions/StringAssert.cs | 20 +-- .../AssertTests.IsInstanceOfTypeTests.cs | 4 +- 17 files changed, 152 insertions(+), 251 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs index d513d6b6d9..0555a8d50e 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreEqual.cs @@ -536,8 +536,8 @@ private static string FormatStringComparisonMessage(string? expected, string? ac { string message = FrameworkMessages.AreEqualFailNew; message += FormatAlignedParameters( - (nameof(expected), FormatValue(expected)), - (nameof(actual), FormatValue(actual))); + new StringPair(nameof(expected), FormatValue(expected)), + new StringPair(nameof(actual), FormatValue(actual))); return message; } @@ -606,15 +606,15 @@ private static string FormatStringDifferenceMessage(string expected, string actu [DoesNotReturn] private static void ThrowAssertAreEqualFailed(object? expected, object? actual, string? userMessage, string expectedExpression, string actualExpression) { - string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); + string callSite = FormatCallSite("Assert.AreEqual", new StringPair(nameof(expected), expectedExpression), new StringPair(nameof(actual), actualExpression)); string message; if (actual is not null && expected is not null && !actual.GetType().Equals(expected.GetType())) { message = FrameworkMessages.AreEqualFailNew; message += FormatAlignedParameters( - (nameof(expected), FormatValueWithType(expected)), - (nameof(actual), FormatValueWithType(actual))); + new StringPair(nameof(expected), FormatValueWithType(expected)), + new StringPair(nameof(actual), FormatValueWithType(actual))); } else if (expected is string expectedString && actual is string actualString) { @@ -627,8 +627,8 @@ private static void ThrowAssertAreEqualFailed(object? expected, object? actual, { message = FrameworkMessages.AreEqualFailNew; message += FormatAlignedParameters( - (nameof(expected), FormatValue(expected)), - (nameof(actual), FormatValue(actual))); + new StringPair(nameof(expected), FormatValue(expected)), + new StringPair(nameof(actual), FormatValue(actual))); } message = AppendUserMessage(message, userMessage); @@ -639,12 +639,12 @@ private static void ThrowAssertAreEqualFailed(object? expected, object? actual, private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, string? userMessage, string expectedExpression, string actualExpression) where T : struct, IConvertible { - string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression), ("...", "...")); + string callSite = FormatCallSite("Assert.AreEqual", new StringPair(nameof(expected), expectedExpression), new StringPair(nameof(actual), actualExpression), new StringPair("...", "...")); string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreEqualDeltaNoGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); message += FormatAlignedParameters( - (nameof(expected), FormatValue(expected)), - (nameof(actual), FormatValue(actual)), - (nameof(delta), FormatValue(delta))); + new StringPair(nameof(expected), FormatValue(expected)), + new StringPair(nameof(actual), FormatValue(actual)), + new StringPair(nameof(delta), FormatValue(delta))); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -652,7 +652,7 @@ private static void ThrowAssertAreEqualFailed(T expected, T actual, T delta, [DoesNotReturn] private static void ThrowAssertAreEqualFailed(string? expected, string? actual, bool ignoreCase, CultureInfo culture, string? userMessage, string expectedExpression, string actualExpression) { - string callSite = FormatCallSite("Assert.AreEqual", (nameof(expected), expectedExpression), (nameof(actual), actualExpression), ("...", "...")); + string callSite = FormatCallSite("Assert.AreEqual", new StringPair(nameof(expected), expectedExpression), new StringPair(nameof(actual), actualExpression), new StringPair("...", "...")); string message; // If the user requested to match case, and the difference between expected/actual is casing only, then we use a different message. @@ -660,10 +660,10 @@ private static void ThrowAssertAreEqualFailed(string? expected, string? actual, { message = FrameworkMessages.AreEqualCaseDiffersMsg; message += FormatAlignedParameters( - (nameof(expected), FormatValue(expected)), - (nameof(actual), FormatValue(actual)), - ("ignore case", ignoreCase.ToString()), - (nameof(culture), culture.Name)); + new StringPair(nameof(expected), FormatValue(expected)), + new StringPair(nameof(actual), FormatValue(actual)), + new StringPair("ignore case", ignoreCase.ToString()), + new StringPair(nameof(culture), culture.Name)); } else { @@ -1185,12 +1185,12 @@ private static bool AreNotEqualFailing(double notExpected, double actual, double private static void ThrowAssertAreNotEqualFailed(T notExpected, T actual, T delta, string? userMessage, string notExpectedExpression, string actualExpression) where T : struct, IConvertible { - string callSite = FormatCallSite("Assert.AreNotEqual", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression), ("...", "...")); + string callSite = FormatCallSite("Assert.AreNotEqual", new StringPair(nameof(notExpected), notExpectedExpression), new StringPair(nameof(actual), actualExpression), new StringPair("...", "...")); string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.AreNotEqualDeltaGreaterThanFailMsg, delta.ToString(CultureInfo.CurrentCulture.NumberFormat)); message += FormatAlignedParameters( - ("not expected", FormatValue(notExpected)), - (nameof(actual), FormatValue(actual)), - (nameof(delta), FormatValue(delta))); + new StringPair("not expected", FormatValue(notExpected)), + new StringPair(nameof(actual), FormatValue(actual)), + new StringPair(nameof(delta), FormatValue(delta))); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -1392,11 +1392,11 @@ private static bool AreNotEqualFailing(T? notExpected, T? actual, IEqualityCo [DoesNotReturn] private static void ThrowAssertAreNotEqualFailed(object? notExpected, object? actual, string? userMessage, string notExpectedExpression, string actualExpression) { - string callSite = FormatCallSite("Assert.AreNotEqual", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression)); + string callSite = FormatCallSite("Assert.AreNotEqual", new StringPair(nameof(notExpected), notExpectedExpression), new StringPair(nameof(actual), actualExpression)); string message = FrameworkMessages.AreNotEqualFailNew; message += FormatAlignedParameters( - ("not expected", FormatValue(notExpected)), - (nameof(actual), FormatValue(actual))); + new StringPair("not expected", FormatValue(notExpected)), + new StringPair(nameof(actual), FormatValue(actual))); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index a25ba3d650..c9266e7fe6 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -188,7 +188,7 @@ private static bool IsAreSameFailing(T? expected, T? actual) [DoesNotReturn] private static void ThrowAssertAreSameFailed(T? expected, T? actual, string? userMessage, string expectedExpression, string actualExpression) { - string callSite = FormatCallSite("Assert.AreSame", (nameof(expected), expectedExpression), (nameof(actual), actualExpression)); + string callSite = FormatCallSite("Assert.AreSame", new StringPair(nameof(expected), expectedExpression), new StringPair(nameof(actual), actualExpression)); // When both values have the same string representation, include hash codes // to help the user understand they are different object instances. @@ -231,8 +231,8 @@ private static void ThrowAssertAreSameFailed(T? expected, T? actual, string? } message += FormatAlignedParameters( - (nameof(expected), expectedValue), - (nameof(actual), actualValue)); + new StringPair(nameof(expected), expectedValue), + new StringPair(nameof(actual), actualValue)); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); @@ -289,7 +289,7 @@ private static bool IsAreNotSameFailing(T? notExpected, T? actual) [DoesNotReturn] private static void ThrowAssertAreNotSameFailed(T? notExpected, T? actual, string? userMessage, string notExpectedExpression, string actualExpression) { - string callSite = FormatCallSite("Assert.AreNotSame", (nameof(notExpected), notExpectedExpression), (nameof(actual), actualExpression)); + string callSite = FormatCallSite("Assert.AreNotSame", new StringPair(nameof(notExpected), notExpectedExpression), new StringPair(nameof(actual), actualExpression)); string message = FrameworkMessages.AreNotSameFailNew; string notExpectedFormatted = FormatValue(notExpected); @@ -304,8 +304,8 @@ private static void ThrowAssertAreNotSameFailed(T? notExpected, T? actual, st } message += FormatAlignedParameters( - ("not expected", notExpectedFormatted), - (nameof(actual), actualFormatted)); + new StringPair("not expected", notExpectedFormatted), + new StringPair(nameof(actual), actualFormatted)); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs index 9ab35793ed..2c92c6d798 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs @@ -270,7 +270,7 @@ public static void Contains(T expected, IEnumerable collection, string? me { // Materialize non-ICollection enumerables to prevent multiple enumeration // that could yield different results or fail on second pass. - ICollection snapshot = collection as ICollection ?? new List(collection); + ICollection snapshot = collection as ICollection ?? [.. collection]; if (!snapshot.Contains(expected)) { ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, snapshot); @@ -327,7 +327,7 @@ public static void Contains(object? expected, IEnumerable collection, string? me /// public static void Contains(T expected, IEnumerable collection, IEqualityComparer comparer, string? message = "", [CallerArgumentExpression(nameof(expected))] string expectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - ICollection snapshot = collection as ICollection ?? new List(collection); + ICollection snapshot = collection as ICollection ?? [.. collection]; if (!snapshot.Contains(expected, comparer)) { ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, snapshot); @@ -384,7 +384,7 @@ public static void Contains(object? expected, IEnumerable collection, IEqualityC /// public static void Contains(Func predicate, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(predicate))] string predicateExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - ICollection snapshot = collection as ICollection ?? new List(collection); + ICollection snapshot = collection as ICollection ?? [.. collection]; if (!snapshot.Any(predicate)) { ThrowAssertContainsPredicateFailed(message, predicateExpression, collectionExpression, snapshot); @@ -517,7 +517,7 @@ public static void Contains(string substring, string value, StringComparison com /// public static void DoesNotContain(T notExpected, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(notExpected))] string notExpectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - ICollection snapshot = collection as ICollection ?? new List(collection); + ICollection snapshot = collection as ICollection ?? [.. collection]; if (snapshot.Contains(notExpected)) { ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, snapshot); @@ -571,7 +571,7 @@ public static void DoesNotContain(object? notExpected, IEnumerable collection, s /// public static void DoesNotContain(T notExpected, IEnumerable collection, IEqualityComparer comparer, string? message = "", [CallerArgumentExpression(nameof(notExpected))] string notExpectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - ICollection snapshot = collection as ICollection ?? new List(collection); + ICollection snapshot = collection as ICollection ?? [.. collection]; if (snapshot.Contains(notExpected, comparer)) { ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, snapshot); @@ -626,7 +626,7 @@ public static void DoesNotContain(object? notExpected, IEnumerable collection, I /// public static void DoesNotContain(Func predicate, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(predicate))] string predicateExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - ICollection snapshot = collection as ICollection ?? new List(collection); + ICollection snapshot = collection as ICollection ?? [.. collection]; if (snapshot.Any(predicate)) { ThrowAssertDoesNotContainPredicateFailed(message, predicateExpression, collectionExpression, snapshot); @@ -780,7 +780,7 @@ public static void IsInRange(T minValue, T maxValue, T value, string? message [DoesNotReturn] private static void ThrowAssertSingleMatchFailed(int actualCount, string? userMessage, string predicateExpression, string collectionExpression, IEnumerable? collectionValue = null) { - string callSite = FormatCallSite("Assert.ContainsSingle", ("predicate", predicateExpression), ("collection", collectionExpression)); + string callSite = FormatCallSite("Assert.ContainsSingle", new StringPair("predicate", predicateExpression), new StringPair("collection", collectionExpression)); string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleMatchFailNew, actualCount); if (collectionValue is not null) { @@ -794,7 +794,7 @@ private static void ThrowAssertSingleMatchFailed(int actualCount, string? userMe [DoesNotReturn] private static void ThrowAssertContainsSingleFailed(int actualCount, string? userMessage, string collectionExpression, IEnumerable? collectionValue = null) { - string callSite = FormatCallSite("Assert.ContainsSingle", ("collection", collectionExpression)); + string callSite = FormatCallSite("Assert.ContainsSingle", new StringPair("collection", collectionExpression)); string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsSingleFailNew, actualCount); if (collectionValue is not null) { @@ -808,7 +808,7 @@ private static void ThrowAssertContainsSingleFailed(int actualCount, string? use [DoesNotReturn] private static void ThrowAssertContainsItemFailed(string? userMessage, string expectedExpression, string collectionExpression, IEnumerable? collectionValue = null) { - string callSite = FormatCallSite("Assert.Contains", ("expected", expectedExpression), ("collection", collectionExpression)); + string callSite = FormatCallSite("Assert.Contains", new StringPair("expected", expectedExpression), new StringPair("collection", collectionExpression)); string message = FrameworkMessages.ContainsItemFailNew; if (collectionValue is not null) { @@ -822,7 +822,7 @@ private static void ThrowAssertContainsItemFailed(string? userMessage, string ex [DoesNotReturn] private static void ThrowAssertContainsPredicateFailed(string? userMessage, string predicateExpression, string collectionExpression, IEnumerable? collectionValue = null) { - string callSite = FormatCallSite("Assert.Contains", ("predicate", predicateExpression), ("collection", collectionExpression)); + string callSite = FormatCallSite("Assert.Contains", new StringPair("predicate", predicateExpression), new StringPair("collection", collectionExpression)); string message = FrameworkMessages.ContainsPredicateFailNew; if (collectionValue is not null) { @@ -836,7 +836,7 @@ private static void ThrowAssertContainsPredicateFailed(string? userMessage, stri [DoesNotReturn] private static void ThrowAssertDoesNotContainItemFailed(string? userMessage, string notExpectedExpression, string collectionExpression, IEnumerable? collectionValue = null) { - string callSite = FormatCallSite("Assert.DoesNotContain", ("notExpected", notExpectedExpression), ("collection", collectionExpression)); + string callSite = FormatCallSite("Assert.DoesNotContain", new StringPair("notExpected", notExpectedExpression), new StringPair("collection", collectionExpression)); string message = FrameworkMessages.DoesNotContainItemFailNew; if (collectionValue is not null) { @@ -850,7 +850,7 @@ private static void ThrowAssertDoesNotContainItemFailed(string? userMessage, str [DoesNotReturn] private static void ThrowAssertDoesNotContainPredicateFailed(string? userMessage, string predicateExpression, string collectionExpression, IEnumerable? collectionValue = null) { - string callSite = FormatCallSite("Assert.DoesNotContain", ("predicate", predicateExpression), ("collection", collectionExpression)); + string callSite = FormatCallSite("Assert.DoesNotContain", new StringPair("predicate", predicateExpression), new StringPair("collection", collectionExpression)); string message = FrameworkMessages.DoesNotContainPredicateFailNew; if (collectionValue is not null) { @@ -864,11 +864,11 @@ private static void ThrowAssertDoesNotContainPredicateFailed(string? userMessage [DoesNotReturn] private static void ThrowAssertStringContainsFailed(string value, string substring, string? userMessage, string substringExpression, string valueExpression) { - string callSite = FormatCallSite("Assert.Contains", (nameof(substring), substringExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.Contains", new StringPair(nameof(substring), substringExpression), new StringPair(nameof(value), valueExpression)); string message = FrameworkMessages.ContainsStringFailNew; message += FormatAlignedParameters( - (nameof(substring), FormatValue(substring)), - (nameof(value), FormatValue(value))); + new StringPair(nameof(substring), FormatValue(substring)), + new StringPair(nameof(value), FormatValue(value))); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -876,11 +876,11 @@ private static void ThrowAssertStringContainsFailed(string value, string substri [DoesNotReturn] private static void ThrowAssertStringDoesNotContainFailed(string value, string substring, string? userMessage, string substringExpression, string valueExpression) { - string callSite = FormatCallSite("Assert.DoesNotContain", (nameof(substring), substringExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.DoesNotContain", new StringPair(nameof(substring), substringExpression), new StringPair(nameof(value), valueExpression)); string message = FrameworkMessages.DoesNotContainStringFailNew; message += FormatAlignedParameters( - (nameof(substring), FormatValue(substring)), - (nameof(value), FormatValue(value))); + new StringPair(nameof(substring), FormatValue(substring)), + new StringPair(nameof(value), FormatValue(value))); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } @@ -888,11 +888,11 @@ private static void ThrowAssertStringDoesNotContainFailed(string value, string s [DoesNotReturn] private static void ThrowAssertIsInRangeFailed(T value, T minValue, T maxValue, string? userMessage, string minValueExpression, string maxValueExpression, string valueExpression) { - string callSite = FormatCallSite("Assert.IsInRange", (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsInRange", new StringPair(nameof(value), valueExpression)); string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsInRangeFailNew, FormatValue(value), FormatValue(minValue), FormatValue(maxValue)); message += FormatAlignedParameters( - ("range", $"[{FormatValue(minValue)}, {FormatValue(maxValue)}]"), - (nameof(value), FormatValue(value))); + new StringPair("range", $"[{FormatValue(minValue)}, {FormatValue(maxValue)}]"), + new StringPair(nameof(value), FormatValue(value))); message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs index 47cf7483ea..f08734d322 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs @@ -321,7 +321,7 @@ private static void HasCount(string assertionName, int expected, IEnumerable< { // Materialize non-ICollection enumerables to prevent multiple enumeration // that could yield different results or fail on second pass. - ICollection snapshot = collection as ICollection ?? new List(collection); + ICollection snapshot = collection as ICollection ?? [.. collection]; if (snapshot.Count == expected) { return; @@ -336,12 +336,12 @@ private static void HasCount(string assertionName, int expected, IEnumerable col [DoesNotReturn] private static void ThrowAssertCountFailed(string assertionName, int expectedCount, int actualCount, IEnumerable collection, string? userMessage, string collectionExpression) { - string callSite = FormatCallSite($"Assert.{assertionName}", ("collection", collectionExpression)); + string callSite = FormatCallSite($"Assert.{assertionName}", new StringPair("collection", collectionExpression)); string msg = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.HasCountFailNew, expectedCount, actualCount); msg += FormatCollectionParameter(collectionExpression, collection); msg += FormatAlignedParameters( - ("expected count", expectedCount.ToString(CultureInfo.InvariantCulture)), - ("actual count", actualCount.ToString(CultureInfo.InvariantCulture))); + new StringPair("expected count", expectedCount.ToString(CultureInfo.InvariantCulture)), + new StringPair("actual count", actualCount.ToString(CultureInfo.InvariantCulture))); msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -349,7 +349,7 @@ private static void ThrowAssertCountFailed(string assertionName, int expectedCou [DoesNotReturn] private static void ThrowAssertIsNotEmptyFailed(string? userMessage, string collectionExpression) { - string callSite = FormatCallSite("Assert.IsNotEmpty", ("collection", collectionExpression)); + string callSite = FormatCallSite("Assert.IsNotEmpty", new StringPair("collection", collectionExpression)); string msg = FrameworkMessages.IsNotEmptyFailNew; msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs b/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs index 5aec763303..08e8e7d46f 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs @@ -76,11 +76,11 @@ public static void EndsWith([NotNull] string? expectedSuffix, [NotNull] string? CheckParameterNotNull(expectedSuffix, "Assert.EndsWith", "expectedSuffix"); if (!value.EndsWith(expectedSuffix, comparisonType)) { - string callSite = FormatCallSite("Assert.EndsWith", (nameof(expectedSuffix), expectedSuffixExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.EndsWith", new StringPair(nameof(expectedSuffix), expectedSuffixExpression), new StringPair(nameof(value), valueExpression)); string msg = FrameworkMessages.EndsWithFailNew; msg += FormatAlignedParameters( - ("expected suffix", FormatValue(expectedSuffix)), - (nameof(value), FormatValue(value))); + new StringPair("expected suffix", FormatValue(expectedSuffix)), + new StringPair(nameof(value), FormatValue(value))); msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } @@ -154,11 +154,11 @@ public static void DoesNotEndWith([NotNull] string? notExpectedSuffix, [NotNull] CheckParameterNotNull(notExpectedSuffix, "Assert.DoesNotEndWith", "notExpectedSuffix"); if (value.EndsWith(notExpectedSuffix, comparisonType)) { - string callSite = FormatCallSite("Assert.DoesNotEndWith", (nameof(notExpectedSuffix), notExpectedSuffixExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.DoesNotEndWith", new StringPair(nameof(notExpectedSuffix), notExpectedSuffixExpression), new StringPair(nameof(value), valueExpression)); string msg = FrameworkMessages.DoesNotEndWithFailNew; msg += FormatAlignedParameters( - ("unwanted suffix", FormatValue(notExpectedSuffix)), - (nameof(value), FormatValue(value))); + new StringPair("unwanted suffix", FormatValue(notExpectedSuffix)), + new StringPair(nameof(value), FormatValue(value))); msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs b/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs index 8154f57ace..4f107e7cc6 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IComparable.cs @@ -291,11 +291,11 @@ public static void IsNegative(T value, string? message = "", [CallerArgumentE [DoesNotReturn] private static void ThrowAssertIsGreaterThanFailed(T lowerBound, T value, string? userMessage, string lowerBoundExpression, string valueExpression) { - string callSite = FormatCallSite("Assert.IsGreaterThan", (nameof(lowerBound), lowerBoundExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsGreaterThan", new StringPair(nameof(lowerBound), lowerBoundExpression), new StringPair(nameof(value), valueExpression)); string msg = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsGreaterThanFailNew, FormatValue(value), FormatValue(lowerBound)); msg += FormatAlignedParameters( - ("lower bound", FormatValue(lowerBound)), - (nameof(value), FormatValue(value))); + new StringPair("lower bound", FormatValue(lowerBound)), + new StringPair(nameof(value), FormatValue(value))); msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -303,11 +303,11 @@ private static void ThrowAssertIsGreaterThanFailed(T lowerBound, T value, str [DoesNotReturn] private static void ThrowAssertIsGreaterThanOrEqualToFailed(T lowerBound, T value, string? userMessage, string lowerBoundExpression, string valueExpression) { - string callSite = FormatCallSite("Assert.IsGreaterThanOrEqualTo", (nameof(lowerBound), lowerBoundExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsGreaterThanOrEqualTo", new StringPair(nameof(lowerBound), lowerBoundExpression), new StringPair(nameof(value), valueExpression)); string msg = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsGreaterThanOrEqualToFailNew, FormatValue(value), FormatValue(lowerBound)); msg += FormatAlignedParameters( - ("lower bound", FormatValue(lowerBound)), - (nameof(value), FormatValue(value))); + new StringPair("lower bound", FormatValue(lowerBound)), + new StringPair(nameof(value), FormatValue(value))); msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -315,11 +315,11 @@ private static void ThrowAssertIsGreaterThanOrEqualToFailed(T lowerBound, T v [DoesNotReturn] private static void ThrowAssertIsLessThanFailed(T upperBound, T value, string? userMessage, string upperBoundExpression, string valueExpression) { - string callSite = FormatCallSite("Assert.IsLessThan", (nameof(upperBound), upperBoundExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsLessThan", new StringPair(nameof(upperBound), upperBoundExpression), new StringPair(nameof(value), valueExpression)); string msg = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsLessThanFailNew, FormatValue(value), FormatValue(upperBound)); msg += FormatAlignedParameters( - ("upper bound", FormatValue(upperBound)), - (nameof(value), FormatValue(value))); + new StringPair("upper bound", FormatValue(upperBound)), + new StringPair(nameof(value), FormatValue(value))); msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -327,11 +327,11 @@ private static void ThrowAssertIsLessThanFailed(T upperBound, T value, string [DoesNotReturn] private static void ThrowAssertIsLessThanOrEqualToFailed(T upperBound, T value, string? userMessage, string upperBoundExpression, string valueExpression) { - string callSite = FormatCallSite("Assert.IsLessThanOrEqualTo", (nameof(upperBound), upperBoundExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsLessThanOrEqualTo", new StringPair(nameof(upperBound), upperBoundExpression), new StringPair(nameof(value), valueExpression)); string msg = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsLessThanOrEqualToFailNew, FormatValue(value), FormatValue(upperBound)); msg += FormatAlignedParameters( - ("upper bound", FormatValue(upperBound)), - (nameof(value), FormatValue(value))); + new StringPair("upper bound", FormatValue(upperBound)), + new StringPair(nameof(value), FormatValue(value))); msg = AppendUserMessage(msg, userMessage); ThrowAssertFailed(callSite, msg); } @@ -339,7 +339,7 @@ private static void ThrowAssertIsLessThanOrEqualToFailed(T upperBound, T valu [DoesNotReturn] private static void ThrowAssertIsPositiveFailed(T value, string? userMessage, string valueExpression) { - string callSite = FormatCallSite("Assert.IsPositive", (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsPositive", new StringPair(nameof(value), valueExpression)); string msg = FrameworkMessages.IsPositiveFailNew; msg += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); msg = AppendUserMessage(msg, userMessage); @@ -349,7 +349,7 @@ private static void ThrowAssertIsPositiveFailed(T value, string? userMessage, [DoesNotReturn] private static void ThrowAssertIsNegativeFailed(T value, string? userMessage, string valueExpression) { - string callSite = FormatCallSite("Assert.IsNegative", (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsNegative", new StringPair(nameof(value), valueExpression)); string msg = FrameworkMessages.IsNegativeFailNew; msg += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); msg = AppendUserMessage(msg, userMessage); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs index 3b6f56aaaf..9f5344e4bd 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsExactInstanceOfType.cs @@ -322,7 +322,7 @@ private static bool IsExactInstanceOfTypeFailing([NotNullWhen(false)] object? va [DoesNotReturn] private static void ThrowAssertIsExactInstanceOfTypeFailed(object? value, Type? expectedType, string? userMessage, string valueExpression) { - string callSite = FormatCallSite("Assert.IsExactInstanceOfType", (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsExactInstanceOfType", new StringPair(nameof(value), valueExpression)); string message; if (expectedType is null) @@ -403,7 +403,7 @@ private static bool IsNotExactInstanceOfTypeFailing(object? value, [NotNullWhen( [DoesNotReturn] private static void ThrowAssertIsNotExactInstanceOfTypeFailed(object? value, Type? wrongType, string? userMessage, string valueExpression) { - string callSite = FormatCallSite("Assert.IsNotExactInstanceOfType", (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsNotExactInstanceOfType", new StringPair(nameof(value), valueExpression)); string message; if (wrongType is null) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs index 220ed86a54..dd2e821c37 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsInstanceOfType.cs @@ -329,7 +329,7 @@ private static bool IsInstanceOfTypeFailing([NotNullWhen(false)] object? value, [DoesNotReturn] private static void ThrowAssertIsInstanceOfTypeFailed(object? value, Type? expectedType, string? userMessage, string valueExpression) { - string callSite = FormatCallSite("Assert.IsInstanceOfType", (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsInstanceOfType", new StringPair(nameof(value), valueExpression)); string message; if (expectedType is null) @@ -412,7 +412,7 @@ private static bool IsNotInstanceOfTypeFailing(object? value, [NotNullWhen(false [DoesNotReturn] private static void ThrowAssertIsNotInstanceOfTypeFailed(object? value, Type? wrongType, string? userMessage, string valueExpression) { - string callSite = FormatCallSite("Assert.IsNotInstanceOfType", (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsNotInstanceOfType", new StringPair(nameof(value), valueExpression)); string message; if (wrongType is null) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs index 3a8f0cbe7a..3c67c71260 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsNull.cs @@ -161,7 +161,7 @@ public static void IsNull(object? value, string? message = "", [CallerArgumentEx [DoesNotReturn] private static void ThrowAssertIsNullFailed(object? value, string? userMessage, string valueExpression) { - string callSite = FormatCallSite("Assert.IsNull", (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.IsNull", new StringPair(nameof(value), valueExpression)); string message = FrameworkMessages.IsNullFailNew; message += Environment.NewLine + FormatParameter(nameof(value), valueExpression, value); message = AppendUserMessage(message, userMessage); @@ -207,7 +207,7 @@ public static void IsNotNull([NotNull] object? value, string? message = "", [Cal [DoesNotReturn] private static void ThrowAssertIsNotNullFailed(string? userMessage, string valueExpression) { - string callSite = FormatCallSite("Assert.IsNotNull", ("value", valueExpression)); + string callSite = FormatCallSite("Assert.IsNotNull", new StringPair("value", valueExpression)); string message = FrameworkMessages.IsNotNullFailNew; message = AppendUserMessage(message, userMessage); ThrowAssertFailed(callSite, message); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs index 18ba993561..4e7e413651 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.IsTrue.cs @@ -162,7 +162,7 @@ private static bool IsTrueFailing(bool? condition) [DoesNotReturn] private static void ThrowAssertIsTrueFailed(bool? condition, string? userMessage, string conditionExpression) { - string callSite = FormatCallSite("Assert.IsTrue", (nameof(condition), conditionExpression)); + string callSite = FormatCallSite("Assert.IsTrue", new StringPair(nameof(condition), conditionExpression)); string message = FrameworkMessages.IsTrueFailNew; message += Environment.NewLine + FormatParameter(nameof(condition), conditionExpression, condition); message = AppendUserMessage(message, userMessage); @@ -207,7 +207,7 @@ private static bool IsFalseFailing(bool? condition) [DoesNotReturn] private static void ThrowAssertIsFalseFailed(bool? condition, string? userMessage, string conditionExpression) { - string callSite = FormatCallSite("Assert.IsFalse", (nameof(condition), conditionExpression)); + string callSite = FormatCallSite("Assert.IsFalse", new StringPair(nameof(condition), conditionExpression)); string message = FrameworkMessages.IsFalseFailNew; message += Environment.NewLine + FormatParameter(nameof(condition), conditionExpression, condition); message = AppendUserMessage(message, userMessage); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs b/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs index f2eff640ef..5bc144e817 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Matches.cs @@ -44,11 +44,11 @@ public static void MatchesRegex([NotNull] Regex? pattern, [NotNull] string? valu if (!pattern.IsMatch(value)) { - string callSite = FormatCallSite("Assert.MatchesRegex", (nameof(pattern), patternExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.MatchesRegex", new StringPair(nameof(pattern), patternExpression), new StringPair(nameof(value), valueExpression)); string msg = FrameworkMessages.MatchesRegexFailNew; msg += FormatAlignedParameters( - (nameof(pattern), FormatValue(pattern)), - (nameof(value), FormatValue(value))); + new StringPair(nameof(pattern), FormatValue(pattern)), + new StringPair(nameof(value), FormatValue(value))); msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } @@ -124,11 +124,11 @@ public static void DoesNotMatchRegex([NotNull] Regex? pattern, [NotNull] string? if (pattern.IsMatch(value)) { - string callSite = FormatCallSite("Assert.DoesNotMatchRegex", (nameof(pattern), patternExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.DoesNotMatchRegex", new StringPair(nameof(pattern), patternExpression), new StringPair(nameof(value), valueExpression)); string msg = FrameworkMessages.DoesNotMatchRegexFailNew; msg += FormatAlignedParameters( - (nameof(pattern), FormatValue(pattern)), - (nameof(value), FormatValue(value))); + new StringPair(nameof(pattern), FormatValue(pattern)), + new StringPair(nameof(value), FormatValue(value))); msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs b/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs index 2695d15ae1..0383011efb 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs @@ -76,11 +76,11 @@ public static void StartsWith([NotNull] string? expectedPrefix, [NotNull] string CheckParameterNotNull(expectedPrefix, "Assert.StartsWith", "expectedPrefix"); if (!value.StartsWith(expectedPrefix, comparisonType)) { - string callSite = FormatCallSite("Assert.StartsWith", (nameof(expectedPrefix), expectedPrefixExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.StartsWith", new StringPair(nameof(expectedPrefix), expectedPrefixExpression), new StringPair(nameof(value), valueExpression)); string msg = FrameworkMessages.StartsWithFailNew; msg += FormatAlignedParameters( - ("expected prefix", FormatValue(expectedPrefix)), - (nameof(value), FormatValue(value))); + new StringPair("expected prefix", FormatValue(expectedPrefix)), + new StringPair(nameof(value), FormatValue(value))); msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } @@ -152,11 +152,11 @@ public static void DoesNotStartWith([NotNull] string? notExpectedPrefix, [NotNul CheckParameterNotNull(notExpectedPrefix, "Assert.DoesNotStartWith", "notExpectedPrefix"); if (value.StartsWith(notExpectedPrefix, comparisonType)) { - string callSite = FormatCallSite("Assert.DoesNotStartWith", (nameof(notExpectedPrefix), notExpectedPrefixExpression), (nameof(value), valueExpression)); + string callSite = FormatCallSite("Assert.DoesNotStartWith", new StringPair(nameof(notExpectedPrefix), notExpectedPrefixExpression), new StringPair(nameof(value), valueExpression)); string msg = FrameworkMessages.DoesNotStartWithFailNew; msg += FormatAlignedParameters( - ("unwanted prefix", FormatValue(notExpectedPrefix)), - (nameof(value), FormatValue(value))); + new StringPair("unwanted prefix", FormatValue(notExpectedPrefix)), + new StringPair(nameof(value), FormatValue(value))); msg = AppendUserMessage(msg, message); ThrowAssertFailed(callSite, msg); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.That.cs b/src/TestFramework/TestFramework/Assertions/Assert.That.cs index a7b8a072e7..399d10db39 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.That.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.That.cs @@ -116,24 +116,21 @@ private static string BuildMethodCallMessage(MethodCallExpression methodCall) string methodName = methodCall.Method.Name; // String-specific methods - if (methodCall.Object is not null && methodCall.Object.Type == typeof(string)) - { - return methodName switch + return methodCall.Object is not null && methodCall.Object.Type == typeof(string) + ? methodName switch { "StartsWith" => FrameworkMessages.StartsWithFailNew, "EndsWith" => FrameworkMessages.EndsWithFailNew, nameof(string.Contains) => FrameworkMessages.ContainsStringFailNew, _ => FrameworkMessages.IsTrueFailNew, + } + : methodName switch + { + nameof(string.Contains) => FrameworkMessages.ContainsItemFailNew, + "All" => FrameworkMessages.AllMatchPredicateFailNew, + "Any" => FrameworkMessages.ContainsPredicateFailNew, + _ => FrameworkMessages.IsTrueFailNew, }; - } - - return methodName switch - { - nameof(string.Contains) => FrameworkMessages.ContainsItemFailNew, - "All" => FrameworkMessages.AllMatchPredicateFailNew, - "Any" => FrameworkMessages.ContainsPredicateFailNew, - _ => FrameworkMessages.IsTrueFailNew, - }; } private static string TryEvaluateFormatted(Expression expr) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 6b2f8c42d3..000f7bea5b 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -207,109 +207,6 @@ private static string EscapeNewlines(string value) ? value.Replace("\r\n", "\\r\\n").Replace("\n", "\\n").Replace("\r", "\\r") : value; - private static bool IsExpressionRedundant(string expression, string formattedValue) - { - if (string.IsNullOrEmpty(expression)) - { - return true; - } - - // Exact match: expression "5" == formattedValue "5" - if (expression == formattedValue) - { - return true; - } - - // Null literal: expression "null" vs formattedValue "null" - if (expression is "null" && formattedValue is "null") - { - return true; - } - - // Boolean/true/false: expression "true" vs formattedValue "True" - if (string.Equals(expression, formattedValue, StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - // Numeric literal in different notation (e.g., "100E-2" vs "1") - if (double.TryParse(expression, NumberStyles.Any, CultureInfo.InvariantCulture, out double exprNum) - && double.TryParse(formattedValue, NumberStyles.Any, CultureInfo.InvariantCulture, out double fmtNum) - && exprNum == fmtNum) - { - return true; - } - - // C# string literal expression: @"\d+" or "\d+" vs formattedValue \d+ - // Strip the string literal syntax and compare the inner content - string? innerContent = TryExtractStringLiteralContent(expression); - return innerContent is not null && innerContent == formattedValue; - } - - /// - /// Tries to extract the string content from a C# string literal expression. - /// Returns the inner string value for @"..." and "..." literals, or null if not a string literal. - /// - private static string? TryExtractStringLiteralContent(string expression) - { - // Verbatim string: @"content" - if (expression.Length >= 3 && expression[0] == '@' && expression[1] == '"' && expression[expression.Length - 1] == '"') - { - return expression.Substring(2, expression.Length - 3).Replace("\"\"", "\""); - } - - // Regular string: "content" - if (expression.Length >= 2 && expression[0] == '"' && expression[expression.Length - 1] == '"') - { - return expression.Substring(1, expression.Length - 2); - } - - // Not a string literal - return null; - } - - /// - /// Checks if the expression is a typed numeric literal (e.g., 1.0f, 1.1d, 0.001m, 2L) - /// or a well-known numeric constant (float.NaN, double.NaN) that is a more informative - /// representation than the plain ToString() value. - /// - private static bool IsExpressionMoreSpecificNumericLiteral(string expression, string formattedValue) - { - if (string.IsNullOrEmpty(expression) || expression.Length < 2) - { - return false; - } - - // Well-known numeric constants: float.NaN, double.NaN, float.PositiveInfinity, etc. - if (expression.StartsWith("float.", StringComparison.Ordinal) || expression.StartsWith("double.", StringComparison.Ordinal)) - { - return true; - } - - // Check if expression ends with a numeric type suffix - char lastChar = expression[expression.Length - 1]; - if (lastChar is not ('f' or 'F' or 'd' or 'D' or 'm' or 'M' or 'L' or 'l' or 'u' or 'U')) - { - return false; - } - - // The formatted value should be the numeric part without the suffix - // e.g., expression "1.0d" -> formattedValue "1" or "1.0" - string numericPart = expression.Substring(0, expression.Length - 1); - - // Handle UL/ul suffix (two chars) - if (numericPart.Length > 0 && numericPart[numericPart.Length - 1] is 'u' or 'U' or 'l' or 'L') - { - numericPart = numericPart.Substring(0, numericPart.Length - 1); - } - - // Check if removing the suffix gives the formatted value, or if they represent the same number - return numericPart == formattedValue - || (double.TryParse(numericPart, NumberStyles.Any, CultureInfo.InvariantCulture, out double exprNum) - && double.TryParse(formattedValue, NumberStyles.Any, CultureInfo.InvariantCulture, out double valNum) - && exprNum == valNum); - } - internal static string FormatParameter(string paramName, string expression, T? value) { string formattedValue = FormatValue(value); @@ -432,29 +329,36 @@ private static string FormatCollectionPreview(IEnumerable collection, int maxLen return $"[{elementList}]"; } - internal static string FormatParameterWithValue(string paramName, string expression, string formattedValue) - => $" {paramName}: {formattedValue}"; - /// - /// Formats a parameter line, checking expression redundancy against a base value - /// while displaying a different (enriched) display value. + /// A simple name-value pair used by and + /// to avoid relying on System.ValueTuple which is not available on net462. /// - internal static string FormatParameterWithExpressionCheck(string paramName, string expression, string baseValue, string displayValue) - => $" {paramName}: {displayValue}"; + internal readonly struct StringPair + { + public StringPair(string name, string value) + { + Name = name; + Value = value; + } + + public string Name { get; } + + public string Value { get; } + } /// /// Builds the "Assert.Method(expr1, expr2)" call site string for the first line. /// Only the primary/semantic parameters are included (not message, culture, delta, etc.). /// - internal static string FormatCallSite(string methodName, params (string ParamName, string Expression)[] args) + internal static string FormatCallSite(string methodName, params StringPair[] args) { var sb = new StringBuilder(methodName); sb.Append('('); bool hasVisibleArgs = false; for (int i = 0; i < args.Length; i++) { - string expression = args[i].Expression; - string paramName = args[i].ParamName; + string expression = args[i].Value; + string paramName = args[i].Name; // Sentinel "..." indicates additional parameters were omitted. if (paramName == "...") @@ -488,26 +392,26 @@ internal static string FormatCallSite(string methodName, params (string ParamNam /// Formats multiple parameter lines with aligned values. /// All labels are padded so that values start at the same column. /// - internal static string FormatAlignedParameters(params (string Label, string Value)[] parameters) + internal static string FormatAlignedParameters(params StringPair[] parameters) { int maxLabelLength = 0; - foreach ((string label, string _) in parameters) + for (int i = 0; i < parameters.Length; i++) { - if (label.Length > maxLabelLength) + if (parameters[i].Name.Length > maxLabelLength) { - maxLabelLength = label.Length; + maxLabelLength = parameters[i].Name.Length; } } var sb = new StringBuilder(); - foreach ((string label, string value) in parameters) + for (int i = 0; i < parameters.Length; i++) { sb.Append(Environment.NewLine); sb.Append(" "); - sb.Append(label); + sb.Append(parameters[i].Name); sb.Append(':'); - sb.Append(new string(' ', maxLabelLength - label.Length + 1)); - sb.Append(value); + sb.Append(new string(' ', maxLabelLength - parameters[i].Name.Length + 1)); + sb.Append(parameters[i].Value); } return sb.ToString(); diff --git a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs index c009cbc8ae..799cb27ec3 100644 --- a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs +++ b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs @@ -225,7 +225,7 @@ public static void AllItemsAreUnique([NotNull] ICollection? collection, string? // Found a second occurrence of null. string msg = FrameworkMessages.AllItemsAreUniqueFailMsg; msg += Assert.FormatAlignedParameters( - ("duplicate", FrameworkMessages.Common_NullInMessages)); + new Assert.StringPair("duplicate", FrameworkMessages.Common_NullInMessages)); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreUnique", msg); } @@ -236,7 +236,7 @@ public static void AllItemsAreUnique([NotNull] ICollection? collection, string? { string msg = FrameworkMessages.AllItemsAreUniqueFailMsg; msg += Assert.FormatAlignedParameters( - ("duplicate", Assert.ReplaceNulls(current))); + new Assert.StringPair("duplicate", Assert.ReplaceNulls(current))); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreUnique", msg); } @@ -489,8 +489,8 @@ public static void AreEquivalent( { string msg = FrameworkMessages.ElementNumbersDontMatch; msg += Assert.FormatAlignedParameters( - ("expected count", expectedCollectionCount.ToString(CultureInfo.CurrentCulture)), - ("actual count", actualCollectionCount.ToString(CultureInfo.CurrentCulture))); + new Assert.StringPair("expected count", expectedCollectionCount.ToString(CultureInfo.CurrentCulture)), + new Assert.StringPair("actual count", actualCollectionCount.ToString(CultureInfo.CurrentCulture))); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("CollectionAssert.AreEquivalent", msg); } @@ -506,9 +506,9 @@ public static void AreEquivalent( { string msg = FrameworkMessages.ActualHasMismatchedElements; msg += Assert.FormatAlignedParameters( - ("element", Assert.ReplaceNulls(mismatchedElement)), - ("expected occurrences", expectedCount.ToString(CultureInfo.CurrentCulture)), - ("actual occurrences", actualCount.ToString(CultureInfo.CurrentCulture))); + new Assert.StringPair("element", Assert.ReplaceNulls(mismatchedElement)), + new Assert.StringPair("expected occurrences", expectedCount.ToString(CultureInfo.CurrentCulture)), + new Assert.StringPair("actual occurrences", actualCount.ToString(CultureInfo.CurrentCulture))); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("CollectionAssert.AreEquivalent", msg); } @@ -734,8 +734,8 @@ public static void AllItemsAreInstancesOfType( FrameworkMessages.ElementTypesAtIndexDontMatch, i); msg += Assert.FormatAlignedParameters( - ("expected type", Assert.FormatType(expectedType)), - ("actual type", Assert.FormatType(element.GetType()))); + new Assert.StringPair("expected type", Assert.FormatType(expectedType)), + new Assert.StringPair("actual type", Assert.FormatType(element.GetType()))); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreInstancesOfType", msg); } @@ -1212,8 +1212,8 @@ private static bool CompareIEnumerable(IEnumerable? expected, IEnumerable? actua FrameworkMessages.ElementsAtIndexDontMatch, position) + Assert.FormatAlignedParameters( - ("expected", Assert.ReplaceNulls(curExpected)), - ("actual", Assert.ReplaceNulls(curActual))); + new Assert.StringPair("expected", Assert.ReplaceNulls(curExpected)), + new Assert.StringPair("actual", Assert.ReplaceNulls(curActual))); return false; } } diff --git a/src/TestFramework/TestFramework/Assertions/StringAssert.cs b/src/TestFramework/TestFramework/Assertions/StringAssert.cs index 21401abd64..f7b94896fc 100644 --- a/src/TestFramework/TestFramework/Assertions/StringAssert.cs +++ b/src/TestFramework/TestFramework/Assertions/StringAssert.cs @@ -122,8 +122,8 @@ public static void Contains([NotNull] string? value, [NotNull] string? substring { string msg = FrameworkMessages.ContainsStringFailNew; msg += Assert.FormatAlignedParameters( - (nameof(substring), Assert.FormatValue(substring)), - (nameof(value), Assert.FormatValue(value))); + new Assert.StringPair(nameof(substring), Assert.FormatValue(substring)), + new Assert.StringPair(nameof(value), Assert.FormatValue(value))); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("StringAssert.Contains", msg); } @@ -222,8 +222,8 @@ public static void StartsWith([NotNull] string? value, [NotNull] string? substri { string msg = FrameworkMessages.StartsWithFailNew; msg += Assert.FormatAlignedParameters( - ("expected prefix", Assert.FormatValue(substring)), - (nameof(value), Assert.FormatValue(value))); + new Assert.StringPair("expected prefix", Assert.FormatValue(substring)), + new Assert.StringPair(nameof(value), Assert.FormatValue(value))); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("StringAssert.StartsWith", msg); } @@ -322,8 +322,8 @@ public static void EndsWith([NotNull] string? value, [NotNull] string? substring { string msg = FrameworkMessages.EndsWithFailNew; msg += Assert.FormatAlignedParameters( - ("expected suffix", Assert.FormatValue(substring)), - (nameof(value), Assert.FormatValue(value))); + new Assert.StringPair("expected suffix", Assert.FormatValue(substring)), + new Assert.StringPair(nameof(value), Assert.FormatValue(value))); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("StringAssert.EndsWith", msg); } @@ -380,8 +380,8 @@ public static void Matches([NotNull] string? value, [NotNull] Regex? pattern, st { string msg = FrameworkMessages.MatchesRegexFailNew; msg += Assert.FormatAlignedParameters( - (nameof(pattern), Assert.FormatValue(pattern)), - (nameof(value), Assert.FormatValue(value))); + new Assert.StringPair(nameof(pattern), Assert.FormatValue(pattern)), + new Assert.StringPair(nameof(value), Assert.FormatValue(value))); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("StringAssert.Matches", msg); } @@ -434,8 +434,8 @@ public static void DoesNotMatch([NotNull] string? value, [NotNull] Regex? patter { string msg = FrameworkMessages.DoesNotMatchRegexFailNew; msg += Assert.FormatAlignedParameters( - (nameof(pattern), Assert.FormatValue(pattern)), - (nameof(value), Assert.FormatValue(value))); + new Assert.StringPair(nameof(pattern), Assert.FormatValue(pattern)), + new Assert.StringPair(nameof(value), Assert.FormatValue(value))); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("StringAssert.DoesNotMatch", msg); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs index 7e1307bb15..94ee85127e 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInstanceOfTypeTests.cs @@ -207,13 +207,13 @@ public void IsInstanceOfTypeUsingGenericTypeWithOutParameter_OnHigherInstance_Do instance.Should().BeSameAs(testInstance); } - public void IsNotInstanceOfTypeUsingGenericType_WhenValueIsNull_DoesNotThrow() + public void IsNotInstanceOfTypeUsingGenericType_WhenValueIsNull_DoesNotThrow() => Assert.IsNotInstanceOfType(null); public void IsNotInstanceOfType_OnWrongInstanceUsingGenericType_DoesNotThrow() => Assert.IsNotInstanceOfType(5L); - public void IsNotInstanceOfTypeUsingGenericType_OnSubInstance_DoesNotThrow() + public void IsNotInstanceOfTypeUsingGenericType_OnSubInstance_DoesNotThrow() => Assert.IsNotInstanceOfType(new object()); public void IsInstanceOfType_WhenNonNullNullableValue_LearnNonNull() From 2034d491026d39e96d4f514ec035421a2733f593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 23 Mar 2026 16:25:42 +0100 Subject: [PATCH 47/58] Fix integration tests for new assertion message format - OutputTests: Update expected AreEqual message to new callsite format - TrxReportTests: Update expected AreEqual message with aligned spacing - RetryTests: Split Assert.Fail message check (no longer 'Assert.Fail failed.') - GenericTestMethodTests: Update regex to match new Assert.Fail format (callsite on separate line) --- .../GenericTestMethodTests.cs | 18 ++++++++++++------ .../OutputTests.cs | 4 ++-- .../RetryTests.cs | 3 ++- .../TrxReportTests.cs | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs index eee0e3471a..66bb442ed6 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/GenericTestMethodTests.cs @@ -27,13 +27,16 @@ public async Task TestDifferentGenericMethodTestCases() The generic test method 'NonParameterizedTestMethod' doesn't have arguments, so the generic parameter cannot be inferred\. .+? failed ParameterizedMethodSimple \(1\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodSimple' did run with parameter '1' and type 'System\.Byte'\. + Assert\.Fail + Test method 'ParameterizedMethodSimple' did run with parameter '1' and type 'System\.Byte'\. .+? failed ParameterizedMethodSimple \(2\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodSimple' did run with parameter '2' and type 'System\.Int32'\. + Assert\.Fail + Test method 'ParameterizedMethodSimple' did run with parameter '2' and type 'System\.Int32'\. .+? failed ParameterizedMethodSimple \("Hello world"\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodSimple' did run with parameter 'Hello world' and type 'System\.String'\. + Assert\.Fail + Test method 'ParameterizedMethodSimple' did run with parameter 'Hello world' and type 'System\.String'\. .+? failed ParameterizedMethodSimple \(null\) \((\d+s )?\d+ms\) Test method TestClass\.ParameterizedMethodSimple threw exception: @@ -44,7 +47,8 @@ public async Task TestDifferentGenericMethodTestCases() System\.InvalidOperationException: Found two conflicting types for generic parameter 'T2'\. The conflicting types are 'System\.Byte' and 'System\.Int32'\. .+? failed ParameterizedMethodTwoGenericParametersAndFourMethodParameters \(null,"Hello world","Hello again",3\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodTwoGenericParametersAndFourMethodParameters' did run with parameters '', 'Hello world', 'Hello again', '3' and generic types 'System\.Int32', 'System\.String'\. + Assert\.Fail + Test method 'ParameterizedMethodTwoGenericParametersAndFourMethodParameters' did run with parameters '', 'Hello world', 'Hello again', '3' and generic types 'System\.Int32', 'System\.String'\. .+? failed ParameterizedMethodTwoGenericParametersAndFourMethodParameters \("Hello hello","Hello world",null,null\) \((\d+s )?\d+ms\) Test method TestClass\.ParameterizedMethodTwoGenericParametersAndFourMethodParameters threw exception: @@ -70,10 +74,12 @@ Cannot create an instance of T\[] because Type\.ContainsGenericParameters is tru Cannot create an instance of T\[] because Type\.ContainsGenericParameters is true\. .+? failed ParameterizedMethodWithNestedGeneric \(System\.Collections\.Generic\.List`1\[System.String],System\.Collections\.Generic\.List`1\[System.String]\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodWithNestedGeneric' did run with first list \[Hello, World] and second list \[Unit, Testing] + Assert\.Fail + Test method 'ParameterizedMethodWithNestedGeneric' did run with first list \[Hello, World] and second list \[Unit, Testing] .+? failed ParameterizedMethodWithNestedGeneric \(System\.Collections\.Generic\.List`1\[System.Int32],System\.Collections\.Generic\.List`1\[System.Int32]\) \((\d+s )?\d+ms\) - Assert\.Fail failed\. Test method 'ParameterizedMethodWithNestedGeneric' did run with first list \[0, 1] and second list \[2, 3] + Assert\.Fail + Test method 'ParameterizedMethodWithNestedGeneric' did run with first list \[0, 1] and second list \[2, 3] .+? """, RegexOptions.Singleline); } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs index 4f260239db..7c684a742d 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs @@ -18,10 +18,10 @@ public async Task DetailedOutputIsAsExpected(string tfm) // Assert testHostResult.AssertOutputContains(""" - Assert.AreEqual failed. + Assert.AreEqual(1, 2) Expected values to be equal. expected: 1 - actual: 2 + actual: 2 """); testHostResult.AssertOutputContains(""" Standard output diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RetryTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RetryTests.cs index 54405e8e69..881842360b 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RetryTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/RetryTests.cs @@ -26,7 +26,8 @@ TestMethod5 executed 4 times. """); testHostResult.AssertOutputContains("failed TestMethod5"); - testHostResult.AssertOutputContains("Assert.Fail failed. Failing TestMethod4. Attempts: 4 (from TestContext: 4)"); + testHostResult.AssertOutputContains("Assert.Fail"); + testHostResult.AssertOutputContains("Failing TestMethod4. Attempts: 4 (from TestContext: 4)"); testHostResult.AssertOutputContainsSummary(failed: 1, passed: 4, skipped: 0); } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs index 87f16e337b..98fdd54ee0 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs @@ -35,10 +35,10 @@ public async Task TrxReport_WhenTestFails_ContainsExceptionInfoInOutput(string t Assert.Contains(@"", trxContent, trxContent); Assert.Contains( """ - Assert.AreEqual failed. + Assert.AreEqual(1, 2) Expected values to be equal. expected: 1 - actual: 2 + actual: 2 """, trxContent, trxContent); From 8da553481f3da58439331c9f5889235327dd0be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 23 Mar 2026 16:43:06 +0100 Subject: [PATCH 48/58] Address unresolved Copilot review comments - Fix FormatCollectionPreview: Use failedEnumeration flag instead of forcing truncated=true, avoiding misleading '... 0+ more' suffix on exception - Fix CollectionAssert.AreEquivalent null check: Use dedicated 'Expected collections to be equivalent.' message with expected/actual nullness instead of generic AreEqualFailNew - Fix FormatValue culture: Use Convert.ToString with InvariantCulture for primitive types to ensure consistent output across locales --- .../TestFramework/Assertions/Assert.cs | 27 +++++++++++++------ .../Assertions/CollectionAssert.cs | 5 +++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 000f7bea5b..11d9d2fe54 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -126,7 +126,8 @@ internal static string FormatValue(T? value, int maxLength = 256) if (type.IsPrimitive || value is decimal or DateTime or DateTimeOffset or TimeSpan or Guid or Enum) { - string formatted = EscapeNewlines(Truncate(value.ToString() ?? string.Empty, maxLength)); + string formatted = EscapeNewlines(Truncate( + Convert.ToString(value, CultureInfo.InvariantCulture) ?? string.Empty, maxLength)); string suffix = GetNumericTypeSuffix(value); return suffix.Length > 0 ? formatted + suffix : formatted; } @@ -275,6 +276,7 @@ private static string FormatCollectionPreview(IEnumerable collection, int maxLen int enumeratedCount = 0; int currentLength = 0; bool truncated = false; + bool failedEnumeration = false; // Perf: wrap in try-catch so that faulting enumerators (e.g. collection modified during // iteration, or user-defined iterators that throw) don't bubble up from assertion formatting. @@ -309,21 +311,30 @@ private static string FormatCollectionPreview(IEnumerable collection, int maxLen } catch (Exception) { - // If enumeration fails, report what we've collected so far - truncated = elements.Count > 0; + // If enumeration fails, report what we've collected so far. + // Only mark as truncated if we actually collected some elements, + // and rely on the failedEnumeration flag to handle the suffix. + failedEnumeration = true; } int totalCount = knownCount ?? enumeratedCount; int displayedCount = elements.Count; string elementList = string.Join(", ", elements); - if (truncated) + if (truncated || (failedEnumeration && displayedCount > 0)) { int remaining = totalCount - displayedCount; - string remainingText = knownCount is null - ? $"{remaining}+" - : $"{remaining}"; - elementList += $", ... {remainingText} more"; + if (failedEnumeration) + { + elementList += ", ..."; + } + else if (remaining > 0) + { + string remainingText = knownCount is null + ? $"{remaining}+" + : $"{remaining}"; + elementList += $", ... {remainingText} more"; + } } return $"[{elementList}]"; diff --git a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs index 799cb27ec3..a1f789601a 100644 --- a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs +++ b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs @@ -468,7 +468,10 @@ public static void AreEquivalent( // Check whether one is null while the other is not. if (expected == null != (actual == null)) { - string msg = FrameworkMessages.AreEqualFailNew; + string msg = "Expected collections to be equivalent."; + msg += Assert.FormatAlignedParameters( + new Assert.StringPair("expected", expected is null ? "null" : "not null"), + new Assert.StringPair("actual", actual is null ? "null" : "not null")); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("CollectionAssert.AreEquivalent", msg); } From ae8e6336963ebf2a0da98b56fddf7283a2429f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 23 Mar 2026 17:40:34 +0100 Subject: [PATCH 49/58] Address new Copilot review comments - Fix ReplaceNulls: Return 'null' instead of empty string for null input - Move AreSame equality hints to resx (AreSameObjectsAreEqualHint/AreSameObjectsAreNotEqualHint) - Move AreEquivalent null mismatch message to resx (AreEquivalentNullMismatchFailNew) - Move Assert.That comparison/bool messages to resx (AssertThatEqualFailNew, AssertThatNotEqualFailNew, AssertThatGreaterThanFailNew, etc.) - All user-facing strings now go through FrameworkMessages for localization --- .../Assertions/Assert.AreSame.cs | 4 +- .../TestFramework/Assertions/Assert.That.cs | 16 +++--- .../TestFramework/Assertions/Assert.cs | 2 +- .../Assertions/CollectionAssert.cs | 2 +- .../Resources/FrameworkMessages.resx | 33 +++++++++++ .../Resources/xlf/FrameworkMessages.cs.xlf | 55 +++++++++++++++++++ .../Resources/xlf/FrameworkMessages.de.xlf | 55 +++++++++++++++++++ .../Resources/xlf/FrameworkMessages.es.xlf | 55 +++++++++++++++++++ .../Resources/xlf/FrameworkMessages.fr.xlf | 55 +++++++++++++++++++ .../Resources/xlf/FrameworkMessages.it.xlf | 55 +++++++++++++++++++ .../Resources/xlf/FrameworkMessages.ja.xlf | 55 +++++++++++++++++++ .../Resources/xlf/FrameworkMessages.ko.xlf | 55 +++++++++++++++++++ .../Resources/xlf/FrameworkMessages.pl.xlf | 55 +++++++++++++++++++ .../Resources/xlf/FrameworkMessages.pt-BR.xlf | 55 +++++++++++++++++++ .../Resources/xlf/FrameworkMessages.ru.xlf | 55 +++++++++++++++++++ .../Resources/xlf/FrameworkMessages.tr.xlf | 55 +++++++++++++++++++ .../xlf/FrameworkMessages.zh-Hans.xlf | 55 +++++++++++++++++++ .../xlf/FrameworkMessages.zh-Hant.xlf | 55 +++++++++++++++++++ 18 files changed, 760 insertions(+), 12 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs index c9266e7fe6..452e1c910b 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.AreSame.cs @@ -218,8 +218,8 @@ private static void ThrowAssertAreSameFailed(T? expected, T? actual, string? try { equalityHint = expected.Equals(actual) - ? " Objects are equal." - : " Objects are not equal."; + ? FrameworkMessages.AreSameObjectsAreEqualHint + : FrameworkMessages.AreSameObjectsAreNotEqualHint; } catch (Exception) { diff --git a/src/TestFramework/TestFramework/Assertions/Assert.That.cs b/src/TestFramework/TestFramework/Assertions/Assert.That.cs index 399d10db39..4cd75652be 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.That.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.That.cs @@ -78,7 +78,7 @@ or ExpressionType.LessThan case UnaryExpression unary when body.NodeType == ExpressionType.Not && unary.Operand is not MethodCallExpression: string innerName = GetCleanMemberName(unary.Operand); - return $"Expected {innerName} to be false."; + return string.Format(CultureInfo.InvariantCulture, FrameworkMessages.AssertThatExpectedFalseFailNew, innerName); // Method calls: text.StartsWith("x"), list.Contains(item), etc. case MethodCallExpression methodCall: @@ -87,7 +87,7 @@ or ExpressionType.LessThan // Bool member access: user.IsActive, flag case MemberExpression: string memberName = GetCleanMemberName(body); - return $"Expected {memberName} to be true."; + return string.Format(CultureInfo.InvariantCulture, FrameworkMessages.AssertThatExpectedTrueFailNew, memberName); default: return FrameworkMessages.IsTrueFailNew; @@ -101,12 +101,12 @@ private static string BuildComparisonMessage(BinaryExpression binary) return binary.NodeType switch { - ExpressionType.Equal => $"Expected {leftValue} to equal {rightValue}.", - ExpressionType.NotEqual => $"Expected {leftValue} to not equal {rightValue}.", - ExpressionType.GreaterThan => $"Expected {leftValue} to be greater than {rightValue}.", - ExpressionType.GreaterThanOrEqual => $"Expected {leftValue} to be greater than or equal to {rightValue}.", - ExpressionType.LessThan => $"Expected {leftValue} to be less than {rightValue}.", - ExpressionType.LessThanOrEqual => $"Expected {leftValue} to be less than or equal to {rightValue}.", + ExpressionType.Equal => string.Format(CultureInfo.InvariantCulture, FrameworkMessages.AssertThatEqualFailNew, leftValue, rightValue), + ExpressionType.NotEqual => string.Format(CultureInfo.InvariantCulture, FrameworkMessages.AssertThatNotEqualFailNew, leftValue, rightValue), + ExpressionType.GreaterThan => string.Format(CultureInfo.InvariantCulture, FrameworkMessages.AssertThatGreaterThanFailNew, leftValue, rightValue), + ExpressionType.GreaterThanOrEqual => string.Format(CultureInfo.InvariantCulture, FrameworkMessages.AssertThatGreaterThanOrEqualFailNew, leftValue, rightValue), + ExpressionType.LessThan => string.Format(CultureInfo.InvariantCulture, FrameworkMessages.AssertThatLessThanFailNew, leftValue, rightValue), + ExpressionType.LessThanOrEqual => string.Format(CultureInfo.InvariantCulture, FrameworkMessages.AssertThatLessThanOrEqualFailNew, leftValue, rightValue), _ => FrameworkMessages.IsTrueFailNew, }; } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 11d9d2fe54..0c8dc735fd 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -99,7 +99,7 @@ internal static void CheckParameterNotNull([NotNull] object? param, string asser } internal static string ReplaceNulls(object? input) - => input?.ToString() ?? string.Empty; + => input?.ToString() ?? "null"; internal static string FormatValue(T? value, int maxLength = 256) { diff --git a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs index a1f789601a..9989789b71 100644 --- a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs +++ b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs @@ -468,7 +468,7 @@ public static void AreEquivalent( // Check whether one is null while the other is not. if (expected == null != (actual == null)) { - string msg = "Expected collections to be equivalent."; + string msg = FrameworkMessages.AreEquivalentNullMismatchFailNew; msg += Assert.FormatAlignedParameters( new Assert.StringPair("expected", expected is null ? "null" : "not null"), new Assert.StringPair("actual", actual is null ? "null" : "not null")); diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index 965947311d..d202d868f4 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -371,4 +371,37 @@ Expected value to be negative. + + Objects are equal. + + + Objects are not equal. + + + Expected collections to be equivalent. + + + Expected {0} to equal {1}. + + + Expected {0} to not equal {1}. + + + Expected {0} to be greater than {1}. + + + Expected {0} to be greater than or equal to {1}. + + + Expected {0} to be less than {1}. + + + Expected {0} to be less than or equal to {1}. + + + Expected {0} to be true. + + + Expected {0} to be false. + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index 9592489ea7..7685e1f55d 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -47,6 +47,11 @@ Očekávaná délka řetězce je {0}, ale byla {1}. + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ Nevkládejte hodnotu typů do AreSame(). Hodnoty převedené do typu Object už nebudou nikdy stejné. Zvažte použití AreEqual(). {0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index 445f8b28ca..914162dcfe 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -47,6 +47,11 @@ Die erwartete Länge der Zeichenfolge ist {0}, war aber {1}. + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ Übergeben Sie keine Werttypen an AreSame(). In ein Objekt konvertierte Werte sind niemals identisch. Verwenden Sie stattdessen AreEqual(). {0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index 96b961aa92..fa1e6e9617 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -47,6 +47,11 @@ Se esperaba una longitud de cadena {0} pero fue {1}. + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ No pase tipos de valor a AreSame(). Los valores convertidos a Object no serán nunca iguales. Considere el uso de AreEqual(). {0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index 70d0d6d83a..8065668f84 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -47,6 +47,11 @@ La longueur de chaîne attendue {0} mais était {1}. + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ Ne passez pas de types valeur à AreSame(). Les valeurs converties en Object ne seront plus jamais les mêmes. Si possible, utilisez AreEqual(). {0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index 4d258a5234..72193b266d 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -47,6 +47,11 @@ La lunghezza della stringa prevista è {0} ma era {1}. + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ Non passare tipi valore a AreSame(). I valori convertiti in Object non saranno mai uguali. Usare AreEqual(). {0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index d858e8b746..22078097dc 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -47,6 +47,11 @@ 期待される文字列の長さは {0} ですが、実際は {1} でした。 + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ AreSame() には値型を渡すことはできません。オブジェクトに変換された値が同じにはなりません。AreEqual() を使用することを検討してください。{0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index 70ed44695f..5f03253cf0 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -47,6 +47,11 @@ 문자열 길이 {0}(을)를 예상했지만 {1}입니다. + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ AreSame()에 값 형식을 전달하면 안 됩니다. Object로 변환된 값은 동일한 값으로 간주되지 않습니다. AreEqual()을 사용해 보세요. {0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index eaaf923f6f..ee0312f249 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -47,6 +47,11 @@ Oczekiwano ciągu o długości {0}, ale miał wartość {1}. + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ Nie przekazuj typów wartości do metody AreSame(). Wartości przekonwertowane na typ Object nigdy nie będą takie same. Rozważ użycie metody AreEqual(). {0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index 18b55371e2..3eb5e5a6d1 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -47,6 +47,11 @@ Comprimento esperado da cadeia de caracteres {0}, mas foi {1}. + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ Não passe tipos de valores para AreSame(). Os valores convertidos para Object nunca serão os mesmos. Considere usar AreEqual(). {0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index db55e28ead..b4e2078127 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -47,6 +47,11 @@ Ожидалась длина строки: {0}, фактическая длина строки: {1}. + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ Не передавайте типы значений в функцию AreSame(). Значения, преобразованные в Object, никогда не будут одинаковыми. Попробуйте использовать AreEqual(). {0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index 9e98081b26..dd7358cc99 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -47,6 +47,11 @@ Beklenen dize uzunluğu {0} idi, ancak dize uzunluğu {1} oldu. + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ AreSame()'e değer türleri geçirmeyin. Object olarak dönüştürülen değerler asla aynı olamayacak. AreEqual() kullanmayı düşün. {0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index 861b921af1..50d5496be2 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -47,6 +47,11 @@ 字符串长度应为 {0},但为 {1}。 + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ 不要向 AreSame() 传递值类型。转换为 Object 的值将永远不会相等。请考虑使用 AreEqual()。{0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index 8b42dde962..84fd992ec1 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -47,6 +47,11 @@ 預期的字串長度為 {0},但為 {1}。 + + Expected collections to be equivalent. + Expected collections to be equivalent. + + Expected difference to be greater than {0}. Expected difference to be greater than {0}. @@ -72,6 +77,56 @@ 不要將實值型別傳遞給 AreSame()。轉換成 Object 的值從此不再一樣。請考慮使用 AreEqual()。{0} + + Objects are equal. + Objects are equal. + + + + Objects are not equal. + Objects are not equal. + + + + Expected {0} to equal {1}. + Expected {0} to equal {1}. + + + + Expected {0} to be false. + Expected {0} to be false. + + + + Expected {0} to be true. + Expected {0} to be true. + + + + Expected {0} to be greater than {1}. + Expected {0} to be greater than {1}. + + + + Expected {0} to be greater than or equal to {1}. + Expected {0} to be greater than or equal to {1}. + + + + Expected {0} to be less than {1}. + Expected {0} to be less than {1}. + + + + Expected {0} to be less than or equal to {1}. + Expected {0} to be less than or equal to {1}. + + + + Expected {0} to not equal {1}. + Expected {0} to not equal {1}. + + Both collections are empty. Both collections are empty. From 6e578b316a0d96161ac81ea03602914e1f175c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 23 Mar 2026 17:51:00 +0100 Subject: [PATCH 50/58] Fix 17 failing unit tests - ContainsSingle predicate tests: Add wildcard for new collection preview line - Items interpolated string tests: Remove collection lines, add wildcards - IsInRange DateTime: Use wildcards for InvariantCulture date format - AreEqual culture: Add ... to expected callsite for culture overload - Assert.That char: Update expected values for InvariantCulture char formatting --- .../Assertions/AssertTests.AreEqualTests.cs | 2 +- .../Assertions/AssertTests.Contains.cs | 18 +++++++++--------- .../Assertions/AssertTests.IsInRange.cs | 8 ++++---- .../Assertions/AssertTests.Items.cs | 14 ++++++-------- .../Assertions/AssertTests.That.cs | 2 +- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs index 103b9fff0f..7e4102387d 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs @@ -1708,7 +1708,7 @@ public void AreEqualStringWithCultureShouldUseEnhancedMessage() Action action = () => Assert.AreEqual("aaaa", "aaab", false, CultureInfo.InvariantCulture); action.Should().Throw() .WithMessage(""" - Assert.AreEqual("aaaa", "aaab") + Assert.AreEqual("aaaa", "aaab", ...) String lengths are both 4 but differ at index 3. expected: "aaaa" actual: "aaab" diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs index ea66b41186..ad8a603fca 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Contains.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -1573,7 +1573,7 @@ public void ContainsSinglePredicate_NoItemMatches_ThrowsException() action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) - Expected exactly one item to match the predicate but found 0 item(s). + Expected exactly one item to match the predicate but found 0 item(s).* """); } @@ -1593,7 +1593,7 @@ public void ContainsSinglePredicate_InNonGenericCollection_NoItemMatches_ThrowsE action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) - Expected exactly one item to match the predicate but found 0 item(s). + Expected exactly one item to match the predicate but found 0 item(s).* """); } @@ -1613,7 +1613,7 @@ public void ContainsSinglePredicate_MultipleItemsMatch_ThrowsException() action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) - Expected exactly one item to match the predicate but found 4 item(s). + Expected exactly one item to match the predicate but found 4 item(s).* """); } @@ -1633,7 +1633,7 @@ public void ContainsSinglePredicate_InNonGenericCollection_MultipleItemsMatch_Th action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) - Expected exactly one item to match the predicate but found 2 item(s). + Expected exactly one item to match the predicate but found 2 item(s).* """); } @@ -1654,7 +1654,7 @@ public void ContainsSinglePredicate_WithMessage_NoItemMatches_ThrowsException() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) No even numbers found in collection with 3 items - Expected exactly one item to match the predicate but found 0 item(s). + Expected exactly one item to match the predicate but found 0 item(s).* """); } @@ -1675,7 +1675,7 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_NoItemMat .WithMessage(""" Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) No even numbers found in collection with 3 items - Expected exactly one item to match the predicate but found 0 item(s). + Expected exactly one item to match the predicate but found 0 item(s).* """); } @@ -1696,7 +1696,7 @@ public void ContainsSinglePredicate_WithMessage_MultipleItemsMatch_ThrowsExcepti .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) Too many even numbers found: 3 - Expected exactly one item to match the predicate but found 3 item(s). + Expected exactly one item to match the predicate but found 3 item(s).* """); } @@ -1717,7 +1717,7 @@ public void ContainsSinglePredicate_InNonGenericCollection_WithMessage_MultipleI .WithMessage(""" Assert.ContainsSingle(x => x is int i && i % 2 == 0, collection) Too many even numbers found: 2 - Expected exactly one item to match the predicate but found 2 item(s). + Expected exactly one item to match the predicate but found 2 item(s).* """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index bf5e83a93c..53dbc92d66 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -139,11 +139,11 @@ public void IsInRange_WithDateTimeValues_WorksCorrectly() // Assert action.Should().ThrowExactly() - .WithMessage($""" + .WithMessage(""" Assert.IsInRange(valueOutOfRange) - Expected value {valueOutOfRange} to be in range [{minValue}, {maxValue}]. - range: [{minValue}, {maxValue}] - value: {valueOutOfRange} + Expected value * to be in range [*, *]. + range: [*, *] + value: * """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs index 3ddb12930a..c858f45421 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs @@ -139,8 +139,7 @@ public async Task Single_InterpolatedString_WhenNoItem_ShouldFail() .WithMessage(""" Assert.ContainsSingle(Array.Empty()) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected collection to contain exactly one item but found 0 item(s). - collection: [] + Expected collection to contain exactly one item but found 0 item(s).* """); o.WasToStringCalled.Should().BeTrue(); } @@ -154,8 +153,7 @@ public async Task Single_InterpolatedString_WhenMultipleItems_ShouldFail() .WithMessage(""" Assert.ContainsSingle([1, 2, 3]) User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString()* - Expected collection to contain exactly one item but found 3 item(s). - collection: [1, 2, 3] + Expected collection to contain exactly one item but found 3 item(s).* """); o.WasToStringCalled.Should().BeTrue(); } @@ -183,7 +181,7 @@ public void SinglePredicate_WhenNoItemMatches_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) - Expected exactly one item to match the predicate but found 0 item(s). + Expected exactly one item to match the predicate but found 0 item(s).* """); } @@ -194,7 +192,7 @@ public void SinglePredicate_WhenMultipleItemsMatch_ShouldFail() action.Should().Throw() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) - Expected exactly one item to match the predicate but found 3 item(s). + Expected exactly one item to match the predicate but found 3 item(s).* """); } @@ -206,7 +204,7 @@ public void SinglePredicate_Message_WhenNoItemMatches_ShouldFail() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) No even numbers found: test - Expected exactly one item to match the predicate but found 0 item(s). + Expected exactly one item to match the predicate but found 0 item(s).* """); } @@ -218,7 +216,7 @@ public void SinglePredicate_Message_WhenMultipleItemsMatch_ShouldFail() .WithMessage(""" Assert.ContainsSingle(x => x % 2 == 0, collection) Too many even numbers: test - Expected exactly one item to match the predicate but found 3 item(s). + Expected exactly one item to match the predicate but found 3 item(s).* """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs index 8950acd89b..b97f8e7942 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs @@ -780,7 +780,7 @@ public void That_WithCharacterLiterals_SkipsLiteralInDetails() act.Should().Throw() .WithMessage(""" Assert.That(letter == 'b') - Expected a to equal b. + Expected 97 to equal 98. letter = a """); } From 8a34f9e7173783b1705b3b6933bf8bede660aece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 23 Mar 2026 17:53:55 +0100 Subject: [PATCH 51/58] Add RFC 011: Structured Assertion Failure Messages design document --- .../RFCs/011-Structured-Assertion-Messages.md | 317 ++++++++++++++++++ 1 file changed, 317 insertions(+) create mode 100644 docs/RFCs/011-Structured-Assertion-Messages.md diff --git a/docs/RFCs/011-Structured-Assertion-Messages.md b/docs/RFCs/011-Structured-Assertion-Messages.md new file mode 100644 index 0000000000..eb9aa1eb49 --- /dev/null +++ b/docs/RFCs/011-Structured-Assertion-Messages.md @@ -0,0 +1,317 @@ +# RFC 011 - Structured Assertion Failure Messages + +- [x] Approved in principle +- [ ] Under discussion +- [ ] Implementation +- [ ] Shipped + +## Summary + +This document describes the unified format for assertion failure messages across `Assert`, `StringAssert`, `CollectionAssert`, and `Assert.That`. All assertion failures now follow a consistent structured layout that separates the call site, user message, framework explanation, and diagnostic values into distinct, predictable sections. + +## Motivation + +Before this change, assertion failure messages used inconsistent formats across the framework: + +- **Mixed tone**: Some messages used passive voice ("String does not contain..."), others active ("Expected a non-null value"), others factual ("Wrong exception type was thrown"), and others imperative ("Do not pass value types..."). +- **User message embedding**: User-provided messages were sometimes embedded inside the framework message via `string.Format` positional placeholders (`{0}`), making them hard to visually separate from the diagnostic information. +- **No structured parameters**: Values like `expected`, `actual`, and `delta` were inlined into prose sentences with inconsistent formatting (angle brackets `<>`, single quotes, or no decoration). +- **No call site**: The old format started with `Assert.AreEqual failed.` — telling the user *what* failed but not *what was passed*. +- **`Assert.That`**: Used a different layout entirely (`Assert.That(...) failed.` / `Message: ...` / `Details:` / ` x = 5`). +- **`CollectionAssert`/`StringAssert`**: Used legacy `string.Format` with positional placeholders for both user messages and values, making the output hard to parse visually. + +These inconsistencies made it harder for users to quickly scan failure output and understand what went wrong. + +## Design Goals + +1. **Consistent structure**: Every assertion failure follows the same layout regardless of which assert class or method is used. +2. **User message first**: When the user provides a custom message, it appears before the framework explanation — it is the most important context. +3. **Expressions over names**: The call site shows the syntactic expressions the user wrote (via `CallerArgumentExpression`), not just parameter names. +4. **Aligned parameters**: Diagnostic values are indented and column-aligned for easy scanning. +5. **Localizable**: All user-facing framework messages go through `FrameworkMessages.resx` for localization support. +6. **Actionable**: Messages describe what was expected, not just what happened. + +## Message Format + +Every assertion failure message follows this structure: + +``` + +[] + +[ : ] +[ : ] +``` + +### Line 1: Call Site + +The first line identifies which assertion failed and what expressions were passed: + +``` +Assert.AreEqual(expectedVar, actualVar) +Assert.IsTrue(result.IsValid) +Assert.That(x > 10) +CollectionAssert.AreEqual +StringAssert.Contains +``` + +For `Assert.*` methods, expressions are captured via `[CallerArgumentExpression]` and truncated at 50 characters. For `CollectionAssert` and `StringAssert` (legacy APIs without expression capture), the method name alone is shown. + +#### Omitted Parameters + +When overloads accept additional parameters not captured by `CallerArgumentExpression` (such as `delta`, `ignoreCase`, `culture`), the call site uses a trailing `...` to signal that the displayed signature is abbreviated: + +``` +Assert.AreEqual(1.0m, 1.1m, ...) // delta overload +Assert.AreEqual(expected, actual, ...) // culture overload +``` + +This avoids mixing runtime values with source expressions in the call site. + +#### Lambda Stripping + +For `Assert.That`, the `() => ` lambda wrapper is stripped from the call site since it is syntactic noise: + +``` +// Source code: Assert.That(() => x > 10) +// Call site: Assert.That(x > 10) +``` + +### Line 2 (Optional): User Message + +If the user provided a custom message, it appears on its own line immediately after the call site, without any prefix: + +``` +Assert.AreEqual(result, 42) +The calculation returned an unexpected value +Expected values to be equal. + expected: 42 + actual: 37 +``` + +This was a deliberate choice. Earlier iterations prefixed user messages with `Message:` or embedded them inline with the framework message. Both approaches made the user's intent harder to spot in multi-line output. Placing the user message on its own line — before the framework explanation — gives it the highest visual priority. + +### Line 3: Framework Message + +The framework's explanation of what was expected. All messages follow the tone **"Expected [subject] to [verb phrase]."**: + +``` +Expected values to be equal. +Expected string to start with the specified prefix. +Expected collection to contain the specified item. +Expected the specified exception type to be thrown. +Expected condition to be true. +``` + +This tone was chosen after evaluating several alternatives: + +| Style | Example | Verdict | +|-------|---------|---------| +| Passive: "String does not match..." | `String does not contain the expected substring.` | Rejected — describes outcome, not expectation | +| Factual: "Wrong exception type was thrown." | `No exception was thrown.` | Rejected — not actionable | +| Active nominal: "Expected a non-null value." | `Expected a positive value.` | Rejected — inconsistent structure with parameterized variants | +| **Active verbal: "Expected [X] to [Y]."** | `Expected value to be null.` | **Chosen** — consistent, actionable, parameterizable | + +The verbal form scales naturally to parameterized messages like `Expected value {0} to be greater than {1}.` and negative forms like `Expected value to not be null.` + +### Lines 4+: Aligned Parameters + +Diagnostic values are shown as indented, colon-separated, column-aligned pairs: + +``` + expected: 42 + actual: 37 +``` + +The alignment padding ensures all values start at the same column, making it easy to compare expected vs actual at a glance. When labels have different lengths, the shorter ones are padded: + +``` + expected prefix: "Hello" + value: "World" +``` + +Additional contextual parameters like `delta`, `ignore case`, and `culture` appear when relevant: + +``` + expected: "i" + actual: "I" + ignore case: False + culture: en-EN +``` + +Collection previews are shown inline with truncation: + +``` + collection: [1, 2, 3, ... 97 more] +``` + +## `Assert.That` Expression-Aware Messages + +`Assert.That` accepts an `Expression>` and uses the expression tree to generate context-specific failure messages instead of a generic "Expected condition to be true." + +| Expression Type | Example | Message | +|----------------|---------|---------| +| `==` | `x == 5` | `Expected 3 to equal 5.` | +| `!=` | `s != "test"` | `Expected "test" to not equal "test".` | +| `>` | `x > 10` | `Expected 5 to be greater than 10.` | +| `>=` | `x >= 10` | `Expected 5 to be greater than or equal to 10.` | +| `<` | `year < 2000` | `Expected 2026 to be less than 2000.` | +| `<=` | `x <= 3` | `Expected 5 to be less than or equal to 3.` | +| `!flag` | `!flag` | `Expected flag to be false.` | +| Bool member | `user.IsActive` | `Expected user.IsActive to be true.` | +| `StartsWith` | `text.StartsWith(...)` | `Expected string to start with the specified prefix.` | +| `Contains` (string) | `text.Contains(...)` | `Expected string to contain the specified substring.` | +| `Contains` (collection) | `list.Contains(...)` | `Expected collection to contain the specified item.` | +| `All` | `nums.All(...)` | `Expected all elements to match the predicate.` | +| `Any` | `coll.Any(...)` | `Expected at least one item to match the predicate.` | +| `&&` / `\|\|` / fallback | compound | `Expected condition to be true.` | + +For binary comparisons, both sides of the expression are evaluated at runtime and their values are displayed. For known methods (`StartsWith`, `Contains`, `All`, `Any`), the corresponding framework message is reused. String-specific methods are type-checked to avoid false matches on types that happen to have methods with the same name. Compound expressions (`&&`, `||`) fall back to the generic message since the specific failing sub-expression cannot be determined. + +Variable details are extracted from the expression tree and displayed below the message: + +``` +Assert.That(x > 10) +Expected 5 to be greater than 10. + x = 5 +``` + +## `CollectionAssert` and `StringAssert` + +These legacy APIs follow the same structural pattern but without `CallerArgumentExpression` (since they predate it): + +``` +CollectionAssert.AreEqual +User-provided message +Element at index 1 do not match. + expected: 2 + actual: 5 +``` + +``` +StringAssert.Contains +Expected string to contain the specified substring. + substring: "xyz" + value: "The quick brown fox..." +``` + +User messages are positioned using `AppendUserMessage` (before the framework message), and parameter values use `FormatAlignedParameters` for consistent alignment. + +## Value Formatting + +All values are formatted through a unified `FormatValue` method that applies consistent rules: + +| Type | Format | Example | +|------|--------|---------| +| `null` | `null` | `null` | +| `string` | Quoted, escaped, truncated at 256 chars | `"hello\r\nworld"` | +| `int` | Plain | `42` | +| `long` | With suffix | `42L` | +| `float` | With suffix | `1.5f` | +| `decimal` | With suffix | `0.1m` | +| `double` | Plain | `3.14` | +| Collections | Inline preview with truncation | `[1, 2, 3, ... 97 more]` | +| Types (no useful ToString) | Angle-bracketed full name | `` | +| Other (custom ToString) | Escaped, truncated | `MyCustomType{Id=5}` | + +Numeric primitives are formatted using `CultureInfo.InvariantCulture` to ensure consistent output across locales. Collections are safe-enumerated with budget-based truncation to avoid hanging on infinite sequences. + +## Implementation Details + +### `StringPair` struct + +To support `net462` (which lacks `System.ValueTuple`), the aligned parameter and call site methods use a simple `StringPair` struct instead of tuple syntax: + +```csharp +internal readonly struct StringPair +{ + public StringPair(string name, string value) { Name = name; Value = value; } + public string Name { get; } + public string Value { get; } +} +``` + +### Localization + +All user-facing message strings are defined in `FrameworkMessages.resx` and generated via the standard xlf pipeline. This includes the `Assert.That` expression-aware messages, which use `string.Format` placeholders (`{0}`, `{1}`) for runtime values. + +### Collection Safety + +Collection parameters are materialized at the assertion boundary (via `as ICollection ?? [.. collection]`) to prevent multiple enumeration. The `FormatCollectionPreview` method uses budget-based truncation and catches enumeration exceptions gracefully, falling back to a `...` suffix rather than failing the assertion formatting. + +## Examples + +### `Assert.AreEqual` (generic) + +``` +Assert.AreEqual(expected, actual) +Expected values to be equal. + expected: 42 + actual: 37 +``` + +### `Assert.AreEqual` (delta overload) + +``` +Assert.AreEqual(1.0m, 1.1m, ...) +Expected difference to be no greater than 0.001. + expected: 1.0m + actual: 1.1m + delta: 0.001m +``` + +### `Assert.AreEqual` (string with culture) + +``` +Assert.AreEqual(expected, actual, ...) +Case differs. + expected: "i" + actual: "I" + ignore case: False + culture: en-EN +``` + +### `Assert.IsNull` + +``` +Assert.IsNull(result) +Expected value to be null. + value: 42 +``` + +### `Assert.Throws` + +``` +Assert.Throws(action) +Expected the specified exception type to be thrown. + action: () => service.Process() + expected exception type: + actual exception type: +``` + +### `Assert.That` (comparison) + +``` +Assert.That(x > 10) +x should be greater than 10 +Expected 5 to be greater than 10. + x = 5 +``` + +### `CollectionAssert.AreEqual` + +``` +CollectionAssert.AreEqual +Element at index 1 do not match. + expected: 2 + actual: 5 +``` + +### `StringAssert.StartsWith` + +``` +StringAssert.StartsWith +Expected string to start with the specified prefix. + expected prefix: "Hello" + value: "World says goodbye" +``` From d17a284e300ab5a50bfb32b831040d847ae03d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 23 Mar 2026 17:58:58 +0100 Subject: [PATCH 52/58] Fix markdown lint issues in RFC 011 --- .../RFCs/011-Structured-Assertion-Messages.md | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/RFCs/011-Structured-Assertion-Messages.md b/docs/RFCs/011-Structured-Assertion-Messages.md index eb9aa1eb49..f126c3116f 100644 --- a/docs/RFCs/011-Structured-Assertion-Messages.md +++ b/docs/RFCs/011-Structured-Assertion-Messages.md @@ -17,7 +17,7 @@ Before this change, assertion failure messages used inconsistent formats across - **User message embedding**: User-provided messages were sometimes embedded inside the framework message via `string.Format` positional placeholders (`{0}`), making them hard to visually separate from the diagnostic information. - **No structured parameters**: Values like `expected`, `actual`, and `delta` were inlined into prose sentences with inconsistent formatting (angle brackets `<>`, single quotes, or no decoration). - **No call site**: The old format started with `Assert.AreEqual failed.` — telling the user *what* failed but not *what was passed*. -- **`Assert.That`**: Used a different layout entirely (`Assert.That(...) failed.` / `Message: ...` / `Details:` / ` x = 5`). +- **`Assert.That`**: Used a different layout entirely (`Assert.That(...) failed.` / `Message: ...` / `Details:` / `x = 5`). - **`CollectionAssert`/`StringAssert`**: Used legacy `string.Format` with positional placeholders for both user messages and values, making the output hard to parse visually. These inconsistencies made it harder for users to quickly scan failure output and understand what went wrong. @@ -35,7 +35,7 @@ These inconsistencies made it harder for users to quickly scan failure output an Every assertion failure message follows this structure: -``` +```text [] @@ -47,7 +47,7 @@ Every assertion failure message follows this structure: The first line identifies which assertion failed and what expressions were passed: -``` +```text Assert.AreEqual(expectedVar, actualVar) Assert.IsTrue(result.IsValid) Assert.That(x > 10) @@ -61,7 +61,7 @@ For `Assert.*` methods, expressions are captured via `[CallerArgumentExpression] When overloads accept additional parameters not captured by `CallerArgumentExpression` (such as `delta`, `ignoreCase`, `culture`), the call site uses a trailing `...` to signal that the displayed signature is abbreviated: -``` +```text Assert.AreEqual(1.0m, 1.1m, ...) // delta overload Assert.AreEqual(expected, actual, ...) // culture overload ``` @@ -70,9 +70,9 @@ This avoids mixing runtime values with source expressions in the call site. #### Lambda Stripping -For `Assert.That`, the `() => ` lambda wrapper is stripped from the call site since it is syntactic noise: +For `Assert.That`, the `() =>` lambda wrapper is stripped from the call site since it is syntactic noise: -``` +```text // Source code: Assert.That(() => x > 10) // Call site: Assert.That(x > 10) ``` @@ -81,7 +81,7 @@ For `Assert.That`, the `() => ` lambda wrapper is stripped from the call site si If the user provided a custom message, it appears on its own line immediately after the call site, without any prefix: -``` +```text Assert.AreEqual(result, 42) The calculation returned an unexpected value Expected values to be equal. @@ -95,7 +95,7 @@ This was a deliberate choice. Earlier iterations prefixed user messages with `Me The framework's explanation of what was expected. All messages follow the tone **"Expected [subject] to [verb phrase]."**: -``` +```text Expected values to be equal. Expected string to start with the specified prefix. Expected collection to contain the specified item. @@ -106,7 +106,7 @@ Expected condition to be true. This tone was chosen after evaluating several alternatives: | Style | Example | Verdict | -|-------|---------|---------| +| ----- | ------- | ------- | | Passive: "String does not match..." | `String does not contain the expected substring.` | Rejected — describes outcome, not expectation | | Factual: "Wrong exception type was thrown." | `No exception was thrown.` | Rejected — not actionable | | Active nominal: "Expected a non-null value." | `Expected a positive value.` | Rejected — inconsistent structure with parameterized variants | @@ -118,21 +118,21 @@ The verbal form scales naturally to parameterized messages like `Expected value Diagnostic values are shown as indented, colon-separated, column-aligned pairs: -``` +```text expected: 42 actual: 37 ``` The alignment padding ensures all values start at the same column, making it easy to compare expected vs actual at a glance. When labels have different lengths, the shorter ones are padded: -``` +```text expected prefix: "Hello" value: "World" ``` Additional contextual parameters like `delta`, `ignore case`, and `culture` appear when relevant: -``` +```text expected: "i" actual: "I" ignore case: False @@ -141,7 +141,7 @@ Additional contextual parameters like `delta`, `ignore case`, and `culture` appe Collection previews are shown inline with truncation: -``` +```text collection: [1, 2, 3, ... 97 more] ``` @@ -150,7 +150,7 @@ Collection previews are shown inline with truncation: `Assert.That` accepts an `Expression>` and uses the expression tree to generate context-specific failure messages instead of a generic "Expected condition to be true." | Expression Type | Example | Message | -|----------------|---------|---------| +| --------------- | ------- | ------- | | `==` | `x == 5` | `Expected 3 to equal 5.` | | `!=` | `s != "test"` | `Expected "test" to not equal "test".` | | `>` | `x > 10` | `Expected 5 to be greater than 10.` | @@ -170,7 +170,7 @@ For binary comparisons, both sides of the expression are evaluated at runtime an Variable details are extracted from the expression tree and displayed below the message: -``` +```text Assert.That(x > 10) Expected 5 to be greater than 10. x = 5 @@ -180,7 +180,7 @@ Expected 5 to be greater than 10. These legacy APIs follow the same structural pattern but without `CallerArgumentExpression` (since they predate it): -``` +```text CollectionAssert.AreEqual User-provided message Element at index 1 do not match. @@ -188,7 +188,7 @@ Element at index 1 do not match. actual: 5 ``` -``` +```text StringAssert.Contains Expected string to contain the specified substring. substring: "xyz" @@ -202,7 +202,7 @@ User messages are positioned using `AppendUserMessage` (before the framework mes All values are formatted through a unified `FormatValue` method that applies consistent rules: | Type | Format | Example | -|------|--------|---------| +| ---- | ------ | ------- | | `null` | `null` | `null` | | `string` | Quoted, escaped, truncated at 256 chars | `"hello\r\nworld"` | | `int` | Plain | `42` | @@ -243,7 +243,7 @@ Collection parameters are materialized at the assertion boundary (via `as IColle ### `Assert.AreEqual` (generic) -``` +```text Assert.AreEqual(expected, actual) Expected values to be equal. expected: 42 @@ -252,7 +252,7 @@ Expected values to be equal. ### `Assert.AreEqual` (delta overload) -``` +```text Assert.AreEqual(1.0m, 1.1m, ...) Expected difference to be no greater than 0.001. expected: 1.0m @@ -262,7 +262,7 @@ Expected difference to be no greater than 0.001. ### `Assert.AreEqual` (string with culture) -``` +```text Assert.AreEqual(expected, actual, ...) Case differs. expected: "i" @@ -273,7 +273,7 @@ Case differs. ### `Assert.IsNull` -``` +```text Assert.IsNull(result) Expected value to be null. value: 42 @@ -281,7 +281,7 @@ Expected value to be null. ### `Assert.Throws` -``` +```text Assert.Throws(action) Expected the specified exception type to be thrown. action: () => service.Process() @@ -291,7 +291,7 @@ Expected the specified exception type to be thrown. ### `Assert.That` (comparison) -``` +```text Assert.That(x > 10) x should be greater than 10 Expected 5 to be greater than 10. @@ -300,7 +300,7 @@ Expected 5 to be greater than 10. ### `CollectionAssert.AreEqual` -``` +```text CollectionAssert.AreEqual Element at index 1 do not match. expected: 2 @@ -309,7 +309,7 @@ Element at index 1 do not match. ### `StringAssert.StartsWith` -``` +```text StringAssert.StartsWith Expected string to start with the specified prefix. expected prefix: "Hello" From 938bc2003da1f043a300e521be14120e910c33f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 23 Mar 2026 18:02:26 +0100 Subject: [PATCH 53/58] RFC 011: Add ToString handling and size limits documentation --- .../RFCs/011-Structured-Assertion-Messages.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/RFCs/011-Structured-Assertion-Messages.md b/docs/RFCs/011-Structured-Assertion-Messages.md index f126c3116f..749eaeeabc 100644 --- a/docs/RFCs/011-Structured-Assertion-Messages.md +++ b/docs/RFCs/011-Structured-Assertion-Messages.md @@ -216,6 +216,26 @@ All values are formatted through a unified `FormatValue` method that applies Numeric primitives are formatted using `CultureInfo.InvariantCulture` to ensure consistent output across locales. Collections are safe-enumerated with budget-based truncation to avoid hanging on infinite sequences. +### ToString Handling + +For non-primitive, non-collection types, `FormatValue` checks whether the runtime type has a meaningful `ToString()` override: + +1. If `ToString()` is overridden (i.e., declared on a type other than `System.Object` or `System.ValueType`), its result is used, escaped, and truncated. +2. If `ToString()` throws an exception, the exception is caught and the type name is displayed instead (e.g., ``). +3. If `ToString()` is not overridden (inherited from `Object`), the type name is displayed directly — this avoids showing the unhelpful default `"MyNamespace.MyType"` as if it were a meaningful value. + +This ensures that types with useful `ToString()` (like `DateTime`, records, or custom domain objects) show their value, while types without it show their type name in angle brackets. + +### Size Limits + +| Element | Limit | Behavior when exceeded | +| ------- | ----- | ---------------------- | +| Expression in call site | 50 characters | Truncated with `...` suffix | +| Formatted value (string, ToString) | 256 characters | Truncated with `... N more` suffix | +| Collection preview | 256 characters total | Elements stop being added; remaining count shown as `... N more` (or `N+` for non-ICollection) | +| Collection element value | 50 characters | Each element individually truncated | +| Newlines in values | N/A | Escaped as `\r\n`, `\n`, `\r` — never produce actual line breaks | + ## Implementation Details ### `StringPair` struct From 9eedbd7f0c0c901400cc444ac07b56c66acb02fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 23 Mar 2026 18:36:22 +0100 Subject: [PATCH 54/58] Address 9 review comments - Add safety comment to TryEvaluateFormatted about re-evaluation side effects - Fix FormatValue: Pass maxLength to FormatCollectionPreview for consistency - Fix ThrowAssertIsInRangeFailed: Remove unused minValueExpression/maxValueExpression params - Fix Contains/DoesNotContain: Avoid eager materialization when ICollection is available - Fix AllItemsAreUnique: Use FormatValue instead of ReplaceNulls for proper escaping - Fix IsSubsetOf: Use FormatValue instead of Convert.ToString for null-safe formatting - Update IsSubsetOf tests for quoted string values --- .../Assertions/Assert.Contains.cs | 72 ++++++++++++++----- .../TestFramework/Assertions/Assert.That.cs | 3 + .../TestFramework/Assertions/Assert.cs | 2 +- .../Assertions/CollectionAssert.cs | 4 +- .../Assertions/CollectionAssertTests.cs | 4 +- 5 files changed, 64 insertions(+), 21 deletions(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs index 2c92c6d798..f7660d5ceb 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Contains.cs @@ -268,12 +268,22 @@ public static T ContainsSingle(Func predicate, IEnumerable collec /// public static void Contains(T expected, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(expected))] string expectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - // Materialize non-ICollection enumerables to prevent multiple enumeration - // that could yield different results or fail on second pass. - ICollection snapshot = collection as ICollection ?? [.. collection]; - if (!snapshot.Contains(expected)) + if (collection is ICollection col) { - ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, snapshot); + if (!col.Contains(expected)) + { + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, col); + } + } + else + { + // Materialize to prevent multiple enumeration and to provide + // the collection preview in the failure message. + ICollection snapshot = [.. collection]; + if (!snapshot.Contains(expected)) + { + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, snapshot); + } } } @@ -327,10 +337,20 @@ public static void Contains(object? expected, IEnumerable collection, string? me /// public static void Contains(T expected, IEnumerable collection, IEqualityComparer comparer, string? message = "", [CallerArgumentExpression(nameof(expected))] string expectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - ICollection snapshot = collection as ICollection ?? [.. collection]; - if (!snapshot.Contains(expected, comparer)) + if (collection is ICollection col) { - ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, snapshot); + if (!col.Contains(expected, comparer)) + { + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, col); + } + } + else + { + ICollection snapshot = [.. collection]; + if (!snapshot.Contains(expected, comparer)) + { + ThrowAssertContainsItemFailed(message, expectedExpression, collectionExpression, snapshot); + } } } @@ -517,10 +537,20 @@ public static void Contains(string substring, string value, StringComparison com /// public static void DoesNotContain(T notExpected, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(notExpected))] string notExpectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - ICollection snapshot = collection as ICollection ?? [.. collection]; - if (snapshot.Contains(notExpected)) + if (collection is ICollection col) { - ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, snapshot); + if (col.Contains(notExpected)) + { + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, col); + } + } + else + { + ICollection snapshot = [.. collection]; + if (snapshot.Contains(notExpected)) + { + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, snapshot); + } } } @@ -571,10 +601,20 @@ public static void DoesNotContain(object? notExpected, IEnumerable collection, s /// public static void DoesNotContain(T notExpected, IEnumerable collection, IEqualityComparer comparer, string? message = "", [CallerArgumentExpression(nameof(notExpected))] string notExpectedExpression = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") { - ICollection snapshot = collection as ICollection ?? [.. collection]; - if (snapshot.Contains(notExpected, comparer)) + if (collection is ICollection col) { - ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, snapshot); + if (col.Contains(notExpected, comparer)) + { + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, col); + } + } + else + { + ICollection snapshot = [.. collection]; + if (snapshot.Contains(notExpected, comparer)) + { + ThrowAssertDoesNotContainItemFailed(message, notExpectedExpression, collectionExpression, snapshot); + } } } @@ -771,7 +811,7 @@ public static void IsInRange(T minValue, T maxValue, T value, string? message if (value.CompareTo(minValue) < 0 || value.CompareTo(maxValue) > 0) { - ThrowAssertIsInRangeFailed(value, minValue, maxValue, message, minValueExpression, maxValueExpression, valueExpression); + ThrowAssertIsInRangeFailed(value, minValue, maxValue, message, valueExpression); } } @@ -886,7 +926,7 @@ private static void ThrowAssertStringDoesNotContainFailed(string value, string s } [DoesNotReturn] - private static void ThrowAssertIsInRangeFailed(T value, T minValue, T maxValue, string? userMessage, string minValueExpression, string maxValueExpression, string valueExpression) + private static void ThrowAssertIsInRangeFailed(T value, T minValue, T maxValue, string? userMessage, string valueExpression) { string callSite = FormatCallSite("Assert.IsInRange", new StringPair(nameof(value), valueExpression)); string message = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsInRangeFailNew, FormatValue(value), FormatValue(minValue), FormatValue(maxValue)); diff --git a/src/TestFramework/TestFramework/Assertions/Assert.That.cs b/src/TestFramework/TestFramework/Assertions/Assert.That.cs index 4cd75652be..d24d7c9ec6 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.That.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.That.cs @@ -137,6 +137,9 @@ private static string TryEvaluateFormatted(Expression expr) { try { + // Note: This re-evaluates the sub-expression, which can re-run user code. + // This is acceptable because we only reach this path when the assertion has + // already failed, and the values are used solely for diagnostic display. object? value = Expression.Lambda(expr).Compile().DynamicInvoke(); return FormatValue(value); } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 0c8dc735fd..cb84be4ba8 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -116,7 +116,7 @@ internal static string FormatValue(T? value, int maxLength = 256) // For collections, show a preview with element values if (value is IEnumerable enumerable) { - return FormatCollectionPreview(enumerable); + return FormatCollectionPreview(enumerable, maxLength); } // Always use the runtime type for non-null values so that interface/base-class diff --git a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs index 9989789b71..121255d26a 100644 --- a/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs +++ b/src/TestFramework/TestFramework/Assertions/CollectionAssert.cs @@ -236,7 +236,7 @@ public static void AllItemsAreUnique([NotNull] ICollection? collection, string? { string msg = FrameworkMessages.AllItemsAreUniqueFailMsg; msg += Assert.FormatAlignedParameters( - new Assert.StringPair("duplicate", Assert.ReplaceNulls(current))); + new Assert.StringPair("duplicate", Assert.FormatValue(current))); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("CollectionAssert.AllItemsAreUnique", msg); } @@ -295,7 +295,7 @@ public static void IsSubsetOf([NotNull] ICollection? subset, [NotNull] ICollecti Tuple> isSubsetValue = IsSubsetOfHelper(subset, superset); if (!isSubsetValue.Item1) { - string missingElements = string.Join(", ", isSubsetValue.Item2.Select(item => Convert.ToString(item, CultureInfo.InvariantCulture))); + string missingElements = string.Join(", ", isSubsetValue.Item2.Select(item => Assert.FormatValue(item))); string msg = string.Format(CultureInfo.InvariantCulture, FrameworkMessages.ReturnedSubsetValueMessage, missingElements); msg = Assert.AppendUserMessage(msg, message); Assert.ThrowAssertFailed("CollectionAssert.IsSubsetOf", msg); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs index 1c78467066..a9efe26e84 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs @@ -105,7 +105,7 @@ public void CollectionAssertIsSubsetOf_ReturnedSubsetValueMessage_ThrowException // Assert action.Should().Throw().WithMessage(""" CollectionAssert.IsSubsetOf - Element(s) is/are not present in the collection. + Element(s) <"iem", "a", "b"> is/are not present in the collection. """); } @@ -122,7 +122,7 @@ public void CollectionAssertIsSubsetOf_WithMessage_ReturnedSubsetValueMessage_Th action.Should().Throw().WithMessage(""" CollectionAssert.IsSubsetOf message - Element(s) is/are not present in the collection. + Element(s) <"iem", "a", "b"> is/are not present in the collection. """); } From 4c6fe776b4e264a495582a8869c28405cdc2fbaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 24 Mar 2026 10:48:26 +0100 Subject: [PATCH 55/58] Fix test expectations for new Assert.Fail message format Update tests to match the structured assertion message format where Assert.Fail no longer includes 'failed.' suffix and uses newline separator between assertion name and user message. --- .../Execution/TestAssemblyInfoTests.cs | 4 ++-- .../Execution/TestClassInfoTests.cs | 4 ++-- .../Execution/TestExecutionManagerTests.cs | 2 +- .../Execution/TestMethodInfoTests.cs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs index fe081e28cd..991a96ad1d 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestAssemblyInfoTests.cs @@ -146,7 +146,7 @@ public async Task RunAssemblyInitializeShouldThrowTestFailedExceptionOnAssertion var exception = (await _testAssemblyInfo.RunAssemblyInitializeAsync(_testContext)).TestFailureException as TestFailedException; exception.Should().NotBeNull(); exception.Outcome.Should().Be(UnitTestOutcome.Failed); - exception.Message.Should().Be("Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail failed. Test failure. Aborting test execution."); + exception.Message.Should().Be($"Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail{Environment.NewLine}Test failure. Aborting test execution."); exception.StackTraceInformation!.ErrorStackTrace.Should().Contain( "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.DummyTestClass.AssemblyInitializeMethod"); exception.InnerException.Should().BeOfType(); @@ -264,7 +264,7 @@ public async Task RunAssemblyCleanupShouldReturnAssertFailureExceptionDetails() _testAssemblyInfo.AssemblyCleanupMethod = typeof(DummyTestClass).GetMethod("AssemblyCleanupMethod")!; string? actualErrorMessage = (await _testAssemblyInfo.ExecuteAssemblyCleanupAsync(GetTestContext()))?.Message; actualErrorMessage!.StartsWith( - "Assembly Cleanup method DummyTestClass.AssemblyCleanupMethod failed. Error Message: Assert.Fail failed. Test Failure..", StringComparison.Ordinal).Should().BeTrue($"Value: {actualErrorMessage}"); + $"Assembly Cleanup method DummyTestClass.AssemblyCleanupMethod failed. Error Message: Assert.Fail{Environment.NewLine}Test Failure..", StringComparison.Ordinal).Should().BeTrue($"Value: {actualErrorMessage}"); } public async Task RunAssemblyCleanupShouldReturnAssertInconclusiveExceptionDetails() diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs index 1db8a177bc..0e839eba03 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestClassInfoTests.cs @@ -350,7 +350,7 @@ public void RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure() exception.Should().NotBeNull(); exception.Outcome.Should().Be(UnitTestOutcome.Failed); - exception.Message.Should().Be("Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail failed. Test failure."); + exception.Message.Should().Be($"Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail{Environment.NewLine}Test failure."); exception.StackTraceInformation!.ErrorStackTrace.Contains( "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.DummyTestClass.ClassInitializeMethod", StringComparison.Ordinal).Should().BeTrue(); exception.InnerException.Should().BeOfType(); @@ -481,7 +481,7 @@ public async Task RunClassCleanupShouldReturnAssertFailureExceptionDetails() // Assert classCleanupException.Should().NotBeNull(); classCleanupException.Message.StartsWith("Class Cleanup method DummyTestClass.ClassCleanupMethod failed.", StringComparison.Ordinal).Should().BeTrue(); - classCleanupException.Message.Contains("Error Message: Assert.Fail failed. Test Failure.").Should().BeTrue(); + classCleanupException.Message.Contains($"Error Message: Assert.Fail{Environment.NewLine}Test Failure.").Should().BeTrue(); classCleanupException.Message.Should().Contain( $"{typeof(TestClassInfoTests).FullName}.DummyTestClass.ClassCleanupMethod", $"Value: {classCleanupException.Message}"); diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestExecutionManagerTests.cs index aaad4a34b1..76bfcba301 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestExecutionManagerTests.cs @@ -159,7 +159,7 @@ public async Task RunTestsForMultipleTestShouldSendMultipleResults() List expectedTestCaseStartList = ["PassingTest", "FailingTest"]; List expectedTestCaseEndList = ["PassingTest:Passed", "FailingTest:Failed"]; - List expectedResultList = ["PassingTest Passed", "FailingTest Failed\r\n Message: Assert.Fail failed."]; + List expectedResultList = ["PassingTest Passed", "FailingTest Failed\r\n Message: Assert.Fail"]; expectedTestCaseStartList.SequenceEqual(_frameworkHandle.TestCaseStartList).Should().BeTrue(); expectedTestCaseEndList.SequenceEqual(_frameworkHandle.TestCaseEndList).Should().BeTrue(); diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs index 98e17cfcb3..614414947f 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Execution/TestMethodInfoTests.cs @@ -715,7 +715,7 @@ public async Task TestMethodInfoInvokeWhenTestThrowsAssertFailReturnsExpectedRes Resource.UTA_InitMethodThrows, typeof(DummyTestClass).FullName, _testClassInfo.TestInitializeMethod!.Name, - "Assert.Fail failed. dummyFailMessage"); + $"Assert.Fail{Environment.NewLine}dummyFailMessage"); var testMethodInfo = new TestMethodInfo(_methodInfo, _testClassInfo) { @@ -989,7 +989,7 @@ public async Task TestMethodInfoInvokeWhenTestCleanupThrowsAssertFailedReturnsEx Resource.UTA_CleanupMethodThrows, typeof(DummyTestClass).FullName, _testClassInfo.TestCleanupMethod!.Name, - "Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail failed. Test failed"); + $"Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail{Environment.NewLine}Test failed"); TestResult result = await _testMethodInfo.InvokeAsync(null); From d81b16a49ffb5b9a4a80292ccee1a58f44af4f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 24 Mar 2026 11:53:54 +0100 Subject: [PATCH 56/58] More rework --- .../OutputTests.cs | 5 +++-- .../TrxReportTests.cs | 2 +- .../Assertions/AssertTests.IsInRange.cs | 5 +++-- .../Assertions/AssertTests.That.cs | 12 +++++++----- .../Assertions/AssertTests.ThrowsExceptionTests.cs | 7 +++++-- .../Assertions/AssertTests.cs | 12 +++++++++--- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs index 7c684a742d..753b9dac82 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/OutputTests.cs @@ -17,12 +17,13 @@ public async Task DetailedOutputIsAsExpected(string tfm) TestHostResult testHostResult = await testHost.ExecuteAsync("--output detailed", cancellationToken: TestContext.CancellationToken); // Assert - testHostResult.AssertOutputContains(""" + testHostResult.AssertOutputContains( + """ Assert.AreEqual(1, 2) Expected values to be equal. expected: 1 actual: 2 - """); + """.ReplaceLineEndings()); testHostResult.AssertOutputContains(""" Standard output Console message diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs index 98fdd54ee0..ed0d041151 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/TrxReportTests.cs @@ -39,7 +39,7 @@ public async Task TrxReport_WhenTestFails_ContainsExceptionInfoInOutput(string t Expected values to be equal. expected: 1 actual: 2 - """, + """.ReplaceLineEndings(), trxContent, trxContent); diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index 53dbc92d66..fa16146166 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -348,8 +348,9 @@ public void IsInRange_WithMaxValueLessThanMinValue_ThrowsArgumentOutOfRangeExcep Action action = () => Assert.IsInRange(minValue, maxValue, value); // Assert - action.Should().ThrowExactly() - .WithMessage("The maximum value must be greater than or equal to the minimum value. (Parameter 'maxValue')"); + var ex = action.Should().ThrowExactly().Which; + ex.ParamName.Should().Be("maxValue"); + ex.Message.Should().Contain("The maximum value must be greater than or equal to the minimum value."); } public void IsInRange_WithMaxValueEqualToMinValue_Int_ShouldPassIfValueIsEqual() diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs index b97f8e7942..f91e1b63f0 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.That.cs @@ -1013,17 +1013,19 @@ Expected condition to be true. public void That_WithCapturedDecimalLiteral_SkipsInDetails() { // Test decimal literals with 'm' suffix + // Use values that don't produce trailing zeros in arithmetic to avoid + // differences between .NET Framework (strips trailing zeros) and .NET Core (preserves them). decimal price = 19.99m; - decimal tax = 2.50m; + decimal tax = 3.02m; - Action act = () => Assert.That(() => price + tax == 25.00m); + Action act = () => Assert.That(() => price + tax == 25.01m); act.Should().Throw() .WithMessage(""" - Assert.That(price + tax == 25.00m) - Expected 22.49 to equal 25.00. + Assert.That(price + tax == 25.01m) + Expected 23.01 to equal 25.01. price = 19.99 - tax = 2.50 + tax = 3.02 """); } diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs index 731a0cdfbd..b033cb6049 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -13,7 +13,10 @@ public void ThrowAssertFailedDoesNotThrowIfMessageContainsInvalidStringFormatCom { Action action = () => Assert.ThrowAssertFailed("name", "{"); action.Should().Throw() - .WithMessage("name\n{"); + .WithMessage(""" + name + { + """); } #endregion diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index 9d68d02208..670491a5f3 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using AwesomeAssertions; @@ -31,7 +31,10 @@ public void ObsoleteEqualsMethodThrowsAssertFailedException() Action act = () => Assert.Equals("test", "test"); #pragma warning restore CS0618 // Type or member is obsolete act.Should().Throw() - .WithMessage("Assert.Fail\nAssert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead."); + .WithMessage(""" + Assert.Fail + Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. + """); } public void ObsoleteReferenceEqualsMethodThrowsAssertFailedException() @@ -41,7 +44,10 @@ public void ObsoleteReferenceEqualsMethodThrowsAssertFailedException() Action act = () => Assert.ReferenceEquals(obj, obj); #pragma warning restore CS0618 // Type or member is obsolete act.Should().Throw() - .WithMessage("Assert.Fail\nAssert.ReferenceEquals should not be used for Assertions. Please use Assert.AreSame & overloads instead."); + .WithMessage(""" + Assert.Fail + Assert.ReferenceEquals should not be used for Assertions. Please use Assert.AreSame & overloads instead. + """); } #endif #endregion From 33a13a78e621c730be525633dd43f9f9e2417175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 26 Mar 2026 14:33:55 +0100 Subject: [PATCH 57/58] Fix IDE0008: Use explicit type instead of var --- .../TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs index fa16146166..1231f37ac6 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.IsInRange.cs @@ -348,7 +348,7 @@ public void IsInRange_WithMaxValueLessThanMinValue_ThrowsArgumentOutOfRangeExcep Action action = () => Assert.IsInRange(minValue, maxValue, value); // Assert - var ex = action.Should().ThrowExactly().Which; + ArgumentOutOfRangeException ex = action.Should().ThrowExactly().Which; ex.ParamName.Should().Be("maxValue"); ex.Message.Should().Contain("The maximum value must be greater than or equal to the minimum value."); } From 3bd6e1591339e57075e17f12a19d33d22d95b84c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 26 Mar 2026 14:59:05 +0100 Subject: [PATCH 58/58] Address review comments: use Environment.NewLine in test assertions for cross-platform robustness --- .../Assertions/AssertTests.ThrowsExceptionTests.cs | 5 +---- .../Assertions/AssertTests.cs | 14 ++++++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs index b033cb6049..86e28c8432 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.ThrowsExceptionTests.cs @@ -13,10 +13,7 @@ public void ThrowAssertFailedDoesNotThrowIfMessageContainsInvalidStringFormatCom { Action action = () => Assert.ThrowAssertFailed("name", "{"); action.Should().Throw() - .WithMessage(""" - name - { - """); + .WithMessage("name" + Environment.NewLine + "{"); } #endregion diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs index 670491a5f3..48c6404d5b 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.cs @@ -31,10 +31,9 @@ public void ObsoleteEqualsMethodThrowsAssertFailedException() Action act = () => Assert.Equals("test", "test"); #pragma warning restore CS0618 // Type or member is obsolete act.Should().Throw() - .WithMessage(""" - Assert.Fail - Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead. - """); + .WithMessage( + "Assert.Fail" + Environment.NewLine + + "Assert.Equals should not be used for Assertions. Please use Assert.AreEqual & overloads instead."); } public void ObsoleteReferenceEqualsMethodThrowsAssertFailedException() @@ -44,10 +43,9 @@ public void ObsoleteReferenceEqualsMethodThrowsAssertFailedException() Action act = () => Assert.ReferenceEquals(obj, obj); #pragma warning restore CS0618 // Type or member is obsolete act.Should().Throw() - .WithMessage(""" - Assert.Fail - Assert.ReferenceEquals should not be used for Assertions. Please use Assert.AreSame & overloads instead. - """); + .WithMessage( + "Assert.Fail" + Environment.NewLine + + "Assert.ReferenceEquals should not be used for Assertions. Please use Assert.AreSame & overloads instead."); } #endif #endregion