From 24bb5c26e114917885e979d1fe2585e53bbc85f2 Mon Sep 17 00:00:00 2001 From: JohanLarsson Date: Tue, 22 Mar 2022 08:27:44 +0100 Subject: [PATCH] More tests. --- .../RoslynAssertTests/FixAll.Fail.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Gu.Roslyn.Asserts.Tests/RoslynAssertTests/FixAll.Fail.cs b/Gu.Roslyn.Asserts.Tests/RoslynAssertTests/FixAll.Fail.cs index 1a96da49..404afdfb 100644 --- a/Gu.Roslyn.Asserts.Tests/RoslynAssertTests/FixAll.Fail.cs +++ b/Gu.Roslyn.Asserts.Tests/RoslynAssertTests/FixAll.Fail.cs @@ -314,6 +314,48 @@ class C CodeAssert.AreEqual(expected, exception.Message); } + [Test] + public static void WhenFixDoesNotDoAnything() + { + var before = @" +namespace N +{ + class C + { + private readonly int ↓_f = 1; + } +}"; + + var after = @" +namespace N +{ + class C + { + private readonly int _f = 1; + } +}"; + var analyzer = new FieldNameMustNotBeginWithUnderscore(); + var fix = new EmptyFix(); + var exception = Assert.Throws(() => RoslynAssert.FixAll(analyzer, fix, before, after)); + var expected = @"The fixed code by EmptyFix contains compiler diagnostic. + - fix the code used in the test + - suppress the warning in the test code using for example pragma + - suppress the warning by providing Settings to the assert. +CS0414 The field 'C._f' is assigned but its value is never used + at line 5 and character 29 in file C.cs | private readonly int ↓_f = 1; +First source file with diagnostic is: + +namespace N +{ + class C + { + private readonly int _f = 1; + } +} +"; + CodeAssert.AreEqual(expected, exception.Message); + } + [Test] public static void DuplicateId() {