Skip to content

feat: default to identity for Func<T, T> and no-op for Action<T> - #1132

Merged
vbreuss merged 3 commits into
mainfrom
feat/default-option-delegates
Nov 25, 2026
Merged

vbreuss merged 3 commits into
mainfrom
feat/default-option-delegates

Conversation

@vbreuss

@vbreuss vbreuss commented Nov 25, 2026

Copy link
Copy Markdown
Member

Options callbacks such as MockFileSystem(Func<MockFileSystemOptions, MockFileSystemOptions> options) or Action configure parameters are a common constructor pattern. Without a default value, [AutoMockArguments] cannot create such a class and throws at runtime, so the default value generator now returns a callback that leaves the options unchanged. A custom generator or WithDefaultValueFor still takes precedence.

Options callbacks such as MockFileSystem(Func<MockFileSystemOptions, MockFileSystemOptions> options) or Action<TOptions> configure parameters are a common constructor pattern. Without a default value, [AutoMockArguments] cannot create such a class and throws at runtime, so the default value generator now returns a callback that leaves the options unchanged. A custom generator or WithDefaultValueFor still takes precedence.
@vbreuss vbreuss self-assigned this Nov 25, 2026
@vbreuss vbreuss added the enhancement New feature or request label Nov 25, 2026
@github-actions

Copy link
Copy Markdown

Test Results

   108 files  ± 0     108 suites  ±0   2h 36m 39s ⏱️ +52s
 5 859 tests + 5   5 844 ✅  - 8   2 💤 ±0  13 ❌ +13 
57 135 runs  +54  57 063 ✅ +2  20 💤 ±0  52 ❌ +52 

For more details on these failures, see this check.

Results for commit 789c141. ± Comparison against base commit ca10aa2.

@github-actions

github-actions Bot commented Nov 25, 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 Δ
Indexer (N=1000) 105,720 B 105,721 B 🔴 +1 B (±0%)

Time

Benchmark main PR Δ
Property (N=1) 313.1 ns 251.9 ns 🟢 -20%
Property (N=10) 1.12 μs 621.6 ns 🟢 -44%
Property (N=1000) 99.48 μs 40.03 μs 🟢 -60%
CompleteWorkflowBenchmarks
Complete Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1.726 μs 0.0265 μs 0.0221 μs 1.00 5.14 KB 1.00
Imposter 1.988 μs 0.0475 μs 0.0444 μs 1.15 7.21 KB 1.40
TUnitMocks 3.528 μs 0.0740 μs 0.0693 μs 2.04 10.66 KB 2.07
Moq 1,030.597 μs 5.5170 μs 5.1606 μs 597.24 90.99 KB 17.70
NSubstitute 271.255 μs 0.6542 μs 0.5463 μs 157.20 53.11 KB 10.33
FakeItEasy 306.739 μs 1.4215 μs 1.2601 μs 177.76 64.06 KB 12.46
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.65GHz, 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  

MockCreationBenchmarks
CreateMock Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 9.970 ns 0.2341 ns 0.2075 ns 1.00 136 B 1.00
Imposter 57.958 ns 0.9166 ns 0.8126 ns 5.82 504 B 3.71
TUnitMocks 17.413 ns 0.5672 ns 0.5306 ns 1.75 216 B 1.59
Moq 775.486 ns 25.3858 ns 23.7459 ns 77.81 2088 B 15.35
NSubstitute 1,029.827 ns 30.6308 ns 28.6521 ns 103.33 5032 B 37.00
FakeItEasy 958.888 ns 33.2701 ns 31.1209 ns 96.21 2755 B 20.26
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V45 4.25GHz, 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  

CompleteUnconfiguredBenchmarks
Unconfigured N Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1 485.3 ns 17.11 ns 16.01 ns 1.00 1.51 KB 1.00
Imposter 1 265.8 ns 5.47 ns 5.11 ns 0.55 1.06 KB 0.70
TUnitMocks 1 503.1 ns 14.55 ns 13.61 ns 1.04 1.74 KB 1.16
Moq 1 115,010.6 ns 914.07 ns 810.30 ns 237.23 9.79 KB 6.50
NSubstitute 1 7,470.4 ns 74.70 ns 69.88 ns 15.41 10.01 KB 6.64
FakeItEasy 1 7,996.0 ns 82.05 ns 76.75 ns 16.49 11.69 KB 7.75
Mockolate 10 1,627.4 ns 21.92 ns 20.50 ns 1.00 3.92 KB 1.00
Imposter 10 988.1 ns 21.85 ns 20.44 ns 0.61 2.89 KB 0.74
TUnitMocks 10 3,331.4 ns 48.06 ns 44.95 ns 2.05 8.4 KB 2.14
Moq 10 129,985.6 ns 798.63 ns 747.04 ns 79.88 24.53 KB 6.25
NSubstitute 10 22,402.7 ns 93.64 ns 83.01 ns 13.77 22.93 KB 5.85
FakeItEasy 10 30,708.7 ns 553.90 ns 518.12 ns 18.87 54.03 KB 13.78
Mockolate 1000 126,263.0 ns 1,345.63 ns 1,258.70 ns 1.00 266.89 KB 1.00
Imposter 1000 81,219.2 ns 931.08 ns 870.93 ns 0.64 203.99 KB 0.76
TUnitMocks 1000 309,925.1 ns 3,358.60 ns 3,141.64 ns 2.45 691.13 KB 2.59
Moq 1000 1,538,707.4 ns 7,193.93 ns 6,377.23 ns 12.19 1653.01 KB 6.19
NSubstitute 1000 1,623,159.1 ns 8,345.94 ns 7,398.46 ns 12.86 1434.49 KB 5.37
FakeItEasy 1000 2,942,372.9 ns 31,230.03 ns 29,212.59 ns 23.31 4690.93 KB 17.58
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 2.75GHz, 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  

CompleteMethodBenchmarks
Method N Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1 112.6 ns 0.77 ns 0.68 ns 1.00 592 B 1.00
Imposter 1 156.4 ns 1.00 ns 0.89 ns 1.39 808 B 1.36
TUnitMocks 1 282.8 ns 3.36 ns 3.14 ns 2.51 1424 B 2.41
Moq 1 3,551.8 ns 30.35 ns 26.90 ns 31.54 6552 B 11.07
NSubstitute 1 4,513.6 ns 56.01 ns 49.65 ns 40.08 9816 B 16.58
FakeItEasy 1 3,745.7 ns 47.46 ns 44.39 ns 33.26 7742 B 13.08
Mockolate 10 286.1 ns 3.56 ns 3.16 ns 1.00 1096 B 1.00
Imposter 10 309.6 ns 5.25 ns 4.65 ns 1.08 1168 B 1.07
TUnitMocks 10 951.1 ns 11.17 ns 10.45 ns 3.32 3288 B 3.00
Moq 10 5,033.4 ns 101.83 ns 95.25 ns 17.60 10536 B 9.61
NSubstitute 10 6,464.7 ns 115.60 ns 108.13 ns 22.60 12840 B 11.72
FakeItEasy 10 6,492.4 ns 127.04 ns 118.83 ns 22.70 15978 B 14.58
Mockolate 1000 20,477.6 ns 176.68 ns 156.62 ns 1.00 56536 B 1.00
Imposter 1000 19,321.2 ns 277.19 ns 259.28 ns 0.94 40768 B 0.72
TUnitMocks 1000 67,131.1 ns 762.16 ns 712.92 ns 3.28 178353 B 3.15
Moq 1000 156,818.9 ns 2,229.78 ns 1,976.64 ns 7.66 423564 B 7.49
NSubstitute 1000 214,540.8 ns 3,360.96 ns 3,143.84 ns 10.48 378537 B 6.70
FakeItEasy 1000 308,252.9 ns 3,167.77 ns 2,963.13 ns 15.05 943986 B 16.70
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 251.9 ns 9.70 ns 9.07 ns 1.00 920 B 1.00
Imposter 1 170.4 ns 4.47 ns 4.18 ns 0.68 672 B 0.73
TUnitMocks 1 384.8 ns 6.20 ns 5.80 ns 1.53 1464 B 1.59
Moq 1 10,894.6 ns 42.91 ns 35.83 ns 43.31 10569 B 11.49
NSubstitute 1 7,569.8 ns 82.60 ns 77.27 ns 30.09 11664 B 12.68
FakeItEasy 1 7,723.3 ns 60.81 ns 53.91 ns 30.70 11196 B 12.17
Mockolate 10 621.6 ns 11.19 ns 10.47 ns 1.00 1784 B 1.00
Imposter 10 346.8 ns 4.26 ns 3.56 ns 0.56 960 B 0.54
TUnitMocks 10 1,424.0 ns 29.54 ns 27.63 ns 2.29 3600 B 2.02
Moq 10 17,230.8 ns 67.60 ns 52.78 ns 27.73 18505 B 10.37
NSubstitute 10 17,213.9 ns 258.07 ns 228.77 ns 27.70 21529 B 12.07
FakeItEasy 10 19,223.5 ns 364.75 ns 341.19 ns 30.94 30785 B 17.26
Mockolate 1000 40,033.2 ns 723.61 ns 676.86 ns 1.00 96824 B 1.00
Imposter 1000 17,014.0 ns 145.90 ns 129.33 ns 0.43 32641 B 0.34
TUnitMocks 1000 103,214.4 ns 1,319.26 ns 1,234.04 ns 2.58 218305 B 2.25
Moq 1000 709,403.2 ns 7,077.40 ns 6,620.20 ns 17.73 836541 B 8.64
NSubstitute 1000 1,079,443.3 ns 7,172.96 ns 5,989.75 ns 26.97 1139703 B 11.77
FakeItEasy 1000 1,309,446.4 ns 20,330.91 ns 19,017.54 ns 32.72 2194291 B 22.66
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 3.24GHz, 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 475.2 ns 14.10 ns 13.19 ns 1.00 1.78 KB 1.00
Imposter 1 323.0 ns 10.67 ns 9.98 ns 0.68 1.19 KB 0.67
TUnitMocks 1 632.0 ns 6.03 ns 5.04 ns 1.33 2.16 KB 1.21
Moq 1 523,394.3 ns 2,753.97 ns 2,576.06 ns 1,102.17 37.48 KB 21.04
NSubstitute 1 207,946.1 ns 2,314.49 ns 2,164.98 ns 437.89 27.44 KB 15.41
FakeItEasy 1 236,651.1 ns 640.85 ns 568.10 ns 498.34 29.55 KB 16.59
Mockolate 10 1,351.5 ns 9.11 ns 8.07 ns 1.00 2.7 KB 1.00
Imposter 10 778.6 ns 6.16 ns 5.46 ns 0.58 2.24 KB 0.83
TUnitMocks 10 2,429.7 ns 16.51 ns 14.64 ns 1.80 5.13 KB 1.90
Moq 10 533,630.6 ns 987.14 ns 770.69 ns 394.84 45.84 KB 17.01
NSubstitute 10 225,539.2 ns 2,122.20 ns 1,985.10 ns 166.88 40.25 KB 14.93
FakeItEasy 10 262,521.1 ns 2,234.85 ns 1,981.14 ns 194.24 48.76 KB 18.09
Mockolate 1000 96,737.5 ns 1,054.30 ns 986.19 ns 1.00 103.24 KB 1.00
Imposter 1000 50,342.7 ns 485.74 ns 430.60 ns 0.52 118.26 KB 1.15
TUnitMocks 1000 182,621.6 ns 1,828.67 ns 1,621.07 ns 1.89 292.52 KB 2.83
Moq 1000 1,346,189.6 ns 7,253.85 ns 6,785.25 ns 13.92 914.36 KB 8.86
NSubstitute 1000 1,802,215.8 ns 16,952.36 ns 15,857.25 ns 18.63 1480.33 KB 14.34
FakeItEasy 1000 1,681,669.0 ns 22,546.83 ns 19,987.18 ns 17.39 2169.32 KB 21.01
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 2.65GHz, 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 149.4 ns 4.80 ns 4.26 ns 1.00 712 B 1.00
Imposter 174.2 ns 2.86 ns 2.54 ns 1.17 512 B 0.72
TUnitMocks 159.2 ns 1.73 ns 1.44 ns 1.07 1392 B 1.96
Moq 14,879.2 ns 168.46 ns 157.58 ns 99.66 12761 B 17.92
NSubstitute 5,640.3 ns 91.31 ns 85.41 ns 37.78 9192 B 12.91
FakeItEasy 214,345.4 ns 958.79 ns 896.85 ns 1,435.71 15738 B 22.10
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  

CallbackBenchmarks
Callback Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 199.5 ns 2.65 ns 2.48 ns 1.00 800 B 1.00
Imposter 197.6 ns 1.59 ns 1.41 ns 0.99 616 B 0.77
TUnitMocks 338.1 ns 4.03 ns 3.57 ns 1.69 1352 B 1.69
Moq 76,529.5 ns 500.27 ns 467.96 ns 383.59 9056 B 11.32
NSubstitute 4,135.0 ns 36.24 ns 33.90 ns 20.73 7864 B 9.83
FakeItEasy 3,998.1 ns 17.92 ns 13.99 ns 20.04 6930 B 8.66
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 2.87GHz, 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 250.8 ns 7.69 ns 7.20 ns 1.00 1 KB 1.00
Imposter 1 341.2 ns 4.28 ns 3.79 ns 1.36 1.58 KB 1.58
TUnitMocks 1 647.9 ns 11.23 ns 9.95 ns 2.59 2.57 KB 2.57
Moq 1 204,520.4 ns 759.57 ns 634.28 ns 816.06 22.76 KB 22.76
NSubstitute 1 11,182.4 ns 305.42 ns 285.69 ns 44.62 19.09 KB 19.09
FakeItEasy 1 7,845.7 ns 115.56 ns 102.44 ns 31.31 14.22 KB 14.22
Mockolate 10 1,203.0 ns 14.74 ns 13.07 ns 1.00 2.97 KB 1.00
Imposter 10 1,122.3 ns 9.41 ns 7.86 ns 0.93 3.41 KB 1.15
TUnitMocks 10 3,481.6 ns 52.48 ns 49.09 ns 2.89 9.22 KB 3.11
Moq 10 236,040.6 ns 2,187.83 ns 2,046.50 ns 196.24 40.19 KB 13.54
NSubstitute 10 19,003.2 ns 162.39 ns 151.90 ns 15.80 29.4 KB 9.90
FakeItEasy 10 30,223.0 ns 126.30 ns 105.47 ns 25.13 59.3 KB 19.97
Mockolate 1000 104,040.8 ns 785.98 ns 735.21 ns 1.00 219.53 KB 1.00
Imposter 1000 87,268.8 ns 343.29 ns 286.67 ns 0.84 204.5 KB 0.93
TUnitMocks 1000 295,562.7 ns 2,911.46 ns 2,580.94 ns 2.84 638.22 KB 2.91
Moq 1000 3,201,092.8 ns 38,475.55 ns 34,107.57 ns 30.77 1891.02 KB 8.61
NSubstitute 1000 892,036.5 ns 10,393.74 ns 9,722.31 ns 8.57 1092.82 KB 4.98
FakeItEasy 1000 2,971,020.0 ns 39,369.97 ns 34,900.45 ns 28.56 4933.61 KB 22.47
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.61GHz, 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.672 μs 0.0346 μs 0.0307 μs 1.00 2.23 KB 1.00
Imposter 2.440 μs 0.0463 μs 0.0410 μs 0.91 2.23 KB 1.00
TUnitMocks 2.794 μs 0.0344 μs 0.0305 μs 1.05 2.84 KB 1.27
Moq 10.182 μs 0.0703 μs 0.0623 μs 3.81 10.79 KB 4.83
NSubstitute 8.700 μs 0.1481 μs 0.1385 μs 3.26 14.29 KB 6.40
FakeItEasy 9.042 μs 0.0367 μs 0.0306 μs 3.38 14.28 KB 6.39
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  

The generated default-value overloads changed the MockBehaviorExtensions output, so the snapshot tests failed. The lambda parameter no longer shadows the pattern variable, and the MockBehavior.Default remarks now name the new defaults.
@sonarqubecloud

Copy link
Copy Markdown

@vbreuss
vbreuss merged commit 4123439 into main Nov 25, 2026
23 of 24 checks passed
@vbreuss
vbreuss deleted the feat/default-option-delegates branch November 25, 2026 18:50
github-actions Bot added a commit that referenced this pull request Nov 25, 2026
…> and no-op for Action<T> (#1132) by Valentin Breuß
github-actions Bot added a commit that referenced this pull request Nov 25, 2026
…> and no-op for Action<T> (#1132) by Valentin Breuß
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant