Skip to content

fix: make events only nullable when source is nullable#630

Merged
vbreuss merged 1 commit into
mainfrom
topic/fix-event-nullability
Apr 6, 2026
Merged

fix: make events only nullable when source is nullable#630
vbreuss merged 1 commit into
mainfrom
topic/fix-event-nullability

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Apr 6, 2026

Updates the source generator’s event emission so the generated mock’s event nullability matches the source declaration, reducing incorrect ? annotations in generated mocks.

Key Changes:

  • Adjusted mock event generation to use the event type as-is (preserving ? only when present on the source event).
  • Updated source generator tests to assert the new nullability behavior for interface/class events and overrides.

@vbreuss vbreuss self-assigned this Apr 6, 2026
@vbreuss vbreuss added the bug Something isn't working label Apr 6, 2026
Copilot AI review requested due to automatic review settings April 6, 2026 16:28
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

Updates the source generator’s event emission so the generated mock’s event nullability matches the source declaration, reducing incorrect ? annotations in generated mocks.

Changes:

  • Adjusted mock event generation to use the event type as-is (preserving ? only when present on the source event).
  • Updated source generator tests to assert the new nullability behavior for interface/class events and overrides.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
Tests/Mockolate.SourceGenerators.Tests/MockTests.ClassTests.EventsTests.cs Updates expected generated event signatures to match source nullability (? only when declared).
Tests/Mockolate.SourceGenerators.Tests/GeneralTests.cs Updates event-related expectations and one test input event to validate preserved nullability.
Source/Mockolate.SourceGenerators/Sources/Sources.MockClass.cs Changes event declaration emission to use @event.Type.Fullname directly (no forced nullable suffix).

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 6, 2026

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 6, 2026

Test Results

    21 files  ±0      21 suites  ±0   5m 34s ⏱️ +28s
 3 035 tests ±0   3 034 ✅ ±0  1 💤 ±0  0 ❌ ±0 
20 388 runs  ±0  20 387 ✅ ±0  1 💤 ±0  0 ❌ ±0 

Results for commit 85b5b63. ± Comparison against base commit 3c67756.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 6, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.62GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.201
[Host] : .NET 10.0.5 (10.0.5, 10.0.526.15411), 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
Indexer_Mockolate 951.5 ns 11.62 ns 10.87 ns 1.00 0.02 0.1564 - 2.56 KB 1.00
Indexer_Moq 187,927.6 ns 923.42 ns 863.77 ns 197.54 2.35 0.7324 0.4883 14.57 KB 5.69
Indexer_NSubstitute 6,157.7 ns 36.90 ns 32.71 ns 6.47 0.08 0.5722 - 9.41 KB 3.67
Indexer_FakeItEasy 6,308.0 ns 50.56 ns 47.30 ns 6.63 0.09 0.4883 0.0153 8.03 KB 3.13
Indexer_Imposter 799.8 ns 12.03 ns 11.26 ns 0.84 0.01 0.2928 0.0048 4.8 KB 1.87
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.62GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.201
[Host] : .NET 10.0.5 (10.0.5, 10.0.526.15411), 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
Method_Mockolate 716.2 ns 8.00 ns 7.48 ns 1.00 0.01 0.1326 - 2.17 KB 1.00
Method_Moq 187,943.5 ns 1,045.52 ns 926.83 ns 262.45 2.93 0.7324 0.4883 14.59 KB 6.72
Method_NSubstitute 5,935.8 ns 45.11 ns 42.19 ns 8.29 0.10 0.5493 0.0076 9.09 KB 4.18
Method_FakeItEasy 6,432.6 ns 30.41 ns 23.74 ns 8.98 0.10 0.4883 0.0153 8.05 KB 3.71
Method_Imposter 580.8 ns 8.45 ns 7.90 ns 0.81 0.01 0.2537 0.0029 4.15 KB 1.91
Method_TUnitMocks 751.3 ns 8.77 ns 8.20 ns 1.05 0.02 0.1774 0.0010 2.9 KB 1.33
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.62GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.201
[Host] : .NET 10.0.5 (10.0.5, 10.0.526.15411), 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
Property_Mockolate 511.5 ns 4.30 ns 3.59 ns 1.00 0.01 0.0801 - 1.32 KB 1.00
Property_Moq 4,936.0 ns 36.37 ns 34.02 ns 9.65 0.09 0.3281 - 5.48 KB 4.15
Property_NSubstitute 4,958.3 ns 27.40 ns 25.63 ns 9.69 0.08 0.5188 0.0076 8.58 KB 6.50
Property_FakeItEasy 4,725.1 ns 17.56 ns 16.43 ns 9.24 0.07 0.3815 0.0153 6.35 KB 4.81
Property_Imposter 366.1 ns 3.45 ns 3.05 ns 0.72 0.01 0.1783 0.0019 2.91 KB 2.21
Property_TUnitMocks 613.5 ns 6.80 ns 6.36 ns 1.20 0.01 0.1249 - 2.05 KB 1.56
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.62GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.201
[Host] : .NET 10.0.5 (10.0.5, 10.0.526.15411), 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 380.3 ns 5.67 ns 5.30 ns 1.00 0.02 0.0658 - 1.08 KB 1.00
Event_Moq 16,710.2 ns 50.77 ns 42.40 ns 43.94 0.60 0.7629 - 12.57 KB 11.66
Event_NSubstitute 5,807.9 ns 23.94 ns 21.22 ns 15.27 0.21 0.5569 0.0076 9.17 KB 8.51
Event_FakeItEasy 213,652.7 ns 748.49 ns 700.14 ns 561.87 7.76 0.7324 0.4883 15.26 KB 14.16
Event_Imposter 1,410.2 ns 20.24 ns 18.94 ns 3.71 0.07 0.5379 0.0153 8.8 KB 8.17
Event_TUnitMocks 192.4 ns 3.26 ns 3.05 ns 0.51 0.01 0.0837 0.0002 1.37 KB 1.27
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.62GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.201
[Host] : .NET 10.0.5 (10.0.5, 10.0.526.15411), 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 463.8 ns 3.89 ns 3.64 ns 1.00 0.01 0.1049 - 1.72 KB 1.00
Callback_Moq 96,018.0 ns 684.39 ns 606.69 ns 207.04 2.02 0.4883 0.2441 8.88 KB 5.17
Callback_NSubstitute 4,454.6 ns 11.66 ns 10.33 ns 9.61 0.08 0.4730 0.0076 7.74 KB 4.50
Callback_FakeItEasy 4,859.4 ns 31.00 ns 29.00 ns 10.48 0.10 0.4120 0.0153 6.81 KB 3.96
Callback_Imposter 413.6 ns 6.93 ns 6.14 ns 0.89 0.01 0.1454 0.0010 2.38 KB 1.39
Callback_TUnitMocks 650.2 ns 4.51 ns 4.22 ns 1.40 0.01 0.1602 0.0010 2.63 KB 1.53

@vbreuss vbreuss merged commit 589d44c into main Apr 6, 2026
16 checks passed
@vbreuss vbreuss deleted the topic/fix-event-nullability branch April 6, 2026 16:47
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

This is addressed in release v2.4.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 state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants