Skip to content

coverage: add missing MockRegistry tests#729

Merged
vbreuss merged 1 commit into
mainfrom
topic/tests-for-mockregistry-verify
Apr 30, 2026
Merged

coverage: add missing MockRegistry tests#729
vbreuss merged 1 commit into
mainfrom
topic/tests-for-mockregistry-verify

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Apr 30, 2026

This pull request improves the fast-path verification logic in the MockRegistry class and significantly expands the unit tests for indexer, property, method, and event verification when using member IDs and fast buffers. The changes ensure that verification methods correctly use the available buffers for efficient interaction counting and expectation generation, and they add comprehensive tests to cover both fast-path and fallback scenarios.

Key changes include:

Fast-path logic improvements

  • Simplified the implementations of IndexerGot and IndexerSet in MockRegistry.Verify.cs to directly use the result of TryGetBuffer(memberId) in the VerificationResult constructor, removing unnecessary null checks and fallback logic within these methods.

Unit test coverage expansion

  • Added new tests in TypedVerifyFastPathTests.cs to cover:
    • Indexer getter/setter verification with member IDs and buffers, ensuring correct counting and expectation messages.
    • Event subscription/unsubscription verification with and without buffers, checking both fast-path and fallback behavior.
    • Method invocation verification with member IDs but no matching buffer, confirming fallback predicate matches.
    • Property getter/setter verification with member IDs and buffers, validating correct interaction counting and expectation formatting.

@vbreuss vbreuss self-assigned this Apr 30, 2026
@vbreuss vbreuss added the coverage Additional tests for edge cases or improvement of test coverage label Apr 30, 2026
@sonarqubecloud
Copy link
Copy Markdown

@vbreuss vbreuss enabled auto-merge (squash) April 30, 2026 18:28
@github-actions
Copy link
Copy Markdown

Test Results

    21 files  ± 0      21 suites  ±0   10m 52s ⏱️ +42s
 3 883 tests + 9   3 881 ✅ + 9  2 💤 ±0  0 ❌ ±0 
25 199 runs  +63  25 195 ✅ +63  4 💤 ±0  0 ❌ ±0 

Results for commit 3640b2c. ± Comparison against base commit 211fda2.

@vbreuss vbreuss merged commit ffa9d1c into main Apr 30, 2026
16 checks passed
@vbreuss vbreuss deleted the topic/tests-for-mockregistry-verify branch April 30, 2026 18:34
@github-actions
Copy link
Copy Markdown

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Event_Mockolate 398.0 ns 6.98 ns 6.53 ns 1.00 0.02 0.1254 0.0005 2.05 KB 1.00
Event_Moq 16,637.4 ns 43.02 ns 35.92 ns 41.81 0.67 0.7324 - 12.51 KB 6.09
Event_NSubstitute 5,920.7 ns 39.97 ns 35.43 ns 14.88 0.25 0.5493 0.0076 9.05 KB 4.40
Event_FakeItEasy 214,307.1 ns 1,310.04 ns 1,161.31 ns 538.62 9.02 0.7324 0.4883 15.39 KB 7.49
Event_Imposter 1,478.7 ns 28.74 ns 24.00 ns 3.72 0.08 0.5379 0.0153 8.8 KB 4.29
Event_TUnitMocks 204.2 ns 6.28 ns 5.88 ns 0.51 0.02 0.0837 0.0002 1.37 KB 0.67
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 9V74 2.86GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Indexer_Mockolate 1 1,020.8 ns 18.49 ns 16.39 ns 1.00 0.02 0.2460 0.0019 4.03 KB 1.00
Indexer_Moq 1 169,676.2 ns 1,044.78 ns 977.29 ns 166.26 2.75 0.9766 0.4883 20.37 KB 5.05
Indexer_NSubstitute 1 8,778.8 ns 79.88 ns 70.81 ns 8.60 0.15 0.7782 - 12.84 KB 3.18
Indexer_FakeItEasy 1 10,181.9 ns 198.20 ns 185.40 ns 9.98 0.23 0.8392 0.0305 13.88 KB 3.44
Indexer_Imposter 1 931.7 ns 15.85 ns 14.05 ns 0.91 0.02 0.3147 0.0048 5.16 KB 1.28
Indexer_Mockolate 10 2,649.2 ns 13.25 ns 11.74 ns 1.00 0.01 0.3090 - 5.09 KB 1.00
Indexer_Moq 10 179,997.4 ns 625.42 ns 585.02 ns 67.94 0.36 1.7090 1.4648 29.89 KB 5.88
Indexer_NSubstitute 10 22,715.7 ns 185.52 ns 154.92 ns 8.57 0.07 1.5564 0.0305 25.63 KB 5.04
Indexer_FakeItEasy 10 22,687.4 ns 94.51 ns 88.40 ns 8.56 0.05 2.1667 0.0610 35.47 KB 6.97
Indexer_Imposter 10 2,332.4 ns 40.96 ns 38.32 ns 0.88 0.01 0.4845 0.0076 7.97 KB 1.57
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Method_Mockolate 1 465.3 ns 10.45 ns 9.78 ns 1.00 0.03 0.1416 0.0010 2.32 KB 1.00
Method_Moq 1 180,132.4 ns 924.97 ns 819.96 ns 387.31 7.99 0.4883 - 14.58 KB 6.28
Method_NSubstitute 1 5,896.1 ns 37.45 ns 35.03 ns 12.68 0.27 0.5569 0.0076 9.12 KB 3.93
Method_FakeItEasy 1 6,135.0 ns 30.41 ns 28.44 ns 13.19 0.27 0.4959 - 8.11 KB 3.50
Method_Imposter 1 605.5 ns 17.05 ns 15.95 ns 1.30 0.04 0.2470 0.0029 4.04 KB 1.74
Method_TUnitMocks 1 711.2 ns 8.01 ns 6.69 ns 1.53 0.03 0.1774 0.0010 2.9 KB 1.25
Method_Mockolate 10 806.1 ns 10.29 ns 9.63 ns 1.00 0.02 0.1545 0.0010 2.53 KB 1.00
Method_Moq 10 186,579.7 ns 1,674.48 ns 1,566.31 ns 231.50 3.27 0.9766 0.7324 18.48 KB 7.30
Method_NSubstitute 10 8,784.9 ns 88.98 ns 83.23 ns 10.90 0.16 0.7324 0.0153 12.07 KB 4.77
Method_FakeItEasy 10 9,535.8 ns 72.05 ns 67.40 ns 11.83 0.16 0.9766 0.0305 16.05 KB 6.34
Method_Imposter 10 1,282.4 ns 29.37 ns 27.47 ns 1.59 0.04 0.3376 0.0057 5.52 KB 2.18
Method_TUnitMocks 10 1,735.9 ns 13.81 ns 11.53 ns 2.15 0.03 0.2747 0.0019 4.49 KB 1.77
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Property_Mockolate 1 551.3 ns 17.80 ns 16.65 ns 1.00 0.04 0.1574 0.0010 2.58 KB 1.00
Property_Moq 1 12,435.0 ns 53.84 ns 50.37 ns 22.57 0.66 0.6104 - 10.39 KB 4.03
Property_NSubstitute 1 7,724.0 ns 70.05 ns 62.10 ns 14.02 0.42 0.6866 - 11.45 KB 4.44
Property_FakeItEasy 1 9,064.4 ns 39.76 ns 37.19 ns 16.45 0.48 0.6866 - 11.24 KB 4.36
Property_Imposter 1 543.4 ns 19.31 ns 17.12 ns 0.99 0.04 0.1907 0.0019 3.13 KB 1.21
Property_TUnitMocks 1 766.2 ns 24.08 ns 22.52 ns 1.39 0.06 0.1526 0.0010 2.51 KB 0.97
Property_Mockolate 10 1,145.2 ns 12.30 ns 10.90 ns 1.00 0.01 0.1869 - 3.07 KB 1.00
Property_Moq 10 19,032.0 ns 344.24 ns 287.46 ns 16.62 0.29 1.0986 - 18.28 KB 5.95
Property_NSubstitute 10 17,420.2 ns 23.28 ns 18.18 ns 15.21 0.14 1.2817 0.0305 21.08 KB 6.87
Property_FakeItEasy 10 22,019.2 ns 104.67 ns 87.40 ns 19.23 0.19 1.8616 - 30.81 KB 10.03
Property_Imposter 10 1,395.7 ns 13.31 ns 12.45 ns 1.22 0.02 0.2842 0.0019 4.67 KB 1.52
Property_TUnitMocks 10 2,342.9 ns 9.08 ns 7.58 ns 2.05 0.02 0.2823 - 4.66 KB 1.52
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.66GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Callback_Mockolate 437.5 ns 5.33 ns 4.99 ns 1.00 0.02 0.1197 - 1.96 KB 1.00
Callback_Moq 96,319.7 ns 516.15 ns 457.55 ns 220.16 2.64 0.4883 0.2441 8.88 KB 4.53
Callback_NSubstitute 4,639.0 ns 56.33 ns 52.69 ns 10.60 0.17 0.4730 0.0076 7.74 KB 3.95
Callback_FakeItEasy 4,876.6 ns 66.47 ns 62.18 ns 11.15 0.19 0.4120 0.0153 6.81 KB 3.47
Callback_Imposter 419.3 ns 9.57 ns 8.95 ns 0.96 0.02 0.1454 0.0010 2.38 KB 1.22
Callback_TUnitMocks 637.6 ns 19.58 ns 18.32 ns 1.46 0.04 0.1602 0.0010 2.63 KB 1.34

@github-actions
Copy link
Copy Markdown

This is addressed in release v3.0.0.

@github-actions github-actions Bot added the state: released The issue is released label Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coverage Additional tests for edge cases or improvement of test coverage state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant