public async Task TestCSharpCompilerWarningDeclaredWithWrongArgument() { var testCode = @" class TestClass { int value = 3; } "; var exception = await Assert.ThrowsAsync <InvalidOperationException>(async() => { await new CSharpTest { TestCode = testCode, ExpectedDiagnostics = { DiagnosticResult.CompilerWarning("CS0414").WithSpan(3, 7, 3, 12).WithArguments("TestClass2.value") }, CompilerDiagnostics = CompilerDiagnostics.Warnings, }.RunAsync(); }); var expected = "Expected diagnostic message arguments to match" + Environment.NewLine + Environment.NewLine + "Expected diagnostic:" + Environment.NewLine + " // /0/Test0.cs(3,7,3,12): warning CS0414" + Environment.NewLine + "DiagnosticResult.CompilerWarning(\"CS0414\").WithSpan(3, 7, 3, 12).WithArguments(\"TestClass2.value\")," + Environment.NewLine + Environment.NewLine + "Actual diagnostic:" + Environment.NewLine + " // /0/Test0.cs(3,7): warning CS0414: The field 'TestClass.value' is assigned but its value is never used" + Environment.NewLine + "DiagnosticResult.CompilerWarning(\"CS0414\").WithSpan(3, 7, 3, 12).WithArguments(\"TestClass.value\")," + Environment.NewLine + Environment.NewLine; new DefaultVerifier().EqualOrDiff(expected, exception.Message); }
public async Task VerifySimpleSyntaxWorks() { var before = @" using System; namespace ConsoleApp1 { public class TestClass { private int someField; public void SomeMethod(){} } }"; var after = @" using System; namespace ConsoleApp1 { public class TestClass { public void SomeMethod(){} } }"; var diagnostic = DiagnosticResult.CompilerWarning("CS0169").WithSpan(8, 21, 8, 30).WithArguments("ConsoleApp1.TestClass.someField"); await Verify <SomeCodeFix> .VerifyCodeFixAsync(before, diagnostic, after); }
public async Task TestCSharpCompilerWarning() { var testCode = @" class TestClass { int value = 3; } "; // By default the warning is ignored Assert.Equal(CompilerDiagnostics.Errors, new CSharpTest { TestCode = testCode }.CompilerDiagnostics); await new CSharpTest { TestCode = testCode }.RunAsync(); // The warning is checked with explicit configuration await new CSharpTest { TestCode = testCode, ExpectedDiagnostics = { DiagnosticResult.CompilerWarning("CS0414").WithSpan(3, 7, 3, 12).WithArguments("TestClass.value") }, CompilerDiagnostics = CompilerDiagnostics.Warnings, }.RunAsync(); }