Skip to content

Commit

Permalink
Revert "Update AZC00002 to match method pair with required requestcon…
Browse files Browse the repository at this point in the history
…text and optional convenience method (#6156)" (#6742)

This reverts commit 59b104e.
  • Loading branch information
annelo-msft authored Aug 10, 2023
1 parent 5f40621 commit 1fc61f9
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 944 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Azure.ClientSdk.Analyzers.Tests
public class AZC0002Tests
{
[Fact]
public async Task AZC0002ProducedForMethodsWithoutCancellationTokenOrRequestContext()
public async Task AZC0002ProducedForMethodsWithoutCancellationToken()
{
const string code = @"
using System.Threading.Tasks;
Expand All @@ -35,7 +35,7 @@ await Verifier.CreateAnalyzer(code)
}

[Fact]
public async Task AZC0002ProducedForMethodsWithWrongNameCancellationToken()
public async Task AZC0002ProducedForMethodsWithNonOptionalCancellationToken()
{
const string code = @"
using System.Threading;
Expand All @@ -45,12 +45,12 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}(CancellationToken cancellation = default)
public virtual Task {|AZC0002:GetAsync|}(CancellationToken cancellationToken)
{
return null;
}
public virtual void {|AZC0002:Get|}(CancellationToken cancellation = default)
public virtual void {|AZC0002:Get|}(CancellationToken cancellationToken)
{
}
}
Expand All @@ -61,23 +61,22 @@ await Verifier.CreateAnalyzer(code)
}

[Fact]
public async Task AZC0002ProducedForMethodsWithWrongNameRequestContext()
public async Task AZC0002ProducedForMethodsWithWrongNameParameter()
{
const string code = @"
using Azure;
using System.Threading;
using System.Threading.Tasks;
namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}(RequestContext cancellation = default)
public virtual Task {|AZC0002:GetAsync|}(CancellationToken cancellation = default)
{
return null;
}
public virtual void {|AZC0002:Get|}(RequestContext cancellation = default)
public virtual void {|AZC0002:Get|}(CancellationToken cancellation = default)
{
}
}
Expand All @@ -86,24 +85,25 @@ await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}


[Fact]
public async Task AZC0002ProducedForMethodsWithNonOptionalCancellationToken()
public async Task AZC0002ProducedForMethodsWhereRequestContextIsNotLast()
{
const string code = @"
using Azure;
using System.Threading;
using System.Threading.Tasks;
namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}(CancellationToken cancellationToken)
public virtual Task {|AZC0002:GetAsync|}(RequestContext context = default, string text = default)
{
return null;
}
public virtual void {|AZC0002:Get|}(CancellationToken cancellationToken)
public virtual void {|AZC0002:Get|}(RequestContext context = default, string text = default)
{
}
}
Expand All @@ -112,36 +112,44 @@ await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}


[Fact]
public async Task AZC0002ProducedForMethodsWhereRequestContextIsNotLast()
public async Task AZC0002DoesntFireIfThereIsAnOverloadWithCancellationToken()
{
const string code = @"
using Azure;
using System.Threading;
using System.Threading.Tasks;
namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}(RequestContext context = default, string text = default)
public virtual Task GetAsync(string s)
{
return null;
}
public virtual void {|AZC0002:Get|}(RequestContext context = default, string text = default)
public virtual void Get(string s)
{
}
public virtual Task GetAsync(string s, CancellationToken cancellationToken)
{
return null;
}
public virtual void Get(string s, CancellationToken cancellationToken)
{
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

}

[Fact]
public async Task AZC0002ProducedForMethodsWhereCancellationTokenIsNotLast()
public async Task AZC0002DoesntFireIfThereIsAnOverloadWithRequestContext()
{
const string code = @"
using Azure;
Expand All @@ -152,103 +160,91 @@ namespace RandomNamespace
{
public class SomeClient
{
public virtual Task {|AZC0002:GetAsync|}(CancellationToken cancellationToken = default, string text = default)
public virtual Task GetAsync(string s)
{
return null;
}
public virtual void {|AZC0002:Get|}(CancellationToken cancellationToken = default, string text = default)
public virtual void Get(string s)
{
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}
[Fact]
public async Task AZC0002NotProducedForMethodsWithCancellationToken()
{
const string code = @"
using System.Threading;
using System.Threading.Tasks;
namespace RandomNamespace
{
public class SomeClient
{
public virtual Task GetAsync(CancellationToken cancellationToken = default)
public virtual Task GetAsync(string s, RequestContext context = default)
{
return null;
}
public virtual void Get(CancellationToken cancellationToken = default)
public virtual void Get(string s, RequestContext context = default)
{
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

}

[Fact]
public async Task AZC0002NotProducedForMethodsWithRequestContextAndCancellationToken()
public async Task AZC0002ProducedWhenCancellationTokenOverloadsDontMatch()
{
const string code = @"
using Azure;
using System.Threading;
using System.Threading.Tasks;
namespace RandomNamespace
{
public class SomeClient
{
public virtual Task Get1Async(string s, CancellationToken cancellationToken = default)
public virtual Task {|AZC0002:GetAsync|}(string s)
{
return null;
}
public virtual void Get1(string s, CancellationToken cancellationToken = default)
public virtual void {|AZC0002:Get|}(string s)
{
}
public virtual Task Get1Async(string s, RequestContext context)
public virtual Task {|AZC0002:GetAsync|}(CancellationToken cancellationToken)
{
return null;
}
public virtual void Get1(string s, RequestContext context)
public virtual void {|AZC0002:Get|}(CancellationToken cancellationToken)
{
}
public virtual Task Get2Async(CancellationToken cancellationToken = default)
{
return null;
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

public virtual void Get2(CancellationToken cancellationToken = default)
[Fact]
public async Task AZC0002NotProducedForMethodsWithCancellationToken()
{
}
const string code = @"
using System.Threading;
using System.Threading.Tasks;
public virtual Task Get2Async(RequestContext context)
namespace RandomNamespace
{
public class SomeClient
{
public virtual Task GetAsync(CancellationToken cancellationToken = default)
{
return null;
}
public virtual void Get2(RequestContext context)
public virtual void Get(CancellationToken cancellationToken = default)
{
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.WithDisabledDiagnostics("AZC0018")
.WithDisabledDiagnostics("AD0001")
.RunAsync();
}

}

[Fact]
public async Task AZC0002NotProducedForMethodsWithRequestContext()
{
Expand All @@ -269,20 +265,10 @@ public virtual Task GetAsync(RequestContext context = default)
public virtual void Get(RequestContext context = default)
{
}
public virtual Task Get2Async(RequestContext context)
{
return null;
}
public virtual void Get2(RequestContext context)
{
}
}
}";
await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.WithDisabledDiagnostics("AZC0018")
.RunAsync();
}
}
Expand Down
Loading

0 comments on commit 1fc61f9

Please sign in to comment.