Skip to content
Open
557 changes: 557 additions & 0 deletions src/TestFramework/TestFramework/Assertions/Assert.ContainsAll.cs

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/TestFramework/TestFramework/Assertions/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,29 @@ internal static void ThrowAssertFailed(StructuredAssertionMessage structuredMess
return $"{assertionMethodName}({arg1}, {arg2})";
}

/// <summary>
/// Formats a call-site expression for display at the bottom of a structured assertion message,
/// using three captured expressions. Multiline (or empty/whitespace) expressions are replaced with the
/// supplied placeholders. Only when all three expressions are empty/whitespace is the entire call-site
/// line suppressed.
/// </summary>
internal static string? FormatCallSiteExpression(string assertionMethodName, string expression1, string expression2, string expression3, string placeholder1 = "<arg1>", string placeholder2 = "<arg2>", string placeholder3 = "<arg3>")
{
bool empty1 = string.IsNullOrWhiteSpace(expression1);
bool empty2 = string.IsNullOrWhiteSpace(expression2);
bool empty3 = string.IsNullOrWhiteSpace(expression3);
if (empty1 && empty2 && empty3)
{
return null;
}

string arg1 = empty1 || IsMultiline(expression1) ? NormalizeCallSitePlaceholder(placeholder1) : expression1;
string arg2 = empty2 || IsMultiline(expression2) ? NormalizeCallSitePlaceholder(placeholder2) : expression2;
string arg3 = empty3 || IsMultiline(expression3) ? NormalizeCallSitePlaceholder(placeholder3) : expression3;

return $"{assertionMethodName}({arg1}, {arg2}, {arg3})";
}

// string.Contains(char) is not available on netstandard2.0 / net462, so use IndexOf to check for newline characters.
private static bool IsMultiline(string expression)
=> expression.IndexOf('\n') >= 0 || expression.IndexOf('\r') >= 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEquivalent<T>(T? e
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEquivalent<T>(T? expected, T? actual, string? message = "", string! expectedExpression = "", string! actualExpression = "") -> void
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEquivalent<T>(T? notExpected, T? actual, bool strict, string? message = "", string! notExpectedExpression = "", string! actualExpression = "") -> void
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreNotEquivalent<T>(T? notExpected, T? actual, string? message = "", string! notExpectedExpression = "", string! actualExpression = "") -> void
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ContainsAll(System.Collections.IEnumerable? expected, System.Collections.IEnumerable? collection, string? message = "", string! expectedExpression = "", string! collectionExpression = "") -> void
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ContainsAll(System.Collections.IEnumerable? expected, System.Collections.IEnumerable? collection, System.Collections.IEqualityComparer? comparer, string? message = "", string! expectedExpression = "", string! collectionExpression = "") -> void
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ContainsAll<T>(System.Collections.Generic.IEnumerable<T>? expected, System.Collections.Generic.IEnumerable<T>? collection, string? message = "", string! expectedExpression = "", string! collectionExpression = "") -> void
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ContainsAll<T>(System.Collections.Generic.IEnumerable<T>? expected, System.Collections.Generic.IEnumerable<T>? collection, System.Collections.Generic.IEqualityComparer<T>? comparer, string? message = "", string! expectedExpression = "", string! collectionExpression = "") -> void
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.DoesNotContainAll(System.Collections.IEnumerable? expected, System.Collections.IEnumerable? collection, string? message = "", string! expectedExpression = "", string! collectionExpression = "") -> void
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.DoesNotContainAll(System.Collections.IEnumerable? expected, System.Collections.IEnumerable? collection, System.Collections.IEqualityComparer? comparer, string? message = "", string! expectedExpression = "", string! collectionExpression = "") -> void
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.DoesNotContainAll<T>(System.Collections.Generic.IEnumerable<T>? expected, System.Collections.Generic.IEnumerable<T>? collection, string? message = "", string! expectedExpression = "", string! collectionExpression = "") -> void
static Microsoft.VisualStudio.TestTools.UnitTesting.Assert.DoesNotContainAll<T>(System.Collections.Generic.IEnumerable<T>? expected, System.Collections.Generic.IEnumerable<T>? collection, System.Collections.Generic.IEqualityComparer<T>? comparer, string? message = "", string! expectedExpression = "", string! collectionExpression = "") -> void
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@ Actual: {2}</value>
<data name="DoesNotMatchRegexFailedSummary" xml:space="preserve">
<value>Expected string to not match the specified regular expression.</value>
</data>
<data name="ContainsAllFailedSummary" xml:space="preserve">
<value>Expected collection to contain all specified items.</value>
</data>
<data name="DoesNotContainAllFailedSummary" xml:space="preserve">
<value>Expected collection to not contain all specified items.</value>
</data>
<data name="ContainsSingleFailedSummary" xml:space="preserve">
<value>Expected collection to contain exactly one element.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}. {1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">Řetězec '{0}' neobsahuje řetězec '{1}'. {2}.</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">Řetězec {0} obsahuje řetězec {1}. {2}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}. {1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">Die Zeichenfolge "{0}" enthält nicht die Zeichenfolge "{1}". {2}.</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">Die Zeichenfolge „{0}“ enthält die Zeichenfolge „{1}“. {2}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}. {1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">La cadena '{0}' no contiene la cadena '{1}'. {2}.</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">La cadena '{0}' contiene la cadena '{1}'. {2}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}. {1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">La chaîne '{0}' ne contient pas la chaîne '{1}'. {2}.</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">La chaîne « {0} » contient la chaîne « {1} ». {2}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}. {1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">La stringa '{0}' non contiene la stringa '{1}'. {2}.</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">La stringa '{0}' contiene la stringa '{1}'. {2}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}。{1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">文字列 '{0}' は文字列 '{1}' を含んでいません。{2}。</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">文字列 '{0}' は文字列 '{1}' を含んでいます。{2}。</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}. {1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">'{0}' 문자열이 '{1}' 문자열을 포함하지 않습니다. {2}</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">'{0}' 문자열에 '{1}' 문자열이 포함되어 있습니다. {2}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}. {1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">Ciąg „{0}” nie zawiera ciągu „{1}”. {2}.</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">Ciąg „{0}” zawiera ciąg „{1}”. {2}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}. {1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">A cadeia de caracteres '{0}' não contém a cadeia de caracteres '{1}'. {2}.</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">A cadeia de caracteres "{0}" contém a cadeia de caracteres "{1}". {2}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}. {1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">Строка "{0}" не содержит строку "{1}". {2}.</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">Строка "{0}" не содержит строку "{1}". {2}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}. {1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">'{0}' dizesi, '{1}' dizesini içermiyor. {2}.</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">'{0}' dizesi, '{1}' dizesini içermiyor. {2}.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
<target state="translated">{0}。{1}</target>
<note />
</trans-unit>
<trans-unit id="ContainsAllFailedSummary">
<source>Expected collection to contain all specified items.</source>
<target state="new">Expected collection to contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="ContainsFail">
<source>String '{0}' does not contain string '{1}'. {2}.</source>
<target state="translated">字符串“{0}”不包含字符串“{1}”。{2}。</target>
Expand Down Expand Up @@ -348,6 +353,11 @@
<target state="new">Expected string to contain the specified substring.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainAllFailedSummary">
<source>Expected collection to not contain all specified items.</source>
<target state="new">Expected collection to not contain all specified items.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotContainFail">
<source>String '{0}' does contain string '{1}'. {2}.</source>
<target state="translated">字符串“{0}”确实包含字符串“{1}”。{2}</target>
Expand Down
Loading
Loading