Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions src/TestFramework/TestFramework/Assertions/Assert.EndsWith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,29 @@ 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);
ReportAssertFailed("Assert.EndsWith", finalMessage);
ReportAssertEndsWithFailed(expectedSuffix, value, comparisonType, message, expectedSuffixExpression, valueExpression);
Comment thread
Evangelink marked this conversation as resolved.
}
}

[DoesNotReturn]
private static void ReportAssertEndsWithFailed(string expectedSuffix, string value, StringComparison comparisonType, string? userMessage, string expectedSuffixExpression, string valueExpression)
{
string expectedText = AssertionValueRenderer.RenderValue(expectedSuffix);
string actualText = AssertionValueRenderer.RenderValue(value);
EvidenceBlock evidence = EvidenceBlock.Create()
.AddLine("expected suffix:", expectedText)
.AddLine("actual:", actualText)
.AddLine("comparison:", comparisonType.ToString());

StructuredAssertionMessage structured = new(FrameworkMessages.EndsWithFailedSummary);
structured.WithUserMessage(userMessage);
structured.WithEvidence(evidence);
structured.WithExpectedAndActual(expectedText, actualText);
structured.WithCallSiteExpression(FormatCallSiteExpression("Assert.EndsWith", expectedSuffixExpression, valueExpression, "<expectedSuffix>", "<value>"));

ReportAssertFailed(structured);
}

/// <summary>
/// Tests whether the specified string does not end with the specified unexpected suffix
/// and throws an exception if the test string ends with the
Expand Down Expand Up @@ -150,9 +167,26 @@ 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);
ReportAssertFailed("Assert.DoesNotEndWith", finalMessage);
ReportAssertDoesNotEndWithFailed(notExpectedSuffix, value, comparisonType, message, notExpectedSuffixExpression, valueExpression);
}
}

[DoesNotReturn]
private static void ReportAssertDoesNotEndWithFailed(string notExpectedSuffix, string value, StringComparison comparisonType, string? userMessage, string notExpectedSuffixExpression, string valueExpression)
{
string notExpectedText = AssertionValueRenderer.RenderValue(notExpectedSuffix);
string actualText = AssertionValueRenderer.RenderValue(value);
EvidenceBlock evidence = EvidenceBlock.Create()
.AddLine("unexpected suffix:", notExpectedText)
.AddLine("actual:", actualText)
.AddLine("comparison:", comparisonType.ToString());

StructuredAssertionMessage structured = new(FrameworkMessages.DoesNotEndWithFailedSummary);
structured.WithUserMessage(userMessage);
structured.WithEvidence(evidence);
structured.WithExpectedAndActual(notExpectedText, actualText);
structured.WithCallSiteExpression(FormatCallSiteExpression("Assert.DoesNotEndWith", notExpectedSuffixExpression, valueExpression, "<notExpectedSuffix>", "<value>"));

ReportAssertFailed(structured);
}
}
46 changes: 40 additions & 6 deletions src/TestFramework/TestFramework/Assertions/Assert.StartsWith.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,29 @@ 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);
ReportAssertFailed("Assert.StartsWith", finalMessage);
ReportAssertStartsWithFailed(expectedPrefix, value, comparisonType, message, expectedPrefixExpression, valueExpression);
Comment thread
Evangelink marked this conversation as resolved.
}
}

[DoesNotReturn]
private static void ReportAssertStartsWithFailed(string expectedPrefix, string value, StringComparison comparisonType, string? userMessage, string expectedPrefixExpression, string valueExpression)
{
string expectedText = AssertionValueRenderer.RenderValue(expectedPrefix);
string actualText = AssertionValueRenderer.RenderValue(value);
EvidenceBlock evidence = EvidenceBlock.Create()
.AddLine("expected prefix:", expectedText)
.AddLine("actual:", actualText)
.AddLine("comparison:", comparisonType.ToString());

StructuredAssertionMessage structured = new(FrameworkMessages.StartsWithFailedSummary);
structured.WithUserMessage(userMessage);
structured.WithEvidence(evidence);
structured.WithExpectedAndActual(expectedText, actualText);
structured.WithCallSiteExpression(FormatCallSiteExpression("Assert.StartsWith", expectedPrefixExpression, valueExpression, "<expectedPrefix>", "<value>"));

ReportAssertFailed(structured);
}

/// <summary>
/// Tests whether the specified string does not begin with the specified unexpected prefix
/// and throws an exception if the test string does start with the prefix.
Expand Down Expand Up @@ -148,9 +165,26 @@ 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);
ReportAssertFailed("Assert.DoesNotStartWith", finalMessage);
ReportAssertDoesNotStartWithFailed(notExpectedPrefix, value, comparisonType, message, notExpectedPrefixExpression, valueExpression);
}
}

[DoesNotReturn]
private static void ReportAssertDoesNotStartWithFailed(string notExpectedPrefix, string value, StringComparison comparisonType, string? userMessage, string notExpectedPrefixExpression, string valueExpression)
{
string notExpectedText = AssertionValueRenderer.RenderValue(notExpectedPrefix);
string actualText = AssertionValueRenderer.RenderValue(value);
EvidenceBlock evidence = EvidenceBlock.Create()
.AddLine("unexpected prefix:", notExpectedText)
.AddLine("actual:", actualText)
.AddLine("comparison:", comparisonType.ToString());

StructuredAssertionMessage structured = new(FrameworkMessages.DoesNotStartWithFailedSummary);
structured.WithUserMessage(userMessage);
structured.WithEvidence(evidence);
structured.WithExpectedAndActual(notExpectedText, actualText);
structured.WithCallSiteExpression(FormatCallSiteExpression("Assert.DoesNotStartWith", notExpectedPrefixExpression, valueExpression, "<notExpectedPrefix>", "<value>"));

ReportAssertFailed(structured);
}
}
12 changes: 0 additions & 12 deletions src/TestFramework/TestFramework/Assertions/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,6 @@ private static string BuildUserMessageForCollectionExpression(string? format, st
private static string BuildUserMessageForSubstringExpressionAndValueExpression(string? format, string substringExpression, string valueExpression)
=> BuildUserMessageForTwoExpressions(format, substringExpression, "substring", valueExpression, "value");

private static string BuildUserMessageForExpectedSuffixExpressionAndValueExpression(string? format, string expectedSuffixExpression, string valueExpression)
=> BuildUserMessageForTwoExpressions(format, expectedSuffixExpression, "expectedSuffix", valueExpression, "value");

private static string BuildUserMessageForNotExpectedSuffixExpressionAndValueExpression(string? format, string notExpectedSuffixExpression, string valueExpression)
=> BuildUserMessageForTwoExpressions(format, notExpectedSuffixExpression, "notExpectedSuffix", valueExpression, "value");

private static string BuildUserMessageForExpectedPrefixExpressionAndValueExpression(string? format, string expectedPrefixExpression, string valueExpression)
=> BuildUserMessageForTwoExpressions(format, expectedPrefixExpression, "expectedPrefix", valueExpression, "value");

private static string BuildUserMessageForNotExpectedPrefixExpressionAndValueExpression(string? format, string notExpectedPrefixExpression, string valueExpression)
=> BuildUserMessageForTwoExpressions(format, notExpectedPrefixExpression, "notExpectedPrefix", valueExpression, "value");

private static string BuildUserMessageForPatternExpressionAndValueExpression(string? format, string patternExpression, string valueExpression)
=> BuildUserMessageForTwoExpressions(format, patternExpression, "pattern", valueExpression, "value");

Expand Down
12 changes: 12 additions & 0 deletions src/TestFramework/TestFramework/Resources/FrameworkMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,16 @@ Actual: {2}</value>
<data name="IsNotNullFailedSummary" xml:space="preserve">
<value>Expected value to not be null.</value>
</data>
<data name="StartsWithFailedSummary" xml:space="preserve">
<value>Expected string to start with the specified prefix.</value>
</data>
<data name="DoesNotStartWithFailedSummary" xml:space="preserve">
<value>Expected string to not start with the specified prefix.</value>
</data>
<data name="EndsWithFailedSummary" xml:space="preserve">
<value>Expected string to end with the specified suffix.</value>
</data>
<data name="DoesNotEndWithFailedSummary" xml:space="preserve">
<value>Expected string to not end with the specified suffix.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,21 @@
<target state="translated">Řetězec „{0}“ končí řetězcem „{1}“. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotEndWithFailedSummary">
<source>Expected string to not end with the specified suffix.</source>
<target state="new">Expected string to not end with the specified suffix.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">Řetězec „{0}“ začíná řetězcem „{1}“. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFailedSummary">
<source>Expected string to not start with the specified prefix.</source>
<target state="new">Expected string to not start with the specified prefix.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataInvalidFieldLayout">
<source>Dynamic data field '{0}' should be static.</source>
<target state="translated">Dynamické datové pole {0} by mělo být statické.</target>
Expand Down Expand Up @@ -257,6 +267,11 @@ Skutečnost: {2}</target>
<target state="translated">Selhalo: {0}.</target>
<note />
</trans-unit>
<trans-unit id="EndsWithFailedSummary">
<source>Expected string to end with the specified suffix.</source>
<target state="new">Expected string to end with the specified suffix.</target>
<note />
</trans-unit>
<trans-unit id="HasCountFailMsg">
<source>Expected collection of size {1}. Actual: {2}. {0}</source>
<target state="translated">Očekávala se kolekce {1} velikosti. Skutečnost: {2} {0}</target>
Expand Down Expand Up @@ -403,6 +418,11 @@ Skutečnost: {2}</target>
<target state="translated">(objekt)</target>
<note></note>
</trans-unit>
<trans-unit id="StartsWithFailedSummary">
<source>Expected string to start with the specified prefix.</source>
<target state="new">Expected string to start with the specified prefix.</target>
<note />
</trans-unit>
<trans-unit id="UTF_FailedToGetExceptionMessage">
<source>(Failed to get the message for an exception of type {0} due to an exception.)</source>
<target state="translated">(Z důvodu výjimky se nepodařilo získat zprávu o výjimce typu {0}.)</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,21 @@
<target state="translated">Die Zeichenfolge „{0}“ endet mit der Zeichenfolge „{1}“. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotEndWithFailedSummary">
<source>Expected string to not end with the specified suffix.</source>
<target state="new">Expected string to not end with the specified suffix.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">Die Zeichenfolge „{0}“ beginnt mit der Zeichenfolge „{1}“. {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFailedSummary">
<source>Expected string to not start with the specified prefix.</source>
<target state="new">Expected string to not start with the specified prefix.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataInvalidFieldLayout">
<source>Dynamic data field '{0}' should be static.</source>
<target state="translated">Das dynamische Datenfeld „{0}“ sollte statisch sein.</target>
Expand Down Expand Up @@ -257,6 +267,11 @@ Tatsächlich: {2}</target>
<target state="translated">{0} fehlgeschlagen.</target>
<note />
</trans-unit>
<trans-unit id="EndsWithFailedSummary">
<source>Expected string to end with the specified suffix.</source>
<target state="new">Expected string to end with the specified suffix.</target>
<note />
</trans-unit>
<trans-unit id="HasCountFailMsg">
<source>Expected collection of size {1}. Actual: {2}. {0}</source>
<target state="translated">Es wurde eine Sammlung mit einer Größe {1} erwartet. Tatsächlich: {2}. {0}</target>
Expand Down Expand Up @@ -403,6 +418,11 @@ Tatsächlich: {2}</target>
<target state="translated">(Objekt)</target>
<note></note>
</trans-unit>
<trans-unit id="StartsWithFailedSummary">
<source>Expected string to start with the specified prefix.</source>
<target state="new">Expected string to start with the specified prefix.</target>
<note />
</trans-unit>
<trans-unit id="UTF_FailedToGetExceptionMessage">
<source>(Failed to get the message for an exception of type {0} due to an exception.)</source>
<target state="translated">(Fehler beim Abrufen der Meldung für eine Ausnahme vom Typ "{0}" aufgrund einer Ausnahme.)</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,21 @@
<target state="translated">La cadena "{0}" termina con la cadena "{1}". {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotEndWithFailedSummary">
<source>Expected string to not end with the specified suffix.</source>
<target state="new">Expected string to not end with the specified suffix.</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFail">
<source>String '{0}' starts with string '{1}'. {2}</source>
<target state="translated">La cadena "{0}" comienza con la cadena "{1}". {2}</target>
<note />
</trans-unit>
<trans-unit id="DoesNotStartWithFailedSummary">
<source>Expected string to not start with the specified prefix.</source>
<target state="new">Expected string to not start with the specified prefix.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataInvalidFieldLayout">
<source>Dynamic data field '{0}' should be static.</source>
<target state="translated">El campo de datos dinámico '{0}' debe ser estático.</target>
Expand Down Expand Up @@ -257,6 +267,11 @@ Real: {2}</target>
<target state="translated">{0} erróneo.</target>
<note />
</trans-unit>
<trans-unit id="EndsWithFailedSummary">
<source>Expected string to end with the specified suffix.</source>
<target state="new">Expected string to end with the specified suffix.</target>
<note />
</trans-unit>
<trans-unit id="HasCountFailMsg">
<source>Expected collection of size {1}. Actual: {2}. {0}</source>
<target state="translated">Se esperaba una colección de tamaño {1}. Real: {2}. {0}</target>
Expand Down Expand Up @@ -403,6 +418,11 @@ Real: {2}</target>
<target state="translated">(objeto)</target>
<note></note>
</trans-unit>
<trans-unit id="StartsWithFailedSummary">
<source>Expected string to start with the specified prefix.</source>
<target state="new">Expected string to start with the specified prefix.</target>
<note />
</trans-unit>
<trans-unit id="UTF_FailedToGetExceptionMessage">
<source>(Failed to get the message for an exception of type {0} due to an exception.)</source>
<target state="translated">(No se pudo obtener el mensaje para una excepción del tipo {0} debido a una excepción.)</target>
Expand Down
Loading