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 = """
|
||||
|
||||
@@ -9,7 +9,8 @@ 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 +24,8 @@ public sealed class AocGuardEndpointFilterExtensionsTests
|
||||
Assert.Same(route, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void RequireAocGuard_WithNullBuilder_Throws()
|
||||
{
|
||||
RouteHandlerBuilder? builder = null;
|
||||
@@ -34,13 +36,15 @@ public sealed class AocGuardEndpointFilterExtensionsTests
|
||||
_ => Array.Empty<object?>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void RequireAocGuard_WithObjectSelector_UsesOverload()
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder();
|
||||
builder.Services.AddAocGuard();
|
||||
using var app = builder.Build();
|
||||
|
||||
using StellaOps.TestKit;
|
||||
var route = app.MapPost("/guard-object", (GuardPayload _) => TypedResults.Ok());
|
||||
|
||||
var result = route.RequireAocGuard<GuardPayload>(_ => new GuardPayload(JsonDocument.Parse("{}").RootElement));
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace StellaOps.Aoc.AspNetCore.Tests;
|
||||
|
||||
public sealed class AocHttpResultsTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Problem_WritesProblemDetails_WithGuardViolations()
|
||||
{
|
||||
// Arrange
|
||||
@@ -34,6 +35,7 @@ public sealed class AocHttpResultsTests
|
||||
context.Response.Body.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
using var document = await JsonDocument.ParseAsync(context.Response.Body, cancellationToken: TestContext.Current.CancellationToken);
|
||||
using StellaOps.TestKit;
|
||||
var root = document.RootElement;
|
||||
|
||||
// Assert
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -7,7 +7,8 @@ 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 +34,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 +65,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 +91,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 +120,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 +148,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 +180,8 @@ public sealed class AocWriteGuardTests
|
||||
Assert.True(result.IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Validate_FlagsInvalidSignatureMetadata()
|
||||
{
|
||||
using var document = JsonDocument.Parse("""
|
||||
@@ -194,6 +201,7 @@ public sealed class AocWriteGuardTests
|
||||
}
|
||||
""");
|
||||
|
||||
using StellaOps.TestKit;
|
||||
var result = Guard.Validate(document.RootElement);
|
||||
|
||||
Assert.False(result.IsValid);
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user