Refactor code structure and optimize performance across multiple modules

This commit is contained in:
StellaOps Bot
2025-12-26 20:03:22 +02:00
parent c786faae84
commit b4fc66feb6
3353 changed files with 88254 additions and 1590657 deletions

View File

@@ -14,11 +14,14 @@ using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Text;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.AirGap.Policy.Analyzers.Tests;
public sealed class HttpClientUsageAnalyzerTests
{
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ReportsDiagnostic_ForNewHttpClient()
{
const string source = """
@@ -39,7 +42,8 @@ public sealed class HttpClientUsageAnalyzerTests
Assert.Contains(diagnostics, d => d.Id == HttpClientUsageAnalyzer.DiagnosticId);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DoesNotReportDiagnostic_InsidePolicyAssembly()
{
const string source = """
@@ -57,7 +61,8 @@ public sealed class HttpClientUsageAnalyzerTests
Assert.DoesNotContain(diagnostics, d => d.Id == HttpClientUsageAnalyzer.DiagnosticId);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CodeFix_RewritesToFactoryCall()
{
const string source = """

View File

@@ -22,6 +22,8 @@ using Microsoft.CodeAnalysis.Text;
using Xunit;
using FluentAssertions;
using StellaOps.TestKit;
namespace StellaOps.AirGap.Policy.Analyzers.Tests;
/// <summary>
@@ -33,7 +35,8 @@ public sealed class PolicyAnalyzerRoslynTests
{
#region AIRGAP-5100-005: Expected Diagnostics & No False Positives
[Theory]
[Trait("Category", TestCategories.Unit)]
[Theory]
[InlineData("var client = new HttpClient();", true, "Direct construction should trigger diagnostic")]
[InlineData("var client = new System.Net.Http.HttpClient();", true, "Fully qualified construction should trigger diagnostic")]
[InlineData("HttpClient client = new();", true, "Target-typed new should trigger diagnostic")]
@@ -60,7 +63,8 @@ public sealed class PolicyAnalyzerRoslynTests
hasDiagnostic.Should().Be(shouldTrigger, reason);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task NoDiagnostic_ForHttpClientParameter()
{
const string source = """
@@ -83,7 +87,8 @@ public sealed class PolicyAnalyzerRoslynTests
"Using HttpClient as parameter should not trigger diagnostic");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task NoDiagnostic_ForHttpClientField()
{
const string source = """
@@ -107,7 +112,8 @@ public sealed class PolicyAnalyzerRoslynTests
"Declaring HttpClient field should not trigger diagnostic");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task NoDiagnostic_ForFactoryMethodReturn()
{
const string source = """
@@ -138,7 +144,8 @@ public sealed class PolicyAnalyzerRoslynTests
"Using factory method should not trigger diagnostic");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task NoDiagnostic_InTestAssembly()
{
const string source = """
@@ -160,7 +167,8 @@ public sealed class PolicyAnalyzerRoslynTests
"Test assemblies should be exempt from diagnostic");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task NoDiagnostic_InPolicyAssembly()
{
const string source = """
@@ -179,7 +187,8 @@ public sealed class PolicyAnalyzerRoslynTests
"Policy assembly itself should be exempt");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Diagnostic_HasCorrectSeverity()
{
const string source = """
@@ -203,7 +212,8 @@ public sealed class PolicyAnalyzerRoslynTests
"Diagnostic should be a warning, not an error");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Diagnostic_HasCorrectLocation()
{
const string source = """
@@ -228,7 +238,8 @@ public sealed class PolicyAnalyzerRoslynTests
lineSpan.StartLinePosition.Line.Should().Be(8, "Diagnostic should point to line 9 (0-indexed: 8)");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task MultipleHttpClientUsages_ReportMultipleDiagnostics()
{
const string source = """
@@ -265,7 +276,8 @@ public sealed class PolicyAnalyzerRoslynTests
#region AIRGAP-5100-006: Golden Generated Code Tests
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CodeFix_GeneratesExpectedFactoryCall()
{
const string source = """
@@ -301,7 +313,8 @@ public sealed class PolicyAnalyzerRoslynTests
"Code fix should match golden output exactly");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CodeFix_PreservesTrivia()
{
const string source = """
@@ -326,7 +339,8 @@ public sealed class PolicyAnalyzerRoslynTests
"Leading comment should be preserved");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CodeFix_DeterministicOutput()
{
const string source = """
@@ -352,7 +366,8 @@ public sealed class PolicyAnalyzerRoslynTests
result2.Should().Be(result3, "Code fix should be deterministic");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CodeFix_ContainsRequiredPlaceholders()
{
const string source = """
@@ -383,7 +398,8 @@ public sealed class PolicyAnalyzerRoslynTests
fixedCode.Should().Contain("REPLACE_INTENT");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CodeFix_UsesFullyQualifiedNames()
{
const string source = """
@@ -408,7 +424,8 @@ public sealed class PolicyAnalyzerRoslynTests
fixedCode.Should().Contain("global::System.Uri");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FixAllProvider_IsWellKnownBatchFixer()
{
var provider = new HttpClientUsageCodeFixProvider();
@@ -418,7 +435,8 @@ public sealed class PolicyAnalyzerRoslynTests
"Should use batch fixer for efficient multi-fix application");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Analyzer_SupportedDiagnostics_ContainsExpectedId()
{
var analyzer = new HttpClientUsageAnalyzer();
@@ -428,7 +446,8 @@ public sealed class PolicyAnalyzerRoslynTests
supportedDiagnostics[0].Id.Should().Be("AIRGAP001");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CodeFixProvider_FixableDiagnosticIds_MatchesAnalyzer()
{
var analyzer = new HttpClientUsageAnalyzer();

View File

@@ -17,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\StellaOps.AirGap.Policy.Analyzers\StellaOps.AirGap.Policy.Analyzers.csproj" />
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
</ItemGroup>
</Project>