Skip to content

Commit f873ecd

Browse files
Upgrade to xUnit 3 and FsCheck 3
1 parent cd54e54 commit f873ecd

40 files changed

+2218
-2537
lines changed

Matchmaker.Tests/AsyncMatchExpressionBuilderTests.cs

Lines changed: 212 additions & 266 deletions
Large diffs are not rendered by default.

Matchmaker.Tests/AsyncMatchExpressionTests.cs

Lines changed: 220 additions & 274 deletions
Large diffs are not rendered by default.

Matchmaker.Tests/AsyncMatchStatementBuilderTests.cs

Lines changed: 158 additions & 196 deletions
Large diffs are not rendered by default.

Matchmaker.Tests/AsyncMatchStatementTests.cs

Lines changed: 156 additions & 196 deletions
Large diffs are not rendered by default.

Matchmaker.Tests/Extensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ public static bool ImpliesThat(this bool premise, bool consequence) =>
77

88
public static bool ImpliesThat(this bool premise, Func<bool> consequence) =>
99
!premise || consequence();
10+
11+
public static async Task<bool> ImpliesThatAsync(this bool premise, Func<Task<bool>> consequence) =>
12+
!premise || await consequence();
1013
}

Matchmaker.Tests/Generators.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[assembly: Properties(Arbitrary = new[] { typeof(Generators) })]
2+
13
namespace Matchmaker;
24

35
public static class Generators
@@ -85,7 +87,7 @@ private static IEnumerable<IAsyncPattern<string, string>> AsyncPatterns(string i
8587
private class ArbitraryPattern : Arbitrary<IPattern<string, string>>
8688
{
8789
public override Gen<IPattern<string, string>> Generator =>
88-
from input in Arb.Default.String().Generator
90+
from input in ArbMap.Default.ArbFor<string>().Generator
8991
from item in Gen.Elements(Patterns(input))
9092
select item;
9193
}
@@ -135,8 +137,8 @@ private class ArbitraryMatchResult : Arbitrary<MatchResult<string>>
135137
{
136138
public override Gen<MatchResult<string>> Generator =>
137139
Gen.Frequency(
138-
Tuple.Create(9, Arb.Default.String().Generator.Select(MatchResult.Success)),
139-
Tuple.Create(1, Gen.Constant(MatchResult.Failure<string>())));
140+
(9, ArbMap.Default.ArbFor<string>().Generator.Select(MatchResult.Success)),
141+
(1, Gen.Constant(MatchResult.Failure<string>())));
140142
}
141143

142144
private class ArbitraryResultBinder : Arbitrary<Func<string, MatchResult<int>>>
@@ -152,7 +154,7 @@ private class ArbitraryResultBinder : Arbitrary<Func<string, MatchResult<int>>>
152154
private class ArbitraryAsyncPattern : Arbitrary<IAsyncPattern<string, string>>
153155
{
154156
public override Gen<IAsyncPattern<string, string>> Generator =>
155-
from input in Arb.Default.String().Generator
157+
from input in ArbMap.Default.ArbFor<string>().Generator
156158
from item in Gen.Elements(AsyncPatterns(input))
157159
select item;
158160
}
@@ -193,9 +195,8 @@ private class ArbitraryAsyncMatchResult : Arbitrary<Task<MatchResult<string>>>
193195
{
194196
public override Gen<Task<MatchResult<string>>> Generator =>
195197
Gen.Frequency(
196-
Tuple.Create(9, Arb.Default.String().Generator.Select(
197-
str => Task.FromResult(MatchResult.Success(str)))),
198-
Tuple.Create(1, Gen.Constant(Task.FromResult(MatchResult.Failure<string>()))));
198+
(9, ArbMap.Default.ArbFor<string>().Generator.Select(str => Task.FromResult(MatchResult.Success(str)))),
199+
(1, Gen.Constant(Task.FromResult(MatchResult.Failure<string>()))));
199200
}
200201

201202
private class ArbitraryAsyncResultBinder : Arbitrary<Func<string, Task<MatchResult<int>>>>
@@ -211,6 +212,6 @@ private class ArbitraryAsyncResultBinder : Arbitrary<Func<string, Task<MatchResu
211212
private class ArbitraryAsyncString : Arbitrary<Task<string>>
212213
{
213214
public override Gen<Task<string>> Generator =>
214-
Arb.Default.String().Generator.Select(Task.FromResult);
215+
ArbMap.Default.ArbFor<string>().Generator.Select(Task.FromResult);
215216
}
216217
}

Matchmaker.Tests/Linq/AsAsyncTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ namespace Matchmaker.Linq;
22

33
public class AsAsyncTests
44
{
5-
[Property(Arbitrary = new[] { typeof(Generators) })]
6-
public Property AsAsyncShouldMatchSameAsPattern(IPattern<string, string> pattern, string x) =>
7-
(pattern.Match(x) == pattern.AsAsync().MatchAsync(x).Result).ToProperty();
5+
[Property]
6+
public async Task<Property> AsAsyncShouldMatchSameAsPattern(IPattern<string, string> pattern, string x) =>
7+
(pattern.Match(x) == await pattern.AsAsync().MatchAsync(x)).ToProperty();
88

9-
[Property(Arbitrary = new[] { typeof(Generators) })]
10-
public Property AsAsyncWithDescriptionShouldMatchSameAsPattern(
9+
[Property]
10+
public async Task<Property> AsAsyncWithDescriptionShouldMatchSameAsPattern(
1111
IPattern<string, string> pattern,
1212
NonNull<string> description,
1313
string x) =>
14-
(pattern.Match(x) == pattern.AsAsync(description.Get).MatchAsync(x).Result).ToProperty();
14+
(pattern.Match(x) == await pattern.AsAsync(description.Get).MatchAsync(x)).ToProperty();
1515

16-
[Property(Arbitrary = new[] { typeof(Generators) })]
16+
[Property]
1717
public Property AsAsyncShouldNeverReturnNull(IPattern<string, string> pattern) =>
1818
(pattern.AsAsync() != null).ToProperty();
1919

20-
[Property(Arbitrary = new[] { typeof(Generators) })]
20+
[Property]
2121
public Property AsAsyncWithDescriptionShouldNeverReturnNull(
2222
IPattern<string, string> pattern,
2323
NonNull<string> description) =>
2424
(pattern.AsAsync(description.Get) != null).ToProperty();
2525

26-
[Property(Arbitrary = new[] { typeof(Generators) })]
26+
[Property]
2727
public Property AsAsyncShouldHaveSameDescriptionAsPattern(IPattern<string, string> pattern) =>
2828
(pattern.Description == pattern.AsAsync().Description).ToProperty();
2929

30-
[Property(Arbitrary = new[] { typeof(Generators) })]
30+
[Property]
3131
public Property AsAsyncWithDescriptionShouldHaveSpecifiedDescription(
3232
IPattern<string, string> pattern,
3333
NonNull<string> description) =>
@@ -47,7 +47,7 @@ public void AsAsyncWithDescriptionShouldThrowIfPatternIsNull(NonNull<string> des
4747
action.Should().Throw<ArgumentNullException>();
4848
}
4949

50-
[Property(Arbitrary = new[] { typeof(Generators) })]
50+
[Property]
5151
public void AsAsyncWithDescriptionShouldThrowIfDescriptionIsNull(IPattern<string, string> pattern)
5252
{
5353
var action = () => pattern.AsAsync(null);

Matchmaker.Tests/Linq/AsyncBindTests.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,65 @@ namespace Matchmaker.Linq;
22

33
public class AsyncBindTests
44
{
5-
[Property(Arbitrary = new[] { typeof(Generators) })]
5+
[Property]
66
public Property BindPatternShouldNeverReturnNull(
77
IAsyncPattern<string, string> pattern,
88
Func<string, IAsyncPattern<string, string>> binder) =>
99
(pattern.Bind(binder) != null).ToProperty();
1010

11-
[Property(Arbitrary = new[] { typeof(Generators) })]
11+
[Property]
1212
public Property BindPatternWithDescriptionShouldNeverReturnNull(
1313
IAsyncPattern<string, string> pattern,
1414
Func<string, IAsyncPattern<string, string>> binder,
1515
NonNull<string> description) =>
1616
(pattern.Bind(binder, description.Get) != null).ToProperty();
1717

18-
[Property(Arbitrary = new[] { typeof(Generators) })]
19-
public Property BindPatternShouldMatchSameAsBinderResult(
18+
[Property]
19+
public async Task<Property> BindPatternShouldMatchSameAsBinderResult(
2020
IAsyncPattern<string, string> pattern,
2121
Func<string, IAsyncPattern<string, string>> binder,
2222
string x)
2323
{
24-
var result = pattern.MatchAsync(x);
25-
return result.Result.IsSuccessful.ImpliesThat(() =>
26-
pattern.Bind(binder).MatchAsync(x).Result == binder(result.Result.Value).MatchAsync(x).Result)
24+
var result = await pattern.MatchAsync(x);
25+
return (await result.IsSuccessful.ImpliesThatAsync(async () =>
26+
await pattern.Bind(binder).MatchAsync(x) == await binder(result.Value).MatchAsync(x)))
2727
.ToProperty();
2828
}
2929

30-
[Property(Arbitrary = new[] { typeof(Generators) })]
31-
public Property BindPatternWithDescriptionShouldMatchSameAsBinderResult(
30+
[Property]
31+
public async Task<Property> BindPatternWithDescriptionShouldMatchSameAsBinderResult(
3232
IAsyncPattern<string, string> pattern,
3333
Func<string, IAsyncPattern<string, string>> binder,
3434
string x,
3535
NonNull<string> description)
3636
{
37-
var result = pattern.MatchAsync(x);
38-
return result.Result.IsSuccessful.ImpliesThat(() =>
39-
pattern.Bind(binder, description.Get).MatchAsync(x).Result ==
40-
binder(result.Result.Value).MatchAsync(x).Result)
37+
var result = await pattern.MatchAsync(x);
38+
return (await result.IsSuccessful.ImpliesThatAsync(async () =>
39+
await pattern.Bind(binder, description.Get).MatchAsync(x) == await binder(result.Value).MatchAsync(x)))
4140
.ToProperty();
4241
}
4342

44-
[Property(Arbitrary = new[] { typeof(Generators) })]
43+
[Property]
4544
public Property BindPatternShouldHaveSameDescriptionAsPattern(
4645
IAsyncPattern<string, string> pattern,
4746
Func<string, IAsyncPattern<string, string>> binder) =>
4847
(pattern.Bind(binder).Description == pattern.Description).ToProperty();
4948

50-
[Property(Arbitrary = new[] { typeof(Generators) })]
49+
[Property]
5150
public Property BindPatternWithDescriptionShouldHaveSpecifiedDescription(
5251
IAsyncPattern<string, string> pattern,
5352
Func<string, IAsyncPattern<string, string>> binder,
5453
NonNull<string> description) =>
5554
(pattern.Bind(binder, description.Get).Description == description.Get).ToProperty();
5655

57-
[Property(Arbitrary = new[] { typeof(Generators) })]
56+
[Property]
5857
public void BindPatternShouldThrowIfPatternIsNull(Func<string, IAsyncPattern<string, string>> binder)
5958
{
6059
var action = () => ((IAsyncPattern<string, string>)null).Bind(binder);
6160
action.Should().Throw<ArgumentNullException>();
6261
}
6362

64-
[Property(Arbitrary = new[] { typeof(Generators) })]
63+
[Property]
6564
public void BindPatternWithDescriptionShouldThrowIfPatternIsNull(
6665
Func<string, IAsyncPattern<string, string>> binder,
6766
NonNull<string> description)
@@ -70,14 +69,14 @@ public void BindPatternWithDescriptionShouldThrowIfPatternIsNull(
7069
action.Should().Throw<ArgumentNullException>();
7170
}
7271

73-
[Property(Arbitrary = new[] { typeof(Generators) })]
72+
[Property]
7473
public void BindPatternShouldThrowIfBinderIsNull(IAsyncPattern<string, string> pattern)
7574
{
7675
var action = () => pattern.Bind((Func<string, IAsyncPattern<string, int>>)null);
7776
action.Should().Throw<ArgumentNullException>();
7877
}
7978

80-
[Property(Arbitrary = new[] { typeof(Generators) })]
79+
[Property]
8180
public void BindPatternWithDescriptionShouldThrowIfDescriptionIsNull(
8281
IAsyncPattern<string, string> pattern,
8382
Func<string, IAsyncPattern<string, string>> binder)

Matchmaker.Tests/Linq/AsyncCachedTests.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@ namespace Matchmaker.Linq;
22

33
public class AsyncCachedTests
44
{
5-
[Property(Arbitrary = new[] { typeof(Generators) })]
5+
[Property]
66
public Property CachedPatternShouldNeverReturnNull(IAsyncPattern<string, string> pattern) =>
77
(pattern.Cached() != null).ToProperty();
88

9-
[Property(Arbitrary = new[] { typeof(Generators) })]
9+
[Property]
1010
public Property CachedPatternWithDescriptionShouldNeverReturnNull(
1111
IAsyncPattern<string, string> pattern,
1212
NonNull<string> description) =>
1313
(pattern.Cached(description.Get) != null).ToProperty();
1414

15-
[Property(Arbitrary = new[] { typeof(Generators) })]
16-
public Property CachedPatternShouldMatchSameAsPattern(IAsyncPattern<string, string> pattern, string x) =>
17-
(pattern.Cached().MatchAsync(x).Result == pattern.MatchAsync(x).Result).ToProperty();
15+
[Property]
16+
public async Task<Property> CachedPatternShouldMatchSameAsPattern(
17+
IAsyncPattern<string, string> pattern, string x) =>
18+
(await pattern.Cached().MatchAsync(x) == await pattern.MatchAsync(x)).ToProperty();
1819

19-
[Property(Arbitrary = new[] { typeof(Generators) })]
20-
public Property CachedPatternWithDescriptionShouldMatchSameAsPattern(
20+
[Property]
21+
public async Task<Property> CachedPatternWithDescriptionShouldMatchSameAsPattern(
2122
IAsyncPattern<string, string> pattern,
2223
string x,
2324
NonNull<string> description) =>
24-
(pattern.Cached(description.Get).MatchAsync(x).Result == pattern.MatchAsync(x).Result).ToProperty();
25+
(await pattern.Cached(description.Get).MatchAsync(x) == await pattern.MatchAsync(x)).ToProperty();
2526

26-
[Property(Arbitrary = new[] { typeof(Generators) })]
27-
public Property CachedPatternShouldBeCached(string x)
27+
[Property]
28+
public async Task<Property> CachedPatternShouldBeCached(string x)
2829
{
2930
int count = 0;
3031

@@ -34,14 +35,14 @@ public Property CachedPatternShouldBeCached(string x)
3435
return Task.FromResult(true);
3536
}).Cached();
3637

37-
pattern.MatchAsync(x);
38-
pattern.MatchAsync(x);
38+
await pattern.MatchAsync(x);
39+
await pattern.MatchAsync(x);
3940

4041
return (count == 1).ToProperty();
4142
}
4243

43-
[Property(Arbitrary = new[] { typeof(Generators) })]
44-
public Property CachedPatternWithDescriptionShouldBeCached(string x, NonNull<string> description)
44+
[Property]
45+
public async Task<Property> CachedPatternWithDescriptionShouldBeCached(string x, NonNull<string> description)
4546
{
4647
int count = 0;
4748

@@ -51,17 +52,17 @@ public Property CachedPatternWithDescriptionShouldBeCached(string x, NonNull<str
5152
return Task.FromResult(true);
5253
}).Cached(description.Get);
5354

54-
pattern.MatchAsync(x);
55-
pattern.MatchAsync(x);
55+
await pattern.MatchAsync(x);
56+
await pattern.MatchAsync(x);
5657

5758
return (count == 1).ToProperty();
5859
}
5960

60-
[Property(Arbitrary = new[] { typeof(Generators) })]
61+
[Property]
6162
public Property CachedPatternShouldHaveSameDescriptionAsPattern(IAsyncPattern<string, string> pattern) =>
6263
(pattern.Cached().Description == pattern.Description).ToProperty();
6364

64-
[Property(Arbitrary = new[] { typeof(Generators) })]
65+
[Property]
6566
public Property CachedPatternWithDescriptionShouldHaveSpecifiedDescription(
6667
IAsyncPattern<string, string> pattern,
6768
NonNull<string> description) =>
@@ -74,14 +75,14 @@ public void CachedPatternShouldThrowIfPatternIsNull()
7475
action.Should().Throw<ArgumentNullException>();
7576
}
7677

77-
[Property(Arbitrary = new[] { typeof(Generators) })]
78+
[Property]
7879
public void CachedPatternWithDescriptionShouldThrowIfPatternIsNull(NonNull<string> description)
7980
{
8081
var action = () => ((IAsyncPattern<string, string>)null).Cached(description.Get);
8182
action.Should().Throw<ArgumentNullException>();
8283
}
8384

84-
[Property(Arbitrary = new[] { typeof(Generators) })]
85+
[Property]
8586
public void CachedPatternWithDescriptionShouldThrowIfDescriptionIsNull(IAsyncPattern<string, string> pattern)
8687
{
8788
var action = () => pattern.Cached(null);

0 commit comments

Comments
 (0)