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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ await Expect.That(request).HasHeader("Cache-Control").WithValue("max-age=0");

```text title="Failure message"
Expected that request
has a `Cache-Control` header whose value is equal to "max-age=0",
but the value was "no-cache", which differs at index 0:
has a "Cache-Control" header whose value is equal to "max-age=0",
but it had header value "no-cache", which differs at index 0:
↓ (actual)
"no-cache"
"max-age=0"
Expand Down Expand Up @@ -233,7 +233,7 @@ await Expect.That(response).HasContentType("text/plain");
```text title="Failure message"
Expected that response
has a `Content-Type` header equal to "text/plain",
but it was "application/json", which differs at index 0:
but it had content type "application/json", which differs at index 0:
↓ (actual)
"application/json"
"text/plain"
Expand Down
13 changes: 13 additions & 0 deletions Source/aweXpect.Web/Helpers/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,17 @@ public static void ThrowIfNull(object? value, string paramName)
throw Tracing.WriteException(new ArgumentNullException(paramName, $"The '{paramName}' cannot be null."));
}
}

/// <summary>
/// Rejects the <paramref name="option" /> when it <paramref name="isAlreadySpecified" />, because the later
/// value would silently replace the earlier one.
/// </summary>
public static void ThrowIfOptionIsAlreadySpecified(bool isAlreadySpecified, string option)
{
if (isAlreadySpecified)
{
throw Tracing.WriteException(new InvalidOperationException(
$"{option} cannot be specified more than once."));
}
}
}
6 changes: 3 additions & 3 deletions Source/aweXpect.Web/ThatHttpRequestMessage.HasContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public async ValueTask<ConstraintResult> IsMetBy(
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("has a string content ")
=> stringBuilder.Append(Grammars.Verb("has a string content ", "have a string content "))
.Append(options.GetExpectation(expected, ExpectationGrammars.None));

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
Expand All @@ -104,12 +104,12 @@ protected override void AppendNormalResult(StringBuilder stringBuilder, string?
}
else
{
stringBuilder.Append(options.GetExtendedFailure(It, Grammars, _message, expected));
stringBuilder.Append(options.GetExtendedMemberFailure(It, "string content", Grammars, _message, expected));
}
}

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("does not have a string content ")
=> stringBuilder.Append(Grammars.Verb("does not have a string content ", "do not have a string content "))
.Append(options.GetExpectation(expected, ExpectationGrammars.None));

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
Expand Down
19 changes: 14 additions & 5 deletions Source/aweXpect.Web/ThatHttpRequestMessage.HasHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,28 @@ public ConstraintResult IsMetBy(HttpRequestMessage? actual)
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("has ").Append(expected.IndefiniteArticleForHeader()).Append(" `").Append(expected)
.Append("` header");
{
stringBuilder.Append(Grammars.Verb("has ", "have ")).Append(expected.IndefiniteArticleForHeader()).Append(' ');
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" header");
}

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append(It).Append(" did not contain the expected header");

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("does not have ").Append(expected.IndefiniteArticleForHeader()).Append(" `")
.Append(expected).Append("` header");
{
stringBuilder.Append(Grammars.Verb("does not have ", "do not have "))
.Append(expected.IndefiniteArticleForHeader()).Append(' ');
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" header");
}

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append(It).Append(" did contain the `").Append(expected).Append("` header: ");
stringBuilder.Append(It).Append(" did contain the ");
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" header: ");
Formatter.Format(stringBuilder, _foundHeader);
}
}
Expand Down
12 changes: 10 additions & 2 deletions Source/aweXpect.Web/ThatHttpRequestMessage.HasMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public override string ToString()
=> $"has {Article} {expected} method";

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("has ").Append(Article).Append(' ').Append(expected).Append(" method");
{
stringBuilder.Append(Grammars.Verb("has ", "have ")).Append(Article).Append(' ');
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" method");
}

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
Expand All @@ -66,7 +70,11 @@ protected override void AppendNormalResult(StringBuilder stringBuilder, string?
}

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("does not have ").Append(Article).Append(' ').Append(expected).Append(" method");
{
stringBuilder.Append(Grammars.Verb("does not have ", "do not have ")).Append(Article).Append(' ');
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" method");
}

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append(It).Append(" had");
Expand Down
16 changes: 6 additions & 10 deletions Source/aweXpect.Web/ThatHttpRequestMessage.HasRequestUri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private sealed class HasRequestUriConstraint(
: ConstraintResult.WithNotNullValue<HttpRequestMessage>(it, grammars),
IValueConstraint<HttpRequestMessage>
{
private readonly StringEqualityOptions _options = new StringEqualityOptions(nameof(expected)).IgnoringCase();
private string? _requestUri;

public ConstraintResult IsMetBy(HttpRequestMessage? actual)
Expand All @@ -81,20 +82,15 @@ public ConstraintResult IsMetBy(HttpRequestMessage? actual)
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append("has a request URI equal to ");
Formatter.Format(stringBuilder, expected);
}
=> stringBuilder.Append(Grammars.Verb("has a request URI ", "have a request URI "))
.Append(_options.GetExpectation(expected, ExpectationGrammars.None));

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append(new StringEqualityOptions(nameof(expected)).IgnoringCase()
.GetExtendedFailure(It, Grammars, _requestUri, expected));
=> stringBuilder.Append(_options.GetExtendedMemberFailure(It, "request URI", Grammars, _requestUri, expected));

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append("does not have a request URI equal to ");
Formatter.Format(stringBuilder, expected);
}
=> stringBuilder.Append(Grammars.Verb("does not have a request URI ", "do not have a request URI "))
.Append(_options.GetExpectation(expected, ExpectationGrammars.None));

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append(It).Append(" had");
Expand Down
6 changes: 3 additions & 3 deletions Source/aweXpect.Web/ThatHttpResponseMessage.HasContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async ValueTask<ConstraintResult> IsMetBy(
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("has a string content ")
=> stringBuilder.Append(Grammars.Verb("has a string content ", "have a string content "))
.Append(options.GetExpectation(expected, ExpectationGrammars.None));

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
Expand All @@ -98,12 +98,12 @@ protected override void AppendNormalResult(StringBuilder stringBuilder, string?
}
else
{
stringBuilder.Append(options.GetExtendedFailure(It, Grammars, _message, expected));
stringBuilder.Append(options.GetExtendedMemberFailure(It, "string content", Grammars, _message, expected));
}
}

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("does not have a string content ")
=> stringBuilder.Append(Grammars.Verb("does not have a string content ", "do not have a string content "))
.Append(options.GetExpectation(expected, ExpectationGrammars.None));

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
Expand Down
6 changes: 3 additions & 3 deletions Source/aweXpect.Web/ThatHttpResponseMessage.HasContentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async ValueTask<ConstraintResult> IsMetBy(HttpResponseMessage? actual, Ca
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("has a `Content-Type` header ")
=> stringBuilder.Append(Grammars.Verb("has a `Content-Type` header ", "have a `Content-Type` header "))
.Append(options.GetExpectation(expected, Grammars));

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
Expand All @@ -83,12 +83,12 @@ protected override void AppendNormalResult(StringBuilder stringBuilder, string?
}
else
{
stringBuilder.Append(options.GetExtendedFailure(It, Grammars, _contentType, expected));
stringBuilder.Append(options.GetExtendedMemberFailure(It, "content type", Grammars, _contentType, expected));
}
}

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("does not have a `Content-Type` header ")
=> stringBuilder.Append(Grammars.Verb("does not have a `Content-Type` header ", "do not have a `Content-Type` header "))
.Append(options.GetExpectation(expected, Grammars.Negate()));

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
Expand Down
19 changes: 14 additions & 5 deletions Source/aweXpect.Web/ThatHttpResponseMessage.HasHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,28 @@ public ConstraintResult IsMetBy(HttpResponseMessage? actual)
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("has ").Append(expected.IndefiniteArticleForHeader()).Append(" `").Append(expected)
.Append("` header");
{
stringBuilder.Append(Grammars.Verb("has ", "have ")).Append(expected.IndefiniteArticleForHeader()).Append(' ');
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" header");
}

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append(It).Append(" did not contain the expected header");

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("does not have ").Append(expected.IndefiniteArticleForHeader()).Append(" `")
.Append(expected).Append("` header");
{
stringBuilder.Append(Grammars.Verb("does not have ", "do not have "))
.Append(expected.IndefiniteArticleForHeader()).Append(' ');
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" header");
}

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append(It).Append(" did contain the `").Append(expected).Append("` header: ");
stringBuilder.Append(It).Append(" did contain the ");
Formatter.Format(stringBuilder, expected);
stringBuilder.Append(" header: ");
Formatter.Format(stringBuilder, _foundHeader);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,14 @@ private static string DescribeKind(JsonValueKind kind)

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append(Grammars.Verb("has a ProblemDetails content with ", "have a ProblemDetails content with "));
if (expectedType is null)
{
stringBuilder.Append("has a ProblemDetails content with any type");
stringBuilder.Append("any type");
}
else
{
stringBuilder.Append("has a ProblemDetails content with type ");
stringBuilder.Append("type ");
Formatter.Format(stringBuilder, expectedType);
stringBuilder.Append(typeOptions);
}
Expand All @@ -240,13 +241,10 @@ private void AppendParseError(StringBuilder stringBuilder)

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
{
if (expectedType is null)
{
stringBuilder.Append("does not have a ProblemDetails content");
}
else
stringBuilder.Append(Grammars.Verb("does not have a ProblemDetails content", "do not have a ProblemDetails content"));
if (expectedType is not null)
{
stringBuilder.Append("does not have a ProblemDetails content with type ");
stringBuilder.Append(" with type ");
Formatter.Format(stringBuilder, expectedType);
stringBuilder.Append(typeOptions);
}
Expand Down
3 changes: 1 addition & 2 deletions Source/aweXpect.Web/ThatHttpResponseMessage.HasStatusCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ public static StatusCodeResult HasStatusCode(this IThat<HttpResponseMessage?> so
expected,
m => m.StatusCode,
(a, e) => a.Equals(e),
$"has status code {Formatter.Format(expected)}",
$"does not have status code {Formatter.Format(expected)}")), source);
$"status code {Formatter.Format(expected)}")), source);
}
4 changes: 2 additions & 2 deletions Source/aweXpect.Web/ThatUri.HasDefaultPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ConstraintResult IsMetBy(Uri? actual)
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("has the default port for the used scheme");
=> stringBuilder.Append(Grammars.Verb("has ", "have ")).Append("the default port for the used scheme");

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
Expand All @@ -55,7 +55,7 @@ protected override void AppendNormalResult(StringBuilder stringBuilder, string?
}

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("does not have the default port for the used scheme");
=> stringBuilder.Append(Grammars.Verb("does not have ", "do not have ")).Append("the default port for the used scheme");

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> AppendNormalResult(stringBuilder, indentation);
Expand Down
4 changes: 2 additions & 2 deletions Source/aweXpect.Web/ThatUri.IsAbsolute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ConstraintResult IsMetBy(Uri? actual)
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("is an absolute URI");
=> stringBuilder.Append(Grammars.Verb("is an absolute URI", "are absolute URIs"));

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
Expand All @@ -55,7 +55,7 @@ protected override void AppendNormalResult(StringBuilder stringBuilder, string?
}

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("is not an absolute URI");
=> stringBuilder.Append(Grammars.Verb("is not an absolute URI", "are not absolute URIs"));

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> AppendNormalResult(stringBuilder, indentation);
Expand Down
4 changes: 2 additions & 2 deletions Source/aweXpect.Web/ThatUri.IsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ConstraintResult IsMetBy(Uri? actual)
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("is a file URI");
=> stringBuilder.Append(Grammars.Verb("is a file URI", "are file URIs"));

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
Expand All @@ -55,7 +55,7 @@ protected override void AppendNormalResult(StringBuilder stringBuilder, string?
}

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("is not a file URI");
=> stringBuilder.Append(Grammars.Verb("is not a file URI", "are not file URIs"));

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> AppendNormalResult(stringBuilder, indentation);
Expand Down
4 changes: 2 additions & 2 deletions Source/aweXpect.Web/ThatUri.IsLoopback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ConstraintResult IsMetBy(Uri? actual)
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("references the local host");
=> stringBuilder.Append(Grammars.Verb("references ", "reference ")).Append("the local host");

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
Expand All @@ -55,7 +55,7 @@ protected override void AppendNormalResult(StringBuilder stringBuilder, string?
}

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("does not reference the local host");
=> stringBuilder.Append(Grammars.Verb("does not ", "do not ")).Append("reference the local host");

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> AppendNormalResult(stringBuilder, indentation);
Expand Down
4 changes: 2 additions & 2 deletions Source/aweXpect.Web/ThatUri.IsUnc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ConstraintResult IsMetBy(Uri? actual)
}

protected override void AppendNormalExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("is an UNC path");
=> stringBuilder.Append(Grammars.Verb("is an UNC path", "are UNC paths"));

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
Expand All @@ -55,7 +55,7 @@ protected override void AppendNormalResult(StringBuilder stringBuilder, string?
}

protected override void AppendNegatedExpectation(StringBuilder stringBuilder, string? indentation = null)
=> stringBuilder.Append("is not an UNC path");
=> stringBuilder.Append(Grammars.Verb("is not an UNC path", "are not UNC paths"));

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> AppendNormalResult(stringBuilder, indentation);
Expand Down
Loading
Loading