diff --git a/eng/Versions.props b/eng/Versions.props index 106d12fb72c13..6db4d3d6970bb 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -28,7 +28,7 @@ 3.0.0-beta2.20059.3+77df2220 3.3.1 - 1.0.1-beta1.20114.4 + 1.0.1-beta1.20118.1 3.5.0-beta3-20078-04 16.4.248 5.0.0-alpha1.19409.1 diff --git a/src/EditorFeatures/CSharpTest/AddObsoleteAttribute/AddObsoleteAttributeTests.cs b/src/EditorFeatures/CSharpTest/AddObsoleteAttribute/AddObsoleteAttributeTests.cs index cc872b0f6f4a8..b6a13e8e09a14 100644 --- a/src/EditorFeatures/CSharpTest/AddObsoleteAttribute/AddObsoleteAttributeTests.cs +++ b/src/EditorFeatures/CSharpTest/AddObsoleteAttribute/AddObsoleteAttributeTests.cs @@ -3,29 +3,25 @@ // See the LICENSE file in the project root for more information. using System.Threading.Tasks; -using Microsoft.CodeAnalysis.CodeFixes; -using Microsoft.CodeAnalysis.CSharp.AddObsoleteAttribute; -using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics; using Microsoft.CodeAnalysis.Test.Utilities; using Xunit; +using VerifyCS = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.CSharpCodeFixVerifier< + Microsoft.CodeAnalysis.Testing.EmptyDiagnosticAnalyzer, + Microsoft.CodeAnalysis.CSharp.AddObsoleteAttribute.CSharpAddObsoleteAttributeCodeFixProvider>; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.AddObsoleteAttribute { - public class AddObsoleteAttributeTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest + public class AddObsoleteAttributeTests { - internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace) - => (null, new CSharpAddObsoleteAttributeCodeFixProvider()); - [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteClassNoMessage() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" [System.Obsolete] class Base {} -class Derived : [||]Base { +class Derived : {|CS0612:Base|} { } ", @" @@ -41,12 +37,12 @@ class Derived : Base { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteClassWithMessage() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" [System.Obsolete(""message"")] class Base {} -class Derived : [||]Base { +class Derived : {|CS0618:Base|} { } ", @" @@ -62,12 +58,12 @@ class Derived : Base { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteClassWithMessageAndErrorFalse() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" [System.Obsolete(""message"", error: false)] class Base {} -class Derived : [||]Base { +class Derived : {|CS0618:Base|} { } ", @" @@ -83,26 +79,26 @@ class Derived : Base { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteClassWithMessageAndErrorTrue() { - await TestMissingInRegularAndScriptAsync( -@" + var code = @" [System.Obsolete(""message"", error: true)] class Base {} -class Derived : [||]Base { +class Derived : {|CS0619:Base|} { } -"); +"; + await VerifyCS.VerifyCodeFixAsync(code, code); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteClassUsedInField() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" [System.Obsolete] class Base { public static int i; } class Derived { - int i = [||]Base.i; + int i = {|CS0612:Base|}.i; } ", @" @@ -119,14 +115,14 @@ class Derived { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteClassUsedInMethod() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" [System.Obsolete] class Base { public static int i; } class Derived { void Goo() { - int i = [||]Base.i; + int i = {|CS0612:Base|}.i; } } ", @@ -146,7 +142,7 @@ void Goo() { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteOverride() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" class Base { [System.Obsolete] @@ -154,7 +150,7 @@ protected virtual void ObMethod() { } } class Derived : Base { - protected override void [||]ObMethod() { } + protected override void {|CS0672:ObMethod|}() { } } ", @" @@ -173,15 +169,15 @@ protected override void ObMethod() { } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteClassFixAll1() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" [System.Obsolete] class Base { public static int i; } class Derived { void Goo() { - int i = {|FixAllInDocument:|}Base.i; - int j = Base.i; + int i = {|CS0612:Base|}.i; + int j = {|CS0612:Base|}.i; } } ", @@ -202,15 +198,15 @@ void Goo() { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteClassFixAll2() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" [System.Obsolete] class Base { public static int i; } class Derived { void Goo() { - int i = Base.i; - int j = {|FixAllInDocument:|}Base.i; + int i = {|CS0612:Base|}.i; + int j = {|CS0612:Base|}.i; } } ", @@ -231,18 +227,18 @@ void Goo() { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteClassFixAll3() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" [System.Obsolete] class Base { public static int i; } class Derived { void Goo() { - int i = {|FixAllInDocument:|}Base.i; + int i = {|CS0612:Base|}.i; } void Bar() { - int j = Base.i; + int j = {|CS0612:Base|}.i; } } ", @@ -267,17 +263,20 @@ void Bar() { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteCollectionAddMethod() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" class Collection : System.Collections.Generic.IEnumerable { [System.Obsolete] public void Add(int i) { } + + public System.Collections.Generic.IEnumerator GetEnumerator() => throw null; + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null; } class Derived { void Goo() { var c = new Collection { - [||]1, 2, 3 + {|CS1064:1|}, {|CS1064:2|}, {|CS1064:3|} }; } } @@ -286,6 +285,9 @@ void Goo() { class Collection : System.Collections.Generic.IEnumerable { [System.Obsolete] public void Add(int i) { } + + public System.Collections.Generic.IEnumerator GetEnumerator() => throw null; + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null; } class Derived { @@ -302,17 +304,20 @@ void Goo() { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteCollectionAddMethodWithMessage() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" class Collection : System.Collections.Generic.IEnumerable { [System.Obsolete(""message"")] public void Add(int i) { } + + public System.Collections.Generic.IEnumerator GetEnumerator() => throw null; + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null; } class Derived { void Goo() { var c = new Collection { - [||]1, 2, 3 + {|CS1062:1|}, {|CS1062:2|}, {|CS1062:3|} }; } } @@ -321,6 +326,9 @@ void Goo() { class Collection : System.Collections.Generic.IEnumerable { [System.Obsolete(""message"")] public void Add(int i) { } + + public System.Collections.Generic.IEnumerator GetEnumerator() => throw null; + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null; } class Derived { @@ -337,17 +345,20 @@ void Goo() { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteCollectionAddMethodWithMessageAndErrorFalse() { - await TestInRegularAndScript1Async( + await VerifyCS.VerifyCodeFixAsync( @" class Collection : System.Collections.Generic.IEnumerable { [System.Obsolete(""message"", error: false)] public void Add(int i) { } + + public System.Collections.Generic.IEnumerator GetEnumerator() => throw null; + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null; } class Derived { void Goo() { var c = new Collection { - [||]1, 2, 3 + {|CS1062:1|}, {|CS1062:2|}, {|CS1062:3|} }; } } @@ -356,6 +367,9 @@ void Goo() { class Collection : System.Collections.Generic.IEnumerable { [System.Obsolete(""message"", error: false)] public void Add(int i) { } + + public System.Collections.Generic.IEnumerator GetEnumerator() => throw null; + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null; } class Derived { @@ -372,21 +386,25 @@ void Goo() { [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)] public async Task TestObsoleteCollectionAddMethodWithMessageAndErrorTrue() { - await TestMissingInRegularAndScriptAsync( -@" + var code = @" class Collection : System.Collections.Generic.IEnumerable { [System.Obsolete(""message"", error: true)] public void Add(int i) { } + + public System.Collections.Generic.IEnumerator GetEnumerator() => throw null; + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null; } class Derived { void Goo() { var c = new Collection { - [||]1, 2, 3 + {|CS1063:1|}, {|CS1063:2|}, {|CS1063:3|} }; } } -"); +"; + + await VerifyCS.VerifyCodeFixAsync(code, code); } } }