diff --git a/.github/workflows/github-actions-release.yml b/.github/workflows/github-actions-release.yml index 2b9cec9..e36436c 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: 1.9.2 + default: 1.9.3 VersionSuffix: type: string description: The version suffix of the library (for example rc.1) diff --git a/PosInformatique.Moq.Analyzers.sln b/PosInformatique.Moq.Analyzers.sln index 26db6a1..5195eea 100644 --- a/PosInformatique.Moq.Analyzers.sln +++ b/PosInformatique.Moq.Analyzers.sln @@ -53,6 +53,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Compilation", "Compilation" 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 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -80,6 +88,8 @@ Global {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} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3307E7F7-9CD7-4C12-B34A-943F5A8B62A4} diff --git a/src/Moq.Analyzers/Analyzers/SetupProtectedMustBeUsedWithProtectedOrInternalMembersAnalyzer.cs b/src/Moq.Analyzers/Analyzers/SetupProtectedMustBeUsedWithProtectedOrInternalMembersAnalyzer.cs index 526a7de..6a6194e 100644 --- a/src/Moq.Analyzers/Analyzers/SetupProtectedMustBeUsedWithProtectedOrInternalMembersAnalyzer.cs +++ b/src/Moq.Analyzers/Analyzers/SetupProtectedMustBeUsedWithProtectedOrInternalMembersAnalyzer.cs @@ -81,7 +81,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context) } // Check if a method exists with the specified name - foreach (var method in mockedType.GetMembers(methodName).OfType()) + foreach (var method in mockedType.GetAllMembers(methodName).OfType()) { if (!method.IsAbstract && !method.IsVirtual && !method.IsOverride) { diff --git a/src/Moq.Analyzers/SymbolExtensions.cs b/src/Moq.Analyzers/SymbolExtensions.cs index 8a8c5d4..8c5a0c1 100644 --- a/src/Moq.Analyzers/SymbolExtensions.cs +++ b/src/Moq.Analyzers/SymbolExtensions.cs @@ -32,5 +32,21 @@ public static bool IsOrInheritFrom(this ITypeSymbol? symbol, ITypeSymbol type) return IsOrInheritFrom(symbol.BaseType, type); } + + public static IEnumerable GetAllMembers(this ITypeSymbol symbol, string name) + { + IEnumerable baseTypeMembers; + + if (symbol.BaseType is not null) + { + baseTypeMembers = symbol.BaseType.GetAllMembers(name); + } + else + { + baseTypeMembers = Enumerable.Empty(); + } + + return symbol.GetMembers(name).Concat(baseTypeMembers); + } } } diff --git a/tests/Moq.Analyzers.Tests/Analyzers/SetupProtectedMustBeUsedWithProtectedOrInternalMembersAnalyzerTest.cs b/tests/Moq.Analyzers.Tests/Analyzers/SetupProtectedMustBeUsedWithProtectedOrInternalMembersAnalyzerTest.cs index 327d033..1652c4e 100644 --- a/tests/Moq.Analyzers.Tests/Analyzers/SetupProtectedMustBeUsedWithProtectedOrInternalMembersAnalyzerTest.cs +++ b/tests/Moq.Analyzers.Tests/Analyzers/SetupProtectedMustBeUsedWithProtectedOrInternalMembersAnalyzerTest.cs @@ -31,8 +31,11 @@ public void TestMethod() mock1.Protected().Setup(""ProtectedAbstractMethod""); mock1.Protected().Setup(""ProtectedInternalAbstractMethod""); mock1.Protected().Setup(""InternalAbstractMethod""); + mock1.Protected().Setup(""ProtectedMethod""); mock1.Protected().Setup(""ProtectedOverrideMethod""); mock1.Protected().Setup(""ProtectedInternalOverrideMethod""); + mock1.Protected().Setup(""ProtectedInternalMethod""); + mock1.Protected().Setup(""InternalMethod""); mock1.Protected().Setup(""InternalOverrideMethod""); mock1.Protected().Setup(""ProtectedVirtualMethod""); @@ -75,9 +78,15 @@ public abstract class BaseClass { protected virtual void ProtectedOverrideMethod() { } + protected virtual void ProtectedMethod() { } + protected internal virtual void ProtectedInternalOverrideMethod() { } + protected internal virtual void ProtectedInternalMethod() { } + internal virtual void InternalOverrideMethod() { } + + internal virtual void InternalMethod() { } } }";