Skip to content

Commit

Permalink
Fix the PosInfoMoq2005 rule to check only the class types.
Browse files Browse the repository at this point in the history
  • Loading branch information
GillesTourreau committed Jul 13, 2024
1 parent 64faf38 commit 33de2d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ private static void Analyze(SyntaxNodeAnalysisContext context)
return;
}

// Check the type is a class (other type are ignored)
if (mockedType.TypeKind != TypeKind.Class)
{
return;
}

// Check the type is a named type
if (mockedType is not INamedTypeSymbol namedTypeSymbol)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,12 @@ private C(int a, object b, int c, System.IDisposable d)
await Verifier.VerifyAnalyzerAsync(source);
}

Check warning on line 210 in tests/Moq.Analyzers.Tests/Analyzers/ConstructorArgumentsMustMatchAnalyzerTest.cs

View workflow job for this annotation

GitHub Actions / build

Check warning on line 210 in tests/Moq.Analyzers.Tests/Analyzers/ConstructorArgumentsMustMatchAnalyzerTest.cs

View workflow job for this annotation

GitHub Actions / build

Check warning on line 210 in tests/Moq.Analyzers.Tests/Analyzers/ConstructorArgumentsMustMatchAnalyzerTest.cs

View workflow job for this annotation

GitHub Actions / build

Check warning on line 210 in tests/Moq.Analyzers.Tests/Analyzers/ConstructorArgumentsMustMatchAnalyzerTest.cs

View workflow job for this annotation

GitHub Actions / build

[Fact]
public async Task Arguments_Match_WithNoConstructor()

[Theory]
[InlineData("class")]
[InlineData("abstract class")]
[InlineData("interface")]
public async Task Arguments_Match_WithNoConstructor(string type)
{
var source = @"
namespace ConsoleApplication1
Expand All @@ -224,7 +228,7 @@ public void TestMethod()
}
}
public class ClassWithNoConstructor { }
public " + type + @" ClassWithNoConstructor { }
}";

await Verifier.VerifyAnalyzerAsync(source);
Expand Down Expand Up @@ -272,8 +276,11 @@ public C(int a, object b, int c, System.IDisposable d)
await Verifier.VerifyAnalyzerAsync(source);
}

[Fact]
public async Task Arguments_Match_WithMockBehavior_WithNoConstructor()
[Theory]
[InlineData("class")]
[InlineData("abstract class")]
[InlineData("interface")]
public async Task Arguments_Match_WithMockBehavior_WithNoConstructor(string type)
{
var source = @"
namespace ConsoleApplication1
Expand All @@ -288,7 +295,7 @@ public void TestMethod()
}
}
public class ClassWithNoConstructor { }
public " + type + @" ClassWithNoConstructor { }
}";

await Verifier.VerifyAnalyzerAsync(source);
Expand Down

0 comments on commit 33de2d5

Please sign in to comment.