Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.9.3 #32

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions PosInformatique.Moq.Analyzers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IMethodSymbol>())
foreach (var method in mockedType.GetAllMembers(methodName).OfType<IMethodSymbol>())
{
if (!method.IsAbstract && !method.IsVirtual && !method.IsOverride)
{
Expand All @@ -90,7 +90,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context)

if (method.IsSealed)
{
continue;
break;
}

if (method.DeclaredAccessibility == Accessibility.Protected)
Expand Down
3 changes: 3 additions & 0 deletions src/Moq.Analyzers/Moq.Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<PackageProjectUrl>https://github.com/PosInformatique/PosInformatique.Moq.Analyzers</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>
1.9.3
- Fix the PosInfoMoq2006 when Setup() a method/property in inherited class.

1.9.2
- Fix the PosInfoMoq1003 to raise warnings when using InSequence() method.
- Fix the PosInfoMoq2003 to raise errors when using InSequence() method.
Expand Down
16 changes: 16 additions & 0 deletions src/Moq.Analyzers/SymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,21 @@ public static bool IsOrInheritFrom(this ITypeSymbol? symbol, ITypeSymbol type)

return IsOrInheritFrom(symbol.BaseType, type);
}

public static IEnumerable<ISymbol> GetAllMembers(this ITypeSymbol symbol, string name)
{
IEnumerable<ISymbol> baseTypeMembers;

if (symbol.BaseType is not null)
{
baseTypeMembers = symbol.BaseType.GetAllMembers(name);
}
else
{
baseTypeMembers = Enumerable.Empty<ISymbol>();
}

return symbol.GetMembers(name).Concat(baseTypeMembers);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(""ProtectedVirtualMethod"");
Expand Down Expand Up @@ -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() { }
}
}";

Expand Down