Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -14,7 +14,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 +45,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 +81,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 +100,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 +116,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 +142,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 +173,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();
|
||||
@@ -187,11 +194,13 @@ public sealed class ExportCenterClientTests
|
||||
|
||||
Assert.NotNull(stream);
|
||||
using var ms = new MemoryStream();
|
||||
using StellaOps.TestKit;
|
||||
await stream.CopyToAsync(ms);
|
||||
Assert.Equal(bundleContent, ms.ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task DownloadEvidenceExportAsync_WhenNotReady_ReturnsNull()
|
||||
{
|
||||
var handler = new MockHttpMessageHandler(request =>
|
||||
@@ -206,7 +215,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 +240,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(
|
||||
|
||||
@@ -21,7 +21,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 +36,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 +53,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 +67,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 +85,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 +101,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 +119,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];
|
||||
@@ -121,13 +128,15 @@ public sealed class ExportDownloadHelperTests : IDisposable
|
||||
using var source = new MemoryStream(content);
|
||||
using var destination = new MemoryStream();
|
||||
|
||||
using StellaOps.TestKit;
|
||||
var bytesCopied = await ExportDownloadHelper.CopyWithProgressAsync(source, destination);
|
||||
|
||||
Assert.Equal(content.Length, bytesCopied);
|
||||
Assert.Equal(content, destination.ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void CreateProgressLogger_ReturnsWorkingCallback()
|
||||
{
|
||||
var messages = new List<string>();
|
||||
@@ -144,7 +153,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 +166,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>();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user