Skip to content

Commit 13e45e2

Browse files
authored
feat: add HasScheme for Uri (#92)
This PR adds the `HasScheme` method for `Uri` objects to support verifying URI schemes in the testing framework. ### Key changes: - Implements `HasScheme()` extension method that returns a `PropertyResult.String<Uri>` for scheme verification - Adds comprehensive test coverage for both positive and negative assertion scenarios - Updates the aweXpect.Core package dependency from version 2.22.2 to 2.23.0
1 parent 6b5bb2e commit 13e45e2

5 files changed

Lines changed: 170 additions & 1 deletion

File tree

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageVersion Include="aweXpect" Version="2.25.0" />
7-
<PackageVersion Include="aweXpect.Core" Version="2.22.2" />
7+
<PackageVersion Include="aweXpect.Core" Version="2.23.0" />
88
<PackageVersion Include="aweXpect.Json" Version="1.4.0" />
99
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
1010
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using aweXpect.Core;
3+
using aweXpect.Helpers;
4+
using aweXpect.Results;
5+
6+
namespace aweXpect;
7+
8+
#nullable enable
9+
public static partial class ThatUri
10+
{
11+
/// <summary>
12+
/// Verifies that the scheme of the <see cref="Uri" /> subject…
13+
/// </summary>
14+
/// <remarks>
15+
/// <seealso cref="Uri.Scheme" />
16+
/// </remarks>
17+
public static PropertyResult.String<Uri> HasScheme(this IThat<Uri> source)
18+
=> new(source, u => u.Scheme, "scheme");
19+
}

Tests/aweXpect.Web.Api.Tests/Expected/aweXpect.Web_net8.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace aweXpect
2929
{
3030
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> DoesNotHaveDefaultPort(this aweXpect.Core.IThat<System.Uri> source) { }
3131
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> HasDefaultPort(this aweXpect.Core.IThat<System.Uri> source) { }
32+
public static aweXpect.Results.PropertyResult.String<System.Uri> HasScheme(this aweXpect.Core.IThat<System.Uri> source) { }
3233
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsAbsolute(this aweXpect.Core.IThat<System.Uri> source) { }
3334
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsFile(this aweXpect.Core.IThat<System.Uri> source) { }
3435
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsLoopback(this aweXpect.Core.IThat<System.Uri> source) { }

Tests/aweXpect.Web.Api.Tests/Expected/aweXpect.Web_netstandard2.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace aweXpect
2929
{
3030
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> DoesNotHaveDefaultPort(this aweXpect.Core.IThat<System.Uri> source) { }
3131
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> HasDefaultPort(this aweXpect.Core.IThat<System.Uri> source) { }
32+
public static aweXpect.Results.PropertyResult.String<System.Uri> HasScheme(this aweXpect.Core.IThat<System.Uri> source) { }
3233
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsAbsolute(this aweXpect.Core.IThat<System.Uri> source) { }
3334
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsFile(this aweXpect.Core.IThat<System.Uri> source) { }
3435
public static aweXpect.Results.AndOrResult<System.Uri, aweXpect.Core.IThat<System.Uri>> IsLoopback(this aweXpect.Core.IThat<System.Uri> source) { }
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
namespace aweXpect.Tests;
2+
3+
public sealed partial class ThatUri
4+
{
5+
public sealed class HasScheme
6+
{
7+
public sealed class Tests
8+
{
9+
[Fact]
10+
public async Task Containing_WhenSubjectSchemeContainsTheExpectedValue_ShouldSucceed()
11+
{
12+
Uri subject = new("https://www.awexpect.com:80");
13+
14+
async Task Act()
15+
=> await That(subject).HasScheme().Containing("http");
16+
17+
await That(Act).DoesNotThrow();
18+
}
19+
20+
[Fact]
21+
public async Task EqualTo_WhenSubjectDoesNotEqualTheExpectedScheme_ShouldFail()
22+
{
23+
Uri subject = new("https://www.awexpect.com:80");
24+
25+
async Task Act()
26+
=> await That(subject).HasScheme().EqualTo("http");
27+
28+
await That(Act).Throws<XunitException>()
29+
.WithMessage("""
30+
Expected that subject
31+
has scheme equal to "http",
32+
but it had scheme "https"
33+
""");
34+
}
35+
36+
[Fact]
37+
public async Task EqualTo_WhenSubjectEqualsExpectedScheme_ShouldSucceed()
38+
{
39+
Uri subject = new("https://www.awexpect.com:80");
40+
41+
async Task Act()
42+
=> await That(subject).HasScheme().EqualTo("https");
43+
44+
await That(Act).DoesNotThrow();
45+
}
46+
47+
[Fact]
48+
public async Task NotEqualTo_WhenSubjectDoesNotEqualTheExpectedScheme_ShouldFail()
49+
{
50+
Uri subject = new("https://www.awexpect.com:80");
51+
52+
async Task Act()
53+
=> await That(subject).HasScheme().NotEqualTo("https");
54+
55+
await That(Act).Throws<XunitException>()
56+
.WithMessage("""
57+
Expected that subject
58+
has scheme not equal to "https",
59+
but it had scheme "https"
60+
""");
61+
}
62+
63+
[Fact]
64+
public async Task NotEqualTo_WhenSubjectEqualsExpectedScheme_ShouldSucceed()
65+
{
66+
Uri subject = new("https://www.awexpect.com:80");
67+
68+
async Task Act()
69+
=> await That(subject).HasScheme().NotEqualTo("http");
70+
71+
await That(Act).DoesNotThrow();
72+
}
73+
}
74+
75+
public sealed class NegatedTests
76+
{
77+
[Fact]
78+
public async Task Containing_WhenSubjectSchemeContainsTheExpectedValue_ShouldFail()
79+
{
80+
Uri subject = new("https://www.awexpect.com:80");
81+
82+
async Task Act()
83+
=> await That(subject).DoesNotComplyWith(it => it.HasScheme().Containing("http"));
84+
85+
await That(Act).Throws<XunitException>()
86+
.WithMessage("""
87+
Expected that subject
88+
has scheme not containing "http",
89+
but it had scheme "https"
90+
""");
91+
}
92+
93+
[Fact]
94+
public async Task EqualTo_WhenSubjectDoesNotEqualTheExpectedScheme_ShouldSucceed()
95+
{
96+
Uri subject = new("https://www.awexpect.com:80");
97+
98+
async Task Act()
99+
=> await That(subject).DoesNotComplyWith(it => it.HasScheme().EqualTo("http"));
100+
101+
await That(Act).DoesNotThrow();
102+
}
103+
104+
[Fact]
105+
public async Task EqualTo_WhenSubjectEqualsExpectedScheme_ShouldFail()
106+
{
107+
Uri subject = new("https://www.awexpect.com:80");
108+
109+
async Task Act()
110+
=> await That(subject).DoesNotComplyWith(it => it.HasScheme().EqualTo("https"));
111+
112+
await That(Act).Throws<XunitException>()
113+
.WithMessage("""
114+
Expected that subject
115+
has scheme not equal to "https",
116+
but it had scheme "https"
117+
""");
118+
}
119+
120+
[Fact]
121+
public async Task NotEqualTo_WhenSubjectDoesNotEqualTheExpectedScheme_ShouldSucceed()
122+
{
123+
Uri subject = new("https://www.awexpect.com:80");
124+
125+
async Task Act()
126+
=> await That(subject).DoesNotComplyWith(it => it.HasScheme().NotEqualTo("https"));
127+
128+
await That(Act).DoesNotThrow();
129+
}
130+
131+
[Fact]
132+
public async Task NotEqualTo_WhenSubjectEqualsExpectedScheme_ShouldFail()
133+
{
134+
Uri subject = new("https://www.awexpect.com:80");
135+
136+
async Task Act()
137+
=> await That(subject).DoesNotComplyWith(it => it.HasScheme().NotEqualTo("http"));
138+
139+
await That(Act).Throws<XunitException>()
140+
.WithMessage("""
141+
Expected that subject
142+
has scheme equal to "http",
143+
but it had scheme "https"
144+
""");
145+
}
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)