Skip to content

feat: add Within and WithCancellation to verification result#496

Merged
vbreuss merged 4 commits intomainfrom
topic/add-within-and-withcancellation
Feb 28, 2026
Merged

feat: add Within and WithCancellation to verification result#496
vbreuss merged 4 commits intomainfrom
topic/add-within-and-withcancellation

Conversation

@vbreuss
Copy link
Copy Markdown
Contributor

@vbreuss vbreuss commented Feb 28, 2026

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.

Key changes:

  • Add Within(TimeSpan) and WithCancellation(CancellationToken) to VerificationResult<TVerify> and introduce async verification plumbing (IAsyncVerificationResult).
  • Update verification extension methods to translate timeout/cancellation into MockVerificationException messages.
  • Add/extend unit tests and update API baseline snapshots for supported TFMs.

@vbreuss vbreuss self-assigned this Feb 28, 2026
Copilot AI review requested due to automatic review settings February 28, 2026 16:24
@vbreuss vbreuss added the enhancement New feature or request label Feb 28, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and WithCancellation(CancellationToken) to VerificationResult<TVerify> and introduce async verification plumbing (IAsyncVerificationResult).
  • Update verification extension methods to translate timeout/cancellation into MockVerificationException messages.
  • 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

Comment thread Source/Mockolate/Verify/VerificationResult.cs
Comment thread Source/Mockolate/Verify/VerificationResult.cs Outdated
Comment thread Source/Mockolate/Verify/VerificationResult.cs
Comment thread Source/Mockolate/Internals/TaskExtensions.cs Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 28, 2026

Test Results

    21 files  ±  0      21 suites  ±0   6m 4s ⏱️ +57s
 2 779 tests + 21   2 778 ✅ + 21  1 💤 ±0  0 ❌ ±0 
18 670 runs  +147  18 669 ✅ +147  1 💤 ±0  0 ❌ ±0 

Results for commit 8c57ab1. ± Comparison against base commit ddabf6d.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 28, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.62GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.103
[Host] : .NET 10.0.3 (10.0.3, 10.0.326.7603), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.534 μs 0.0202 μs 0.0189 μs 0.2460 - 4.02 KB
Simple_Moq 181.281 μs 0.7334 μs 0.6501 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.687 μs 0.0356 μs 0.0316 μs 0.5493 0.0076 9.09 KB
Simple_FakeItEasy 6.285 μs 0.0501 μs 0.0469 μs 0.4959 - 8.11 KB

@vbreuss vbreuss force-pushed the topic/add-within-and-withcancellation branch from 33098fa to 2448cbd Compare February 28, 2026 16:46
Copilot AI review requested due to automatic review settings February 28, 2026 16:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Comment thread Source/Mockolate/Verify/VerificationResult.cs Outdated
Comment thread Source/Mockolate/Verify/VerificationResult.cs Outdated
Comment thread Source/Mockolate/Internals/TaskExtensions.cs Outdated
Comment thread Source/Mockolate/Verify/VerificationResultExtensions.cs
@sonarqubecloud
Copy link
Copy Markdown

@vbreuss vbreuss enabled auto-merge (squash) February 28, 2026 17:02
@vbreuss vbreuss merged commit e383bf6 into main Feb 28, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/add-within-and-withcancellation branch February 28, 2026 17:04
@github-actions
Copy link
Copy Markdown

This is addressed in release v1.5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support .Within(TimeSpan timeout) when verifing interactions

2 participants