Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert AddObsoleteAttributeTests to the new test framework #41753

Merged
merged 2 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<!-- Versions used by several individual references below -->
<RoslynDiagnosticsNugetPackageVersion>3.0.0-beta2.20059.3+77df2220</RoslynDiagnosticsNugetPackageVersion>
<CodeStyleLayerCodeAnalysisVersion>3.3.1</CodeStyleLayerCodeAnalysisVersion>
<MicrosoftCodeAnalysisTestingVersion>1.0.1-beta1.20114.4</MicrosoftCodeAnalysisTestingVersion>
<MicrosoftCodeAnalysisTestingVersion>1.0.1-beta1.20118.1</MicrosoftCodeAnalysisTestingVersion>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 This is needed for dotnet/roslyn-sdk#462

<CodeStyleAnalyzerVersion>3.5.0-beta3-20078-04</CodeStyleAnalyzerVersion>
<VisualStudioEditorPackagesVersion>16.4.248</VisualStudioEditorPackagesVersion>
<ILToolsPackageVersion>5.0.0-alpha1.19409.1</ILToolsPackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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|} {
}
",
@"
Expand All @@ -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|} {
}
",
@"
Expand All @@ -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|} {
}
",
@"
Expand All @@ -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;
}
",
@"
Expand All @@ -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;
}
}
",
Expand All @@ -146,15 +142,15 @@ void Goo() {
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddObsoleteAttribute)]
public async Task TestObsoleteOverride()
{
await TestInRegularAndScript1Async(
await VerifyCS.VerifyCodeFixAsync(
@"
class Base {
[System.Obsolete]
protected virtual void ObMethod() { }
}

class Derived : Base {
protected override void [||]ObMethod() { }
protected override void {|CS0672:ObMethod|}() { }
}
",
@"
Expand All @@ -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;
}
}
",
Expand All @@ -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;
}
}
",
Expand All @@ -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;
}
}
",
Expand All @@ -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<int> {
[System.Obsolete]
public void Add(int i) { }

public System.Collections.Generic.IEnumerator<int> 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|}
};
}
}
Expand All @@ -286,6 +285,9 @@ void Goo() {
class Collection : System.Collections.Generic.IEnumerable<int> {
[System.Obsolete]
public void Add(int i) { }

public System.Collections.Generic.IEnumerator<int> GetEnumerator() => throw null;
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null;
}

class Derived {
Expand All @@ -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<int> {
[System.Obsolete(""message"")]
public void Add(int i) { }

public System.Collections.Generic.IEnumerator<int> 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|}
};
}
}
Expand All @@ -321,6 +326,9 @@ void Goo() {
class Collection : System.Collections.Generic.IEnumerable<int> {
[System.Obsolete(""message"")]
public void Add(int i) { }

public System.Collections.Generic.IEnumerator<int> GetEnumerator() => throw null;
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null;
}

class Derived {
Expand All @@ -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<int> {
[System.Obsolete(""message"", error: false)]
public void Add(int i) { }

public System.Collections.Generic.IEnumerator<int> 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|}
};
}
}
Expand All @@ -356,6 +367,9 @@ void Goo() {
class Collection : System.Collections.Generic.IEnumerable<int> {
[System.Obsolete(""message"", error: false)]
public void Add(int i) { }

public System.Collections.Generic.IEnumerator<int> GetEnumerator() => throw null;
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw null;
}

class Derived {
Expand All @@ -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<int> {
[System.Obsolete(""message"", error: true)]
public void Add(int i) { }

public System.Collections.Generic.IEnumerator<int> 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);
}
}
}