Skip to content

Commit 88d27b7

Browse files
committed
Address review comment
1 parent d63d12d commit 88d27b7

17 files changed

+73
-53
lines changed

src/TestFramework/TestFramework/Assertions/CollectionAssert.cs

+15-8
Original file line numberDiff line numberDiff line change
@@ -1158,8 +1158,7 @@ public static void AreEqual(ICollection? expected, ICollection? actual, [StringS
11581158
string reason = string.Empty;
11591159
if (!AreCollectionsEqual(expected, actual, new ObjectComparer(), ref reason))
11601160
{
1161-
string userMessage = Assert.BuildUserMessage(message, parameters);
1162-
string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CollectionEqualReason, userMessage, reason);
1161+
string finalMessage = ConstructFinalMessage(reason, message, parameters);
11631162
Assert.ThrowAssertFailed("CollectionAssert.AreEqual", finalMessage);
11641163
}
11651164
}
@@ -1243,8 +1242,7 @@ public static void AreNotEqual(ICollection? notExpected, ICollection? actual, [S
12431242
string reason = string.Empty;
12441243
if (AreCollectionsEqual(notExpected, actual, new ObjectComparer(), ref reason))
12451244
{
1246-
string userMessage = Assert.BuildUserMessage(message, parameters);
1247-
string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CollectionEqualReason, userMessage, reason);
1245+
string finalMessage = ConstructFinalMessage(reason, message, parameters);
12481246
Assert.ThrowAssertFailed("CollectionAssert.AreNotEqual", finalMessage);
12491247
}
12501248
}
@@ -1335,8 +1333,7 @@ public static void AreEqual(ICollection? expected, ICollection? actual, [NotNull
13351333
string reason = string.Empty;
13361334
if (!AreCollectionsEqual(expected, actual, comparer, ref reason))
13371335
{
1338-
string userMessage = Assert.BuildUserMessage(message, parameters);
1339-
string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CollectionEqualReason, userMessage, reason);
1336+
string finalMessage = ConstructFinalMessage(reason, message, parameters);
13401337
Assert.ThrowAssertFailed("CollectionAssert.AreEqual", finalMessage);
13411338
}
13421339
}
@@ -1427,8 +1424,7 @@ public static void AreNotEqual(ICollection? notExpected, ICollection? actual, [N
14271424
string reason = string.Empty;
14281425
if (AreCollectionsEqual(notExpected, actual, comparer, ref reason))
14291426
{
1430-
string userMessage = Assert.BuildUserMessage(message, parameters);
1431-
string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CollectionEqualReason, userMessage, reason);
1427+
string finalMessage = ConstructFinalMessage(reason, message, parameters);
14321428
Assert.ThrowAssertFailed("CollectionAssert.AreNotEqual", finalMessage);
14331429
}
14341430
}
@@ -1674,6 +1670,17 @@ private static bool CompareIEnumerable(IEnumerable? expected, IEnumerable? actua
16741670
return true;
16751671
}
16761672

1673+
private static string ConstructFinalMessage(
1674+
string reason,
1675+
[StringSyntax(StringSyntaxAttribute.CompositeFormat)] string? message,
1676+
params object?[]? parameters)
1677+
{
1678+
string userMessage = Assert.BuildUserMessage(message, parameters);
1679+
return userMessage.Length == 0
1680+
? reason
1681+
: string.Format(CultureInfo.CurrentCulture, FrameworkMessages.CollectionEqualReason, userMessage, reason);
1682+
}
1683+
16771684
/// <summary>
16781685
/// compares the objects using object.Equals.
16791686
/// </summary>

src/TestFramework/TestFramework/Resources/FrameworkMessages.Designer.cs

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TestFramework/TestFramework/Resources/FrameworkMessages.resx

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
<value>Both collections contain the same elements. {0}</value>
161161
</data>
162162
<data name="CollectionEqualReason" xml:space="preserve">
163-
<value>{0}({1})</value>
163+
<value>{0}. {1}</value>
164164
</data>
165165
<data name="ContainsFail" xml:space="preserve">
166166
<value>String '{0}' does not contain string '{1}'. {2}.</value>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<note></note>
7474
</trans-unit>
7575
<trans-unit id="CollectionEqualReason">
76-
<source>{0}({1})</source>
77-
<target state="translated">{0}({1})</target>
78-
<note></note>
76+
<source>{0}. {1}</source>
77+
<target state="needs-review-translation">{0}({1})</target>
78+
<note />
7979
</trans-unit>
8080
<trans-unit id="ContainsFail">
8181
<source>String '{0}' does not contain string '{1}'. {2}.</source>

test/UnitTests/TestFramework.UnitTests/Assertions/CollectionAssertTests.cs

+14-3
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,25 @@ public void CollectionAssertAreNotEquivalent_FailsWithTwoNullsAndComparer_WithMe
465465
Verify(ex.Message.Contains("message"));
466466
}
467467

468-
public void CollectionAssertAreEqual_FailsWithGoodMessage()
468+
public void CollectionAssertAreEqualWithoutUserMessage_FailsWithGoodMessage()
469469
{
470470
Exception ex = VerifyThrows(() => CollectionAssert.AreEqual(new[] { 1, 2, 3 }, new[] { 1, 5, 3 }));
471471
Assert.AreEqual(
472472
"""
473-
CollectionAssert.AreEqual failed. (Element at index 1 do not match.
473+
CollectionAssert.AreEqual failed. Element at index 1 do not match.
474474
Expected: 2
475-
Actual: 5)
475+
Actual: 5
476+
""", ex.Message);
477+
}
478+
479+
public void CollectionAssertAreEqualWithUserMessage_FailsWithGoodMessage()
480+
{
481+
Exception ex = VerifyThrows(() => CollectionAssert.AreEqual(new[] { 1, 2, 3 }, new[] { 1, 5, 3 }, "User-provided message"));
482+
Assert.AreEqual(
483+
"""
484+
CollectionAssert.AreEqual failed. User-provided message. Element at index 1 do not match.
485+
Expected: 2
486+
Actual: 5
476487
""", ex.Message);
477488
}
478489

0 commit comments

Comments
 (0)