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

Revert "Update AZC00002 to match method pair with required requestcontext and optional convenience method" #6742

Merged
merged 1 commit into from
Aug 10, 2023
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
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