Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -13,7 +13,8 @@ public sealed class EpssBundleTests
|
||||
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
||||
};
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task LoadFromStreamAsync_WithValidGzipJson_ReturnsEpssSource()
|
||||
{
|
||||
// Arrange
|
||||
@@ -43,7 +44,8 @@ public sealed class EpssBundleTests
|
||||
result.Source.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task LoadFromStreamAsync_WithPlainJson_ReturnsEpssSource()
|
||||
{
|
||||
// Arrange
|
||||
@@ -71,7 +73,8 @@ public sealed class EpssBundleTests
|
||||
result.RecordCount.Should().Be(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task LoadedSource_ReturnsCorrectScores()
|
||||
{
|
||||
// Arrange
|
||||
@@ -107,7 +110,8 @@ public sealed class EpssBundleTests
|
||||
unknownScore.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task LoadedSource_IsCaseInsensitive()
|
||||
{
|
||||
// Arrange
|
||||
@@ -136,7 +140,8 @@ public sealed class EpssBundleTests
|
||||
upper.Score.Should().Be(mixed!.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task LoadFromStreamAsync_WithEmptyScores_ReturnsEmptySource()
|
||||
{
|
||||
// Arrange
|
||||
@@ -162,7 +167,8 @@ public sealed class EpssBundleTests
|
||||
score.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task LoadFromStreamAsync_WithDuplicates_DeduplicatesScores()
|
||||
{
|
||||
// Arrange - bundle loader should handle duplicates gracefully
|
||||
@@ -191,7 +197,8 @@ public sealed class EpssBundleTests
|
||||
score.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void LoadFromSnapshotAsync_WithMissingFile_ThrowsFileNotFoundException()
|
||||
{
|
||||
// Arrange
|
||||
@@ -203,7 +210,8 @@ public sealed class EpssBundleTests
|
||||
act.Should().ThrowAsync<FileNotFoundException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void LoadFromBundleAsync_WithMissingFile_ThrowsFileNotFoundException()
|
||||
{
|
||||
// Arrange
|
||||
@@ -221,6 +229,7 @@ public sealed class EpssBundleTests
|
||||
using (var gzipStream = new GZipStream(memoryStream, CompressionLevel.Fastest, leaveOpen: true))
|
||||
{
|
||||
JsonSerializer.Serialize(gzipStream, data, JsonOptions);
|
||||
using StellaOps.TestKit;
|
||||
}
|
||||
memoryStream.Position = 0;
|
||||
return memoryStream;
|
||||
|
||||
@@ -5,6 +5,7 @@ using StellaOps.RiskEngine.Core.Contracts;
|
||||
using StellaOps.RiskEngine.Core.Providers;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.RiskEngine.Tests;
|
||||
|
||||
public class RiskEngineApiTests : IClassFixture<WebApplicationFactory<Program>>
|
||||
@@ -16,7 +17,8 @@ public class RiskEngineApiTests : IClassFixture<WebApplicationFactory<Program>>
|
||||
this.factory = factory.WithWebHostBuilder(_ => { });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Providers_ListsDefaultTransforms()
|
||||
{
|
||||
var client = factory.CreateClient();
|
||||
@@ -30,7 +32,8 @@ public class RiskEngineApiTests : IClassFixture<WebApplicationFactory<Program>>
|
||||
Assert.Contains(DefaultTransformsProvider.ProviderName, payload!.Providers);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Job_SubmitAndRetrieve_PersistsResult()
|
||||
{
|
||||
var client = factory.CreateClient();
|
||||
@@ -54,7 +57,8 @@ public class RiskEngineApiTests : IClassFixture<WebApplicationFactory<Program>>
|
||||
Assert.True(fetched.Success);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Simulations_ReturnsBatch()
|
||||
{
|
||||
var client = factory.CreateClient();
|
||||
@@ -75,7 +79,8 @@ public class RiskEngineApiTests : IClassFixture<WebApplicationFactory<Program>>
|
||||
Assert.All(payload.Results, r => Assert.True(r.Success));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Simulations_Summary_ReturnsAggregatesAndTopMovers()
|
||||
{
|
||||
var client = factory.CreateClient();
|
||||
|
||||
@@ -117,6 +117,7 @@
|
||||
|
||||
|
||||
|
||||
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@ using StellaOps.RiskEngine.Core.Providers;
|
||||
using StellaOps.RiskEngine.Core.Services;
|
||||
using StellaOps.RiskEngine.Infrastructure.Stores;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.RiskEngine.Tests;
|
||||
|
||||
public class RiskScoreWorkerTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ProcessesJobsInFifoOrder()
|
||||
{
|
||||
var provider = new DeterministicProvider("default", 1.0);
|
||||
@@ -39,7 +41,8 @@ public class RiskScoreWorkerTests
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task MissingProviderYieldsFailure()
|
||||
{
|
||||
var registry = new RiskScoreProviderRegistry(Array.Empty<IRiskScoreProvider>());
|
||||
@@ -61,7 +64,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.False(stored.Success);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task DeterministicProviderReturnsStableScore()
|
||||
{
|
||||
var provider = new DeterministicProvider("default", weight: 2.0);
|
||||
@@ -84,7 +88,8 @@ public class RiskScoreWorkerTests
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task DefaultProviderClampsAndAveragesSignals()
|
||||
{
|
||||
var provider = new DefaultTransformsProvider();
|
||||
@@ -107,7 +112,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(expected, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CvssKevProviderAddsKevBonus()
|
||||
{
|
||||
var cvssSource = new FakeCvssSource(new Dictionary<string, double>
|
||||
@@ -133,7 +139,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(1.0d, result.Score); // 0.98 + 0.2 capped at 1.0
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CvssKevProviderHandlesMissingCvss()
|
||||
{
|
||||
var cvssSource = new FakeCvssSource(new Dictionary<string, double>());
|
||||
@@ -152,7 +159,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(0d, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task VexGateProviderShortCircuitsOnDenial()
|
||||
{
|
||||
var provider = new VexGateProvider();
|
||||
@@ -173,7 +181,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(0d, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task VexGateProviderUsesMaxSignalWhenNoDenial()
|
||||
{
|
||||
var provider = new VexGateProvider();
|
||||
@@ -195,7 +204,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(0.8d, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task FixExposureProviderAppliesWeights()
|
||||
{
|
||||
var provider = new FixExposureProvider();
|
||||
@@ -218,7 +228,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(expected, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task FixExposureProviderDefaultsMissingSignalsToZero()
|
||||
{
|
||||
var provider = new FixExposureProvider();
|
||||
@@ -239,7 +250,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(0.5d, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ResultsPersistedToStore()
|
||||
{
|
||||
var provider = new DeterministicProvider("default", 1.0);
|
||||
@@ -261,7 +273,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(results.Select(r => r.Score), snapshot.Select(r => r.Score));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task EpssProviderReturnsScoreDirectly()
|
||||
{
|
||||
var epssSource = new FakeEpssSource(new Dictionary<string, EpssData>
|
||||
@@ -283,7 +296,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(0.75d, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task EpssProviderReturnsZeroForUnknown()
|
||||
{
|
||||
var epssSource = new FakeEpssSource(new Dictionary<string, EpssData>());
|
||||
@@ -301,7 +315,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(0d, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CvssKevEpssProviderCombinesAllSignals()
|
||||
{
|
||||
var cvssSource = new FakeCvssSource(new Dictionary<string, double>
|
||||
@@ -332,7 +347,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(1.0d, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CvssKevEpssProviderApplies90thPercentileBonus()
|
||||
{
|
||||
var cvssSource = new FakeCvssSource(new Dictionary<string, double>
|
||||
@@ -360,7 +376,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(0.55d, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CvssKevEpssProviderApplies50thPercentileBonus()
|
||||
{
|
||||
var cvssSource = new FakeCvssSource(new Dictionary<string, double>
|
||||
@@ -388,7 +405,8 @@ public class RiskScoreWorkerTests
|
||||
Assert.Equal(0.42d, result.Score);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CvssKevEpssProviderNoBonusBelowThreshold()
|
||||
{
|
||||
var cvssSource = new FakeCvssSource(new Dictionary<string, double>
|
||||
|
||||
Reference in New Issue
Block a user