Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -18,6 +18,7 @@ using Xunit;
|
||||
|
||||
using MsOptions = Microsoft.Extensions.Options;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Scanner.WebService.Tests;
|
||||
|
||||
/// <summary>
|
||||
@@ -39,7 +40,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
|
||||
#region CreateAttestationAsync Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_ValidInput_ReturnsSuccessResult()
|
||||
{
|
||||
// Arrange
|
||||
@@ -56,7 +58,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Error.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_ValidInput_CreatesInTotoStatement()
|
||||
{
|
||||
// Arrange
|
||||
@@ -71,7 +74,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Statement.PredicateType.Should().Be("stella.ops/richgraph@v1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_ValidInput_IncludesSubjects()
|
||||
{
|
||||
// Arrange
|
||||
@@ -88,7 +92,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Statement.Subject[1].Digest.Should().ContainKey("sha256");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_ValidInput_IncludesPredicateWithGraphMetrics()
|
||||
{
|
||||
// Arrange
|
||||
@@ -106,7 +111,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
predicate.RootCount.Should().Be(input.RootCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_ValidInput_IncludesAnalyzerInfo()
|
||||
{
|
||||
// Arrange
|
||||
@@ -122,7 +128,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
analyzer.ConfigHash.Should().Be(input.AnalyzerConfigHash);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_ValidInput_SetsComputedAtToCurrentTime()
|
||||
{
|
||||
// Arrange
|
||||
@@ -136,7 +143,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Statement!.Predicate.ComputedAt.Should().Be(expectedTime);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_WithDefaultTtl_SetsExpiresAtTo7Days()
|
||||
{
|
||||
// Arrange
|
||||
@@ -150,7 +158,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Statement!.Predicate.ExpiresAt.Should().Be(expectedExpiry);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_WithCustomTtl_SetsExpiresAtToCustomValue()
|
||||
{
|
||||
// Arrange
|
||||
@@ -164,7 +173,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Statement!.Predicate.ExpiresAt.Should().Be(expectedExpiry);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_IncludesOptionalRefs()
|
||||
{
|
||||
// Arrange
|
||||
@@ -184,7 +194,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Statement.Predicate.Language.Should().Be("java");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_GeneratesDeterministicAttestationId()
|
||||
{
|
||||
// Arrange
|
||||
@@ -198,7 +209,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result1.AttestationId.Should().Be(result2.AttestationId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_DifferentInputs_GenerateDifferentAttestationIds()
|
||||
{
|
||||
// Arrange
|
||||
@@ -213,7 +225,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result1.AttestationId.Should().NotBe(result2.AttestationId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CreateAttestationAsync_NullInput_ThrowsArgumentNullException()
|
||||
{
|
||||
// Act & Assert
|
||||
@@ -221,7 +234,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
_service.CreateAttestationAsync(null!));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public async Task CreateAttestationAsync_EmptyGraphId_ThrowsArgumentException(string graphId)
|
||||
@@ -234,7 +248,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
_service.CreateAttestationAsync(input));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public async Task CreateAttestationAsync_EmptyGraphDigest_ThrowsArgumentException(string graphDigest)
|
||||
@@ -247,7 +262,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
_service.CreateAttestationAsync(input));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public async Task CreateAttestationAsync_EmptyAnalyzerName_ThrowsArgumentException(string analyzerName)
|
||||
@@ -264,7 +280,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
|
||||
#region GetAttestationAsync Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task GetAttestationAsync_ExistingAttestation_ReturnsAttestation()
|
||||
{
|
||||
// Arrange
|
||||
@@ -280,7 +297,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Statement!.Predicate.GraphId.Should().Be(input.GraphId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task GetAttestationAsync_NonExistentAttestation_ReturnsNull()
|
||||
{
|
||||
// Act
|
||||
@@ -290,7 +308,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task GetAttestationAsync_WrongScanId_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
@@ -304,7 +323,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task GetAttestationAsync_WrongGraphId_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
@@ -322,7 +342,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
|
||||
#region Serialization Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Statement_SerializesToValidJson()
|
||||
{
|
||||
// Arrange
|
||||
@@ -339,7 +360,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
json.Should().Contain("\"predicate\":");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Statement_PredicateType_IsCorrectUri()
|
||||
{
|
||||
// Arrange
|
||||
@@ -352,7 +374,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
result.Statement!.PredicateType.Should().Be("stella.ops/richgraph@v1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Statement_Schema_IsRichGraphV1()
|
||||
{
|
||||
// Arrange
|
||||
@@ -409,7 +432,8 @@ public sealed class RichGraphAttestationServiceTests
|
||||
/// </summary>
|
||||
public sealed class RichGraphAttestationOptionsTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DefaultGraphTtlDays_DefaultsToSevenDays()
|
||||
{
|
||||
var options = new RichGraphAttestationOptions();
|
||||
@@ -417,7 +441,8 @@ public sealed class RichGraphAttestationOptionsTests
|
||||
options.DefaultGraphTtlDays.Should().Be(7);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void EnableSigning_DefaultsToTrue()
|
||||
{
|
||||
var options = new RichGraphAttestationOptions();
|
||||
@@ -425,7 +450,8 @@ public sealed class RichGraphAttestationOptionsTests
|
||||
options.EnableSigning.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Options_CanBeConfigured()
|
||||
{
|
||||
var options = new RichGraphAttestationOptions
|
||||
@@ -444,7 +470,8 @@ public sealed class RichGraphAttestationOptionsTests
|
||||
/// </summary>
|
||||
public sealed class RichGraphStatementTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Type_AlwaysReturnsInTotoStatementV1()
|
||||
{
|
||||
var statement = CreateValidStatement();
|
||||
@@ -452,7 +479,8 @@ public sealed class RichGraphStatementTests
|
||||
statement.Type.Should().Be("https://in-toto.io/Statement/v1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void PredicateType_AlwaysReturnsCorrectUri()
|
||||
{
|
||||
var statement = CreateValidStatement();
|
||||
@@ -460,7 +488,8 @@ public sealed class RichGraphStatementTests
|
||||
statement.PredicateType.Should().Be("stella.ops/richgraph@v1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Subject_CanContainMultipleEntries()
|
||||
{
|
||||
var statement = CreateValidStatement();
|
||||
@@ -500,7 +529,8 @@ public sealed class RichGraphStatementTests
|
||||
/// </summary>
|
||||
public sealed class RichGraphAttestationResultTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Succeeded_CreatesSuccessResult()
|
||||
{
|
||||
var statement = CreateValidStatement();
|
||||
@@ -512,7 +542,8 @@ public sealed class RichGraphAttestationResultTests
|
||||
result.Error.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Succeeded_WithDsseEnvelope_IncludesEnvelope()
|
||||
{
|
||||
var statement = CreateValidStatement();
|
||||
@@ -524,7 +555,8 @@ public sealed class RichGraphAttestationResultTests
|
||||
result.DsseEnvelope.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Failed_CreatesFailedResult()
|
||||
{
|
||||
var result = RichGraphAttestationResult.Failed("Test error message");
|
||||
|
||||
Reference in New Issue
Block a user