public static void WhenNoAnalyzerDiagnosticsButCompilerError() { var code = @" namespace N { class C { private readonly int ↓value = SYNTAX_ERROR; } }"; var analyzer = new FieldNameMustNotBeginWithUnderscore(); var fix = new CodeFixes.NoFix(); var expectedDiagnostic = ExpectedDiagnostic.Create(FieldNameMustNotBeginWithUnderscore.DiagnosticId); var expected = "Expected and actual diagnostics do not match.\r\n" + "Expected:\r\n" + " SA1309 \r\n" + " at line 5 and character 29 in file C.cs | private readonly int ↓value = SYNTAX_ERROR;\r\n" + "Actual:\r\n" + " CS0103 The name 'SYNTAX_ERROR' does not exist in the current context\r\n" + " at line 5 and character 37 in file C.cs | private readonly int value = ↓SYNTAX_ERROR;\r\n"; var exception = Assert.Throws <AssertException>(() => RoslynAssert.NoFix(analyzer, fix, code)); Assert.AreEqual(expected, exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.NoFix(analyzer, fix, code, string.Empty)); Assert.AreEqual(expected, exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.NoFix(analyzer, fix, expectedDiagnostic, code)); Assert.AreEqual(expected, exception.Message); exception = Assert.Throws <AssertException>(() => RoslynAssert.NoFix(analyzer, fix, expectedDiagnostic, code, string.Empty)); Assert.AreEqual(expected, exception.Message); }
public static void TwoDocumentsOneErrorNoFix() { var barCode = @" namespace N { class Bar { private readonly int value; } }"; var code = @" namespace N { class C { private readonly int ↓_value; } }"; var analyzer = new FieldNameMustNotBeginWithUnderscore(); var fix = new CodeFixes.NoFix(); RoslynAssert.NoFix(analyzer, fix, barCode, code); var expectedDiagnostic = ExpectedDiagnostic.Create(FieldNameMustNotBeginWithUnderscore.DiagnosticId); RoslynAssert.NoFix(analyzer, fix, expectedDiagnostic, barCode, code); }
public static void SingleDocumentOneErrorNoFix() { var before = @" namespace N { class C { private readonly int ↓_value; } }"; var analyzer = new FieldNameMustNotBeginWithUnderscore(); var fix = new CodeFixes.NoFix(); var exception = Assert.Throws <AssertException>(() => RoslynAssert.CodeFix(analyzer, fix, before, string.Empty)); var expected = "Expected one code fix, was 0."; Assert.AreEqual(expected, exception.Message); }
public static void SingleDocumentOneErrorNoFix() { var code = @" namespace N { class C { private readonly int ↓_value; } }"; var analyzer = new FieldNameMustNotBeginWithUnderscore(); var fix = new CodeFixes.NoFix(); var expectedDiagnostic = ExpectedDiagnostic.Create(FieldNameMustNotBeginWithUnderscore.DiagnosticId); RoslynAssert.NoFix(analyzer, fix, code); RoslynAssert.NoFix(analyzer, new CodeFixes.NoFix(), expectedDiagnostic, code); RoslynAssert.NoFix(analyzer, new CodeFixes.NoFix(), expectedDiagnostic, new List <string> { code }); }