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

@@ -2,13 +2,15 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Time.Testing;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Evidence.Bundle.Tests;
public class EvidenceBundleTests
{
private readonly FakeTimeProvider _timeProvider = new(new DateTimeOffset(2024, 12, 15, 12, 0, 0, TimeSpan.Zero));
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Builder_MinimalBundle_CreatesValid()
{
var bundle = new EvidenceBundleBuilder(_timeProvider)
@@ -24,21 +26,24 @@ public class EvidenceBundleTests
Assert.Equal(_timeProvider.GetUtcNow(), bundle.CreatedAt);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Builder_MissingAlertId_Throws()
{
var builder = new EvidenceBundleBuilder(_timeProvider).WithArtifactId("sha256:abc");
Assert.Throws<InvalidOperationException>(() => builder.Build());
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Builder_MissingArtifactId_Throws()
{
var builder = new EvidenceBundleBuilder(_timeProvider).WithAlertId("ALERT-001");
Assert.Throws<InvalidOperationException>(() => builder.Build());
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Builder_WithAllEvidence_ComputesHashSet()
{
var bundle = new EvidenceBundleBuilder(_timeProvider)
@@ -56,7 +61,8 @@ public class EvidenceBundleTests
Assert.Equal(64, bundle.Hashes.CombinedHash.Length);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeCompletenessScore_AllAvailable_Returns4()
{
var bundle = new EvidenceBundleBuilder(_timeProvider)
@@ -71,7 +77,8 @@ public class EvidenceBundleTests
Assert.Equal(4, bundle.ComputeCompletenessScore());
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeCompletenessScore_NoneAvailable_Returns0()
{
var bundle = new EvidenceBundleBuilder(_timeProvider)
@@ -82,7 +89,8 @@ public class EvidenceBundleTests
Assert.Equal(0, bundle.ComputeCompletenessScore());
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeCompletenessScore_PartialAvailable_ReturnsCorrect()
{
var bundle = new EvidenceBundleBuilder(_timeProvider)
@@ -97,7 +105,8 @@ public class EvidenceBundleTests
Assert.Equal(2, bundle.ComputeCompletenessScore());
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void CreateStatusSummary_ReturnsCorrectStatuses()
{
var bundle = new EvidenceBundleBuilder(_timeProvider)
@@ -116,7 +125,8 @@ public class EvidenceBundleTests
Assert.Equal(EvidenceStatus.Unavailable, summary.VexStatus);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ToSigningPredicate_CreatesValidPredicate()
{
var bundle = new EvidenceBundleBuilder(_timeProvider)
@@ -138,7 +148,8 @@ public class EvidenceBundleTests
public class EvidenceHashSetTests
{
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Compute_DeterministicOutput()
{
var hashes1 = new Dictionary<string, string> { ["a"] = "hash1", ["b"] = "hash2" };
@@ -150,7 +161,8 @@ public class EvidenceHashSetTests
Assert.Equal(set1.CombinedHash, set2.CombinedHash);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Compute_DifferentInputs_DifferentHash()
{
var hashes1 = new Dictionary<string, string> { ["a"] = "hash1" };
@@ -162,7 +174,8 @@ public class EvidenceHashSetTests
Assert.NotEqual(set1.CombinedHash, set2.CombinedHash);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Empty_CreatesEmptyHashSet()
{
var empty = EvidenceHashSet.Empty();
@@ -172,7 +185,8 @@ public class EvidenceHashSetTests
Assert.Equal("SHA-256", empty.Algorithm);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Compute_PreservesLabeledHashes()
{
var hashes = new Dictionary<string, string> { ["reachability"] = "h1", ["vex"] = "h2" };
@@ -183,7 +197,8 @@ public class EvidenceHashSetTests
Assert.Equal("h2", set.LabeledHashes["vex"]);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Compute_NullInput_Throws()
{
Assert.Throws<ArgumentNullException>(() => EvidenceHashSet.Compute(null!));
@@ -192,7 +207,8 @@ public class EvidenceHashSetTests
public class ServiceCollectionExtensionsTests
{
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void AddEvidenceBundleServices_RegistersBuilder()
{
var services = new ServiceCollection();
@@ -203,7 +219,8 @@ public class ServiceCollectionExtensionsTests
Assert.NotNull(builder);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void AddEvidenceBundleServices_WithTimeProvider_UsesProvided()
{
var fakeTime = new FakeTimeProvider();
@@ -215,14 +232,16 @@ public class ServiceCollectionExtensionsTests
Assert.Same(fakeTime, timeProvider);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void AddEvidenceBundleServices_NullServices_Throws()
{
IServiceCollection? services = null;
Assert.Throws<ArgumentNullException>(() => services!.AddEvidenceBundleServices());
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void AddEvidenceBundleServices_NullTimeProvider_Throws()
{
var services = new ServiceCollection();

View File

@@ -10,5 +10,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\__Libraries\StellaOps.Evidence.Bundle\StellaOps.Evidence.Bundle.csproj" />
<ProjectReference Include="../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
</ItemGroup>
</Project>