Skip to content

fix: report unsupported ref struct members of interfaces added with Implementing<T>() - #1263

Merged
vbreuss merged 1 commit into
mainfrom
fix/implementing-ref-struct-diagnostics
Dec 4, 2026
Merged

vbreuss merged 1 commit into
mainfrom
fix/implementing-ref-struct-diagnostics

Conversation

@vbreuss

@vbreuss vbreuss commented Dec 4, 2026

Copy link
Copy Markdown
Member

Mockolate0003 only looked at the type of CreateMock(), so a member of an interface added with Implementing<T>() that the combination mock can only stub with a throwing body went unreported, and the user only found out through a NotSupportedException at run time. The analyzer now reports these members at the type argument, like Mockolate0002, and skips the members that the combination does not implement itself: those the mocked type or an earlier Implementing<T>() already declares, and those the mocked class implements with a member the mock overrides.

A class mock never implements the members of the interfaces the class implements, so the analyzer no longer reports them on CreateMock() of such a class, which was a false positive for a class that implements such a member non-virtually.

The other ways to get a mock need no change: mock data sources, constructor dependencies and auto-mocking refuse types with such members, and Wrapping adds no types.

…Implementing<T>()`

Mockolate0003 only looked at the type of `CreateMock()`, so a member of an interface added with `Implementing<T>()` that the combination mock can only stub with a throwing body went unreported, and the user only found out through a NotSupportedException at run time. The analyzer now reports these members at the type argument, like Mockolate0002, and skips the members that the combination does not implement itself: those the mocked type or an earlier `Implementing<T>()` already declares, and those the mocked class implements with a member the mock overrides.

A class mock never implements the members of the interfaces the class implements, so the analyzer no longer reports them on `CreateMock()` of such a class, which was a false positive for a class that implements such a member non-virtually.

The other ways to get a mock need no change: mock data sources, constructor dependencies and auto-mocking refuse types with such members, and `Wrapping` adds no types.
@vbreuss vbreuss self-assigned this Dec 4, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@vbreuss
vbreuss enabled auto-merge (squash) December 4, 2026 16:38
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Test Results

    97 files      97 suites   1h 22m 10s ⏱️
 7 721 tests  7 711 ✅  10 💤 0 ❌
72 472 runs  72 362 ✅ 110 💤 0 ❌

Results for commit 3c97be3.

@vbreuss
vbreuss merged commit 8db29bc into main Dec 4, 2026
26 checks passed
@vbreuss
vbreuss deleted the fix/implementing-ref-struct-diagnostics branch December 4, 2026 17:04
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

🚀 Benchmark Results

Compared to main, which ran on the same runner. Times that change by more than 10% are marked.

Memory

Benchmark main PR Δ
Unconfigured (N=1000) 273,320 B 273,321 B 🔴 +1 B (±0%)
Indexer (N=1000) 105,744 B 105,745 B 🔴 +1 B (±0%)
CompleteWorkflowBenchmarks
Complete Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 2.397 μs 0.0424 μs 0.0396 μs 1.00 5.17 KB 1.00
Imposter 2.706 μs 0.0535 μs 0.0474 μs 1.13 7.21 KB 1.39
TUnitMocks 4.542 μs 0.0605 μs 0.0565 μs 1.90 9.63 KB 1.86
Moq 1,439.309 μs 10.2817 μs 9.6175 μs 600.72 90.19 KB 17.44
NSubstitute 311.823 μs 1.0657 μs 0.9447 μs 130.14 53.11 KB 10.27
FakeItEasy 361.942 μs 4.6396 μs 4.3399 μs 151.06 64.29 KB 12.43
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 2.84GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v3

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

MockCreationBenchmarks
CreateMock Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 16.26 ns 0.647 ns 0.606 ns 1.00 136 B 1.00
Imposter 85.55 ns 0.679 ns 0.635 ns 5.27 504 B 3.71
TUnitMocks 25.93 ns 0.192 ns 0.160 ns 1.60 216 B 1.59
Moq 1,281.39 ns 12.282 ns 11.489 ns 78.90 2088 B 15.35
NSubstitute 1,899.49 ns 13.561 ns 12.021 ns 116.96 5032 B 37.00
FakeItEasy 1,581.78 ns 22.195 ns 20.761 ns 97.40 2755 B 20.26
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 2.59GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v3

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

CompleteUnconfiguredBenchmarks
Unconfigured N Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1 347.4 ns 10.97 ns 9.73 ns 1.00 1.53 KB 1.00
Imposter 1 226.6 ns 2.75 ns 2.43 ns 0.65 1.06 KB 0.69
TUnitMocks 1 301.9 ns 3.12 ns 2.43 ns 0.87 1.36 KB 0.89
Moq 1 72,045.7 ns 552.27 ns 489.58 ns 207.56 9.79 KB 6.40
NSubstitute 1 5,498.3 ns 88.39 ns 78.35 ns 15.84 10.01 KB 6.54
FakeItEasy 1 5,329.9 ns 131.17 ns 122.69 ns 15.36 11.58 KB 7.56
Mockolate 10 1,308.9 ns 19.05 ns 16.89 ns 1.00 3.95 KB 1.00
Imposter 10 840.2 ns 15.23 ns 14.25 ns 0.64 2.89 KB 0.73
TUnitMocks 10 2,816.7 ns 30.08 ns 25.12 ns 2.15 8.13 KB 2.06
Moq 10 83,895.1 ns 539.28 ns 504.44 ns 64.11 24.53 KB 6.22
NSubstitute 10 17,709.0 ns 234.47 ns 195.79 ns 13.53 22.93 KB 5.81
FakeItEasy 10 22,415.1 ns 282.17 ns 263.94 ns 17.13 53.92 KB 13.67
Mockolate 1000 100,720.2 ns 710.59 ns 629.92 ns 1.00 266.92 KB 1.00
Imposter 1000 69,075.4 ns 647.86 ns 574.31 ns 0.69 203.99 KB 0.76
TUnitMocks 1000 265,412.2 ns 3,262.55 ns 2,892.17 ns 2.64 622.59 KB 2.33
Moq 1000 1,185,067.2 ns 10,849.39 ns 9,617.70 ns 11.77 1653.01 KB 6.19
NSubstitute 1000 1,332,920.6 ns 10,707.30 ns 10,015.62 ns 13.23 1434.49 KB 5.37
FakeItEasy 1000 2,307,875.6 ns 59,709.44 ns 52,930.86 ns 22.91 4690.81 KB 17.57
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4

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

CompleteMethodBenchmarks
Method N Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1 104.0 ns 0.58 ns 0.51 ns 1.00 600 B 1.00
Imposter 1 151.4 ns 2.84 ns 2.66 ns 1.46 808 B 1.35
TUnitMocks 1 186.8 ns 2.73 ns 2.56 ns 1.80 1088 B 1.81
Moq 1 3,256.1 ns 19.81 ns 17.56 ns 31.31 6552 B 10.92
NSubstitute 1 4,066.3 ns 27.56 ns 24.43 ns 39.10 9816 B 16.36
FakeItEasy 1 3,159.8 ns 10.21 ns 9.55 ns 30.39 7517 B 12.53
Mockolate 10 281.1 ns 1.83 ns 1.52 ns 1.00 1104 B 1.00
Imposter 10 293.4 ns 1.73 ns 1.54 ns 1.04 1168 B 1.06
TUnitMocks 10 893.1 ns 10.25 ns 9.08 ns 3.18 2952 B 2.67
Moq 10 4,792.5 ns 34.38 ns 30.48 ns 17.05 10536 B 9.54
NSubstitute 10 6,223.1 ns 102.61 ns 90.96 ns 22.14 12840 B 11.63
FakeItEasy 10 5,952.0 ns 51.25 ns 47.94 ns 21.18 15754 B 14.27
Mockolate 1000 19,989.5 ns 75.12 ns 62.73 ns 1.00 56544 B 1.00
Imposter 1000 18,229.1 ns 250.21 ns 234.05 ns 0.91 40768 B 0.72
TUnitMocks 1000 69,191.0 ns 583.01 ns 545.35 ns 3.46 158241 B 2.80
Moq 1000 154,244.0 ns 3,474.22 ns 3,249.79 ns 7.72 423563 B 7.49
NSubstitute 1000 218,657.6 ns 1,350.57 ns 1,263.33 ns 10.94 378535 B 6.69
FakeItEasy 1000 314,664.8 ns 4,494.71 ns 3,753.29 ns 15.74 943722 B 16.69
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4

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

CompletePropertyBenchmarks
Property N Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1 262.0 ns 6.34 ns 5.93 ns 1.00 928 B 1.00
Imposter 1 175.9 ns 2.78 ns 2.32 ns 0.67 672 B 0.72
TUnitMocks 1 285.5 ns 6.16 ns 5.77 ns 1.09 1096 B 1.18
Moq 1 11,218.6 ns 159.12 ns 141.05 ns 42.84 10569 B 11.39
NSubstitute 1 7,740.8 ns 120.61 ns 112.82 ns 29.56 11688 B 12.59
FakeItEasy 1 8,244.6 ns 127.09 ns 118.88 ns 31.48 11196 B 12.06
Mockolate 10 632.8 ns 13.83 ns 12.94 ns 1.00 1792 B 1.00
Imposter 10 356.1 ns 6.77 ns 6.34 ns 0.56 960 B 0.54
TUnitMocks 10 1,343.3 ns 21.59 ns 19.14 ns 2.12 3280 B 1.83
Moq 10 18,366.1 ns 182.80 ns 152.65 ns 29.03 18505 B 10.33
NSubstitute 10 18,603.4 ns 65.53 ns 58.10 ns 29.41 21553 B 12.03
FakeItEasy 10 19,595.6 ns 141.43 ns 132.29 ns 30.98 30785 B 17.18
Mockolate 1000 40,783.1 ns 536.61 ns 501.94 ns 1.00 96832 B 1.00
Imposter 1000 17,685.4 ns 224.35 ns 198.88 ns 0.43 32641 B 0.34
TUnitMocks 1000 107,678.3 ns 1,314.61 ns 1,165.37 ns 2.64 190017 B 1.96
Moq 1000 794,700.3 ns 4,988.39 ns 4,422.08 ns 19.49 836541 B 8.64
NSubstitute 1000 1,180,498.4 ns 9,289.94 ns 8,689.82 ns 28.95 1139728 B 11.77
FakeItEasy 1000 1,298,101.9 ns 12,959.91 ns 12,122.71 ns 31.83 2194291 B 22.66
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 3.10GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v3

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

CompleteIndexerBenchmarks
Indexer N Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1 436.1 ns 12.59 ns 11.78 ns 1.00 1.8 KB 1.00
Imposter 1 310.7 ns 2.59 ns 2.42 ns 0.71 1.19 KB 0.66
TUnitMocks 1 494.4 ns 7.90 ns 7.39 ns 1.13 1.7 KB 0.94
Moq 1 529,245.7 ns 1,680.59 ns 1,572.03 ns 1,214.47 37.89 KB 21.00
NSubstitute 1 210,027.2 ns 887.62 ns 830.28 ns 481.96 27.44 KB 15.21
FakeItEasy 1 243,197.9 ns 1,624.18 ns 1,356.26 ns 558.07 29.56 KB 16.38
Mockolate 10 1,179.4 ns 9.59 ns 8.50 ns 1.00 2.72 KB 1.00
Imposter 10 761.8 ns 5.46 ns 5.11 ns 0.65 2.24 KB 0.82
TUnitMocks 10 2,335.7 ns 18.59 ns 15.53 ns 1.98 4.7 KB 1.73
Moq 10 536,851.1 ns 2,506.73 ns 2,344.79 ns 455.20 47.24 KB 17.38
NSubstitute 10 226,692.7 ns 1,225.16 ns 1,146.02 ns 192.21 40.25 KB 14.80
FakeItEasy 10 267,520.2 ns 5,700.10 ns 5,331.88 ns 226.83 48.76 KB 17.93
Mockolate 1000 79,041.7 ns 590.89 ns 552.72 ns 1.00 103.27 KB 1.00
Imposter 1000 48,239.5 ns 301.02 ns 266.84 ns 0.61 118.26 KB 1.15
TUnitMocks 1000 185,788.1 ns 1,038.76 ns 920.84 ns 2.35 259.13 KB 2.51
Moq 1000 1,328,657.3 ns 6,530.70 ns 5,789.29 ns 16.81 1024.06 KB 9.92
NSubstitute 1000 1,857,316.6 ns 7,813.55 ns 7,308.80 ns 23.50 1480.33 KB 14.34
FakeItEasy 1000 1,669,145.1 ns 11,299.04 ns 10,569.13 ns 21.12 2169.32 KB 21.01
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 3.19GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v3

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

CompleteEventBenchmarks
Event Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 184.7 ns 4.16 ns 3.90 ns 1.00 720 B 1.00
Imposter 188.9 ns 1.14 ns 0.95 ns 1.02 512 B 0.71
TUnitMocks 196.6 ns 4.85 ns 4.54 ns 1.06 1392 B 1.93
Moq 15,411.9 ns 36.27 ns 30.29 ns 83.46 12761 B 17.72
NSubstitute 6,019.6 ns 15.49 ns 12.94 ns 32.60 9192 B 12.77
FakeItEasy 216,314.6 ns 951.65 ns 843.61 ns 1,171.37 15586 B 21.65
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 3.08GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v3

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

CallbackBenchmarks
Callback Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 204.2 ns 2.40 ns 2.12 ns 1.00 808 B 1.00
Imposter 198.4 ns 3.01 ns 2.82 ns 0.97 616 B 0.76
TUnitMocks 241.7 ns 6.34 ns 5.93 ns 1.18 1064 B 1.32
Moq 102,219.6 ns 508.76 ns 451.00 ns 500.75 9056 B 11.21
NSubstitute 4,661.0 ns 38.88 ns 36.37 ns 22.83 7864 B 9.73
FakeItEasy 4,476.1 ns 47.62 ns 44.55 ns 21.93 6930 B 8.58
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 2.63GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v3

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

AsyncBenchmarks
Async N Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1 410.9 ns 4.40 ns 4.12 ns 1.00 1.01 KB 1.00
Imposter 1 503.1 ns 6.91 ns 6.46 ns 1.22 1.58 KB 1.57
TUnitMocks 1 723.5 ns 5.62 ns 5.26 ns 1.76 1.85 KB 1.84
Moq 1 246,665.0 ns 1,280.29 ns 1,134.94 ns 600.34 22.74 KB 22.56
NSubstitute 1 15,517.9 ns 120.19 ns 112.43 ns 37.77 19.06 KB 18.91
FakeItEasy 1 11,123.9 ns 77.80 ns 68.97 ns 27.07 13.98 KB 13.88
Mockolate 10 1,763.5 ns 7.57 ns 7.08 ns 1.00 2.98 KB 1.00
Imposter 10 1,626.3 ns 4.05 ns 3.38 ns 0.92 3.41 KB 1.14
TUnitMocks 10 4,929.8 ns 9.57 ns 8.48 ns 2.80 8.33 KB 2.80
Moq 10 294,437.8 ns 3,952.61 ns 3,697.28 ns 166.96 40.18 KB 13.50
NSubstitute 10 26,908.8 ns 63.76 ns 56.52 ns 15.26 29.38 KB 9.87
FakeItEasy 10 41,638.9 ns 119.81 ns 106.21 ns 23.61 59.08 KB 19.85
Mockolate 1000 148,331.4 ns 491.01 ns 410.01 ns 1.00 219.54 KB 1.00
Imposter 1000 125,311.2 ns 814.74 ns 722.25 ns 0.84 204.5 KB 0.93
TUnitMocks 1000 417,027.0 ns 3,480.30 ns 3,255.48 ns 2.81 555.89 KB 2.53
Moq 1000 4,068,441.4 ns 11,536.64 ns 9,633.61 ns 27.43 1890.93 KB 8.61
NSubstitute 1000 1,205,474.8 ns 1,648.62 ns 1,376.68 ns 8.13 1092.05 KB 4.97
FakeItEasy 1000 4,096,836.2 ns 54,056.37 ns 50,564.37 ns 27.62 4933.48 KB 22.47
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
Intel Xeon Platinum 8370C CPU 2.80GHz (Max: 3.39GHz), 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4

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

SequenceBenchmarks
Sequence Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 2.641 μs 0.0265 μs 0.0222 μs 1.00 2.24 KB 1.00
Imposter 2.387 μs 0.0143 μs 0.0126 μs 0.90 2.23 KB 1.00
TUnitMocks 2.765 μs 0.0212 μs 0.0188 μs 1.05 2.58 KB 1.15
Moq 10.045 μs 0.1582 μs 0.1480 μs 3.80 10.79 KB 4.81
NSubstitute 8.722 μs 0.0903 μs 0.0844 μs 3.30 14.29 KB 6.37
FakeItEasy 9.090 μs 0.0743 μs 0.0695 μs 3.44 14.28 KB 6.37
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant