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 Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="aweXpect" Version="2.21.1" />
<PackageVersion Include="aweXpect.Core" Version="2.18.0" />
<PackageVersion Include="aweXpect.Json" Version="1.3.0" />
<PackageVersion Include="aweXpect" Version="2.23.0" />
<PackageVersion Include="aweXpect.Core" Version="2.21.1" />
<PackageVersion Include="aweXpect.Json" Version="1.4.0" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Source/aweXpect.Web/ThatHttpRequestMessage.HasContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<ConstraintResult> IsMetBy(
#else
_message = await actual.Content.ReadAsStringAsync(cancellationToken);
#endif
if (options.AreConsideredEqual(_message, expected))
if (await options.AreConsideredEqual(_message, expected))
{
Outcome = Outcome.Success;
return this;
Expand Down
2 changes: 1 addition & 1 deletion Source/aweXpect.Web/ThatHttpResponseMessage.HasContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task<ConstraintResult> IsMetBy(
#else
_message = await actual.Content.ReadAsStringAsync(cancellationToken);
#endif
if (options.AreConsideredEqual(_message, expected))
if (await options.AreConsideredEqual(_message, expected))
{
Outcome = Outcome.Success;
return this;
Expand Down
8 changes: 5 additions & 3 deletions Source/aweXpect.Web/ThatHttpResponseMessage.HasContentType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using aweXpect.Core;
using aweXpect.Core.Constraints;
using aweXpect.Helpers;
Expand Down Expand Up @@ -39,11 +41,11 @@ private sealed class HasContentTypeConstraint(
string expected,
StringEqualityOptions options)
: ConstraintResult.WithNotNullValue<HttpResponseMessage>(it, grammars),
IValueConstraint<HttpResponseMessage>
IAsyncConstraint<HttpResponseMessage>
{
private string? _contentType;

public ConstraintResult IsMetBy(HttpResponseMessage? actual)
public async Task<ConstraintResult> IsMetBy(HttpResponseMessage? actual, CancellationToken cancellationToken)
{
Actual = actual;
if (actual == null)
Expand All @@ -59,7 +61,7 @@ public ConstraintResult IsMetBy(HttpResponseMessage? actual)
return this;
}

if (!options.AreConsideredEqual(_contentType, expected))
if (!await options.AreConsideredEqual(_contentType, expected))
{
expectationBuilder.AddContext(actual);
Outcome = Outcome.Failure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<ConstraintResult> IsMetBy(
{
_failures.Add($"{It} did not match the expected format because no 'type' property existed");
}
else if (expectedType != null && !typeOptions.AreConsideredEqual(type, expectedType))
else if (expectedType != null && !await typeOptions.AreConsideredEqual(type, expectedType))
{
_failures.Add(
$"{It} was type {Formatter.Format(type)} which {new StringDifference(type, expectedType)}");
Expand All @@ -101,19 +101,19 @@ public async Task<ConstraintResult> IsMetBy(
_failures.Add($"{It} had status {Formatter.Format(status)}");
}

if (!options.IsTitleConsideredEqualTo(title))
if (!await options.IsTitleConsideredEqualTo(title))
{
_failures.Add(
$"{It} had title {Formatter.Format(title)} which {new StringDifference(title, options.Title)}");
}

if (!options.IsDetailConsideredEqualTo(detail))
if (!await options.IsDetailConsideredEqualTo(detail))
{
_failures.Add(
$"{It} had detail {Formatter.Format(detail)} which {new StringDifference(detail, options.Detail)}");
}

if (!options.IsInstanceConsideredEqualTo(instance))
if (!await options.IsInstanceConsideredEqualTo(instance))
{
_failures.Add(
$"{It} had instance {Formatter.Format(instance)} which {new StringDifference(instance, options.Instance)}");
Expand Down
8 changes: 5 additions & 3 deletions Source/aweXpect.Web/Web/Results/HasHeaderValueResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using aweXpect.Core;
using aweXpect.Core.Constraints;
using aweXpect.Options;
Expand Down Expand Up @@ -88,11 +90,11 @@ private sealed class WithHeaderValueConstraint(
Func<TType, string?[]?> headerValueAccessor,
StringEqualityOptions options)
: ConstraintResult.WithValue<TType?>(grammars),
IValueConstraint<TType?>
IAsyncConstraint<TType?>
{
private string?[]? _headerValues;

public ConstraintResult IsMetBy(TType? actual)
public async Task<ConstraintResult> IsMetBy(TType? actual, CancellationToken cancellationToken)
{
Actual = actual;
if (actual is null)
Expand All @@ -109,7 +111,7 @@ public ConstraintResult IsMetBy(TType? actual)
}

string? headerValue = _headerValues[0];
Outcome = options.AreConsideredEqual(headerValue, expected) ? Outcome.Success : Outcome.Failure;
Outcome = await options.AreConsideredEqual(headerValue, expected) ? Outcome.Success : Outcome.Failure;
return this;
}

Expand Down
24 changes: 20 additions & 4 deletions Source/aweXpect.Web/Web/Results/ProblemDetailsOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using aweXpect.Options;

namespace aweXpect.Web.Results;
Expand Down Expand Up @@ -97,19 +98,34 @@ public StringEqualityOptions WithInstance(string instance)
/// <summary>
/// Checks if the <paramref name="title" /> matches the expected <see cref="Title" />.
/// </summary>
public bool IsTitleConsideredEqualTo(string? title)
#if NET8_0_OR_GREATER
public ValueTask<bool>
#else
public Task<bool>
#endif
IsTitleConsideredEqualTo(string? title)
=> _titleOptions.AreConsideredEqual(title, Title);

/// <summary>
/// Checks if the <paramref name="detail" /> matches the expected <see cref="Detail" />.
/// </summary>
public bool IsDetailConsideredEqualTo(string? detail)
#if NET8_0_OR_GREATER
public ValueTask<bool>
#else
public Task<bool>
#endif
IsDetailConsideredEqualTo(string? detail)
=> _detailOptions.AreConsideredEqual(detail, Detail);

/// <summary>
/// Checks if the <paramref name="instance" /> matches the expected <see cref="Instance" />.
/// </summary>
public bool IsInstanceConsideredEqualTo(string? instance)
#if NET8_0_OR_GREATER
public ValueTask<bool>
#else
public Task<bool>
#endif
IsInstanceConsideredEqualTo(string? instance)
=> _instanceOptions.AreConsideredEqual(instance, Instance);

/// <inheritdoc cref="object.ToString()" />
Expand All @@ -121,6 +137,6 @@ public override string ToString()
_ => $", {string
.Join(", ", _parts
.Take(_parts.Count - 1)
.Select(part => part.Invoke()))} and {_parts[^1].Invoke()}",
.Select(part => part.Invoke()))} and {_parts[^1].Invoke()}"
};
}
6 changes: 3 additions & 3 deletions Tests/aweXpect.Web.Api.Tests/Expected/aweXpect.Web_net8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ namespace aweXpect.Web.Results
public string? Instance { get; }
public int? Status { get; }
public string? Title { get; }
public bool IsDetailConsideredEqualTo(string? detail) { }
public bool IsInstanceConsideredEqualTo(string? instance) { }
public bool IsTitleConsideredEqualTo(string? title) { }
public System.Threading.Tasks.ValueTask<bool> IsDetailConsideredEqualTo(string? detail) { }
public System.Threading.Tasks.ValueTask<bool> IsInstanceConsideredEqualTo(string? instance) { }
public System.Threading.Tasks.ValueTask<bool> IsTitleConsideredEqualTo(string? title) { }
public override string ToString() { }
public aweXpect.Options.StringEqualityOptions WithDetail(string detail) { }
public aweXpect.Options.StringEqualityOptions WithInstance(string instance) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ namespace aweXpect.Web.Results
public string? Instance { get; }
public int? Status { get; }
public string? Title { get; }
public bool IsDetailConsideredEqualTo(string? detail) { }
public bool IsInstanceConsideredEqualTo(string? instance) { }
public bool IsTitleConsideredEqualTo(string? title) { }
public System.Threading.Tasks.Task<bool> IsDetailConsideredEqualTo(string? detail) { }
public System.Threading.Tasks.Task<bool> IsInstanceConsideredEqualTo(string? instance) { }
public System.Threading.Tasks.Task<bool> IsTitleConsideredEqualTo(string? title) { }
public override string ToString() { }
public aweXpect.Options.StringEqualityOptions WithDetail(string detail) { }
public aweXpect.Options.StringEqualityOptions WithInstance(string instance) { }
Expand Down
Loading