Skip to content
59 changes: 35 additions & 24 deletions src/TestFramework/TestFramework/Assertions/Assert.Count.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -202,8 +200,7 @@ public static void IsNotEmpty<T>(IEnumerable<T> collection, string? message = ""
return;
}

string userMessage = BuildUserMessageForCollectionExpression(message, collectionExpression);
ReportAssertIsNotEmptyFailed(userMessage);
ReportAssertIsNotEmptyFailed(message, collectionExpression);
}

/// <summary>
Expand All @@ -222,8 +219,7 @@ public static void IsNotEmpty(IEnumerable collection, string? message = "", [Cal
return;
}

string userMessage = BuildUserMessageForCollectionExpression(message, collectionExpression);
ReportAssertIsNotEmptyFailed(userMessage);
ReportAssertIsNotEmptyFailed(message, collectionExpression);
}
#endregion // IsNotEmpty

Expand Down Expand Up @@ -326,32 +322,47 @@ private static void HasCount<T>(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)
=> HasCount(assertionName, expected, collection.Cast<object>(), message, collectionExpression);

[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);
string summary = assertionName == "IsEmpty"
? FrameworkMessages.IsEmptyFailedSummary
: FrameworkMessages.HasCountFailedSummary;
Comment thread
Evangelink marked this conversation as resolved.
Outdated

string expectedText = expectedCount.ToString(CultureInfo.CurrentCulture);
string actualText = actualCount.ToString(CultureInfo.CurrentCulture);
EvidenceBlock evidence = EvidenceBlock.Create()
.AddLine("expected count:", expectedText)
.AddLine("actual count:", actualText);

StructuredAssertionMessage structured = new(summary);
structured.WithUserMessage(userMessage);
structured.WithEvidence(evidence);
structured.WithExpectedAndActual(expectedText, actualText);
structured.WithCallSiteExpression(assertionName == "IsEmpty"
? FormatCallSiteExpression($"Assert.{assertionName}", collectionExpression, "<collection>")
: FormatCallSiteExpression($"Assert.{assertionName}", expectedText, collectionExpression, "<expected>", "<collection>"));
Comment thread
Evangelink marked this conversation as resolved.
Outdated

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);
EvidenceBlock evidence = EvidenceBlock.Create()
.AddLine("actual count:", "0");
Comment thread
Evangelink marked this conversation as resolved.
Outdated

StructuredAssertionMessage structured = new(FrameworkMessages.IsNotEmptyFailedSummary);
structured.WithUserMessage(userMessage);
structured.WithEvidence(evidence);
Comment thread
Evangelink marked this conversation as resolved.
structured.WithCallSiteExpression(FormatCallSiteExpression("Assert.IsNotEmpty", collectionExpression, "<collection>"));

ReportAssertFailed(structured);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,13 @@ Actual: {2}</value>
<data name="IsNotNullFailedSummary" xml:space="preserve">
<value>Expected value to not be null.</value>
</data>
<data name="HasCountFailedSummary" xml:space="preserve">
<value>Expected collection to contain a specific number of elements.</value>
</data>
<data name="IsEmptyFailedSummary" xml:space="preserve">
<value>Expected collection to be empty.</value>
</data>
<data name="IsNotEmptyFailedSummary" xml:space="preserve">
<value>Expected collection to not be empty.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ Skutečnost: {2}</target>
<target state="translated">Očekávala se kolekce {1} velikosti. Skutečnost: {2} {0}</target>
<note />
</trans-unit>
<trans-unit id="HasCountFailedSummary">
<source>Expected collection to contain a specific number of elements.</source>
<target state="new">Expected collection to contain a specific number of elements.</target>
<note />
</trans-unit>
<trans-unit id="InvalidAccessToTestContextProperty">
<source>The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures.</source>
<target state="translated">Vlastnost TestContext.{0} souvisí s aktuálním testem a není k dispozici během sestavení nebo používání testovacích přípravků tříd.</target>
Expand All @@ -272,6 +277,11 @@ Skutečnost: {2}</target>
<target state="translated">Neplatná adresa URL lístku GitHubu</target>
<note />
</trans-unit>
<trans-unit id="IsEmptyFailedSummary">
<source>Expected collection to be empty.</source>
<target state="new">Expected collection to be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsFalseFailedSummary">
<source>Expected condition to be false.</source>
<target state="new">Expected condition to be false.</target>
Expand Down Expand Up @@ -302,6 +312,11 @@ Skutečnost: {2}</target>
<target state="translated">Očekávalo se, že kolekce bude obsahovat libovolnou položku, ale je prázdná. {0}</target>
<note />
</trans-unit>
<trans-unit id="IsNotEmptyFailedSummary">
<source>Expected collection to not be empty.</source>
<target state="new">Expected collection to not be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsNotInstanceOfFailMsg">
<source>Wrong Type:&lt;{1}&gt;. Actual type:&lt;{2}&gt;. {0}</source>
<target state="translated">Špatný typ:&lt;{1}&gt;. Aktuální typ:&lt;{2}&gt;. {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ Tatsächlich: {2}</target>
<target state="translated">Es wurde eine Sammlung mit einer Größe {1} erwartet. Tatsächlich: {2}. {0}</target>
<note />
</trans-unit>
<trans-unit id="HasCountFailedSummary">
<source>Expected collection to contain a specific number of elements.</source>
<target state="new">Expected collection to contain a specific number of elements.</target>
<note />
</trans-unit>
<trans-unit id="InvalidAccessToTestContextProperty">
<source>The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures.</source>
<target state="translated">Die Eigenschaft „TestContext.{0}“ im Zusammenhang mit dem aktuellen Test steht während Assembly- oder Klassenfixierungen nicht zur Verfügung.</target>
Expand All @@ -272,6 +277,11 @@ Tatsächlich: {2}</target>
<target state="translated">Ungültige GitHub-Ticket-URL.</target>
<note />
</trans-unit>
<trans-unit id="IsEmptyFailedSummary">
<source>Expected collection to be empty.</source>
<target state="new">Expected collection to be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsFalseFailedSummary">
<source>Expected condition to be false.</source>
<target state="new">Expected condition to be false.</target>
Expand Down Expand Up @@ -302,6 +312,11 @@ Tatsächlich: {2}</target>
<target state="translated">Es wurde erwartet, dass die Sammlung ein beliebiges Element enthält, aber leer ist. {0}</target>
<note />
</trans-unit>
<trans-unit id="IsNotEmptyFailedSummary">
<source>Expected collection to not be empty.</source>
<target state="new">Expected collection to not be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsNotInstanceOfFailMsg">
<source>Wrong Type:&lt;{1}&gt;. Actual type:&lt;{2}&gt;. {0}</source>
<target state="translated">Falscher Typ:&lt;{1}&gt;. Tatsächlicher Typ:&lt;{2}&gt;. {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ Real: {2}</target>
<target state="translated">Se esperaba una colección de tamaño {1}. Real: {2}. {0}</target>
<note />
</trans-unit>
<trans-unit id="HasCountFailedSummary">
<source>Expected collection to contain a specific number of elements.</source>
<target state="new">Expected collection to contain a specific number of elements.</target>
<note />
</trans-unit>
<trans-unit id="InvalidAccessToTestContextProperty">
<source>The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures.</source>
<target state="translated">La propiedad "TestContext.{0}" está relacionado con la prueba actual y no está disponible durante los accesorios de ensamblado o clase.</target>
Expand All @@ -272,6 +277,11 @@ Real: {2}</target>
<target state="translated">Dirección URL de vale de GitHub no válida</target>
<note />
</trans-unit>
<trans-unit id="IsEmptyFailedSummary">
<source>Expected collection to be empty.</source>
<target state="new">Expected collection to be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsFalseFailedSummary">
<source>Expected condition to be false.</source>
<target state="new">Expected condition to be false.</target>
Expand Down Expand Up @@ -302,6 +312,11 @@ Real: {2}</target>
<target state="translated">Se esperaba que la colección contenga cualquier elemento, pero está vacía. {0}</target>
<note />
</trans-unit>
<trans-unit id="IsNotEmptyFailedSummary">
<source>Expected collection to not be empty.</source>
<target state="new">Expected collection to not be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsNotInstanceOfFailMsg">
<source>Wrong Type:&lt;{1}&gt;. Actual type:&lt;{2}&gt;. {0}</source>
<target state="translated">Tipo incorrecto:&lt;{1}&gt;. Tipo actual:&lt;{2}&gt;. {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ Réel : {2}</target>
<target state="translated">Collection de tailles attendue {1}. Réel : {2}. {0}</target>
<note />
</trans-unit>
<trans-unit id="HasCountFailedSummary">
<source>Expected collection to contain a specific number of elements.</source>
<target state="new">Expected collection to contain a specific number of elements.</target>
<note />
</trans-unit>
<trans-unit id="InvalidAccessToTestContextProperty">
<source>The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures.</source>
<target state="translated">La propriété « TestContext.{0} », liée au test en cours, n’est pas disponible pendant les fixtures d’assembly ou de classe.</target>
Expand All @@ -272,6 +277,11 @@ Réel : {2}</target>
<target state="translated">URL de ticket GitHub non valide</target>
<note />
</trans-unit>
<trans-unit id="IsEmptyFailedSummary">
<source>Expected collection to be empty.</source>
<target state="new">Expected collection to be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsFalseFailedSummary">
<source>Expected condition to be false.</source>
<target state="new">Expected condition to be false.</target>
Expand Down Expand Up @@ -302,6 +312,11 @@ Réel : {2}</target>
<target state="translated">La collection doit contenir n’importe quel élément, mais elle est vide. {0}</target>
<note />
</trans-unit>
<trans-unit id="IsNotEmptyFailedSummary">
<source>Expected collection to not be empty.</source>
<target state="new">Expected collection to not be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsNotInstanceOfFailMsg">
<source>Wrong Type:&lt;{1}&gt;. Actual type:&lt;{2}&gt;. {0}</source>
<target state="translated">Type incorrect : &lt;{1}&gt;, Type réel : &lt;{2}&gt;. {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ Effettivo: {2}</target>
<target state="translated">Prevista raccolta di dimensioni {1}. Effettivo: {2}. {0}</target>
<note />
</trans-unit>
<trans-unit id="HasCountFailedSummary">
<source>Expected collection to contain a specific number of elements.</source>
<target state="new">Expected collection to contain a specific number of elements.</target>
<note />
</trans-unit>
<trans-unit id="InvalidAccessToTestContextProperty">
<source>The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures.</source>
<target state="translated">La proprietà 'TestContext.{0}' relativa al test corrente non è disponibile durante le fixture di assembly o classe.</target>
Expand All @@ -272,6 +277,11 @@ Effettivo: {2}</target>
<target state="translated">L'URL del ticket GitHub non è valido</target>
<note />
</trans-unit>
<trans-unit id="IsEmptyFailedSummary">
<source>Expected collection to be empty.</source>
<target state="new">Expected collection to be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsFalseFailedSummary">
<source>Expected condition to be false.</source>
<target state="new">Expected condition to be false.</target>
Expand Down Expand Up @@ -302,6 +312,11 @@ Effettivo: {2}</target>
<target state="translated">È previsto che la raccolta contenga qualsiasi elemento, ma è vuota. {0}</target>
<note />
</trans-unit>
<trans-unit id="IsNotEmptyFailedSummary">
<source>Expected collection to not be empty.</source>
<target state="new">Expected collection to not be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsNotInstanceOfFailMsg">
<source>Wrong Type:&lt;{1}&gt;. Actual type:&lt;{2}&gt;. {0}</source>
<target state="translated">Tipo errato:&lt;{1}&gt;. Tipo effettivo:&lt;{2}&gt;. {0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ Actual: {2}</source>
<target state="translated">サイズ {1} のコレクションが必要です。実際: {2}。{0}</target>
<note />
</trans-unit>
<trans-unit id="HasCountFailedSummary">
<source>Expected collection to contain a specific number of elements.</source>
<target state="new">Expected collection to contain a specific number of elements.</target>
<note />
</trans-unit>
<trans-unit id="InvalidAccessToTestContextProperty">
<source>The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures.</source>
<target state="translated">プロパティ 'TestContext.{0}' は現在のテストに関連しており、アセンブリまたはクラス フィクスチャの間は使用できません。</target>
Expand All @@ -272,6 +277,11 @@ Actual: {2}</source>
<target state="translated">GitHub チケット URL が無効です</target>
<note />
</trans-unit>
<trans-unit id="IsEmptyFailedSummary">
<source>Expected collection to be empty.</source>
<target state="new">Expected collection to be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsFalseFailedSummary">
<source>Expected condition to be false.</source>
<target state="new">Expected condition to be false.</target>
Expand Down Expand Up @@ -302,6 +312,11 @@ Actual: {2}</source>
<target state="translated">コレクションには項目が含まれている必要がありますが、空です。{0}</target>
<note />
</trans-unit>
<trans-unit id="IsNotEmptyFailedSummary">
<source>Expected collection to not be empty.</source>
<target state="new">Expected collection to not be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsNotInstanceOfFailMsg">
<source>Wrong Type:&lt;{1}&gt;. Actual type:&lt;{2}&gt;. {0}</source>
<target state="translated">正しくない型は &lt;{1}&gt; であり、実際の型は &lt;{2}&gt; です。{0}</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ Actual: {2}</source>
<target state="translated">{1} 크기 컬렉션이 필요합니다. 실제: {2}. {0}</target>
<note />
</trans-unit>
<trans-unit id="HasCountFailedSummary">
<source>Expected collection to contain a specific number of elements.</source>
<target state="new">Expected collection to contain a specific number of elements.</target>
<note />
</trans-unit>
<trans-unit id="InvalidAccessToTestContextProperty">
<source>The property 'TestContext.{0}' is related to current test is not available during assembly or class fixtures.</source>
<target state="translated">현재 테스트와 관련된 'TestContext.{0}' 속성은 어셈블리나 클래스 픽스처 실행 중에는 사용할 수 없습니다.</target>
Expand All @@ -272,6 +277,11 @@ Actual: {2}</source>
<target state="translated">잘못된 GitHub 티켓 URL</target>
<note />
</trans-unit>
<trans-unit id="IsEmptyFailedSummary">
<source>Expected collection to be empty.</source>
<target state="new">Expected collection to be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsFalseFailedSummary">
<source>Expected condition to be false.</source>
<target state="new">Expected condition to be false.</target>
Expand Down Expand Up @@ -302,6 +312,11 @@ Actual: {2}</source>
<target state="translated">항목을 포함할 컬렉션이 필요한데 비어 있습니다. {0}</target>
<note />
</trans-unit>
<trans-unit id="IsNotEmptyFailedSummary">
<source>Expected collection to not be empty.</source>
<target state="new">Expected collection to not be empty.</target>
<note />
</trans-unit>
<trans-unit id="IsNotInstanceOfFailMsg">
<source>Wrong Type:&lt;{1}&gt;. Actual type:&lt;{2}&gt;. {0}</source>
<target state="translated">잘못된 형식: &lt;{1}&gt;, 실제 형식: &lt;{2}&gt;. {0}</target>
Expand Down
Loading
Loading