feat: add Within and WithCancellation to verification result#496
feat: add Within and WithCancellation to verification result#496
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends Mockolate’s verification results with awaitable behavior by adding Within(...) and WithCancellation(...), enabling verifications to wait for interactions to occur (or time out / be canceled). It also updates verification exception messaging and expands test and API-surface coverage accordingly.
Changes:
- Add
Within(TimeSpan)andWithCancellation(CancellationToken)toVerificationResult<TVerify>and introduce async verification plumbing (IAsyncVerificationResult). - Update verification extension methods to translate timeout/cancellation into
MockVerificationExceptionmessages. - Add/extend unit tests and update API baseline snapshots for supported TFMs.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Mockolate.Tests/Verify/VerificationResultTests.cs | Converts the test class to sealed partial to support splitting async-specific tests into a companion file. |
| Tests/Mockolate.Tests/Verify/VerificationResultTests.AsyncTests.cs | Adds new tests for Within(...)/WithCancellation(...) behavior and timeout messaging. |
| Tests/Mockolate.Tests/Verify/VerificationResultExtensionsTests.cs | Adds coverage ensuring extension methods throw MockVerificationException with timeout messaging for multiple verification variants. |
| Tests/Mockolate.Api.Tests/Expected/Mockolate_netstandard2.0.txt | Updates API baseline to include new interface and new VerificationResult<TVerify> members. |
| Tests/Mockolate.Api.Tests/Expected/Mockolate_net8.0.txt | Updates API baseline to include new interface and new VerificationResult<TVerify> members. |
| Tests/Mockolate.Api.Tests/Expected/Mockolate_net10.0.txt | Updates API baseline to include new interface and new VerificationResult<TVerify> members. |
| Source/Mockolate/Verify/VerificationResultExtensions.cs | Wraps verification calls to convert timeout exceptions into MockVerificationException messages. |
| Source/Mockolate/Verify/VerificationResult.cs | Implements awaitable verification (Within/WithCancellation) and async wait logic via interaction notifications. |
| Source/Mockolate/Verify/IAsyncVerificationResult.cs | Introduces an async verification interface for awaitable verification results. |
| Source/Mockolate/Internals/TaskExtensions.cs | Adds a small polyfill-like helper to await a TaskCompletionSource with cancellation across TFMs. |
| Source/Mockolate/Exceptions/MockVerificationTimeoutException.cs | Adds a dedicated internal exception for timeout/cancellation during awaitable verification. |
Comments suppressed due to low confidence (1)
Source/Mockolate/Exceptions/MockVerificationTimeoutException.cs:8
- The XML summary says this exception represents a general verification error, but the type is specifically for timeouts/cancellation during awaitable verification. Updating the summary to mention timeouts will make the intent clearer and avoid confusion with
MockVerificationException.
/// <summary>
/// Represents a verification error on the mock.
/// </summary>
internal class MockVerificationTimeoutException : MockException
🚀 Benchmark ResultsDetails
|
33098fa to
2448cbd
Compare
|
|
This is addressed in release v1.5.0. |



This PR extends Mockolate’s verification results with awaitable behavior by adding
Within(...)andWithCancellation(...), enabling verifications to wait for interactions to occur (or time out / be canceled). It also updates verification exception messaging and expands test and API-surface coverage accordingly.Key changes:
Within(TimeSpan)andWithCancellation(CancellationToken)toVerificationResult<TVerify>and introduce async verification plumbing (IAsyncVerificationResult).MockVerificationExceptionmessages..Within(TimeSpan timeout)when verifing interactions #494