Skip to content

Commit

Permalink
Add rules for convenience method and protocol method (#6934)
Browse files Browse the repository at this point in the history
* Add rules for convenience method and protocol method

* update

* updadte
  • Loading branch information
pshao25 authored Sep 28, 2023
1 parent 02476be commit f05a61d
Show file tree
Hide file tree
Showing 6 changed files with 687 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,37 @@ await Verifier.CreateAnalyzer(code)
.WithDisabledDiagnostics("AZC0015")
.RunAsync();
}

[Fact]
public async Task AZC0004NotProducedForMethodsWithOverloadAlternative()
{
const string code = @"
using Azure;
using System.Threading;
using System.Threading.Tasks;
namespace RandomNamespace
{
public class SomeClient
{
public virtual Task<Response> GetAsync(CancellationToken cancellationToken = default)
{
return null;
}
public virtual Response Get()
{
return null;
}
public virtual Response Get(CancellationToken cancellationToken)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.RunAsync();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Threading.Tasks;
using Xunit;
using Verifier = Azure.ClientSdk.Analyzers.Tests.AzureAnalyzerVerifier<Azure.ClientSdk.Analyzers.ClientMethodsAnalyzer>;

namespace Azure.ClientSdk.Analyzers.Tests
{
public class AZC0017Tests
{
[Fact]
public async Task AZC0017ProducedForMethodsWithRequestContentParameter()
{
const string code = @"
using Azure;
using Azure.Core;
using System.Threading;
using System.Threading.Tasks;
namespace RandomNamespace
{
public class SomeClient
{
public virtual Task<Response> {|AZC0017:GetAsync|}(RequestContent content, CancellationToken cancellationToken = default)
{
return null;
}
public virtual Response {|AZC0017:Get|}(RequestContent content, CancellationToken cancellationToken = default)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.RunAsync();
}

[Fact]
public async Task AZC0017NotProducedForMethodsWithCancellationToken()
{
const string code = @"
using Azure;
using Azure.Core;
using System.Threading;
using System.Threading.Tasks;
namespace RandomNamespace
{
public class SomeClient
{
public virtual Task<Response> GetAsync(string s, CancellationToken cancellationToken = default)
{
return null;
}
public virtual Response Get(string s, CancellationToken cancellationToken = default)
{
return null;
}
}
}";
await Verifier.CreateAnalyzer(code)
.RunAsync();
}
}
}
Loading

0 comments on commit f05a61d

Please sign in to comment.