Skip to content

Commit 449afd7

Browse files
authored
docs: document missing features (#106)
This pull request updates the `README.md` to document new verification features and clarify usage details for web extensions and JSON content matching. The most important changes are grouped below: ### Verification API Documentation Improvements * Added documentation for the new `Between(...).And(...Times())` verification method, allowing users to assert that a method was called between a minimum and maximum number of times. * Clarified that `Within` and `WithCancellation` are available on `AtLeast*`, `Once`, `Twice`, `Exactly`, and `Between`, but not on `Never` or `AtMost*` verifications. ### Web Extensions Requirements * Noted that web extensions require .NET 8.0 or later. ### JSON Content Matching Enhancements * Documented that, by default, additional properties in actual JSON are ignored during HTTP request verification, and introduced the `IgnoringAdditionalProperties(false)` option for requiring an exact match. Provided a code example demonstrating this stricter matching.
1 parent 441181f commit 449afd7

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,27 @@ Verify that a method was called a specific number of times:
1818
var sut = IMyService.CreateMock();
1919
sut.MyMethod();
2020

21-
await That(sut.Mock.Verify.MyMethod()).Once(); // Exactly once
22-
await That(sut.Mock.Verify.MyMethod()).Twice(); // Exactly twice
23-
await That(sut.Mock.Verify.MyMethod()).Never(); // Never called
24-
await That(sut.Mock.Verify.MyMethod()).AtLeastOnce(); // At least once
25-
await That(sut.Mock.Verify.MyMethod()).AtLeastTwice(); // At least twice
26-
await That(sut.Mock.Verify.MyMethod()).AtLeast(3.Times()); // At least 3 times
27-
await That(sut.Mock.Verify.MyMethod()).AtMostOnce(); // At most once
28-
await That(sut.Mock.Verify.MyMethod()).AtMostTwice(); // At most twice
29-
await That(sut.Mock.Verify.MyMethod()).AtMost(4.Times()); // At most 4 times
30-
await That(sut.Mock.Verify.MyMethod()).Exactly(2.Times()); // Exactly 2 times
21+
await That(sut.Mock.Verify.MyMethod()).Once(); // Exactly once
22+
await That(sut.Mock.Verify.MyMethod()).Twice(); // Exactly twice
23+
await That(sut.Mock.Verify.MyMethod()).Never(); // Never called
24+
await That(sut.Mock.Verify.MyMethod()).AtLeastOnce(); // At least once
25+
await That(sut.Mock.Verify.MyMethod()).AtLeastTwice(); // At least twice
26+
await That(sut.Mock.Verify.MyMethod()).AtLeast(3.Times()); // At least 3 times
27+
await That(sut.Mock.Verify.MyMethod()).AtMostOnce(); // At most once
28+
await That(sut.Mock.Verify.MyMethod()).AtMostTwice(); // At most twice
29+
await That(sut.Mock.Verify.MyMethod()).AtMost(4.Times()); // At most 4 times
30+
await That(sut.Mock.Verify.MyMethod()).Exactly(2.Times()); // Exactly 2 times
31+
await That(sut.Mock.Verify.MyMethod()).Between(2).And(5.Times()); // Between 2 and 5 times
3132
```
3233

3334
#### Asynchronous verification
3435

3536
With `Within(TimeSpan timeout)`, you can check whether the expected number of calls occurred within a given time
3637
interval. This is useful for asynchronous or delayed invocations in the background.
3738

39+
`Within` and `WithCancellation` are available on `AtLeast*`, `Once`, `Twice`, `Exactly`, and `Between`. They are not
40+
available on `Never` or `AtMost*`, since an upper bound cannot be confirmed by waiting longer.
41+
3842
```csharp
3943
var sut = IMyService.CreateMock();
4044

@@ -116,6 +120,8 @@ await That(sut.Mock.Verify).AllSetupsAreUsed();
116120

117121
### Web Extensions
118122

123+
> Web extensions require .NET 8.0 or later.
124+
119125
#### JSON Content
120126

121127
You can precisely verify JSON content in HTTP requests during your tests. This feature is
@@ -132,3 +138,15 @@ httpClient.Mock.Setup
132138
.PostAsync(It.IsAny<Uri>(), It.IsHttpContent().WithJson("{\"bar\": \"baz\", \"foo\": 1}"))
133139
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK));
134140
```
141+
142+
By default, additional properties in the actual JSON are ignored. Use `IgnoringAdditionalProperties(false)` to require
143+
an exact match:
144+
145+
```csharp
146+
// Fails if the request body contains any property other than `foo` and `bar`
147+
httpClient.Mock.Setup
148+
.PostAsync(It.IsAny<Uri>(), It.IsHttpContent()
149+
.WithJsonMatching(new { foo = 1, bar = "baz" })
150+
.IgnoringAdditionalProperties(false))
151+
.ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK));
152+
```

0 commit comments

Comments
 (0)