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

@@ -5,6 +5,8 @@ using System.Text.Json;
using StellaOps.ExportCenter.Client.Models;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.ExportCenter.Client.Tests;
/// <summary>
@@ -14,7 +16,8 @@ public sealed class ExportCenterClientTests
{
private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetDiscoveryMetadataAsync_ReturnsMetadata()
{
var expectedMetadata = new OpenApiDiscoveryMetadata(
@@ -44,7 +47,8 @@ public sealed class ExportCenterClientTests
Assert.Equal("3.0.3", result.SpecVersion);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ListProfilesAsync_ReturnsProfiles()
{
var expectedResponse = new ExportProfileListResponse(
@@ -79,7 +83,8 @@ public sealed class ExportCenterClientTests
Assert.False(result.HasMore);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ListProfilesAsync_WithPagination_IncludesParameters()
{
var expectedResponse = new ExportProfileListResponse([], null, false);
@@ -97,7 +102,8 @@ public sealed class ExportCenterClientTests
await client.ListProfilesAsync(continuationToken: "abc123", limit: 10);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetProfileAsync_WhenNotFound_ReturnsNull()
{
var handler = new MockHttpMessageHandler(request =>
@@ -112,7 +118,8 @@ public sealed class ExportCenterClientTests
Assert.Null(result);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CreateEvidenceExportAsync_ReturnsResponse()
{
var expectedResponse = new CreateEvidenceExportResponse(
@@ -137,7 +144,8 @@ public sealed class ExportCenterClientTests
Assert.Equal("pending", result.Status);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetEvidenceExportStatusAsync_ReturnsStatus()
{
var expectedStatus = new EvidenceExportStatus(
@@ -167,7 +175,8 @@ public sealed class ExportCenterClientTests
Assert.Equal(100, result.Progress);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DownloadEvidenceExportAsync_ReturnsStream()
{
var bundleContent = "test bundle content"u8.ToArray();
@@ -191,7 +200,8 @@ public sealed class ExportCenterClientTests
Assert.Equal(bundleContent, ms.ToArray());
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DownloadEvidenceExportAsync_WhenNotReady_ReturnsNull()
{
var handler = new MockHttpMessageHandler(request =>
@@ -206,7 +216,8 @@ public sealed class ExportCenterClientTests
Assert.Null(result);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CreateAttestationExportAsync_ReturnsResponse()
{
var expectedResponse = new CreateAttestationExportResponse(
@@ -230,7 +241,8 @@ public sealed class ExportCenterClientTests
Assert.Equal("att-run-123", result.RunId);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetAttestationExportStatusAsync_IncludesTransparencyLogField()
{
var expectedStatus = new AttestationExportStatus(

View File

@@ -1,6 +1,8 @@
using StellaOps.ExportCenter.Client.Streaming;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.ExportCenter.Client.Tests;
public sealed class ExportDownloadHelperTests : IDisposable
@@ -21,7 +23,8 @@ public sealed class ExportDownloadHelperTests : IDisposable
}
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DownloadToFileAsync_WritesContentToFile()
{
var content = "test content"u8.ToArray();
@@ -35,7 +38,8 @@ public sealed class ExportDownloadHelperTests : IDisposable
Assert.Equal(content, await File.ReadAllBytesAsync(outputPath));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DownloadToFileAsync_ReportsProgress()
{
var content = new byte[10000];
@@ -51,7 +55,8 @@ public sealed class ExportDownloadHelperTests : IDisposable
Assert.Equal(content.Length, progressReports[^1].bytes);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ComputeSha256Async_ReturnsCorrectHash()
{
var content = "test content for hashing"u8.ToArray();
@@ -64,7 +69,8 @@ public sealed class ExportDownloadHelperTests : IDisposable
Assert.All(hash, c => Assert.True(char.IsLetterOrDigit(c)));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DownloadAndVerifyAsync_SucceedsWithCorrectHash()
{
var content = "deterministic content"u8.ToArray();
@@ -81,7 +87,8 @@ public sealed class ExportDownloadHelperTests : IDisposable
Assert.True(File.Exists(outputPath));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DownloadAndVerifyAsync_ThrowsOnHashMismatch()
{
var content = "actual content"u8.ToArray();
@@ -96,7 +103,8 @@ public sealed class ExportDownloadHelperTests : IDisposable
Assert.False(File.Exists(outputPath));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DownloadAndVerifyAsync_HandlesSha256Prefix()
{
var content = "prefixed hash test"u8.ToArray();
@@ -113,7 +121,8 @@ public sealed class ExportDownloadHelperTests : IDisposable
Assert.Equal(hash, actualHash);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CopyWithProgressAsync_CopiesCorrectly()
{
var content = new byte[5000];
@@ -127,7 +136,8 @@ public sealed class ExportDownloadHelperTests : IDisposable
Assert.Equal(content, destination.ToArray());
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void CreateProgressLogger_ReturnsWorkingCallback()
{
var messages = new List<string>();
@@ -144,7 +154,8 @@ public sealed class ExportDownloadHelperTests : IDisposable
Assert.Contains("300", messages[1]);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void CreateProgressLogger_FormatsWithoutTotalBytes()
{
var messages = new List<string>();
@@ -156,7 +167,8 @@ public sealed class ExportDownloadHelperTests : IDisposable
Assert.DoesNotContain("%", messages[0]);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void CreateProgressLogger_FormatsWithTotalBytes()
{
var messages = new List<string>();

View File

@@ -2,11 +2,13 @@ using StellaOps.ExportCenter.Client.Lifecycle;
using StellaOps.ExportCenter.Client.Models;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.ExportCenter.Client.Tests;
public sealed class ExportJobLifecycleHelperTests
{
[Theory]
[Trait("Category", TestCategories.Unit)]
[Theory]
[InlineData("completed", true)]
[InlineData("failed", true)]
[InlineData("cancelled", true)]
@@ -19,7 +21,8 @@ public sealed class ExportJobLifecycleHelperTests
Assert.Equal(expected, result);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task WaitForEvidenceExportCompletionAsync_ReturnsOnTerminalStatus()
{
var callCount = 0;
@@ -51,7 +54,8 @@ public sealed class ExportJobLifecycleHelperTests
Assert.Equal(3, callCount);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task WaitForEvidenceExportCompletionAsync_ThrowsOnNotFound()
{
var mockClient = new MockExportCenterClient
@@ -64,7 +68,8 @@ public sealed class ExportJobLifecycleHelperTests
mockClient, "nonexistent", TimeSpan.FromMilliseconds(10), TimeSpan.FromSeconds(1)));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task WaitForAttestationExportCompletionAsync_ReturnsOnTerminalStatus()
{
var callCount = 0;
@@ -96,7 +101,8 @@ public sealed class ExportJobLifecycleHelperTests
Assert.True(result.TransparencyLogIncluded);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task CreateEvidenceExportAndWaitAsync_CreatesAndWaits()
{
var createCalled = false;
@@ -126,7 +132,8 @@ public sealed class ExportJobLifecycleHelperTests
Assert.Equal("completed", result.Status);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void TerminalStatuses_ContainsExpectedValues()
{
Assert.Contains("completed", ExportJobLifecycleHelper.TerminalStatuses);

View File

@@ -28,6 +28,7 @@
<ItemGroup>
<ProjectReference Include="..\StellaOps.ExportCenter.Client\StellaOps.ExportCenter.Client.csproj" />
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
</ItemGroup>
</Project>