-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(.net analyzer): ignore property bag with
Options
suffix (#7250)
* fix(.net analyzer): ignore property bag with `Options` suffix - change `GenerlSuffixAnalyzer` to ignore model classes with `Options` suffix if there is no serialization - add test cases fix #7247 * remov check on public serialization --------- Co-authored-by: Mingzhe Huang (from Dev Box) <[email protected]>
- Loading branch information
Showing
2 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...Azure.ClientSdk.Analyzers/Azure.ClientSdk.Analyzers.Tests/ModelName/AZC0030OptionsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
using VerifyCS = Azure.ClientSdk.Analyzers.Tests.AzureAnalyzerVerifier< | ||
Azure.ClientSdk.Analyzers.ModelName.GeneralSuffixAnalyzer>; | ||
|
||
// Test cases for `Options` suffix. We allow `Options` suffix for property bags. | ||
// So need to skip property bags which do not have any serialization codes. | ||
namespace Azure.ClientSdk.Analyzers.Tests.ModelName | ||
{ | ||
public class AZC0030OptionsSuffixTests | ||
{ | ||
private const string diagnosticId = "AZC0030"; | ||
|
||
[Fact] | ||
public async Task WithoutAnySerialization() | ||
{ | ||
var test = @"using System.Text.Json; | ||
namespace Azure.ResourceManager.Models; | ||
public class DiskOptions | ||
{ | ||
}"; | ||
await VerifyCS.VerifyAnalyzerAsync(test); | ||
} | ||
|
||
[Fact] | ||
public async Task WithDeserializationMethod() | ||
{ | ||
var test = @"using System.Text.Json; | ||
namespace Azure.ResourceManager | ||
{ | ||
public class ResponseOptions | ||
{ | ||
public static ResponseOptions DeserializeResponseOptions(JsonElement element) | ||
{ | ||
return null; | ||
} | ||
} | ||
}"; | ||
var expected = VerifyCS.Diagnostic(diagnosticId).WithSpan(4, 18, 4, 33).WithArguments("ResponseOptions", "Options", "'ResponseConfig'"); | ||
await VerifyCS.VerifyAnalyzerAsync(test, expected); | ||
} | ||
|
||
[Fact] | ||
public async Task WithSerializationMethod() | ||
{ | ||
var test = @"using System.Text.Json; | ||
namespace Azure.ResourceManager.Models | ||
{ | ||
internal interface IUtf8JsonSerializable | ||
{ | ||
void Write(Utf8JsonWriter writer); | ||
}; | ||
public class DiskOptions: IUtf8JsonSerializable | ||
{ | ||
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) {} | ||
} | ||
}"; | ||
var expected = VerifyCS.Diagnostic(diagnosticId).WithSpan(9, 18, 9, 29).WithArguments("DiskOptions", "Options", "'DiskConfig'"); | ||
await VerifyCS.VerifyAnalyzerAsync(test, expected); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters