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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="aweXpect" Version="2.23.0" />
<PackageVersion Include="aweXpect.Core" Version="2.21.1" />
<PackageVersion Include="aweXpect.Core" Version="2.21.2" />
<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" />
Expand Down
61 changes: 61 additions & 0 deletions Source/aweXpect.Web/ThatUri.HasDefaultPort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Text;
using aweXpect.Core;
using aweXpect.Core.Constraints;
using aweXpect.Helpers;
using aweXpect.Results;

namespace aweXpect;

#nullable enable
public static partial class ThatUri
{
/// <summary>
/// Verifies that the subject has the default port for the used scheme.
/// </summary>
/// <remarks>
/// <seealso cref="Uri.IsDefaultPort" />
/// </remarks>
public static AndOrResult<Uri, IThat<Uri>> HasDefaultPort(this IThat<Uri> source)
=> new(source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new HasDefaultPortConstraint(it, grammars)),
source);

/// <summary>
/// Verifies that the subject does not have the default port for the used scheme.
/// </summary>
/// <remarks>
/// <seealso cref="Uri.IsDefaultPort" />
/// </remarks>
public static AndOrResult<Uri, IThat<Uri>> DoesNotHaveDefaultPort(this IThat<Uri> source)
=> new(source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new HasDefaultPortConstraint(it, grammars).Invert()),
source);

private sealed class HasDefaultPortConstraint(string it, ExpectationGrammars grammars)
: ConstraintResult.WithValue<Uri>(grammars),
IValueConstraint<Uri>
{
public ConstraintResult IsMetBy(Uri actual)
{
Actual = actual;
Outcome = actual.IsDefaultPort ? Outcome.Success : Outcome.Failure;
return this;
}

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

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append(it).Append(" was ");
Formatter.Format(stringBuilder, Actual);
}

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

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> AppendNormalResult(stringBuilder, indentation);
}
}
61 changes: 61 additions & 0 deletions Source/aweXpect.Web/ThatUri.IsAbsolute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Text;
using aweXpect.Core;
using aweXpect.Core.Constraints;
using aweXpect.Helpers;
using aweXpect.Results;

namespace aweXpect;

#nullable enable
public static partial class ThatUri
{
/// <summary>
/// Verifies that the subject is an absolute URI.
/// </summary>
/// <remarks>
/// <seealso cref="Uri.IsAbsoluteUri" />
/// </remarks>
public static AndOrResult<Uri, IThat<Uri>> IsAbsolute(this IThat<Uri> source)
=> new(source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new IsAbsoluteConstraint(it, grammars)),
source);

/// <summary>
/// Verifies that the subject is not an absolute URI.
/// </summary>
/// <remarks>
/// <seealso cref="Uri.IsAbsoluteUri" />
/// </remarks>
public static AndOrResult<Uri, IThat<Uri>> IsNotAbsolute(this IThat<Uri> source)
=> new(source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new IsAbsoluteConstraint(it, grammars).Invert()),
source);

private sealed class IsAbsoluteConstraint(string it, ExpectationGrammars grammars)
: ConstraintResult.WithValue<Uri>(grammars),
IValueConstraint<Uri>
{
public ConstraintResult IsMetBy(Uri actual)
{
Actual = actual;
Outcome = actual.IsAbsoluteUri ? Outcome.Success : Outcome.Failure;
return this;
}

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

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append(it).Append(" was ");
Formatter.Format(stringBuilder, Actual);
}

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

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> AppendNormalResult(stringBuilder, indentation);
}
}
61 changes: 61 additions & 0 deletions Source/aweXpect.Web/ThatUri.IsFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Text;
using aweXpect.Core;
using aweXpect.Core.Constraints;
using aweXpect.Helpers;
using aweXpect.Results;

namespace aweXpect;

#nullable enable
public static partial class ThatUri
{
/// <summary>
/// Verifies that the subject is a file URI.
/// </summary>
/// <remarks>
/// <seealso cref="Uri.IsFile" />
/// </remarks>
public static AndOrResult<Uri, IThat<Uri>> IsFile(this IThat<Uri> source)
=> new(source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new IsFileConstraint(it, grammars)),
source);

/// <summary>
/// Verifies that the subject is not a file URI.
/// </summary>
/// <remarks>
/// <seealso cref="Uri.IsFile" />
/// </remarks>
public static AndOrResult<Uri, IThat<Uri>> IsNotFile(this IThat<Uri> source)
=> new(source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new IsFileConstraint(it, grammars).Invert()),
source);

private sealed class IsFileConstraint(string it, ExpectationGrammars grammars)
: ConstraintResult.WithValue<Uri>(grammars),
IValueConstraint<Uri>
{
public ConstraintResult IsMetBy(Uri actual)
{
Actual = actual;
Outcome = actual.IsFile ? Outcome.Success : Outcome.Failure;
return this;
}

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

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append(it).Append(" was ");
Formatter.Format(stringBuilder, Actual);
}

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

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> AppendNormalResult(stringBuilder, indentation);
}
}
61 changes: 61 additions & 0 deletions Source/aweXpect.Web/ThatUri.IsLoopback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Text;
using aweXpect.Core;
using aweXpect.Core.Constraints;
using aweXpect.Helpers;
using aweXpect.Results;

namespace aweXpect;

#nullable enable
public static partial class ThatUri
{
/// <summary>
/// Verifies that the subject references the local host.
/// </summary>
/// <remarks>
/// <seealso cref="Uri.IsLoopback" />
/// </remarks>
public static AndOrResult<Uri, IThat<Uri>> IsLoopback(this IThat<Uri> source)
=> new(source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new IsLoopbackConstraint(it, grammars)),
source);

/// <summary>
/// Verifies that the subject does not reference the local host.
/// </summary>
/// <remarks>
/// <seealso cref="Uri.IsLoopback" />
/// </remarks>
public static AndOrResult<Uri, IThat<Uri>> IsNotLoopback(this IThat<Uri> source)
=> new(source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new IsLoopbackConstraint(it, grammars).Invert()),
source);

private sealed class IsLoopbackConstraint(string it, ExpectationGrammars grammars)
: ConstraintResult.WithValue<Uri>(grammars),
IValueConstraint<Uri>
{
public ConstraintResult IsMetBy(Uri actual)
{
Actual = actual;
Outcome = actual.IsLoopback ? Outcome.Success : Outcome.Failure;
return this;
}

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

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append(it).Append(" was ");
Formatter.Format(stringBuilder, Actual);
}

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

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> AppendNormalResult(stringBuilder, indentation);
}
}
61 changes: 61 additions & 0 deletions Source/aweXpect.Web/ThatUri.IsUnc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Text;
using aweXpect.Core;
using aweXpect.Core.Constraints;
using aweXpect.Helpers;
using aweXpect.Results;

namespace aweXpect;

#nullable enable
public static partial class ThatUri
{
/// <summary>
/// Verifies that the subject is an UNC path.
/// </summary>
/// <remarks>
/// <seealso cref="Uri.IsUnc" />
/// </remarks>
public static AndOrResult<Uri, IThat<Uri>> IsUnc(this IThat<Uri> source)
=> new(source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new IsUncConstraint(it, grammars)),
source);

/// <summary>
/// Verifies that the subject is not an UNC path.
/// </summary>
/// <remarks>
/// <seealso cref="Uri.IsUnc" />
/// </remarks>
public static AndOrResult<Uri, IThat<Uri>> IsNotUnc(this IThat<Uri> source)
=> new(source.Get().ExpectationBuilder.AddConstraint((it, grammars) =>
new IsUncConstraint(it, grammars).Invert()),
source);

private sealed class IsUncConstraint(string it, ExpectationGrammars grammars)
: ConstraintResult.WithValue<Uri>(grammars),
IValueConstraint<Uri>
{
public ConstraintResult IsMetBy(Uri actual)
{
Actual = actual;
Outcome = actual.IsUnc ? Outcome.Success : Outcome.Failure;
return this;
}

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

protected override void AppendNormalResult(StringBuilder stringBuilder, string? indentation = null)
{
stringBuilder.Append(it).Append(" was ");
Formatter.Format(stringBuilder, Actual);
}

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

protected override void AppendNegatedResult(StringBuilder stringBuilder, string? indentation = null)
=> AppendNormalResult(stringBuilder, indentation);
}
}
8 changes: 8 additions & 0 deletions Source/aweXpect.Web/ThatUri.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace aweXpect;

/// <summary>
/// Expectations on <see cref="Uri" /> values.
/// </summary>
public static partial class ThatUri;
13 changes: 13 additions & 0 deletions Tests/aweXpect.Web.Api.Tests/Expected/aweXpect.Web_net8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ namespace aweXpect
public static aweXpect.Web.Results.StatusCodeResult HasStatusCode(this aweXpect.Core.IThat<System.Net.Http.HttpResponseMessage?> source) { }
public static aweXpect.Results.AndOrResult<System.Net.Http.HttpResponseMessage?, aweXpect.Core.IThat<System.Net.Http.HttpResponseMessage?>> HasStatusCode(this aweXpect.Core.IThat<System.Net.Http.HttpResponseMessage?> source, System.Net.HttpStatusCode? expected) { }
}
public static class ThatUri
{
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> DoesNotHaveDefaultPort(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> HasDefaultPort(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsAbsolute(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsFile(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsLoopback(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsNotAbsolute(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsNotFile(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsNotLoopback(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsNotUnc(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsUnc(this aweXpect.Core.IThat<System.Uri> source) { }
}
}
namespace aweXpect.Web.ContentProcessors
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ namespace aweXpect
public static aweXpect.Web.Results.StatusCodeResult HasStatusCode(this aweXpect.Core.IThat<System.Net.Http.HttpResponseMessage?> source) { }
public static aweXpect.Results.AndOrResult<System.Net.Http.HttpResponseMessage?, aweXpect.Core.IThat<System.Net.Http.HttpResponseMessage?>> HasStatusCode(this aweXpect.Core.IThat<System.Net.Http.HttpResponseMessage?> source, System.Net.HttpStatusCode? expected) { }
}
public static class ThatUri
{
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> DoesNotHaveDefaultPort(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> HasDefaultPort(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsAbsolute(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsFile(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsLoopback(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsNotAbsolute(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsNotFile(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsNotLoopback(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsNotUnc(this aweXpect.Core.IThat<System.Uri> source) { }
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsUnc(this aweXpect.Core.IThat<System.Uri> source) { }
}
}
namespace aweXpect.Web.ContentProcessors
{
Expand Down
Loading
Loading