Skip to content

fix: skip IMockSetup<T> parent for interfaces with only static abstract events#720

Merged
vbreuss merged 1 commit into
mainfrom
topic/skip-IMockSetup-parent-for-interfaces-with-only-static-abstract-events
Apr 29, 2026
Merged

fix: skip IMockSetup<T> parent for interfaces with only static abstract events#720
vbreuss merged 1 commit into
mainfrom
topic/skip-IMockSetup-parent-for-interfaces-with-only-static-abstract-events

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Apr 29, 2026

This pull request improves the handling of static abstract events in mock generation and adds targeted tests to prevent variable name collisions and ensure correct code generation. The main changes focus on updating interface inheritance logic in the source generator and expanding test coverage.

Source generator improvements

  • Updated the logic in Sources.MockClass.cs so that generated IMockSetupFor and IMockVerifyFor interfaces only inherit from base mock interfaces if the target interface does not have static members or static events, preventing incorrect inheritance for interfaces with static abstract events.

@vbreuss vbreuss self-assigned this Apr 29, 2026
@vbreuss vbreuss added the bug Something isn't working label Apr 29, 2026
@vbreuss vbreuss enabled auto-merge (squash) April 29, 2026 18:19
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Test Results

    21 files  ±0      21 suites  ±0   9m 49s ⏱️ -5s
 3 847 tests +1   3 846 ✅ +1  1 💤 ±0  0 ❌ ±0 
25 055 runs  +3  25 054 ✅ +3  1 💤 ±0  0 ❌ ±0 

Results for commit fd7033b. ± Comparison against base commit 22dfeb1.

@vbreuss vbreuss merged commit e72fcdc into main Apr 29, 2026
16 checks passed
@vbreuss vbreuss deleted the topic/skip-IMockSetup-parent-for-interfaces-with-only-static-abstract-events branch April 29, 2026 18:28
@github-actions
Copy link
Copy Markdown

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz, 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-v4

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

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Event_Mockolate 439.6 ns 6.06 ns 5.67 ns 1.00 0.02 0.0834 0.0005 2.05 KB 1.00
Event_Moq 14,747.3 ns 34.85 ns 30.90 ns 33.55 0.42 0.4883 - 12.51 KB 6.09
Event_NSubstitute 5,839.9 ns 12.88 ns 12.05 ns 13.29 0.17 0.3662 - 9.05 KB 4.40
Event_FakeItEasy 186,934.4 ns 1,010.63 ns 895.90 ns 425.33 5.65 0.4883 0.2441 15.39 KB 7.49
Event_Imposter 1,680.5 ns 27.83 ns 26.04 ns 3.82 0.07 0.3586 0.0095 8.8 KB 4.29
Event_TUnitMocks 258.5 ns 6.62 ns 6.20 ns 0.59 0.02 0.0558 - 1.37 KB 0.67
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
Indexer_Mockolate 1 957.7 ns 11.58 ns 10.26 ns 1.00 0.01 0.2460 0.0019 4.03 KB 1.00
Indexer_Moq 1 210,903.0 ns 686.32 ns 573.11 ns 220.23 2.33 0.9766 0.4883 20.25 KB 5.02
Indexer_NSubstitute 1 9,196.2 ns 40.08 ns 37.49 ns 9.60 0.11 0.7782 - 12.84 KB 3.18
Indexer_FakeItEasy 1 11,648.6 ns 53.22 ns 49.78 ns 12.16 0.13 0.8392 0.0305 13.88 KB 3.44
Indexer_Imposter 1 965.4 ns 15.12 ns 12.63 ns 1.01 0.02 0.3147 0.0048 5.16 KB 1.28
Indexer_Mockolate 10 2,504.0 ns 37.70 ns 35.27 ns 1.00 0.02 0.3090 - 5.09 KB 1.00
Indexer_Moq 10 222,154.5 ns 382.41 ns 339.00 ns 88.74 1.22 1.7090 1.4648 28.64 KB 5.63
Indexer_NSubstitute 10 23,076.3 ns 62.97 ns 58.91 ns 9.22 0.13 1.5564 0.0305 25.63 KB 5.04
Indexer_FakeItEasy 10 25,461.4 ns 165.85 ns 155.14 ns 10.17 0.15 2.1667 0.0610 35.47 KB 6.97
Indexer_Imposter 10 2,236.7 ns 9.97 ns 9.32 ns 0.89 0.01 0.4845 0.0076 7.97 KB 1.57
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz (Max: 2.79GHz), 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-v4

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 489.1 ns 16.90 ns 15.80 ns 1.00 0.04 0.0944 - 2.32 KB 1.00
Method_Moq 1 136,893.8 ns 1,242.28 ns 1,101.25 ns 280.15 8.86 0.4883 0.2441 14.74 KB 6.35
Method_NSubstitute 1 5,950.1 ns 28.45 ns 25.22 ns 12.18 0.38 0.3662 - 9.12 KB 3.93
Method_FakeItEasy 1 6,086.2 ns 55.80 ns 52.20 ns 12.46 0.40 0.3281 0.0153 8.12 KB 3.50
Method_Imposter 1 594.2 ns 16.39 ns 15.33 ns 1.22 0.05 0.1640 0.0019 4.04 KB 1.74
Method_TUnitMocks 1 692.2 ns 22.48 ns 21.03 ns 1.42 0.06 0.1183 0.0010 2.9 KB 1.25
Method_Mockolate 10 872.1 ns 12.46 ns 11.05 ns 1.00 0.02 0.1030 - 2.53 KB 1.00
Method_Moq 10 142,400.4 ns 616.67 ns 546.66 ns 163.31 2.08 0.7324 0.4883 18.64 KB 7.36
Method_NSubstitute 10 8,639.1 ns 91.33 ns 85.43 ns 9.91 0.15 0.4883 - 12.07 KB 4.77
Method_FakeItEasy 10 9,502.3 ns 107.88 ns 100.91 ns 10.90 0.17 0.6409 - 16.04 KB 6.34
Method_Imposter 10 1,284.7 ns 32.02 ns 29.95 ns 1.47 0.04 0.2251 0.0038 5.52 KB 2.18
Method_TUnitMocks 10 2,153.1 ns 20.66 ns 19.32 ns 2.47 0.04 0.1831 - 4.49 KB 1.77
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 9V74 2.87GHz, 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 564.9 ns 1.74 ns 1.36 ns 1.00 0.00 0.1574 0.0010 2.58 KB 1.00
Property_Moq 1 10,366.1 ns 87.75 ns 77.79 ns 18.35 0.14 0.6104 - 10.5 KB 4.07
Property_NSubstitute 1 6,781.4 ns 74.04 ns 69.26 ns 12.01 0.12 0.6943 0.0076 11.45 KB 4.44
Property_FakeItEasy 1 7,055.7 ns 77.80 ns 68.97 ns 12.49 0.12 0.6866 - 11.24 KB 4.36
Property_Imposter 1 448.3 ns 8.06 ns 7.15 ns 0.79 0.01 0.1912 0.0019 3.13 KB 1.21
Property_TUnitMocks 1 751.3 ns 13.82 ns 12.25 ns 1.33 0.02 0.1526 0.0010 2.51 KB 0.97
Property_Mockolate 10 1,068.4 ns 22.56 ns 20.00 ns 1.00 0.03 0.1869 - 3.07 KB 1.00
Property_Moq 10 16,343.5 ns 93.08 ns 87.07 ns 15.30 0.28 1.0986 - 18.39 KB 5.99
Property_NSubstitute 10 15,720.0 ns 189.53 ns 177.28 ns 14.72 0.31 1.2817 0.0305 21.08 KB 6.87
Property_FakeItEasy 10 17,110.0 ns 121.72 ns 107.90 ns 16.02 0.30 1.8616 - 30.81 KB 10.03
Property_Imposter 10 1,058.2 ns 3.25 ns 3.04 ns 0.99 0.02 0.2842 0.0019 4.67 KB 1.52
Property_TUnitMocks 10 2,198.9 ns 8.92 ns 8.35 ns 2.06 0.04 0.2823 - 4.66 KB 1.52
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 9V74 2.87GHz, 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 409.7 ns 2.13 ns 1.78 ns 1.00 0.01 0.1197 - 1.96 KB 1.00
Callback_Moq 70,424.3 ns 523.99 ns 464.51 ns 171.90 1.31 0.4883 0.2441 8.88 KB 4.53
Callback_NSubstitute 4,158.6 ns 89.87 ns 84.06 ns 10.15 0.20 0.4730 0.0076 7.74 KB 3.95
Callback_FakeItEasy 4,349.2 ns 87.62 ns 81.96 ns 10.62 0.20 0.4120 0.0153 6.81 KB 3.47
Callback_Imposter 436.2 ns 2.51 ns 2.34 ns 1.06 0.01 0.1454 0.0010 2.38 KB 1.22
Callback_TUnitMocks 719.7 ns 10.34 ns 9.67 ns 1.76 0.02 0.1602 0.0010 2.63 KB 1.34

@github-actions
Copy link
Copy Markdown

This is addressed in release v3.0.0.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant