From 789ca76bb45b81725cf34a2b9434b68aab878412 Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Tue, 28 Apr 2026 09:05:59 +0200 Subject: [PATCH 01/21] Use centralization package management. --- Directory.Build.props | 2 +- Directory.Packages.props | 19 +++++++++++++++++++ PosInformatique.Moq.Analyzers.sln | 5 +++-- src/Moq.Analyzers/Moq.Analyzers.csproj | 6 +++--- .../Moq.Analyzers.Sandbox.csproj | 8 ++++---- .../Moq.Analyzers.Tests.csproj | 14 +++++++------- 6 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 Directory.Packages.props diff --git a/Directory.Build.props b/Directory.Build.props index 4c73d3c..fe1e5a1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -34,7 +34,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..1493472 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,19 @@ + + + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PosInformatique.Moq.Analyzers.sln b/PosInformatique.Moq.Analyzers.sln index 68f7953..0425890 100644 --- a/PosInformatique.Moq.Analyzers.sln +++ b/PosInformatique.Moq.Analyzers.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.7.34221.43 +# Visual Studio Version 18 +VisualStudioVersion = 18.4.11626.88 stable MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Analyzers.Tests", "tests\Moq.Analyzers.Tests\Moq.Analyzers.Tests.csproj", "{DEE86A7E-8338-4C3D-822B-E8FB976D9905}" EndProject @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .gitignore = .gitignore CodeCoverage.runsettings = CodeCoverage.runsettings Directory.Build.props = Directory.Build.props + Directory.Packages.props = Directory.Packages.props LICENSE = LICENSE README.md = README.md stylecop.json = stylecop.json diff --git a/src/Moq.Analyzers/Moq.Analyzers.csproj b/src/Moq.Analyzers/Moq.Analyzers.csproj index 68efed3..e495ca3 100644 --- a/src/Moq.Analyzers/Moq.Analyzers.csproj +++ b/src/Moq.Analyzers/Moq.Analyzers.csproj @@ -127,9 +127,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj b/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj index 57aa733..c75caed 100644 --- a/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj +++ b/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj @@ -5,10 +5,10 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/Moq.Analyzers.Tests/Moq.Analyzers.Tests.csproj b/tests/Moq.Analyzers.Tests/Moq.Analyzers.Tests.csproj index 84997b4..a48fe05 100644 --- a/tests/Moq.Analyzers.Tests/Moq.Analyzers.Tests.csproj +++ b/tests/Moq.Analyzers.Tests/Moq.Analyzers.Tests.csproj @@ -5,16 +5,16 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all From c22dea59e681559f6178f929371e61b33c9a502c Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Tue, 28 Apr 2026 10:29:39 +0200 Subject: [PATCH 02/21] Upgrades Microsoft.CodeAnalysis packages to the version 5.0.0 (C# 14.0 support). --- Directory.Packages.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 1493472..00be149 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,11 +4,11 @@ - - + + - + From ccdab3f0c2bb308d1dd936e74584e8b29e62ecc0 Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Wed, 29 Apr 2026 09:56:47 +0200 Subject: [PATCH 03/21] Separate analyzers and code fixes. --- PosInformatique.Moq.Analyzers.sln | 27 ++++++++++++++++++- src/Directory.Build.props | 25 +++++++++++++++++ .../CodeFixes/AddVerifyAllCodeFixProvider.cs | 4 +-- .../SetBehaviorToStrictCodeFixProvider.cs | 4 +-- ...tGenericArgumentSetupSetCodeFixProvider.cs | 4 +-- .../Moq.Analyzers.CodeFixes.csproj | 16 +++++++++++ src/Moq.Analyzers.Shared/AnalyzerRules.cs | 17 ++++++++++++ .../ChainInvocationArgument.cs | 0 .../ChainMember.cs | 0 .../ChainMembersInvocation.cs | 0 .../Diagnostics/NotNullWhenAttribute.cs | 0 .../Moq.Analyzers.Shared.projitems | 22 +++++++++++++++ .../Moq.Analyzers.Shared.shproj | 13 +++++++++ .../MoqExpressionAnalyzer.cs | 0 .../MoqSymbols.cs | 0 .../RaiseMethodCall.cs | 0 .../SyntaxNodeHelper.cs | 0 ...kInstanceShouldBeStrictBehaviorAnalyzer.cs | 4 +-- .../Analyzers/SetupSetAnalyzer.cs | 4 +-- .../VerifyAllShouldBeCalledAnalyzer.cs | 2 +- src/Moq.Analyzers/Moq.Analyzers.csproj | 17 ++---------- tests/Directory.Build.props | 19 +++++++++++++ .../AddVerifyAllCodeFixProviderTest.cs | 2 +- .../SetBehaviorToStrictCodeFixProviderTest.cs | 2 +- ...ericArgumentSetupSetCodeFixProviderTest.cs | 2 +- .../Moq.Analyzers.CodeFixes.Tests.csproj | 13 +++++++++ .../MoqCSharpCodeFixVerifier.cs | 2 +- .../Moq.Analyzers.Sandbox.csproj | 9 +------ .../Moq.Analyzers.Tests.csproj | 15 ----------- 29 files changed, 168 insertions(+), 55 deletions(-) create mode 100644 src/Directory.Build.props rename src/{Moq.Analyzers => Moq.Analyzers.CodeFixes}/CodeFixes/AddVerifyAllCodeFixProvider.cs (98%) rename src/{Moq.Analyzers => Moq.Analyzers.CodeFixes}/CodeFixes/SetBehaviorToStrictCodeFixProvider.cs (98%) rename src/{Moq.Analyzers => Moq.Analyzers.CodeFixes}/CodeFixes/SetGenericArgumentSetupSetCodeFixProvider.cs (96%) create mode 100644 src/Moq.Analyzers.CodeFixes/Moq.Analyzers.CodeFixes.csproj create mode 100644 src/Moq.Analyzers.Shared/AnalyzerRules.cs rename src/{Moq.Analyzers => Moq.Analyzers.Shared}/ChainInvocationArgument.cs (100%) rename src/{Moq.Analyzers => Moq.Analyzers.Shared}/ChainMember.cs (100%) rename src/{Moq.Analyzers => Moq.Analyzers.Shared}/ChainMembersInvocation.cs (100%) rename src/{Moq.Analyzers => Moq.Analyzers.Shared}/Diagnostics/NotNullWhenAttribute.cs (100%) create mode 100644 src/Moq.Analyzers.Shared/Moq.Analyzers.Shared.projitems create mode 100644 src/Moq.Analyzers.Shared/Moq.Analyzers.Shared.shproj rename src/{Moq.Analyzers => Moq.Analyzers.Shared}/MoqExpressionAnalyzer.cs (100%) rename src/{Moq.Analyzers => Moq.Analyzers.Shared}/MoqSymbols.cs (100%) rename src/{Moq.Analyzers => Moq.Analyzers.Shared}/RaiseMethodCall.cs (100%) rename src/{Moq.Analyzers => Moq.Analyzers.Shared}/SyntaxNodeHelper.cs (100%) rename tests/{Moq.Analyzers.Tests => Moq.Analyzers.CodeFixes.Tests}/CodeFixes/AddVerifyAllCodeFixProviderTest.cs (99%) rename tests/{Moq.Analyzers.Tests => Moq.Analyzers.CodeFixes.Tests}/CodeFixes/SetBehaviorToStrictCodeFixProviderTest.cs (99%) rename tests/{Moq.Analyzers.Tests => Moq.Analyzers.CodeFixes.Tests}/CodeFixes/SetGenericArgumentSetupSetCodeFixProviderTest.cs (97%) create mode 100644 tests/Moq.Analyzers.CodeFixes.Tests/Moq.Analyzers.CodeFixes.Tests.csproj rename tests/{Moq.Analyzers.Tests => Moq.Analyzers.CodeFixes.Tests}/MoqCSharpCodeFixVerifier.cs (95%) diff --git a/PosInformatique.Moq.Analyzers.sln b/PosInformatique.Moq.Analyzers.sln index 0425890..c30deaf 100644 --- a/PosInformatique.Moq.Analyzers.sln +++ b/PosInformatique.Moq.Analyzers.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 18 -VisualStudioVersion = 18.4.11626.88 stable +VisualStudioVersion = 18.4.11626.88 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Analyzers.Tests", "tests\Moq.Analyzers.Tests\Moq.Analyzers.Tests.csproj", "{DEE86A7E-8338-4C3D-822B-E8FB976D9905}" EndProject @@ -81,6 +81,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{02EA681E-C7D src\.editorconfig = src\.editorconfig EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Analyzers.CodeFixes", "src\Moq.Analyzers.CodeFixes\Moq.Analyzers.CodeFixes.csproj", "{310BC90C-AC67-4DAB-86A9-76E7DE8B1E40}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A0CD9438-DC28-48A0-8CF4-B2A809546FF6}" + ProjectSection(SolutionItems) = preProject + src\Directory.Build.props = src\Directory.Build.props + EndProjectSection +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Moq.Analyzers.Shared", "src\Moq.Analyzers.Shared\Moq.Analyzers.Shared.shproj", "{8C28B748-EF68-4685-A901-49BE72FCAC4C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Analyzers.CodeFixes.Tests", "tests\Moq.Analyzers.CodeFixes.Tests\Moq.Analyzers.CodeFixes.Tests.csproj", "{44AE11BA-BD29-4503-9479-8BD77E99E6CF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -99,6 +110,14 @@ Global {07F970A1-1477-4D4C-B233-C9B4DA6E3AD6}.Debug|Any CPU.Build.0 = Debug|Any CPU {07F970A1-1477-4D4C-B233-C9B4DA6E3AD6}.Release|Any CPU.ActiveCfg = Release|Any CPU {07F970A1-1477-4D4C-B233-C9B4DA6E3AD6}.Release|Any CPU.Build.0 = Release|Any CPU + {310BC90C-AC67-4DAB-86A9-76E7DE8B1E40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {310BC90C-AC67-4DAB-86A9-76E7DE8B1E40}.Debug|Any CPU.Build.0 = Debug|Any CPU + {310BC90C-AC67-4DAB-86A9-76E7DE8B1E40}.Release|Any CPU.ActiveCfg = Release|Any CPU + {310BC90C-AC67-4DAB-86A9-76E7DE8B1E40}.Release|Any CPU.Build.0 = Release|Any CPU + {44AE11BA-BD29-4503-9479-8BD77E99E6CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {44AE11BA-BD29-4503-9479-8BD77E99E6CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {44AE11BA-BD29-4503-9479-8BD77E99E6CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {44AE11BA-BD29-4503-9479-8BD77E99E6CF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -110,8 +129,14 @@ Global {D9C84D36-7F9C-4EFB-BE6F-9F7A05FE957D} = {3C20D95F-AB5F-44EC-8FB6-CB9827B7FD63} {FA7258E1-65F0-4C40-A122-D76A1F0C79A0} = {1D59B801-B4D3-44FC-A2BE-F2F53AC54061} {0EACA365-AFB2-4200-91FD-A20DC9617799} = {FA7258E1-65F0-4C40-A122-D76A1F0C79A0} + {A0CD9438-DC28-48A0-8CF4-B2A809546FF6} = {1D59B801-B4D3-44FC-A2BE-F2F53AC54061} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3307E7F7-9CD7-4C12-B34A-943F5A8B62A4} EndGlobalSection + GlobalSection(SharedMSBuildProjectFiles) = preSolution + src\Moq.Analyzers.Shared\Moq.Analyzers.Shared.projitems*{1962bef9-e6df-4485-a113-e255c84177d4}*SharedItemsImports = 5 + src\Moq.Analyzers.Shared\Moq.Analyzers.Shared.projitems*{310bc90c-ac67-4dab-86a9-76e7de8b1e40}*SharedItemsImports = 5 + src\Moq.Analyzers.Shared\Moq.Analyzers.Shared.projitems*{8c28b748-ef68-4685-a901-49be72fcac4c}*SharedItemsImports = 13 + EndGlobalSection EndGlobal diff --git a/src/Directory.Build.props b/src/Directory.Build.props new file mode 100644 index 0000000..df2970e --- /dev/null +++ b/src/Directory.Build.props @@ -0,0 +1,25 @@ + + + + + + latest + enable + + netstandard2.0 + true + false + true + + true + true + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + \ No newline at end of file diff --git a/src/Moq.Analyzers/CodeFixes/AddVerifyAllCodeFixProvider.cs b/src/Moq.Analyzers.CodeFixes/CodeFixes/AddVerifyAllCodeFixProvider.cs similarity index 98% rename from src/Moq.Analyzers/CodeFixes/AddVerifyAllCodeFixProvider.cs rename to src/Moq.Analyzers.CodeFixes/CodeFixes/AddVerifyAllCodeFixProvider.cs index b52f22d..c2b5a98 100644 --- a/src/Moq.Analyzers/CodeFixes/AddVerifyAllCodeFixProvider.cs +++ b/src/Moq.Analyzers.CodeFixes/CodeFixes/AddVerifyAllCodeFixProvider.cs @@ -4,7 +4,7 @@ // //----------------------------------------------------------------------- -namespace PosInformatique.Moq.Analyzers +namespace PosInformatique.Moq.Analyzers.CodeFixes { using System.Collections.Immutable; using System.Composition; @@ -20,7 +20,7 @@ public class AddVerifyAllCodeFixProvider : CodeFixProvider { public sealed override ImmutableArray FixableDiagnosticIds { - get { return ImmutableArray.Create(VerifyAllShouldBeCalledAnalyzer.Rule.Id); } + get { return ImmutableArray.Create(AnalyzerRules.VerifyAllShouldBeCalledAnalyzerRuleId); } } public sealed override FixAllProvider GetFixAllProvider() diff --git a/src/Moq.Analyzers/CodeFixes/SetBehaviorToStrictCodeFixProvider.cs b/src/Moq.Analyzers.CodeFixes/CodeFixes/SetBehaviorToStrictCodeFixProvider.cs similarity index 98% rename from src/Moq.Analyzers/CodeFixes/SetBehaviorToStrictCodeFixProvider.cs rename to src/Moq.Analyzers.CodeFixes/CodeFixes/SetBehaviorToStrictCodeFixProvider.cs index c85f4dc..f104466 100644 --- a/src/Moq.Analyzers/CodeFixes/SetBehaviorToStrictCodeFixProvider.cs +++ b/src/Moq.Analyzers.CodeFixes/CodeFixes/SetBehaviorToStrictCodeFixProvider.cs @@ -4,7 +4,7 @@ // //----------------------------------------------------------------------- -namespace PosInformatique.Moq.Analyzers +namespace PosInformatique.Moq.Analyzers.CodeFixes { using System.Collections.Generic; using System.Collections.Immutable; @@ -21,7 +21,7 @@ public class SetBehaviorToStrictCodeFixProvider : CodeFixProvider { public sealed override ImmutableArray FixableDiagnosticIds { - get { return ImmutableArray.Create(MockInstanceShouldBeStrictBehaviorAnalyzer.DiagnosticId); } + get { return ImmutableArray.Create(AnalyzerRules.MockInstanceShouldBeStrictBehaviorAnalyzerRuleId); } } public sealed override FixAllProvider GetFixAllProvider() diff --git a/src/Moq.Analyzers/CodeFixes/SetGenericArgumentSetupSetCodeFixProvider.cs b/src/Moq.Analyzers.CodeFixes/CodeFixes/SetGenericArgumentSetupSetCodeFixProvider.cs similarity index 96% rename from src/Moq.Analyzers/CodeFixes/SetGenericArgumentSetupSetCodeFixProvider.cs rename to src/Moq.Analyzers.CodeFixes/CodeFixes/SetGenericArgumentSetupSetCodeFixProvider.cs index eb1c068..5a2d3de 100644 --- a/src/Moq.Analyzers/CodeFixes/SetGenericArgumentSetupSetCodeFixProvider.cs +++ b/src/Moq.Analyzers.CodeFixes/CodeFixes/SetGenericArgumentSetupSetCodeFixProvider.cs @@ -4,7 +4,7 @@ // //----------------------------------------------------------------------- -namespace PosInformatique.Moq.Analyzers +namespace PosInformatique.Moq.Analyzers.CodeFixes { using System.Collections.Immutable; using System.Composition; @@ -20,7 +20,7 @@ public class SetGenericArgumentSetupSetCodeFixProvider : CodeFixProvider { public sealed override ImmutableArray FixableDiagnosticIds { - get { return ImmutableArray.Create(SetupSetAnalyzer.UseSetupSetWithGenericArgumentRule.Id); } + get { return ImmutableArray.Create(AnalyzerRules.UseSetupSetWithGenericArgumentRuleId); } } public sealed override FixAllProvider GetFixAllProvider() diff --git a/src/Moq.Analyzers.CodeFixes/Moq.Analyzers.CodeFixes.csproj b/src/Moq.Analyzers.CodeFixes/Moq.Analyzers.CodeFixes.csproj new file mode 100644 index 0000000..536f80f --- /dev/null +++ b/src/Moq.Analyzers.CodeFixes/Moq.Analyzers.CodeFixes.csproj @@ -0,0 +1,16 @@ + + + + + + + + + + + + <_Parameter1>PosInformatique.Moq.Analyzers.CodeFixes.Tests + + + + diff --git a/src/Moq.Analyzers.Shared/AnalyzerRules.cs b/src/Moq.Analyzers.Shared/AnalyzerRules.cs new file mode 100644 index 0000000..1846d80 --- /dev/null +++ b/src/Moq.Analyzers.Shared/AnalyzerRules.cs @@ -0,0 +1,17 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) P.O.S Informatique. All rights reserved. +// +//----------------------------------------------------------------------- + +namespace PosInformatique.Moq.Analyzers +{ + internal static class AnalyzerRules + { + public const string VerifyAllShouldBeCalledAnalyzerRuleId = "PosInfoMoq1000"; + + public const string MockInstanceShouldBeStrictBehaviorAnalyzerRuleId = "PosInfoMoq1001"; + + public const string UseSetupSetWithGenericArgumentRuleId = "PosInfoMoq1005"; + } +} \ No newline at end of file diff --git a/src/Moq.Analyzers/ChainInvocationArgument.cs b/src/Moq.Analyzers.Shared/ChainInvocationArgument.cs similarity index 100% rename from src/Moq.Analyzers/ChainInvocationArgument.cs rename to src/Moq.Analyzers.Shared/ChainInvocationArgument.cs diff --git a/src/Moq.Analyzers/ChainMember.cs b/src/Moq.Analyzers.Shared/ChainMember.cs similarity index 100% rename from src/Moq.Analyzers/ChainMember.cs rename to src/Moq.Analyzers.Shared/ChainMember.cs diff --git a/src/Moq.Analyzers/ChainMembersInvocation.cs b/src/Moq.Analyzers.Shared/ChainMembersInvocation.cs similarity index 100% rename from src/Moq.Analyzers/ChainMembersInvocation.cs rename to src/Moq.Analyzers.Shared/ChainMembersInvocation.cs diff --git a/src/Moq.Analyzers/Diagnostics/NotNullWhenAttribute.cs b/src/Moq.Analyzers.Shared/Diagnostics/NotNullWhenAttribute.cs similarity index 100% rename from src/Moq.Analyzers/Diagnostics/NotNullWhenAttribute.cs rename to src/Moq.Analyzers.Shared/Diagnostics/NotNullWhenAttribute.cs diff --git a/src/Moq.Analyzers.Shared/Moq.Analyzers.Shared.projitems b/src/Moq.Analyzers.Shared/Moq.Analyzers.Shared.projitems new file mode 100644 index 0000000..42b310f --- /dev/null +++ b/src/Moq.Analyzers.Shared/Moq.Analyzers.Shared.projitems @@ -0,0 +1,22 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 8c28b748-ef68-4685-a901-49be72fcac4c + + + Moq.Analyzers.Shared + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Moq.Analyzers.Shared/Moq.Analyzers.Shared.shproj b/src/Moq.Analyzers.Shared/Moq.Analyzers.Shared.shproj new file mode 100644 index 0000000..44efdfe --- /dev/null +++ b/src/Moq.Analyzers.Shared/Moq.Analyzers.Shared.shproj @@ -0,0 +1,13 @@ + + + + 8c28b748-ef68-4685-a901-49be72fcac4c + 14.0 + + + + + + + + diff --git a/src/Moq.Analyzers/MoqExpressionAnalyzer.cs b/src/Moq.Analyzers.Shared/MoqExpressionAnalyzer.cs similarity index 100% rename from src/Moq.Analyzers/MoqExpressionAnalyzer.cs rename to src/Moq.Analyzers.Shared/MoqExpressionAnalyzer.cs diff --git a/src/Moq.Analyzers/MoqSymbols.cs b/src/Moq.Analyzers.Shared/MoqSymbols.cs similarity index 100% rename from src/Moq.Analyzers/MoqSymbols.cs rename to src/Moq.Analyzers.Shared/MoqSymbols.cs diff --git a/src/Moq.Analyzers/RaiseMethodCall.cs b/src/Moq.Analyzers.Shared/RaiseMethodCall.cs similarity index 100% rename from src/Moq.Analyzers/RaiseMethodCall.cs rename to src/Moq.Analyzers.Shared/RaiseMethodCall.cs diff --git a/src/Moq.Analyzers/SyntaxNodeHelper.cs b/src/Moq.Analyzers.Shared/SyntaxNodeHelper.cs similarity index 100% rename from src/Moq.Analyzers/SyntaxNodeHelper.cs rename to src/Moq.Analyzers.Shared/SyntaxNodeHelper.cs diff --git a/src/Moq.Analyzers/Analyzers/MockInstanceShouldBeStrictBehaviorAnalyzer.cs b/src/Moq.Analyzers/Analyzers/MockInstanceShouldBeStrictBehaviorAnalyzer.cs index f0d14a5..68ee6aa 100644 --- a/src/Moq.Analyzers/Analyzers/MockInstanceShouldBeStrictBehaviorAnalyzer.cs +++ b/src/Moq.Analyzers/Analyzers/MockInstanceShouldBeStrictBehaviorAnalyzer.cs @@ -15,10 +15,8 @@ namespace PosInformatique.Moq.Analyzers [DiagnosticAnalyzer(LanguageNames.CSharp)] public class MockInstanceShouldBeStrictBehaviorAnalyzer : DiagnosticAnalyzer { - public const string DiagnosticId = "PosInfoMoq1001"; - private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor( - DiagnosticId, + AnalyzerRules.MockInstanceShouldBeStrictBehaviorAnalyzerRuleId, "The mocked instances behavior should be defined to Strict mode", "The mocked instances behavior should be defined to Strict mode", "Design", diff --git a/src/Moq.Analyzers/Analyzers/SetupSetAnalyzer.cs b/src/Moq.Analyzers/Analyzers/SetupSetAnalyzer.cs index 9aa6ac1..1185da2 100644 --- a/src/Moq.Analyzers/Analyzers/SetupSetAnalyzer.cs +++ b/src/Moq.Analyzers/Analyzers/SetupSetAnalyzer.cs @@ -15,8 +15,8 @@ namespace PosInformatique.Moq.Analyzers [DiagnosticAnalyzer(LanguageNames.CSharp)] public class SetupSetAnalyzer : DiagnosticAnalyzer { - internal static readonly DiagnosticDescriptor UseSetupSetWithGenericArgumentRule = new DiagnosticDescriptor( - "PosInfoMoq1005", + private static readonly DiagnosticDescriptor UseSetupSetWithGenericArgumentRule = new DiagnosticDescriptor( + AnalyzerRules.UseSetupSetWithGenericArgumentRuleId, "Defines the generic argument of the SetupSet() method with the type of the mocked property", "Defines the generic argument of the SetupSet() method with the type of the mocked property", "Design", diff --git a/src/Moq.Analyzers/Analyzers/VerifyAllShouldBeCalledAnalyzer.cs b/src/Moq.Analyzers/Analyzers/VerifyAllShouldBeCalledAnalyzer.cs index d2ad9eb..07e140e 100644 --- a/src/Moq.Analyzers/Analyzers/VerifyAllShouldBeCalledAnalyzer.cs +++ b/src/Moq.Analyzers/Analyzers/VerifyAllShouldBeCalledAnalyzer.cs @@ -16,7 +16,7 @@ namespace PosInformatique.Moq.Analyzers public class VerifyAllShouldBeCalledAnalyzer : DiagnosticAnalyzer { internal static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor( - "PosInfoMoq1000", + AnalyzerRules.VerifyAllShouldBeCalledAnalyzerRuleId, "VerifyAll() method should be called when instantiate a Mock instances", "The VerifyAll() method should be called at the end of the unit test", "Design", diff --git a/src/Moq.Analyzers/Moq.Analyzers.csproj b/src/Moq.Analyzers/Moq.Analyzers.csproj index e495ca3..d0bce5a 100644 --- a/src/Moq.Analyzers/Moq.Analyzers.csproj +++ b/src/Moq.Analyzers/Moq.Analyzers.csproj @@ -1,16 +1,6 @@  - netstandard2.0 - true - false - true - - latest - enable - - true - true PosInformatique.Moq.Analyzers is a library to verify syntax and code design when writing the unit tests using the Moq library. Icon.png @@ -128,13 +118,10 @@ - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 8910c72..6f81a8b 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -3,6 +3,25 @@ + + + net8.0 + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + diff --git a/tests/Moq.Analyzers.Tests/CodeFixes/AddVerifyAllCodeFixProviderTest.cs b/tests/Moq.Analyzers.CodeFixes.Tests/CodeFixes/AddVerifyAllCodeFixProviderTest.cs similarity index 99% rename from tests/Moq.Analyzers.Tests/CodeFixes/AddVerifyAllCodeFixProviderTest.cs rename to tests/Moq.Analyzers.CodeFixes.Tests/CodeFixes/AddVerifyAllCodeFixProviderTest.cs index 6d61c5b..168f9a7 100644 --- a/tests/Moq.Analyzers.Tests/CodeFixes/AddVerifyAllCodeFixProviderTest.cs +++ b/tests/Moq.Analyzers.CodeFixes.Tests/CodeFixes/AddVerifyAllCodeFixProviderTest.cs @@ -4,7 +4,7 @@ // //----------------------------------------------------------------------- -namespace PosInformatique.Moq.Analyzers.Tests +namespace PosInformatique.Moq.Analyzers.CodeFixes.Tests { using Verifier = MoqCSharpCodeFixVerifier; diff --git a/tests/Moq.Analyzers.Tests/CodeFixes/SetBehaviorToStrictCodeFixProviderTest.cs b/tests/Moq.Analyzers.CodeFixes.Tests/CodeFixes/SetBehaviorToStrictCodeFixProviderTest.cs similarity index 99% rename from tests/Moq.Analyzers.Tests/CodeFixes/SetBehaviorToStrictCodeFixProviderTest.cs rename to tests/Moq.Analyzers.CodeFixes.Tests/CodeFixes/SetBehaviorToStrictCodeFixProviderTest.cs index 70ec544..8123bb9 100644 --- a/tests/Moq.Analyzers.Tests/CodeFixes/SetBehaviorToStrictCodeFixProviderTest.cs +++ b/tests/Moq.Analyzers.CodeFixes.Tests/CodeFixes/SetBehaviorToStrictCodeFixProviderTest.cs @@ -4,7 +4,7 @@ // //----------------------------------------------------------------------- -namespace PosInformatique.Moq.Analyzers.Tests +namespace PosInformatique.Moq.Analyzers.CodeFixes.Tests { using Verifier = MoqCSharpCodeFixVerifier; diff --git a/tests/Moq.Analyzers.Tests/CodeFixes/SetGenericArgumentSetupSetCodeFixProviderTest.cs b/tests/Moq.Analyzers.CodeFixes.Tests/CodeFixes/SetGenericArgumentSetupSetCodeFixProviderTest.cs similarity index 97% rename from tests/Moq.Analyzers.Tests/CodeFixes/SetGenericArgumentSetupSetCodeFixProviderTest.cs rename to tests/Moq.Analyzers.CodeFixes.Tests/CodeFixes/SetGenericArgumentSetupSetCodeFixProviderTest.cs index 4c30477..b8f18db 100644 --- a/tests/Moq.Analyzers.Tests/CodeFixes/SetGenericArgumentSetupSetCodeFixProviderTest.cs +++ b/tests/Moq.Analyzers.CodeFixes.Tests/CodeFixes/SetGenericArgumentSetupSetCodeFixProviderTest.cs @@ -4,7 +4,7 @@ // //----------------------------------------------------------------------- -namespace PosInformatique.Moq.Analyzers.Tests +namespace PosInformatique.Moq.Analyzers.CodeFixes.Tests { using Verifier = MoqCSharpCodeFixVerifier; diff --git a/tests/Moq.Analyzers.CodeFixes.Tests/Moq.Analyzers.CodeFixes.Tests.csproj b/tests/Moq.Analyzers.CodeFixes.Tests/Moq.Analyzers.CodeFixes.Tests.csproj new file mode 100644 index 0000000..96cec04 --- /dev/null +++ b/tests/Moq.Analyzers.CodeFixes.Tests/Moq.Analyzers.CodeFixes.Tests.csproj @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/tests/Moq.Analyzers.Tests/MoqCSharpCodeFixVerifier.cs b/tests/Moq.Analyzers.CodeFixes.Tests/MoqCSharpCodeFixVerifier.cs similarity index 95% rename from tests/Moq.Analyzers.Tests/MoqCSharpCodeFixVerifier.cs rename to tests/Moq.Analyzers.CodeFixes.Tests/MoqCSharpCodeFixVerifier.cs index a09e170..858c674 100644 --- a/tests/Moq.Analyzers.Tests/MoqCSharpCodeFixVerifier.cs +++ b/tests/Moq.Analyzers.CodeFixes.Tests/MoqCSharpCodeFixVerifier.cs @@ -4,7 +4,7 @@ // //----------------------------------------------------------------------- -namespace PosInformatique.Moq.Analyzers.Tests +namespace PosInformatique.Moq.Analyzers.CodeFixes.Tests { using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.Testing; diff --git a/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj b/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj index c75caed..92714bf 100644 --- a/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj +++ b/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj @@ -6,17 +6,10 @@ - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - + diff --git a/tests/Moq.Analyzers.Tests/Moq.Analyzers.Tests.csproj b/tests/Moq.Analyzers.Tests/Moq.Analyzers.Tests.csproj index a48fe05..4eefead 100644 --- a/tests/Moq.Analyzers.Tests/Moq.Analyzers.Tests.csproj +++ b/tests/Moq.Analyzers.Tests/Moq.Analyzers.Tests.csproj @@ -1,23 +1,8 @@  - - net8.0 - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - From 66a4005961094a18f2a660ebf1214a13c2b9647d Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Mon, 8 Jun 2026 17:41:55 +0200 Subject: [PATCH 04/21] Migrate to .slnx file. --- .github/workflows/github-actions-ci.yaml | 6 +- PosInformatique.Moq.Analyzers.sln | 142 ----------------------- PosInformatique.Moq.Analyzers.slnx | 69 +++++++++++ 3 files changed, 72 insertions(+), 145 deletions(-) delete mode 100644 PosInformatique.Moq.Analyzers.sln create mode 100644 PosInformatique.Moq.Analyzers.slnx diff --git a/.github/workflows/github-actions-ci.yaml b/.github/workflows/github-actions-ci.yaml index d4a661b..df26e1f 100644 --- a/.github/workflows/github-actions-ci.yaml +++ b/.github/workflows/github-actions-ci.yaml @@ -18,17 +18,17 @@ jobs: dotnet-version: '8.x' - name: Restore dependencies - run: dotnet restore PosInformatique.Moq.Analyzers.sln + run: dotnet restore PosInformatique.Moq.Analyzers.slnx - name: Build solution run: | - dotnet build PosInformatique.Moq.Analyzers.sln \ + dotnet build PosInformatique.Moq.Analyzers.slnx \ --configuration Release \ --no-restore - name: Run tests run: | - dotnet test PosInformatique.Moq.Analyzers.sln \ + dotnet test PosInformatique.Moq.Analyzers.slnx \ --configuration Release \ --no-build \ --logger "trx;LogFileName=test_results.trx" \ diff --git a/PosInformatique.Moq.Analyzers.sln b/PosInformatique.Moq.Analyzers.sln deleted file mode 100644 index c30deaf..0000000 --- a/PosInformatique.Moq.Analyzers.sln +++ /dev/null @@ -1,142 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 18 -VisualStudioVersion = 18.4.11626.88 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Analyzers.Tests", "tests\Moq.Analyzers.Tests\Moq.Analyzers.Tests.csproj", "{DEE86A7E-8338-4C3D-822B-E8FB976D9905}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Analyzers", "src\Moq.Analyzers\Moq.Analyzers.csproj", "{1962BEF9-E6DF-4485-A113-E255C84177D4}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1D59B801-B4D3-44FC-A2BE-F2F53AC54061}" - ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig - .gitignore = .gitignore - CodeCoverage.runsettings = CodeCoverage.runsettings - Directory.Build.props = Directory.Build.props - Directory.Packages.props = Directory.Packages.props - LICENSE = LICENSE - README.md = README.md - stylecop.json = stylecop.json - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{DC2CDF77-88A9-490D-84ED-34832943104A}" - ProjectSection(SolutionItems) = preProject - tests\.editorconfig = tests\.editorconfig - tests\Directory.Build.props = tests\Directory.Build.props - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{3C20D95F-AB5F-44EC-8FB6-CB9827B7FD63}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Design", "Design", "{815BE8D0-C7D5-4B4E-82E0-DE29C11F258E}" - ProjectSection(SolutionItems) = preProject - docs\design\PosInfoMoq1000.md = docs\design\PosInfoMoq1000.md - docs\design\PosInfoMoq1001.md = docs\design\PosInfoMoq1001.md - docs\Design\PosInfoMoq1002.md = docs\Design\PosInfoMoq1002.md - docs\Design\PosInfoMoq1003.md = docs\Design\PosInfoMoq1003.md - docs\Design\PosInfoMoq1004.md = docs\Design\PosInfoMoq1004.md - docs\Design\PosInfoMoq1005.md = docs\Design\PosInfoMoq1005.md - docs\Design\PosInfoMoq1006.md = docs\Design\PosInfoMoq1006.md - docs\Design\PosInfoMoq1007.md = docs\Design\PosInfoMoq1007.md - docs\Design\PosInfoMoq1008.md = docs\Design\PosInfoMoq1008.md - docs\Design\PosInfoMoq1009.md = docs\Design\PosInfoMoq1009.md - docs\Design\PosInfoMoq1010.md = docs\Design\PosInfoMoq1010.md - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Compilation", "Compilation", "{D9C84D36-7F9C-4EFB-BE6F-9F7A05FE957D}" - ProjectSection(SolutionItems) = preProject - docs\Compilation\PosInfoMoq2000.md = docs\Compilation\PosInfoMoq2000.md - docs\Compilation\PosInfoMoq2001.md = docs\Compilation\PosInfoMoq2001.md - docs\Compilation\PosInfoMoq2002.md = docs\Compilation\PosInfoMoq2002.md - docs\Compilation\PosInfoMoq2003.md = docs\Compilation\PosInfoMoq2003.md - docs\Compilation\PosInfoMoq2004.md = docs\Compilation\PosInfoMoq2004.md - docs\Compilation\PosInfoMoq2005.md = docs\Compilation\PosInfoMoq2005.md - docs\Compilation\PosInfoMoq2006.md = docs\Compilation\PosInfoMoq2006.md - docs\Compilation\PosInfoMoq2007.md = docs\Compilation\PosInfoMoq2007.md - docs\Compilation\PosInfoMoq2008.md = docs\Compilation\PosInfoMoq2008.md - docs\Compilation\PosInfoMoq2009.md = docs\Compilation\PosInfoMoq2009.md - docs\Compilation\PosInfoMoq2010.md = docs\Compilation\PosInfoMoq2010.md - docs\Compilation\PosInfoMoq2011.md = docs\Compilation\PosInfoMoq2011.md - docs\Compilation\PosInfoMoq2012.md = docs\Compilation\PosInfoMoq2012.md - docs\Compilation\PosInfoMoq2013.md = docs\Compilation\PosInfoMoq2013.md - docs\Compilation\PosInfoMoq2014.md = docs\Compilation\PosInfoMoq2014.md - docs\Compilation\PosInfoMoq2015.md = docs\Compilation\PosInfoMoq2015.md - docs\Compilation\PosInfoMoq2016.md = docs\Compilation\PosInfoMoq2016.md - docs\Compilation\PosInfoMoq2017.md = docs\Compilation\PosInfoMoq2017.md - docs\Compilation\PosInfoMoq2018.md = docs\Compilation\PosInfoMoq2018.md - docs\Compilation\PosInfoMoq2019.md = docs\Compilation\PosInfoMoq2019.md - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Moq.Analyzers.Sandbox", "tests\Moq.Analyzers.Sandbox\Moq.Analyzers.Sandbox.csproj", "{07F970A1-1477-4D4C-B233-C9B4DA6E3AD6}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{FA7258E1-65F0-4C40-A122-D76A1F0C79A0}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{0EACA365-AFB2-4200-91FD-A20DC9617799}" - ProjectSection(SolutionItems) = preProject - .github\workflows\github-actions-ci.yaml = .github\workflows\github-actions-ci.yaml - .github\workflows\github-actions-release.yml = .github\workflows\github-actions-release.yml - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" - ProjectSection(SolutionItems) = preProject - src\.editorconfig = src\.editorconfig - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Analyzers.CodeFixes", "src\Moq.Analyzers.CodeFixes\Moq.Analyzers.CodeFixes.csproj", "{310BC90C-AC67-4DAB-86A9-76E7DE8B1E40}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A0CD9438-DC28-48A0-8CF4-B2A809546FF6}" - ProjectSection(SolutionItems) = preProject - src\Directory.Build.props = src\Directory.Build.props - EndProjectSection -EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Moq.Analyzers.Shared", "src\Moq.Analyzers.Shared\Moq.Analyzers.Shared.shproj", "{8C28B748-EF68-4685-A901-49BE72FCAC4C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moq.Analyzers.CodeFixes.Tests", "tests\Moq.Analyzers.CodeFixes.Tests\Moq.Analyzers.CodeFixes.Tests.csproj", "{44AE11BA-BD29-4503-9479-8BD77E99E6CF}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {DEE86A7E-8338-4C3D-822B-E8FB976D9905}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DEE86A7E-8338-4C3D-822B-E8FB976D9905}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DEE86A7E-8338-4C3D-822B-E8FB976D9905}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DEE86A7E-8338-4C3D-822B-E8FB976D9905}.Release|Any CPU.Build.0 = Release|Any CPU - {1962BEF9-E6DF-4485-A113-E255C84177D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1962BEF9-E6DF-4485-A113-E255C84177D4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1962BEF9-E6DF-4485-A113-E255C84177D4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1962BEF9-E6DF-4485-A113-E255C84177D4}.Release|Any CPU.Build.0 = Release|Any CPU - {07F970A1-1477-4D4C-B233-C9B4DA6E3AD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {07F970A1-1477-4D4C-B233-C9B4DA6E3AD6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {07F970A1-1477-4D4C-B233-C9B4DA6E3AD6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {07F970A1-1477-4D4C-B233-C9B4DA6E3AD6}.Release|Any CPU.Build.0 = Release|Any CPU - {310BC90C-AC67-4DAB-86A9-76E7DE8B1E40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {310BC90C-AC67-4DAB-86A9-76E7DE8B1E40}.Debug|Any CPU.Build.0 = Debug|Any CPU - {310BC90C-AC67-4DAB-86A9-76E7DE8B1E40}.Release|Any CPU.ActiveCfg = Release|Any CPU - {310BC90C-AC67-4DAB-86A9-76E7DE8B1E40}.Release|Any CPU.Build.0 = Release|Any CPU - {44AE11BA-BD29-4503-9479-8BD77E99E6CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {44AE11BA-BD29-4503-9479-8BD77E99E6CF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {44AE11BA-BD29-4503-9479-8BD77E99E6CF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {44AE11BA-BD29-4503-9479-8BD77E99E6CF}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {DC2CDF77-88A9-490D-84ED-34832943104A} = {1D59B801-B4D3-44FC-A2BE-F2F53AC54061} - {3C20D95F-AB5F-44EC-8FB6-CB9827B7FD63} = {1D59B801-B4D3-44FC-A2BE-F2F53AC54061} - {815BE8D0-C7D5-4B4E-82E0-DE29C11F258E} = {3C20D95F-AB5F-44EC-8FB6-CB9827B7FD63} - {D9C84D36-7F9C-4EFB-BE6F-9F7A05FE957D} = {3C20D95F-AB5F-44EC-8FB6-CB9827B7FD63} - {FA7258E1-65F0-4C40-A122-D76A1F0C79A0} = {1D59B801-B4D3-44FC-A2BE-F2F53AC54061} - {0EACA365-AFB2-4200-91FD-A20DC9617799} = {FA7258E1-65F0-4C40-A122-D76A1F0C79A0} - {A0CD9438-DC28-48A0-8CF4-B2A809546FF6} = {1D59B801-B4D3-44FC-A2BE-F2F53AC54061} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {3307E7F7-9CD7-4C12-B34A-943F5A8B62A4} - EndGlobalSection - GlobalSection(SharedMSBuildProjectFiles) = preSolution - src\Moq.Analyzers.Shared\Moq.Analyzers.Shared.projitems*{1962bef9-e6df-4485-a113-e255c84177d4}*SharedItemsImports = 5 - src\Moq.Analyzers.Shared\Moq.Analyzers.Shared.projitems*{310bc90c-ac67-4dab-86a9-76e7de8b1e40}*SharedItemsImports = 5 - src\Moq.Analyzers.Shared\Moq.Analyzers.Shared.projitems*{8c28b748-ef68-4685-a901-49be72fcac4c}*SharedItemsImports = 13 - EndGlobalSection -EndGlobal diff --git a/PosInformatique.Moq.Analyzers.slnx b/PosInformatique.Moq.Analyzers.slnx new file mode 100644 index 0000000..132517c --- /dev/null +++ b/PosInformatique.Moq.Analyzers.slnx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From f8e3801820c190d8b6f8f1fbdf38f73656f06969 Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Mon, 8 Jun 2026 20:01:16 +0200 Subject: [PATCH 05/21] Increase the version. --- .github/workflows/github-actions-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions-release.yml b/.github/workflows/github-actions-release.yml index 03c1a56..2a0606a 100644 --- a/.github/workflows/github-actions-release.yml +++ b/.github/workflows/github-actions-release.yml @@ -7,7 +7,7 @@ on: type: string description: The version of the library required: true - default: 2.0.1 + default: 2.1.0 VersionSuffix: type: string description: The version suffix of the library (for example rc.1) From 8ad9d84c028c048f6fd084097fd286015a97ada4 Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Mon, 8 Jun 2026 20:03:01 +0200 Subject: [PATCH 06/21] Fix the PosInfoMoq2003 rule to check the signature of the Callback() method when using the default parameters in the interfaces (fixes #58). --- .../ChainMembersInvocation.cs | 26 ++++++++------ ...ckDelegateMustMatchMockedMethodAnalyzer.cs | 6 ++-- src/Moq.Analyzers/Moq.Analyzers.csproj | 3 ++ ...legateMustMatchMockedMethodAnalyzerTest.cs | 36 +++++++++++++++++++ 4 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/Moq.Analyzers.Shared/ChainMembersInvocation.cs b/src/Moq.Analyzers.Shared/ChainMembersInvocation.cs index 7e1ee71..9ffe2cc 100644 --- a/src/Moq.Analyzers.Shared/ChainMembersInvocation.cs +++ b/src/Moq.Analyzers.Shared/ChainMembersInvocation.cs @@ -14,24 +14,28 @@ public ChainMembersInvocation(IReadOnlyList members, IReadOnlyList< { this.Members = members; this.InvocationArguments = invocationArguments; + + if (this.Members[0].Symbol is IMethodSymbol methodSymbol) + { + this.Parameters = methodSymbol.Parameters; + this.ReturnType = methodSymbol.ReturnType; + } + else + { + var propertySymbol = (IPropertySymbol)this.Members[0].Symbol; + + this.Parameters = propertySymbol.Parameters; + this.ReturnType = propertySymbol.Type; + } } public IReadOnlyList Members { get; } public IReadOnlyList InvocationArguments { get; } - public ITypeSymbol ReturnType - { - get - { - if (this.Members[0].Symbol is IMethodSymbol methodSymbol) - { - return methodSymbol.ReturnType; - } + public IReadOnlyList Parameters { get; } - return ((IPropertySymbol)this.Members[0].Symbol).Type; - } - } + public ITypeSymbol ReturnType { get; } public bool IsProperty { diff --git a/src/Moq.Analyzers/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzer.cs b/src/Moq.Analyzers/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzer.cs index 59c34d1..0b9f52c 100644 --- a/src/Moq.Analyzers/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzer.cs +++ b/src/Moq.Analyzers/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzer.cs @@ -85,7 +85,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context) // Compare the parameters between the mocked method and lambda expression in the CallBack() method. // 1- Compare the number of the parameters - if (callBackLambdaExpressionSymbol.Parameters.Length != setupMethod.InvocationArguments.Count) + if (callBackLambdaExpressionSymbol.Parameters.Length != setupMethod.Parameters.Count) { var diagnostic = Diagnostic.Create(CallbackMustMatchSignature, lambdaExpression!.ParameterList.GetLocation()); context.ReportDiagnostic(diagnostic); @@ -97,7 +97,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context) for (var i = 0; i < callBackLambdaExpressionSymbol.Parameters.Length; i++) { // Special case, if the argument is IsAnyType - if (moqSymbols.IsAnyType(setupMethod.InvocationArguments[i].ParameterSymbol.Type)) + if (moqSymbols.IsAnyType(setupMethod.Parameters[i].Type)) { // The callback parameter associated must be an object. if (callBackLambdaExpressionSymbol.Parameters[i].Type.SpecialType != SpecialType.System_Object) @@ -108,7 +108,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context) continue; } } - else if (!SymbolEqualityComparer.Default.Equals(callBackLambdaExpressionSymbol.Parameters[i].Type, setupMethod.InvocationArguments[i].ParameterSymbol.Type)) + else if (!SymbolEqualityComparer.Default.Equals(callBackLambdaExpressionSymbol.Parameters[i].Type, setupMethod.Parameters[i].Type)) { var diagnostic = Diagnostic.Create(CallbackMustMatchSignature, lambdaExpression!.ParameterList.Parameters[i].GetLocation()); context.ReportDiagnostic(diagnostic); diff --git a/src/Moq.Analyzers/Moq.Analyzers.csproj b/src/Moq.Analyzers/Moq.Analyzers.csproj index d0bce5a..a3873f7 100644 --- a/src/Moq.Analyzers/Moq.Analyzers.csproj +++ b/src/Moq.Analyzers/Moq.Analyzers.csproj @@ -7,6 +7,9 @@ https://github.com/PosInformatique/PosInformatique.Moq.Analyzers README.md + 2.1.0 + - Fix the PosInfoMoq2003 rule to check the signature of the Callback() method when using the default parameters in the interfaces. + 2.0.0 - Add new rules: - PosInfoMoq1010: Use '+= null' syntax when raising events with Raise()/RaiseAsync() diff --git a/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs b/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs index b649dd2..1adf862 100644 --- a/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs +++ b/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs @@ -45,6 +45,9 @@ public void TestMethod() mock1" + sequence + @".Setup(m => m.TestGenericMethod(It.IsAny())) .Callback((object x) => { }) .Throws(new Exception()); + mock1" + sequence + @".Setup(m => m.TestMethodWithDefaultParameters(""A"", 10)) + .Callback((string x, int y, int z, string w) => { }) + .Throws(new Exception()); mock1" + sequence + @".Setup(m => m.TestMethodReturn()) .Callback(() => { }) @@ -74,6 +77,8 @@ public interface I void TestGenericMethod(T value); + void TestMethodWithDefaultParameters(string a, int b, int c = 42, string d = ""default""); + int TestMethodReturn(); int TestMethodReturn(string a); @@ -85,6 +90,37 @@ public interface I await Verifier.VerifyAnalyzerAsync(source); } + [Fact] + public async Task CallBackSignatureNotMatch_DiagnosticReported_SpecialCase() + { + var source = @" + namespace ConsoleApplication1 + { + using Moq; + using System; + + public class TestClass + { + public void TestMethod() + { + var sequence = new MockSequence(); + + var mock1 = new Mock(); + + mock1.Setup(m => m.TestMethod(""The value"", 1234)) + .Callback({|PosInfoMoq2003:(string a, int b)|} => { }); + } + } + + public interface I + { + void TestMethod(string s, int a, int defaultValue = 42); + } + }"; + + await Verifier.VerifyAnalyzerAsync(source); + } + [Theory] [InlineData("")] [InlineData(".InSequence(sequence)")] From b814c80f96d6e31f861e7347a1cbb3cc3a30267a Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Mon, 8 Jun 2026 20:09:40 +0200 Subject: [PATCH 07/21] Migrates to xUnit v3 --- Directory.Packages.props | 7 +++---- PosInformatique.Moq.Analyzers.slnx | 1 + global.json | 9 +++++++++ tests/Directory.Build.props | 18 ++++++++---------- 4 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 global.json diff --git a/Directory.Packages.props b/Directory.Packages.props index 00be149..6ffbbc5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,17 +3,16 @@ true - - + + - - + \ No newline at end of file diff --git a/PosInformatique.Moq.Analyzers.slnx b/PosInformatique.Moq.Analyzers.slnx index 132517c..d2a54ce 100644 --- a/PosInformatique.Moq.Analyzers.slnx +++ b/PosInformatique.Moq.Analyzers.slnx @@ -5,6 +5,7 @@ + diff --git a/global.json b/global.json new file mode 100644 index 0000000..ec05221 --- /dev/null +++ b/global.json @@ -0,0 +1,9 @@ +{ + "sdk": { + "version": "10.0.100", + "rollForward": "latestMajor" + }, + "test": { + "runner": "Microsoft.Testing.Platform" + } +} \ No newline at end of file diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index 6f81a8b..d6b7ffc 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -6,20 +6,18 @@ net8.0 + + + Exe + true + false - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - + + + From ebbc5051bc396b2fd8509b77ffb820450faa4333 Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Mon, 8 Jun 2026 20:22:28 +0200 Subject: [PATCH 08/21] Fix unit tests --- .../CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs b/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs index 1adf862..732f4c0 100644 --- a/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs +++ b/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs @@ -158,6 +158,12 @@ public void TestMethod() mock1" + sequence + @".Setup(m => m.TestGenericMethod(It.IsAny())) .Callback(({|PosInfoMoq2003:string x|}) => { }) .Throws(new Exception()); + mock1" + sequence + @".Setup(m => m.TestMethodWithDefaultParameters(""A"", 10)) + .Callback({|PosInfoMoq2003:(string x, int y)|} => { }) + .Throws(new Exception()); + mock1" + sequence + @".Setup(m => m.TestMethodWithDefaultParameters(""A"", 10)) + .Callback({|PosInfoMoq2003:(string x, int y, string z)|} => { }) + .Throws(new Exception()); mock1" + sequence + @".Setup(m => m.TestMethodReturn()) .Callback({|PosInfoMoq2003:(int too, int much, int parameters)|} => { }) @@ -206,6 +212,8 @@ public interface I void TestGenericMethod(T value); + void TestMethodWithDefaultParameters(string a, int b, int c = 42, string d = ""default""); + int TestMethodReturn(); int TestMethodReturn(string a); From e1a53c2685ac0d009b6a49aceaae39cba5f3ebc2 Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Mon, 8 Jun 2026 20:26:17 +0200 Subject: [PATCH 09/21] Fix the CI --- .github/workflows/github-actions-ci.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github-actions-ci.yaml b/.github/workflows/github-actions-ci.yaml index df26e1f..372554f 100644 --- a/.github/workflows/github-actions-ci.yaml +++ b/.github/workflows/github-actions-ci.yaml @@ -26,12 +26,16 @@ jobs: --configuration Release \ --no-restore - - name: Run tests + - name: Run tests (.NET 10.0) run: | - dotnet test PosInformatique.Moq.Analyzers.slnx \ + dotnet test \ + --solution PosInformatique.Moq.Analyzers.slnx \ --configuration Release \ --no-build \ - --logger "trx;LogFileName=test_results.trx" \ + --coverage \ + --coverage-output-format cobertura \ + --coverage-settings CodeCoverage.runsettings \ + --report-trx \ --results-directory ./TestResults - name: Publish Test Results From 77377791e8daf40dca3d7bf2ec352cc1458c5c3c Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Mon, 8 Jun 2026 20:38:23 +0200 Subject: [PATCH 10/21] Fix CI --- .github/workflows/github-actions-ci.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions-ci.yaml b/.github/workflows/github-actions-ci.yaml index 372554f..f1e3637 100644 --- a/.github/workflows/github-actions-ci.yaml +++ b/.github/workflows/github-actions-ci.yaml @@ -26,10 +26,11 @@ jobs: --configuration Release \ --no-restore - - name: Run tests (.NET 10.0) + - name: Run tests run: | dotnet test \ - --solution PosInformatique.Moq.Analyzers.slnx \ + --test-modules "tests/Moq.Analyzers.Tests/bin/Release/net8.0/*" \ + --test-modules "tests/Moq.Analyzers.CodeFixes.Tests/bin/Release/net8.0/*" \ --configuration Release \ --no-build \ --coverage \ From b5aefac88f674e8d5cb253118df0a8fe19e82ab1 Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Mon, 8 Jun 2026 20:40:07 +0200 Subject: [PATCH 11/21] Fix CI --- .github/workflows/github-actions-ci.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/github-actions-ci.yaml b/.github/workflows/github-actions-ci.yaml index f1e3637..d62a271 100644 --- a/.github/workflows/github-actions-ci.yaml +++ b/.github/workflows/github-actions-ci.yaml @@ -29,8 +29,7 @@ jobs: - name: Run tests run: | dotnet test \ - --test-modules "tests/Moq.Analyzers.Tests/bin/Release/net8.0/*" \ - --test-modules "tests/Moq.Analyzers.CodeFixes.Tests/bin/Release/net8.0/*" \ + --test-modules "tests/Moq.Analyzers.Tests/bin/Release/net8.0/*;tests/Moq.Analyzers.CodeFixes.Tests/bin/Release/net8.0/*" \ --configuration Release \ --no-build \ --coverage \ From 947abc34f3ba5602976b74f4069c7b083aed6767 Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Mon, 8 Jun 2026 20:42:44 +0200 Subject: [PATCH 12/21] Fix CI --- .github/workflows/github-actions-ci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/github-actions-ci.yaml b/.github/workflows/github-actions-ci.yaml index d62a271..98e4ba2 100644 --- a/.github/workflows/github-actions-ci.yaml +++ b/.github/workflows/github-actions-ci.yaml @@ -30,7 +30,6 @@ jobs: run: | dotnet test \ --test-modules "tests/Moq.Analyzers.Tests/bin/Release/net8.0/*;tests/Moq.Analyzers.CodeFixes.Tests/bin/Release/net8.0/*" \ - --configuration Release \ --no-build \ --coverage \ --coverage-output-format cobertura \ From 9f4befea9f1f3865adc30f721b7e03d7b8e9d3ce Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Mon, 8 Jun 2026 20:50:04 +0200 Subject: [PATCH 13/21] Fix CI --- .github/workflows/github-actions-ci.yaml | 3 ++- tests/Moq.Analyzers.Sandbox/Empty.cs | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/Moq.Analyzers.Sandbox/Empty.cs diff --git a/.github/workflows/github-actions-ci.yaml b/.github/workflows/github-actions-ci.yaml index 98e4ba2..25c1257 100644 --- a/.github/workflows/github-actions-ci.yaml +++ b/.github/workflows/github-actions-ci.yaml @@ -29,7 +29,8 @@ jobs: - name: Run tests run: | dotnet test \ - --test-modules "tests/Moq.Analyzers.Tests/bin/Release/net8.0/*;tests/Moq.Analyzers.CodeFixes.Tests/bin/Release/net8.0/*" \ + --solution PosInformatique.Moq.Analyzers.slnx \ + --configuration Release \ --no-build \ --coverage \ --coverage-output-format cobertura \ diff --git a/tests/Moq.Analyzers.Sandbox/Empty.cs b/tests/Moq.Analyzers.Sandbox/Empty.cs new file mode 100644 index 0000000..63f6237 --- /dev/null +++ b/tests/Moq.Analyzers.Sandbox/Empty.cs @@ -0,0 +1,11 @@ +namespace PosInformatique.Moq.Analyzers.Sandbox +{ + public class Empty + { + [Fact] + public void NoTest() + { + // Empty to ensure that the sandbox project compiles and runs for the CI with no errors. + } + } +} From ad6978aeda2a81c3055ce7c0b1c8e916cde1ffae Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Tue, 9 Jun 2026 09:56:33 +0200 Subject: [PATCH 14/21] Fix warnings CI --- .github/workflows/github-actions-ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions-ci.yaml b/.github/workflows/github-actions-ci.yaml index 25c1257..9e6b6ca 100644 --- a/.github/workflows/github-actions-ci.yaml +++ b/.github/workflows/github-actions-ci.yaml @@ -10,10 +10,10 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Setup .NET 8.x - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v5 with: dotnet-version: '8.x' From e3acf0d06cd554eb5d24955bbc5a396b8e97c5fe Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Tue, 9 Jun 2026 11:00:00 +0200 Subject: [PATCH 15/21] Fix release notes --- src/Moq.Analyzers/Moq.Analyzers.csproj | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Moq.Analyzers/Moq.Analyzers.csproj b/src/Moq.Analyzers/Moq.Analyzers.csproj index a3873f7..a1870ed 100644 --- a/src/Moq.Analyzers/Moq.Analyzers.csproj +++ b/src/Moq.Analyzers/Moq.Analyzers.csproj @@ -9,12 +9,15 @@ 2.1.0 - Fix the PosInfoMoq2003 rule to check the signature of the Callback() method when using the default parameters in the interfaces. - + + 2.0.1 + - Fix the PosInfoMoq2005 which raised an error with constructor that contains array parameters + 2.0.0 - Add new rules: - - PosInfoMoq1010: Use '+= null' syntax when raising events with Raise()/RaiseAsync() - - PosInfoMoq2001: Add the support of the SetupSequence() methods. - - PosInfoMoq2017: Mock<T>.Raise()/RaiseAsync() must use parameters matching the event signature. + - PosInfoMoq1010: Use '+= null' syntax when raising events with Raise()/RaiseAsync() + - PosInfoMoq2001: Add the support of the SetupSequence() methods. + - PosInfoMoq2017: Mock<T>.Raise()/RaiseAsync() must use parameters matching the event signature. - PosInfoMoq2018: The first parameter of Raise()/RaiseAsync() must be an event. - PosInfoMoq2019: RaiseAsync() must be used only for events with async handlers (returning Task). - Add new fixers: From 0fceedfb41b574188f88f5d74edc6538e22f677f Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Tue, 9 Jun 2026 11:00:59 +0200 Subject: [PATCH 16/21] Fix Sandbox project --- tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj b/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj index 92714bf..dcbeeaa 100644 --- a/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj +++ b/tests/Moq.Analyzers.Sandbox/Moq.Analyzers.Sandbox.csproj @@ -9,7 +9,7 @@ - + From 4ff0eb91db1335fca69a6abebd8d76b9247b1e8d Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Tue, 9 Jun 2026 11:33:52 +0200 Subject: [PATCH 17/21] Add the code fixes in the NuGet package. --- src/Moq.Analyzers/Moq.Analyzers.csproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Moq.Analyzers/Moq.Analyzers.csproj b/src/Moq.Analyzers/Moq.Analyzers.csproj index a1870ed..e633aa5 100644 --- a/src/Moq.Analyzers/Moq.Analyzers.csproj +++ b/src/Moq.Analyzers/Moq.Analyzers.csproj @@ -144,6 +144,7 @@ + @@ -153,4 +154,9 @@ + + + + From 94198af95f6cb35f2575976bf2ee2e017bb465fa Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Tue, 9 Jun 2026 11:41:24 +0200 Subject: [PATCH 18/21] Fix CD. --- .github/workflows/github-actions-release.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions-release.yml b/.github/workflows/github-actions-release.yml index 2a0606a..675d3ec 100644 --- a/.github/workflows/github-actions-release.yml +++ b/.github/workflows/github-actions-release.yml @@ -18,12 +18,16 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Setup .NET 8.x - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v5 with: dotnet-version: '8.x' + + - name: Restore dependencies + run: dotnet restore \ + --solution PosInformatique.Moq.Analyzers.slnx - name: Build run: dotnet pack From 2da118300d1b0b9855fe3fb937ea939dd54d2c4a Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Tue, 9 Jun 2026 11:46:10 +0200 Subject: [PATCH 19/21] Fix CD --- .github/workflows/github-actions-release.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/github-actions-release.yml b/.github/workflows/github-actions-release.yml index 675d3ec..87b9152 100644 --- a/.github/workflows/github-actions-release.yml +++ b/.github/workflows/github-actions-release.yml @@ -26,8 +26,7 @@ jobs: dotnet-version: '8.x' - name: Restore dependencies - run: dotnet restore \ - --solution PosInformatique.Moq.Analyzers.slnx + run: dotnet restore - name: Build run: dotnet pack From 548a39c118c118b03e28d3324e431a23b2ca51cf Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Tue, 9 Jun 2026 16:46:51 +0200 Subject: [PATCH 20/21] Fix unit tests --- ...legateMustMatchMockedMethodAnalyzerTest.cs | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs b/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs index 732f4c0..5eb920c 100644 --- a/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs +++ b/tests/Moq.Analyzers.Tests/Analyzers/CallBackDelegateMustMatchMockedMethodAnalyzerTest.cs @@ -90,37 +90,6 @@ public interface I await Verifier.VerifyAnalyzerAsync(source); } - [Fact] - public async Task CallBackSignatureNotMatch_DiagnosticReported_SpecialCase() - { - var source = @" - namespace ConsoleApplication1 - { - using Moq; - using System; - - public class TestClass - { - public void TestMethod() - { - var sequence = new MockSequence(); - - var mock1 = new Mock(); - - mock1.Setup(m => m.TestMethod(""The value"", 1234)) - .Callback({|PosInfoMoq2003:(string a, int b)|} => { }); - } - } - - public interface I - { - void TestMethod(string s, int a, int defaultValue = 42); - } - }"; - - await Verifier.VerifyAnalyzerAsync(source); - } - [Theory] [InlineData("")] [InlineData(".InSequence(sequence)")] From 11ca53a9db3686b654fb866137a9e4a2e210589d Mon Sep 17 00:00:00 2001 From: Gilles TOURREAU Date: Wed, 10 Jun 2026 11:36:44 +0200 Subject: [PATCH 21/21] Add the PosInfoMoq1011 rule (fixes #57). --- PosInformatique.Moq.Analyzers.slnx | 1 + README.md | 1 + docs/Design/PosInfoMoq1011.md | 47 +++++ .../ChainMembersInvocation.cs | 16 ++ src/Moq.Analyzers/AnalyzerReleases.Shipped.md | 9 +- ...dShouldSpecifyOptionalArgumentsAnalyzer.cs | 84 ++++++++ src/Moq.Analyzers/Moq.Analyzers.csproj | 8 +- ...uldSpecifyOptionalArgumentsAnalyzerTest.cs | 185 ++++++++++++++++++ 8 files changed, 347 insertions(+), 4 deletions(-) create mode 100644 docs/Design/PosInfoMoq1011.md create mode 100644 src/Moq.Analyzers/Analyzers/SetupMethodShouldSpecifyOptionalArgumentsAnalyzer.cs create mode 100644 tests/Moq.Analyzers.Tests/Analyzers/SetupMethodShouldSpecifyOptionalArgumentsAnalyzerTest.cs diff --git a/PosInformatique.Moq.Analyzers.slnx b/PosInformatique.Moq.Analyzers.slnx index d2a54ce..592cb6a 100644 --- a/PosInformatique.Moq.Analyzers.slnx +++ b/PosInformatique.Moq.Analyzers.slnx @@ -50,6 +50,7 @@ + diff --git a/README.md b/README.md index 9507ef5..8f13623 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Design rules used to make your unit tests more strongly strict. | [PosInfoMoq1008: The `Mock.Verify()` and `Mock.VerifyAll()` methods must specify at least one mock.](docs/Design/PosInfoMoq1008.md) | When calling the static methods `Mock.Verify()` or `Mock.VerifyAll()` without providing any `Mock` instances, no verification is performed. | | [PosInfoMoq1009: Avoid using `Verifiable()` method](docs/Design/PosInfoMoq1009.md) | A `Verify()` of an `Mock` instance has not been called in the *Assert* phase of an unit test for `Verifiable()` setups. | | [PosInfoMoq1010: Use `+= null` syntax when raising events with `Raise()`/`RaiseAsync()`](docs/Design/PosInfoMoq1010.md) | When using `Mock.Raise()` or `Mock.RaiseAsync()`, the lambda expression used to identify the event should consistently use the `+= null` syntax. | +| [PosInfoMoq1011: The `Setup()` expression must explicitly specify optional argument values](docs/Design/PosInfoMoq1011.md) | When setting up a method with optional arguments, the default values must be written explicitly in the `Setup()` expression. | ### Compilation diff --git a/docs/Design/PosInfoMoq1011.md b/docs/Design/PosInfoMoq1011.md new file mode 100644 index 0000000..bb6cfe0 --- /dev/null +++ b/docs/Design/PosInfoMoq1011.md @@ -0,0 +1,47 @@ +# PosInfoMoq1011: The `Setup()` expression must explicitly specify optional argument values + +| Property | Value | +|----------------------|-----------------------------------------------------------------------| +| **Rule ID** | PosInfoMoq1011 | +| **Title** | The `Setup()` expression must explicitly specify optional argument values | +| **Category** | Design | +| **Default severity** | Warning | + +## Cause + +A `Setup()` expression uses omitted optional arguments instead of explicitly specifying their default values. + +## Rule description + +When setting up a method or member that declares optional arguments, the optional values must be written explicitly in the `Setup()` expression, even if C# allows omitting them. + +For example, if a mocked interface declares the following method: + +```csharp +public interface ICalculator +{ + void Method(int a = 10); +} +``` + +The following setup is valid in C#, but it is not accepted by this rule: + +```csharp +calculatorMock.Setup(c => c.Method()); +``` + +Instead, the default value must be written explicitly: + +```csharp +calculatorMock.Setup(c => c.Method(10)); +``` + +This makes the intended behavior of the test clearer and avoids relying on the compiler-generated default argument expansion inside the lambda expression. + +## How to fix violations + +To fix a violation of this rule, update the `Setup()` expression so that every optional argument is explicitly passed with its default value. + +## When to suppress warnings + +Do not suppress warnings from this rule. Optional arguments should be written explicitly in `Setup()` expressions for clarity and consistency. diff --git a/src/Moq.Analyzers.Shared/ChainMembersInvocation.cs b/src/Moq.Analyzers.Shared/ChainMembersInvocation.cs index 9ffe2cc..01c2ad4 100644 --- a/src/Moq.Analyzers.Shared/ChainMembersInvocation.cs +++ b/src/Moq.Analyzers.Shared/ChainMembersInvocation.cs @@ -7,6 +7,7 @@ namespace PosInformatique.Moq.Analyzers { using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp.Syntax; internal sealed class ChainMembersInvocation { @@ -31,6 +32,8 @@ public ChainMembersInvocation(IReadOnlyList members, IReadOnlyList< public IReadOnlyList Members { get; } + public NameSyntax InvocationExpression => this.Members[0].Syntax; + public IReadOnlyList InvocationArguments { get; } public IReadOnlyList Parameters { get; } @@ -67,5 +70,18 @@ public bool HasSameMembers(ChainMembersInvocation otherChainInvocation) return true; } + + public IParameterSymbol? GetInvocationArgument(IParameterSymbol parameter) + { + foreach (var invocationArgument in this.InvocationArguments) + { + if (SymbolEqualityComparer.Default.Equals(invocationArgument.ParameterSymbol, parameter)) + { + return invocationArgument.ParameterSymbol; + } + } + + return null; + } } } diff --git a/src/Moq.Analyzers/AnalyzerReleases.Shipped.md b/src/Moq.Analyzers/AnalyzerReleases.Shipped.md index fcb8544..be241a9 100644 --- a/src/Moq.Analyzers/AnalyzerReleases.Shipped.md +++ b/src/Moq.Analyzers/AnalyzerReleases.Shipped.md @@ -1,4 +1,11 @@ -## Release 2.0.0 +## Release 2.1.0 + +### New Rules +Rule ID | Category | Severity | Notes +--------|----------|----------|------- +PosInfoMoq1011 | Design | Warning | SetupMethodShouldSpecifyOptionalArgumentsAnalyzer, [Documentation](https://posinformatique.github.io/PosInformatique.Moq.Analyzers/docs/Design/PosInfoMoq1011.html) + +## Release 2.0.0 ### New Rules Rule ID | Category | Severity | Notes diff --git a/src/Moq.Analyzers/Analyzers/SetupMethodShouldSpecifyOptionalArgumentsAnalyzer.cs b/src/Moq.Analyzers/Analyzers/SetupMethodShouldSpecifyOptionalArgumentsAnalyzer.cs new file mode 100644 index 0000000..8aece03 --- /dev/null +++ b/src/Moq.Analyzers/Analyzers/SetupMethodShouldSpecifyOptionalArgumentsAnalyzer.cs @@ -0,0 +1,84 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) P.O.S Informatique. All rights reserved. +// +//----------------------------------------------------------------------- + +namespace PosInformatique.Moq.Analyzers +{ + using System.Collections.Immutable; + using Microsoft.CodeAnalysis; + using Microsoft.CodeAnalysis.CSharp; + using Microsoft.CodeAnalysis.CSharp.Syntax; + using Microsoft.CodeAnalysis.Diagnostics; + + [DiagnosticAnalyzer(LanguageNames.CSharp)] + public class SetupMethodShouldSpecifyOptionalArgumentsAnalyzer : DiagnosticAnalyzer + { + private static readonly DiagnosticDescriptor SetupMustExplicitlySpecifyOptionalArgumentsRule = new DiagnosticDescriptor( + "PosInfoMoq1011", + "The Setup() expression must explicitly specify optional argument values", + "The Setup() expression must explicitly specify optional argument values", + "Design", + DiagnosticSeverity.Warning, + isEnabledByDefault: true, + description: "Optional arguments in Setup() must be written explicitly, even when the default value is used.", + helpLinkUri: "https://posinformatique.github.io/PosInformatique.Moq.Analyzers/docs/Design/PosInfoMoq1011.html"); + + public override ImmutableArray SupportedDiagnostics => [SetupMustExplicitlySpecifyOptionalArgumentsRule]; + + public override void Initialize(AnalysisContext context) + { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); + context.EnableConcurrentExecution(); + + context.RegisterSyntaxNodeAction(Analyze, SyntaxKind.InvocationExpression); + } + + private static void Analyze(SyntaxNodeAnalysisContext context) + { + var invocationExpression = (InvocationExpressionSyntax)context.Node; + + var moqSymbols = MoqSymbols.FromCompilation(context.Compilation); + + if (moqSymbols is null) + { + return; + } + + // Check it is a Setup() method. + var methodSymbol = context.SemanticModel.GetSymbolInfo(invocationExpression, context.CancellationToken); + + if (!moqSymbols.IsSetupMethod(methodSymbol.Symbol)) + { + return; + } + + // Extracts the setup method. + var moqExpressionAnalyzer = new MoqExpressionAnalyzer(moqSymbols, context.SemanticModel); + + var setupMethod = moqExpressionAnalyzer.ExtractSetupMethod(invocationExpression, context.CancellationToken); + + if (setupMethod is null) + { + return; + } + + foreach (var parameter in setupMethod.Parameters) + { + if (!parameter.IsOptional) + { + continue; + } + + var invocationArgument = setupMethod.GetInvocationArgument(parameter); + + if (invocationArgument is null) + { + context.ReportDiagnostic(SetupMustExplicitlySpecifyOptionalArgumentsRule, setupMethod.InvocationExpression.GetLocation()); + return; + } + } + } + } +} diff --git a/src/Moq.Analyzers/Moq.Analyzers.csproj b/src/Moq.Analyzers/Moq.Analyzers.csproj index e633aa5..c835ace 100644 --- a/src/Moq.Analyzers/Moq.Analyzers.csproj +++ b/src/Moq.Analyzers/Moq.Analyzers.csproj @@ -8,6 +8,8 @@ README.md 2.1.0 + - Add new rules: + - PosInfoMoq1011: The Setup() expression must explicitly specify optional argument values. - Fix the PosInfoMoq2003 rule to check the signature of the Callback() method when using the default parameters in the interfaces. 2.0.1 @@ -15,9 +17,9 @@ 2.0.0 - Add new rules: - - PosInfoMoq1010: Use '+= null' syntax when raising events with Raise()/RaiseAsync() - - PosInfoMoq2001: Add the support of the SetupSequence() methods. - - PosInfoMoq2017: Mock<T>.Raise()/RaiseAsync() must use parameters matching the event signature. + - PosInfoMoq1010: Use '+= null' syntax when raising events with Raise()/RaiseAsync() + - PosInfoMoq2001: Add the support of the SetupSequence() methods. + - PosInfoMoq2017: Mock<T>.Raise()/RaiseAsync() must use parameters matching the event signature. - PosInfoMoq2018: The first parameter of Raise()/RaiseAsync() must be an event. - PosInfoMoq2019: RaiseAsync() must be used only for events with async handlers (returning Task). - Add new fixers: diff --git a/tests/Moq.Analyzers.Tests/Analyzers/SetupMethodShouldSpecifyOptionalArgumentsAnalyzerTest.cs b/tests/Moq.Analyzers.Tests/Analyzers/SetupMethodShouldSpecifyOptionalArgumentsAnalyzerTest.cs new file mode 100644 index 0000000..37e3d80 --- /dev/null +++ b/tests/Moq.Analyzers.Tests/Analyzers/SetupMethodShouldSpecifyOptionalArgumentsAnalyzerTest.cs @@ -0,0 +1,185 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) P.O.S Informatique. All rights reserved. +// +//----------------------------------------------------------------------- + +namespace PosInformatique.Moq.Analyzers.Tests +{ + using Verifier = MoqCSharpAnalyzerVerifier; + + public class SetupMethodShouldSpecifyOptionalArgumentsAnalyzerTest + { + [Theory] + [InlineData("")] + [InlineData(".InSequence(sequence)")] + public async Task SetupMethodOptionalArguments_NoDiagnosticReported(string sequence) + { + var source = @" + namespace ConsoleApplication1 + { + using Moq; + using System; + + public class TestClass + { + public void TestMethod() + { + var sequence = new MockSequence(); + + var mock1 = new Mock(); + + mock1" + sequence + @".Setup(m => m.TestMethod()) + .Callback(() => { }) + .Throws(new Exception()); + mock1" + sequence + @".Setup(m => m.TestMethod(""A"")) + .Callback((string x) => { }) + .Throws(new Exception()); + mock1" + sequence + @".Setup(m => m.TestMethod(""A"", 10)) + .Callback((string x, int y) => { }) + .Throws(new Exception()); + mock1" + sequence + @".Setup(m => m.TestMethodWithDefaultParameters(""A"", 10, 20, ""B"")) + .Callback((string x, int y, int z, string w) => { }) + .Throws(new Exception()); + } + } + + public interface I + { + void TestMethod(); + + void TestMethod(string a); + + void TestMethod(string a, int b); + + void TestMethodWithDefaultParameters(string a, int b, int c = 42, string d = ""default""); + } + }"; + + await Verifier.VerifyAnalyzerAsync(source); + } + + [Theory] + [InlineData("")] + [InlineData(".InSequence(sequence)")] + public async Task SetupMethodOptionalArguments_MissingArguments_DiagnosticReported(string sequence) + { + var source = @" + namespace ConsoleApplication1 + { + using Moq; + using System; + + public class TestClass + { + public void TestMethod() + { + var sequence = new MockSequence(); + + var mock1 = new Mock(); + + mock1" + sequence + @".Setup(m => m.{|PosInfoMoq1011:TestMethodWithDefaultParameters|}(""A"", 10)) + .Callback(() => { }) + .Throws(new Exception()); + mock1" + sequence + @".Setup(m => m.{|PosInfoMoq1011:TestMethodWithDefaultParameters|}(""A"", 10, 20)) + .Callback(() => { }) + .Throws(new Exception()); + } + } + + public interface I + { + void TestMethod(); + + void TestMethod(string a); + + void TestMethod(string a, int b); + + void TestMethodWithDefaultParameters(string a, int b, int c = 42, string d = ""D""); + } + }"; + + await Verifier.VerifyAnalyzerAsync(source); + } + + [Fact] + public async Task CustomSetupMethod_NoDiagnosticReported() + { + var source = @" + namespace ConsoleApplication1 + { + using Moq; + using Moq.Language.Flow; + using System; + using System.Linq.Expressions; + + public class TestClass + { + public void TestMethod() + { + var m = new Mock(MockBehavior.Strict); + + m.MySetup(i => i.Get(""Foobar"")); + } + } + + public static class MoqExtensions + { + public static ISetup MySetup(this Mock mock, Expression> exp) + where T : class + { + return mock.Setup(exp); + } + } + + public interface IRepository + { + void Get(string s); + } + } + "; + + await Verifier.VerifyAnalyzerAsync(source); + } + + [Fact] + public async Task NoMoqLibrary() + { + var source = @" + namespace ConsoleApplication1 + { + using OtherNamespace; + + public class TestClass + { + public void TestMethod() + { + var mock1 = new Mock(MockBehavior.Strict); + mock1.Setup(m => m.TestMethod()); + } + } + + public interface I + { + void TestMethod(); + } + } + + namespace OtherNamespace + { + using System; + + public class Mock + { + public Mock(MockBehavior _) { } + + public void Setup(Action act) { } + } + + public enum MockBehavior { Strict, Loose } + }"; + + await Verifier.VerifyAnalyzerWithNoMoqLibraryAsync(source); + } + } +} \ No newline at end of file