diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.cs index 3b19f49801178f0b9ff445f992fc191992bdfd93..989e877fe58708dab29c82e361f36d2be41ac72e 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.cs @@ -199,7 +199,7 @@ public void TestFieldAndPropertyInDifferentParts() } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)] - public void TestNotWithFieldWithAttirbute() + public void TestNotWithFieldWithAttribute() { TestMissing( @"class Class { [|[A]int i|]; int P { get { return i; } } }"); @@ -244,5 +244,17 @@ public void TestWriteInNotInConstructor2() @"class Class { [|int i|]; public int P { get { return i; } } public Foo() { i = 1; } }", @"class Class { public int P { get; private set; } public Foo() { P = 1; } }"); } + + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)] + public void TestAlreadyAutoPropertyWithGetterWithNoBody() + { + TestMissing(@"class Class { public int [|P|] { get; } }"); + } + + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseAutoProperty)] + public void TestAlreadyAutoPropertyWithGetterAndSetterWithNoBody() + { + TestMissing(@"class Class { public int [|P|] { get; set; } }"); + } } } diff --git a/src/EditorFeatures/Test/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs b/src/EditorFeatures/Test/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs index cb78404db9cd93405615011e81b417a6f0c99f26..38bf3c4937aefcaaca3bb6bd361b29555d791137 100644 --- a/src/EditorFeatures/Test/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs +++ b/src/EditorFeatures/Test/Diagnostics/AbstractDiagnosticProviderBasedUserDiagnosticTest.cs @@ -36,7 +36,9 @@ internal override IEnumerable GetDiagnostics(TestWorkspace workspace var provider = providerAndFixer.Item1; TextSpan span; var document = GetDocumentAndSelectSpan(workspace, out span); - return DiagnosticProviderTestUtilities.GetAllDiagnostics(provider, document, span); + var allDiagnostics = DiagnosticProviderTestUtilities.GetAllDiagnostics(provider, document, span); + AssertNoAnalyzerExceptionDiagnostics(allDiagnostics); + return allDiagnostics; } internal override IEnumerable> GetDiagnosticAndFixes(TestWorkspace workspace, string fixAllActionId) @@ -55,11 +57,25 @@ internal override IEnumerable GetDiagnostics(TestWorkspace workspace using (var testDriver = new TestDiagnosticAnalyzerDriver(document.Project, provider)) { var diagnostics = testDriver.GetAllDiagnostics(provider, document, span); + AssertNoAnalyzerExceptionDiagnostics(diagnostics); + var fixer = providerAndFixer.Item2; var ids = new HashSet(fixer.FixableDiagnosticIds); var dxs = diagnostics.Where(d => ids.Contains(d.Id)).ToList(); return GetDiagnosticAndFixes(dxs, provider, fixer, testDriver, document, span, annotation, fixAllActionId); } } + + /// + /// The internal method does + /// essentially this, but due to linked files between projects, this project cannot have internals visible + /// access to the Microsoft.CodeAnalysis project without the cascading effect of many extern aliases, so it + /// is re-implemented here in a way that is potentially overly agressive with the knowledge that if this method + /// starts failing on non-analyzer exception diagnostics, it can be appropriately tuned or re-evaluated. + /// + private void AssertNoAnalyzerExceptionDiagnostics(IEnumerable diagnostics) + { + Assert.Equal(0, diagnostics.Count(diag => diag.Descriptor.CustomTags.Contains(WellKnownDiagnosticTags.AnalyzerException))); + } } } diff --git a/src/EditorFeatures/VisualBasicTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.vb b/src/EditorFeatures/VisualBasicTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.vb index 5e5469442ea630732dd0718eb197cb190bce3c15..ec946ef085879915bbdc5bb804e87fa90fb3d936 100644 --- a/src/EditorFeatures/VisualBasicTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.vb @@ -177,7 +177,7 @@ NewLines("partial class Class1 \n end class \n partial class Class1 \n ReadOnly End Sub - Public Sub TestNotWithFieldWithAttirbute() + Public Sub TestNotWithFieldWithAttribute() TestMissing( NewLines("class Class1 \n [|dim i as integer|] \n property P as Integer \n get \n return i \n end property \n end class")) End Sub @@ -221,5 +221,10 @@ NewLines("class Class1 \n [|dim i as integer|] \n public property P as Integer \ NewLines("class Class1 \n [|dim i as integer|] \n public property P as Integer \n get \n return i \n end get \n set \n i = value \n end set \n end property \n public sub Foo() \n i = 1 \n end sub \n end class"), NewLines("class Class1 \n public property P as Integer \n public sub Foo() P = 1 \n end sub \n end class")) End Sub + + + Public Sub TestAlreadyAutoProperty() + TestMissing(NewLines("Class Class1 \n Public Property [|P|] As Integer \n End Class")) + End Sub End Class End Namespace