-
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
- change `GenerlSuffixAnalyzer` to ignore model classes with `Options` suffix if there is no serialization - add test cases fix #7247
- Loading branch information
Mingzhe Huang (from Dev Box)
committed
Nov 7, 2023
1 parent
41c4ad1
commit fbc61ed
Showing
2 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
...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,93 @@ | ||
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); | ||
} | ||
|
||
[Fact] | ||
public async Task WithPublicSerialization() | ||
{ | ||
var test = @"using System.Text.Json; | ||
namespace Azure.ResourceManager.Models | ||
{ | ||
public class ModelReaderWriterOptions | ||
{ | ||
public string Foo; | ||
} | ||
public interface IJsonModel<out T> | ||
{ | ||
void Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); | ||
}; | ||
namespace SubTest | ||
{ | ||
public class DiskOptions: IJsonModel<DiskOptions> | ||
{ | ||
void IJsonModel<DiskOptions>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) {} | ||
} | ||
} | ||
}"; | ||
var expected = VerifyCS.Diagnostic(diagnosticId).WithSpan(16, 22, 16, 33).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