diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs index c106e77bc5..470f8d6383 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs @@ -47,8 +47,7 @@ internal void ComputeAssertion(string assertionName, string collectionExpression { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "collection", collectionExpression) + " "); - ReportAssertCountFailed(assertionName, _expectedCount, _actualCount, _builder.ToString()); + ReportAssertCountFailed(assertionName, _expectedCount, _actualCount, _builder.ToString(), collectionExpression); } } @@ -115,8 +114,7 @@ internal void ComputeAssertion(string collectionExpression) { if (_builder is not null) { - _builder.Insert(0, string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CallerArgumentExpressionSingleParameterMessage, "collection", collectionExpression) + " "); - ReportAssertIsNotEmptyFailed(_builder.ToString()); + ReportAssertIsNotEmptyFailed(_builder.ToString(), collectionExpression); } } @@ -207,8 +205,7 @@ public static void IsNotEmpty(IEnumerable collection, string? message = "" return; } - string userMessage = BuildUserMessageForCollectionExpression(message, collectionExpression); - ReportAssertIsNotEmptyFailed(userMessage); + ReportAssertIsNotEmptyFailed(message, collectionExpression); } /// @@ -229,8 +226,7 @@ public static void IsNotEmpty(IEnumerable collection, string? message = "", [Cal return; } - string userMessage = BuildUserMessageForCollectionExpression(message, collectionExpression); - ReportAssertIsNotEmptyFailed(userMessage); + ReportAssertIsNotEmptyFailed(message, collectionExpression); } #endregion // IsNotEmpty @@ -252,7 +248,7 @@ public static void HasCount(int expected, IEnumerable collection, [Interpo #pragma warning restore IDE0060 // Remove unused parameter { TelemetryCollector.TrackAssertionCall("Assert.HasCount"); - message.ComputeAssertion("HasCount", collectionExpression); + message.ComputeAssertion(nameof(HasCount), collectionExpression); } /// @@ -267,7 +263,7 @@ public static void HasCount(int expected, IEnumerable collection, [Interpo /// Users shouldn't pass a value for this parameter. /// public static void HasCount(int expected, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") - => HasCount("HasCount", expected, collection, message, collectionExpression); + => HasCount(nameof(HasCount), expected, collection, message, collectionExpression); /// /// Tests whether the collection has the expected count/length. @@ -280,7 +276,7 @@ public static void HasCount(int expected, IEnumerable collection, string? /// Users shouldn't pass a value for this parameter. /// public static void HasCount(int expected, IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") - => HasCount("HasCount", expected, collection, message, collectionExpression); + => HasCount(nameof(HasCount), expected, collection, message, collectionExpression); #endregion // HasCount @@ -301,7 +297,7 @@ public static void IsEmpty(IEnumerable collection, [InterpolatedStringHand #pragma warning restore IDE0060 // Remove unused parameter { TelemetryCollector.TrackAssertionCall("Assert.IsEmpty"); - message.ComputeAssertion("IsEmpty", collectionExpression); + message.ComputeAssertion(nameof(IsEmpty), collectionExpression); } /// @@ -315,7 +311,7 @@ public static void IsEmpty(IEnumerable collection, [InterpolatedStringHand /// Users shouldn't pass a value for this parameter. /// public static void IsEmpty(IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") - => HasCount("IsEmpty", 0, collection, message, collectionExpression); + => HasCount(nameof(IsEmpty), 0, collection, message, collectionExpression); /// /// Tests that the collection is empty. @@ -327,7 +323,7 @@ public static void IsEmpty(IEnumerable collection, string? message = "", [ /// Users shouldn't pass a value for this parameter. /// public static void IsEmpty(IEnumerable collection, string? message = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") - => HasCount("IsEmpty", 0, collection, message, collectionExpression); + => HasCount(nameof(IsEmpty), 0, collection, message, collectionExpression); #endregion // IsEmpty @@ -343,8 +339,7 @@ private static void HasCount(string assertionName, int expected, IEnumerable< return; } - string userMessage = BuildUserMessageForCollectionExpression(message, collectionExpression); - ReportAssertCountFailed(assertionName, expected, actualCount, userMessage); + ReportAssertCountFailed(assertionName, expected, actualCount, message, collectionExpression); } private static void HasCount(string assertionName, int expected, IEnumerable collection, string? message, string collectionExpression) @@ -359,24 +354,44 @@ private static string GetTrackedAssertionName(string assertionName) }; [DoesNotReturn] - private static void ReportAssertCountFailed(string assertionName, int expectedCount, int actualCount, string userMessage) + private static void ReportAssertCountFailed(string assertionName, int expectedCount, int actualCount, string? userMessage, string collectionExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.HasCountFailMsg, - userMessage, - expectedCount, - actualCount); - ReportAssertFailed($"Assert.{assertionName}", finalMessage); + bool isEmptyAssertion = string.Equals(assertionName, nameof(IsEmpty), StringComparison.Ordinal); + string summary = isEmptyAssertion + ? FrameworkMessages.IsEmptyFailedSummary + : FrameworkMessages.HasCountFailedSummary; + + string expectedEvidenceText = expectedCount.ToString(CultureInfo.CurrentCulture); + string expectedCallSiteText = expectedCount.ToString(CultureInfo.InvariantCulture); + string actualText = actualCount.ToString(CultureInfo.CurrentCulture); + EvidenceBlock evidence = EvidenceBlock.Create() + .AddLine("expected count:", expectedEvidenceText) + .AddLine("actual count:", actualText); + + StructuredAssertionMessage structured = new(summary); + structured.WithUserMessage(userMessage); + structured.WithEvidence(evidence); + structured.WithExpectedAndActual(expectedEvidenceText, actualText); + structured.WithCallSiteExpression(isEmptyAssertion + ? FormatCallSiteExpression($"Assert.{assertionName}", collectionExpression, "") + : FormatCallSiteExpression($"Assert.{assertionName}", expectedCallSiteText, collectionExpression, "", "")); + + ReportAssertFailed(structured); } [DoesNotReturn] - private static void ReportAssertIsNotEmptyFailed(string userMessage) + private static void ReportAssertIsNotEmptyFailed(string? userMessage, string collectionExpression) { - string finalMessage = string.Format( - CultureInfo.CurrentCulture, - FrameworkMessages.IsNotEmptyFailMsg, - userMessage); - ReportAssertFailed("Assert.IsNotEmpty", finalMessage); + string actualText = 0.ToString(CultureInfo.CurrentCulture); + EvidenceBlock evidence = EvidenceBlock.Create() + .AddLine("actual count:", actualText); + + StructuredAssertionMessage structured = new(FrameworkMessages.IsNotEmptyFailedSummary); + structured.WithUserMessage(userMessage); + structured.WithEvidence(evidence); + structured.WithExpectedAndActual("> 0", actualText); + structured.WithCallSiteExpression(FormatCallSiteExpression("Assert.IsNotEmpty", collectionExpression, "")); + + ReportAssertFailed(structured); } } diff --git a/src/TestFramework/TestFramework/Assertions/Assert.cs b/src/TestFramework/TestFramework/Assertions/Assert.cs index 6a46f4a88f..25f5aab3d1 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.cs @@ -244,20 +244,6 @@ private static string FormatAssertionFailed(string assertionName, string? messag internal static string BuildUserMessage(string? format) => format ?? string.Empty; - private static string BuildUserMessageForSingleExpression(string? format, string callerArgExpression, string parameterName) - { - string userMessage = BuildUserMessage(format); - if (string.IsNullOrEmpty(callerArgExpression)) - { - return userMessage; - } - - 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) { string userMessage = BuildUserMessage(format); @@ -272,9 +258,6 @@ private static string BuildUserMessageForTwoExpressions(string? format, string c : $"{callerArgMessagePart} {userMessage}"; } - private static string BuildUserMessageForCollectionExpression(string? format, string collectionExpression) - => BuildUserMessageForSingleExpression(format, collectionExpression, "collection"); - private static string BuildUserMessageForPatternExpressionAndValueExpression(string? format, string patternExpression, string valueExpression) => BuildUserMessageForTwoExpressions(format, patternExpression, "pattern", valueExpression, "value"); diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index 9d4fdd1f69..4909169fac 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -298,9 +298,6 @@ 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} @@ -319,9 +316,6 @@ Actual: {2} Expected no items to match the predicate. {0} - - Expected collection to contain any item but it is empty. {0} - Invalid GitHub ticket URL @@ -402,6 +396,15 @@ Actual: {2} Expected value to not be null. + + Expected collection to contain a specific number of elements. + + + Expected collection to be empty. + + + Expected collection to not be empty. + Expected collection to contain exactly one element. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index 2d91e4afc7..f04f647311 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -312,9 +312,9 @@ Skutečnost: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - Očekávala se kolekce {1} velikosti. Skutečnost: {2} {0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Skutečnost: {2} Neplatná adresa URL lístku GitHubu + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. Očekávala se podmínka false. @@ -382,9 +387,9 @@ Skutečnost: {2} Expected value to be negative. - - 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 collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index bc6994fd6a..bb350d84a2 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -312,9 +312,9 @@ Tatsächlich: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - Es wurde eine Sammlung mit einer Größe {1} erwartet. Tatsächlich: {2}. {0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Tatsächlich: {2} Ungültige GitHub-Ticket-URL. + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. Es wurde erwartet, dass die Bedingung „falsch“ lautet. @@ -382,9 +387,9 @@ Tatsächlich: {2} Expected value to be negative. - - 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 collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index 07655856ec..7fd09f4bfe 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -312,9 +312,9 @@ Real: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - Se esperaba una colección de tamaño {1}. Real: {2}. {0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Real: {2} Dirección URL de vale de GitHub no válida + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. Se esperaba que la condición fuera false. @@ -382,9 +387,9 @@ Real: {2} Expected value to be negative. - - 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 collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index b910b08c9e..619c062af6 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -312,9 +312,9 @@ Réel : {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - Collection de tailles attendue {1}. Réel : {2}. {0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Réel : {2} URL de ticket GitHub non valide + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. La condition attendue doit être false. @@ -382,9 +387,9 @@ Réel : {2} Expected value to be negative. - - 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 collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index a4706cea2d..8b51dd6364 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -312,9 +312,9 @@ Effettivo: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - Prevista raccolta di dimensioni {1}. Effettivo: {2}. {0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Effettivo: {2} L'URL del ticket GitHub non è valido + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. La condizione prevista deve essere false. @@ -382,9 +387,9 @@ Effettivo: {2} Expected value to be negative. - - Expected collection to contain any item but it is empty. {0} - È previsto che la raccolta contenga qualsiasi elemento, ma è vuota. {0} + + Expected collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index 9f8d221559..899da827f5 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -312,9 +312,9 @@ Actual: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - サイズ {1} のコレクションが必要です。実際: {2}。{0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Actual: {2} GitHub チケット URL が無効です + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. 予期される条件は false です。 @@ -382,9 +387,9 @@ Actual: {2} Expected value to be negative. - - Expected collection to contain any item but it is empty. {0} - コレクションには項目が含まれている必要がありますが、空です。{0} + + Expected collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index 12c6954c61..742dcea241 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -312,9 +312,9 @@ Actual: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - {1} 크기 컬렉션이 필요합니다. 실제: {2}. {0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Actual: {2} 잘못된 GitHub 티켓 URL + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. 조건이 false여야 합니다. @@ -382,9 +387,9 @@ Actual: {2} Expected value to be negative. - - Expected collection to contain any item but it is empty. {0} - 항목을 포함할 컬렉션이 필요한데 비어 있습니다. {0} + + Expected collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index 17ae1b9d3c..9251a56f73 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -312,9 +312,9 @@ Rzeczywiste: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - Oczekiwano kolekcji rozmiaru {1}. Wartość rzeczywista: {2}. {0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Rzeczywiste: {2} Nieprawidłowy adres URL biletu usługi GitHub + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. Oczekiwano warunku o wartości false. @@ -382,9 +387,9 @@ Rzeczywiste: {2} Expected value to be negative. - - Expected collection to contain any item but it is empty. {0} - Oczekiwano, że kolekcja będzie zawierać dowolny element, ale jest pusta. {0} + + Expected collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index 598fb3b128..018ca8d290 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -312,9 +312,9 @@ Real: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - Coleção esperada de tamanho {1}. Real: {2}. {0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Real: {2} URL de tíquete do GitHub inválida + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. Condição esperada como falsa. @@ -382,9 +387,9 @@ Real: {2} Expected value to be negative. - - Expected collection to contain any item but it is empty. {0} - A coleção esperada conter qualquer item, mas ela está vazia. {0} + + Expected collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index a9796fb817..ff45fa5606 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -312,9 +312,9 @@ Actual: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - Ожидается коллекция размеров {1}. Фактически: {2}. {0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Actual: {2} Недопустимый URL-адрес билета GitHub + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. Ожидается, что условие будет ложным (false). @@ -382,9 +387,9 @@ Actual: {2} Expected value to be negative. - - Expected collection to contain any item but it is empty. {0} - Ожидается, что коллекция будет содержать любой элемент, но она пуста. {0} + + Expected collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index 1cf96925c0..22d89b08f0 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -312,9 +312,9 @@ Gerçekte olan: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - Beklenen boyut {1}. Gerçek: {2}. {0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Gerçekte olan: {2} Geçersiz GitHub anahtar URL'si + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. Koşulun yanlış olması bekleniyordu. @@ -382,9 +387,9 @@ Gerçekte olan: {2} Expected value to be negative. - - Expected collection to contain any item but it is empty. {0} - Koleksiyonun herhangi bir öğe içermesi bekleniyordu ancak boş. {0} + + Expected collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index 19197e286b..a5e03714de 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -312,9 +312,9 @@ Actual: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - 大小 {1} 的预期集合。实际: {2}。{0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Actual: {2} GitHub 票证 URL 无效 + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. 预期条件为 false。 @@ -382,9 +387,9 @@ Actual: {2} Expected value to be negative. - - Expected collection to contain any item but it is empty. {0} - 集合应包含任何项,但它为空。{0} + + Expected collection to not be empty. + Expected collection to not be empty. diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index 6876681112..24214c32db 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -312,9 +312,9 @@ Actual: {2} Expected string to end with the specified suffix. - - Expected collection of size {1}. Actual: {2}. {0} - 預期的大小集合 {1}。實際: {2}。{0} + + Expected collection to contain a specific number of elements. + Expected collection to contain a specific number of elements. @@ -327,6 +327,11 @@ Actual: {2} 無效的 GitHub 票證 URL + + Expected collection to be empty. + Expected collection to be empty. + + Expected condition to be false. 預期條件為 False。 @@ -382,9 +387,9 @@ Actual: {2} Expected value to be negative. - - Expected collection to contain any item but it is empty. {0} - 預期集合包含任何專案,但卻是空的。{0} + + Expected collection to not be empty. + Expected collection to not be empty. diff --git a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs index b9ccc46a93..d3b717e3b7 100644 --- a/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs +++ b/test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.Items.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Globalization; + using AwesomeAssertions; namespace Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests; @@ -25,7 +27,15 @@ 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( + """ + Assertion failed. Expected collection to contain a specific number of elements. + + expected count: 3 + actual count: 1 + + Assert.HasCount(3, collection) + """); } public async Task Count_InterpolatedString_WhenCountIsNotSame_ShouldFail() @@ -34,10 +44,48 @@ 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( + $$""" + Assertion failed. Expected collection to contain a specific number of elements. + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {{string.Format(null, "{0:tt}", dateTime)}}, {{string.Format(null, "{0,5:tt}", dateTime)}} + + expected count: 1 + actual count: 0 + + Assert.HasCount(1, Array.Empty()) + """); o.WasToStringCalled.Should().BeTrue(); } + public void Count_WhenCurrentCultureUsesCustomNegativeSign_ShouldUseInvariantCallSiteValue() + { + CultureInfo originalCulture = CultureInfo.CurrentCulture; + var customCulture = (CultureInfo)CultureInfo.InvariantCulture.Clone(); + customCulture.NumberFormat.NegativeSign = "−"; + + try + { + CultureInfo.CurrentCulture = customCulture; + var collection = new List(); + + Action action = () => Assert.HasCount(-1, collection); + action.Should().Throw() + .WithMessage( + """ + Assertion failed. Expected collection to contain a specific number of elements. + + expected count: −1 + actual count: 0 + + Assert.HasCount(-1, collection) + """); + } + finally + { + CultureInfo.CurrentCulture = originalCulture; + } + } + public void NotAny_WhenEmpty_ShouldPass() => Assert.IsEmpty(Array.Empty()); @@ -53,7 +101,15 @@ 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( + """ + Assertion failed. Expected collection to be empty. + + expected count: 0 + actual count: 1 + + Assert.IsEmpty(collection) + """); } public async Task NotAny_InterpolatedString_WhenNotEmpty_ShouldFail() @@ -63,7 +119,16 @@ 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( + $$""" + Assertion failed. Expected collection to be empty. + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {{string.Format(null, "{0:tt}", dateTime)}}, {{string.Format(null, "{0,5:tt}", dateTime)}} + + expected count: 0 + actual count: 1 + + Assert.IsEmpty(collection) + """); o.WasToStringCalled.Should().BeTrue(); } @@ -194,7 +259,14 @@ 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( + """ + Assertion failed. Expected collection to not be empty. + + actual count: 0 + + Assert.IsNotEmpty(Array.Empty()) + """); } public async Task Any_InterpolatedString_WhenNoItem_ShouldFail() @@ -203,7 +275,15 @@ 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( + $$""" + Assertion failed. Expected collection to not be empty. + User-provided message. DummyClassTrackingToStringCalls, DummyClassTrackingToStringCalls, Hello, DummyIFormattable.ToString(), {{string.Format(null, "{0:tt}", dateTime)}}, {{string.Format(null, "{0,5:tt}", dateTime)}} + + actual count: 0 + + Assert.IsNotEmpty(Array.Empty()) + """); o.WasToStringCalled.Should().BeTrue(); } }