Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -24,7 +24,8 @@ public sealed class SliceEndpointsTests : IClassFixture<ScannerApplicationFixtur
|
||||
_client = fixture.Factory.CreateClient();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task QuerySlice_WithValidCve_ReturnsSlice()
|
||||
{
|
||||
// Arrange
|
||||
@@ -47,7 +48,8 @@ public sealed class SliceEndpointsTests : IClassFixture<ScannerApplicationFixtur
|
||||
$"Unexpected status: {response.StatusCode}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task QuerySlice_WithoutScanId_ReturnsBadRequest()
|
||||
{
|
||||
// Arrange
|
||||
@@ -66,7 +68,8 @@ public sealed class SliceEndpointsTests : IClassFixture<ScannerApplicationFixtur
|
||||
$"Expected BadRequest or Unauthorized, got {response.StatusCode}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task QuerySlice_WithoutCveOrSymbols_ReturnsBadRequest()
|
||||
{
|
||||
// Arrange
|
||||
@@ -85,7 +88,8 @@ public sealed class SliceEndpointsTests : IClassFixture<ScannerApplicationFixtur
|
||||
$"Expected BadRequest or Unauthorized, got {response.StatusCode}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task GetSlice_WithValidDigest_ReturnsSlice()
|
||||
{
|
||||
// Arrange
|
||||
@@ -102,7 +106,8 @@ public sealed class SliceEndpointsTests : IClassFixture<ScannerApplicationFixtur
|
||||
$"Unexpected status: {response.StatusCode}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task GetSlice_WithDsseAccept_ReturnsDsseEnvelope()
|
||||
{
|
||||
// Arrange
|
||||
@@ -121,7 +126,8 @@ public sealed class SliceEndpointsTests : IClassFixture<ScannerApplicationFixtur
|
||||
$"Unexpected status: {response.StatusCode}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ReplaySlice_WithValidDigest_ReturnsReplayResult()
|
||||
{
|
||||
// Arrange
|
||||
@@ -141,7 +147,8 @@ public sealed class SliceEndpointsTests : IClassFixture<ScannerApplicationFixtur
|
||||
$"Unexpected status: {response.StatusCode}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ReplaySlice_WithoutDigest_ReturnsBadRequest()
|
||||
{
|
||||
// Arrange
|
||||
@@ -165,7 +172,8 @@ public sealed class SliceDiffComputerTests
|
||||
{
|
||||
private readonly SliceDiffComputer _computer = new();
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Compare_IdenticalSlices_ReturnsMatch()
|
||||
{
|
||||
// Arrange
|
||||
@@ -183,7 +191,8 @@ public sealed class SliceDiffComputerTests
|
||||
Assert.Null(result.VerdictDiff);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Compare_DifferentNodes_ReturnsDiff()
|
||||
{
|
||||
// Arrange
|
||||
@@ -211,7 +220,8 @@ public sealed class SliceDiffComputerTests
|
||||
Assert.Contains("extra-node", result.ExtraNodes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Compare_DifferentEdges_ReturnsDiff()
|
||||
{
|
||||
// Arrange
|
||||
@@ -232,7 +242,8 @@ public sealed class SliceDiffComputerTests
|
||||
Assert.Single(result.MissingEdges);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Compare_DifferentVerdict_ReturnsDiff()
|
||||
{
|
||||
// Arrange
|
||||
@@ -254,7 +265,8 @@ public sealed class SliceDiffComputerTests
|
||||
Assert.Contains("Status:", result.VerdictDiff);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ComputeCacheKey_SameInputs_ReturnsSameKey()
|
||||
{
|
||||
// Arrange
|
||||
@@ -269,7 +281,8 @@ public sealed class SliceDiffComputerTests
|
||||
Assert.Equal(key1, key2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ComputeCacheKey_DifferentInputs_ReturnsDifferentKey()
|
||||
{
|
||||
// Arrange
|
||||
@@ -283,7 +296,8 @@ public sealed class SliceDiffComputerTests
|
||||
Assert.NotEqual(key1, key2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ToSummary_MatchingSlices_ReturnsMatchMessage()
|
||||
{
|
||||
// Arrange
|
||||
@@ -296,7 +310,8 @@ public sealed class SliceDiffComputerTests
|
||||
Assert.Contains("match exactly", summary);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ToSummary_DifferingSlices_ReturnsDetailedDiff()
|
||||
{
|
||||
// Arrange
|
||||
@@ -360,7 +375,8 @@ public sealed class SliceDiffComputerTests
|
||||
/// </summary>
|
||||
public sealed class SliceCacheTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task TryGetAsync_EmptyCache_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
@@ -374,7 +390,8 @@ public sealed class SliceCacheTests
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task SetAsync_ThenTryGetAsync_ReturnsEntry()
|
||||
{
|
||||
// Arrange
|
||||
@@ -391,7 +408,8 @@ public sealed class SliceCacheTests
|
||||
Assert.Equal("sha256:abc123", result!.SliceDigest);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task TryGetAsync_IncrementsCacheStats()
|
||||
{
|
||||
// Arrange
|
||||
@@ -412,7 +430,8 @@ public sealed class SliceCacheTests
|
||||
Assert.Equal(0.5, stats.HitRate, 2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ClearAsync_RemovesAllEntries()
|
||||
{
|
||||
// Arrange
|
||||
@@ -430,7 +449,8 @@ public sealed class SliceCacheTests
|
||||
Assert.Equal(0, stats.EntryCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task RemoveAsync_RemovesSpecificEntry()
|
||||
{
|
||||
// Arrange
|
||||
@@ -448,12 +468,14 @@ public sealed class SliceCacheTests
|
||||
Assert.NotNull(await cache.TryGetAsync("key2"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Disabled_NeverCaches()
|
||||
{
|
||||
// Arrange
|
||||
var options = Microsoft.Extensions.Options.Options.Create(new SliceCacheOptions { Enabled = false });
|
||||
using var cache = new SliceCache(options);
|
||||
using StellaOps.TestKit;
|
||||
var cacheResult = CreateTestCacheResult();
|
||||
|
||||
// Act
|
||||
|
||||
Reference in New Issue
Block a user