Skip to content

Commit 5e2e1fb

Browse files
rjmurilloclaude
andcommitted
fix: use discard assignment for parenthesized diagnostic test cases
Replace invalid C# expression statements (CS0201) with discard assignments to keep test expressions valid while preserving parenthesized wrapping. This ensures the IOperation tree is properly formed during test execution. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 062dddd commit 5e2e1fb

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

tests/Moq.Analyzers.Test/MethodSetupShouldSpecifyReturnValueAnalyzerTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,21 @@ public static IEnumerable<object[]> Issue887_ParenthesizedSetupTestData()
164164
return data.WithNamespaces().WithMoqReferenceAssemblyGroups();
165165
}
166166

167-
// Parenthesized Setup without return value spec triggers both Moq1203 and CS0201
168-
// (parenthesized expressions are not valid C# statements), so compiler errors must be ignored.
167+
// Parenthesized Setup without return value spec should still trigger Moq1203.
168+
// Uses discard assignment to keep expressions valid C# while preserving parentheses.
169169
public static IEnumerable<object[]> Issue887_ParenthesizedSetupWithDiagnosticTestData()
170170
{
171171
IEnumerable<object[]> data =
172172
[
173173

174174
// Parenthesized Setup WITHOUT return value spec should still trigger diagnostic
175-
["""({|Moq1203:new Mock<IFoo>().Setup(x => x.GetValue())|});"""],
175+
["""_ = ({|Moq1203:new Mock<IFoo>().Setup(x => x.GetValue())|});"""],
176176

177177
// Nested parentheses WITHOUT return value spec should still trigger diagnostic
178-
["""(({|Moq1203:new Mock<IFoo>().Setup(x => x.GetValue())|}));"""],
178+
["""_ = (({|Moq1203:new Mock<IFoo>().Setup(x => x.GetValue())|}));"""],
179179

180180
// Parenthesized async Setup WITHOUT return value spec should still trigger diagnostic
181-
["""({|Moq1203:new Mock<IFoo>().Setup(x => x.BarAsync())|});"""],
181+
["""_ = ({|Moq1203:new Mock<IFoo>().Setup(x => x.BarAsync())|});"""],
182182
];
183183

184184
return data.WithNamespaces().WithMoqReferenceAssemblyGroups();
@@ -216,7 +216,7 @@ public async Task ShouldHandleParenthesizedSetupExpressions(string referenceAsse
216216
[MemberData(nameof(Issue887_ParenthesizedSetupWithDiagnosticTestData))]
217217
public async Task ShouldFlagParenthesizedSetupWithoutReturnValue(string referenceAssemblyGroup, string @namespace, string mock)
218218
{
219-
await VerifyMockIgnoringCompilerErrorsAsync(referenceAssemblyGroup, @namespace, mock);
219+
await VerifyMockAsync(referenceAssemblyGroup, @namespace, mock);
220220
}
221221

222222
[Theory]

0 commit comments

Comments
 (0)