Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -13,7 +13,8 @@ namespace StellaOps.Aoc.Analyzers.Tests;
|
||||
|
||||
public sealed class AocForbiddenFieldAnalyzerTests
|
||||
{
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("severity")]
|
||||
[InlineData("cvss")]
|
||||
[InlineData("cvss_vector")]
|
||||
@@ -46,7 +47,8 @@ public sealed class AocForbiddenFieldAnalyzerTests
|
||||
Assert.Contains(diagnostics, d => d.Id == AocForbiddenFieldAnalyzer.DiagnosticIdForbiddenField);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("effective_date")]
|
||||
[InlineData("effective_version")]
|
||||
[InlineData("effective_score")]
|
||||
@@ -73,7 +75,8 @@ public sealed class AocForbiddenFieldAnalyzerTests
|
||||
Assert.Contains(diagnostics, d => d.Id == AocForbiddenFieldAnalyzer.DiagnosticIdDerivedField);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ReportsDiagnostic_ForForbiddenFieldInObjectInitializer()
|
||||
{
|
||||
const string source = """
|
||||
@@ -102,7 +105,8 @@ public sealed class AocForbiddenFieldAnalyzerTests
|
||||
Assert.Contains(diagnostics, d => d.Id == AocForbiddenFieldAnalyzer.DiagnosticIdForbiddenField);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task DoesNotReportDiagnostic_ForAllowedFieldAssignment()
|
||||
{
|
||||
const string source = """
|
||||
@@ -130,7 +134,8 @@ public sealed class AocForbiddenFieldAnalyzerTests
|
||||
d.Id == AocForbiddenFieldAnalyzer.DiagnosticIdDerivedField);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task DoesNotReportDiagnostic_ForNonIngestionAssembly()
|
||||
{
|
||||
const string source = """
|
||||
@@ -154,7 +159,8 @@ public sealed class AocForbiddenFieldAnalyzerTests
|
||||
Assert.DoesNotContain(diagnostics, d => d.Id == AocForbiddenFieldAnalyzer.DiagnosticIdForbiddenField);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task DoesNotReportDiagnostic_ForTestAssembly()
|
||||
{
|
||||
const string source = """
|
||||
@@ -178,12 +184,14 @@ public sealed class AocForbiddenFieldAnalyzerTests
|
||||
Assert.DoesNotContain(diagnostics, d => d.Id == AocForbiddenFieldAnalyzer.DiagnosticIdForbiddenField);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ReportsDiagnostic_ForDictionaryAddWithForbiddenKey()
|
||||
{
|
||||
const string source = """
|
||||
using System.Collections.Generic;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Concelier.Connector.Sample;
|
||||
|
||||
public sealed class Ingester
|
||||
@@ -200,7 +208,8 @@ public sealed class AocForbiddenFieldAnalyzerTests
|
||||
Assert.Contains(diagnostics, d => d.Id == AocForbiddenFieldAnalyzer.DiagnosticIdForbiddenField);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ReportsDiagnostic_CaseInsensitive()
|
||||
{
|
||||
const string source = """
|
||||
@@ -225,7 +234,8 @@ public sealed class AocForbiddenFieldAnalyzerTests
|
||||
Assert.Contains(diagnostics, d => d.Id == AocForbiddenFieldAnalyzer.DiagnosticIdForbiddenField);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ReportsDiagnostic_ForAnonymousObjectWithForbiddenField()
|
||||
{
|
||||
const string source = """
|
||||
@@ -244,7 +254,8 @@ public sealed class AocForbiddenFieldAnalyzerTests
|
||||
Assert.Contains(diagnostics, d => d.Id == AocForbiddenFieldAnalyzer.DiagnosticIdForbiddenField);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task DoesNotReportDiagnostic_ForIngestionNamespaceButNotConnector()
|
||||
{
|
||||
const string source = """
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\__Analyzers\StellaOps.Aoc.Analyzers\StellaOps.Aoc.Analyzers.csproj" />
|
||||
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -5,11 +5,14 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StellaOps.Aoc.AspNetCore.Routing;
|
||||
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Aoc.AspNetCore.Tests;
|
||||
|
||||
public sealed class AocGuardEndpointFilterExtensionsTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void RequireAocGuard_ReturnsBuilderInstance()
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder();
|
||||
@@ -23,7 +26,8 @@ public sealed class AocGuardEndpointFilterExtensionsTests
|
||||
Assert.Same(route, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void RequireAocGuard_WithNullBuilder_Throws()
|
||||
{
|
||||
RouteHandlerBuilder? builder = null;
|
||||
@@ -34,7 +38,8 @@ public sealed class AocGuardEndpointFilterExtensionsTests
|
||||
_ => Array.Empty<object?>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void RequireAocGuard_WithObjectSelector_UsesOverload()
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder();
|
||||
|
||||
@@ -7,11 +7,14 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using StellaOps.Aoc;
|
||||
using StellaOps.Aoc.AspNetCore.Results;
|
||||
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Aoc.AspNetCore.Tests;
|
||||
|
||||
public sealed class AocHttpResultsTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Problem_WritesProblemDetails_WithGuardViolations()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\__Libraries\StellaOps.Aoc.AspNetCore\StellaOps.Aoc.AspNetCore.csproj" />
|
||||
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
using System.Collections.Immutable;
|
||||
using StellaOps.Aoc;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Aoc.Tests;
|
||||
|
||||
public sealed class AocErrorTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void FromResult_UsesFirstViolationCode()
|
||||
{
|
||||
var violations = ImmutableArray.Create(
|
||||
@@ -20,7 +22,8 @@ public sealed class AocErrorTests
|
||||
Assert.Equal(violations, error.Violations);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void FromResult_DefaultsWhenNoViolations()
|
||||
{
|
||||
var error = AocError.FromResult(AocGuardResult.Success);
|
||||
@@ -29,7 +32,8 @@ public sealed class AocErrorTests
|
||||
Assert.Contains("ERR_AOC_000", error.Message, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void FromException_UsesCustomMessage()
|
||||
{
|
||||
var violations = ImmutableArray.Create(
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using System.Text.Json;
|
||||
using StellaOps.Aoc;
|
||||
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Aoc.Tests;
|
||||
|
||||
public sealed class AocWriteGuardTests
|
||||
{
|
||||
private static readonly AocWriteGuard Guard = new();
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_ReturnsSuccess_ForMinimalValidDocument()
|
||||
{
|
||||
using var document = JsonDocument.Parse("""
|
||||
@@ -33,7 +36,8 @@ public sealed class AocWriteGuardTests
|
||||
Assert.Empty(result.Violations);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_AllowsLinksAndAdvisoryKey_ByDefault()
|
||||
{
|
||||
using var document = JsonDocument.Parse("""
|
||||
@@ -63,7 +67,8 @@ public sealed class AocWriteGuardTests
|
||||
Assert.Empty(result.Violations);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_FlagsMissingTenant()
|
||||
{
|
||||
using var document = JsonDocument.Parse("""
|
||||
@@ -88,7 +93,8 @@ public sealed class AocWriteGuardTests
|
||||
Assert.Contains(result.Violations, v => v.ErrorCode == "ERR_AOC_004" && v.Path == "/tenant");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_FlagsForbiddenField()
|
||||
{
|
||||
using var document = JsonDocument.Parse("""
|
||||
@@ -116,7 +122,8 @@ public sealed class AocWriteGuardTests
|
||||
Assert.Contains(result.Violations, v => v.ErrorCode == "ERR_AOC_001" && v.Path == "/severity");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_FlagsUnknownField()
|
||||
{
|
||||
using var document = JsonDocument.Parse("""
|
||||
@@ -143,7 +150,8 @@ public sealed class AocWriteGuardTests
|
||||
Assert.Contains(result.Violations, v => v.ErrorCode == "ERR_AOC_007" && v.Path == "/custom_field");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_AllowsCustomField_WhenConfigured()
|
||||
{
|
||||
using var document = JsonDocument.Parse("""
|
||||
@@ -174,7 +182,8 @@ public sealed class AocWriteGuardTests
|
||||
Assert.True(result.IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_FlagsInvalidSignatureMetadata()
|
||||
{
|
||||
using var document = JsonDocument.Parse("""
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../__Libraries/StellaOps.Aoc/StellaOps.Aoc.csproj" />
|
||||
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,8 +1,10 @@
|
||||
namespace StellaOps.Aoc.Tests;
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Aoc.Tests;
|
||||
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user