-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDMS-179 patches CDMS change to BTMS (#3)
- Loading branch information
1 parent
c497790
commit 5edf433
Showing
35 changed files
with
748 additions
and
185 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
Btms.Analytics.Tests/Fixtures/BasicSampleDataTestCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Xunit; | ||
|
||
namespace Btms.Analytics.Tests.Fixtures; | ||
|
||
[CollectionDefinition(nameof(BasicSampleDataTestCollection))] | ||
public class BasicSampleDataTestCollection : ICollectionFixture<BasicSampleDataTestFixture> | ||
{ | ||
// This class has no code, and is never created. Its purpose is simply | ||
// to be the place to apply [CollectionDefinition] and all the | ||
// ICollectionFixture<> interfaces. | ||
} |
66 changes: 66 additions & 0 deletions
66
Btms.Analytics.Tests/Fixtures/BasicSampleDataTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Btms.Analytics.Tests.Helpers; | ||
using Btms.Backend.Data; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using TestDataGenerator.Scenarios; | ||
|
||
namespace Btms.Analytics.Tests.Fixtures; | ||
|
||
#pragma warning disable S3881 | ||
public class BasicSampleDataTestFixture : IDisposable | ||
#pragma warning restore S3881 | ||
{ | ||
public IHost App; | ||
public IImportNotificationsAggregationService ImportNotificationsAggregationService; | ||
public IMovementsAggregationService MovementsAggregationService; | ||
|
||
public IMongoDbContext MongoDbContext; | ||
public BasicSampleDataTestFixture() | ||
{ | ||
var builder = TestContextHelper.CreateBuilder<BasicSampleDataTestFixture>(); | ||
|
||
App = builder.Build(); | ||
var rootScope = App.Services.CreateScope(); | ||
|
||
MongoDbContext = rootScope.ServiceProvider.GetRequiredService<IMongoDbContext>(); | ||
ImportNotificationsAggregationService = rootScope.ServiceProvider.GetRequiredService<IImportNotificationsAggregationService>(); | ||
MovementsAggregationService = rootScope.ServiceProvider.GetRequiredService<IMovementsAggregationService>(); | ||
|
||
// Would like to pick this up from env/config/DB state | ||
var insertToMongo = true; | ||
|
||
if (insertToMongo) | ||
{ | ||
MongoDbContext.ResetCollections().GetAwaiter().GetResult(); | ||
|
||
// Ensure we have some data scenarios around 24/48 hour tests | ||
App.PushToConsumers(App.CreateScenarioConfig<ChedASimpleMatchScenarioGenerator>(10, 3, arrivalDateRange: 0)) | ||
.GetAwaiter().GetResult(); | ||
|
||
App.PushToConsumers(App.CreateScenarioConfig<ChedPSimpleMatchScenarioGenerator>(10, 3, arrivalDateRange: 2)) | ||
.GetAwaiter().GetResult(); | ||
|
||
App.PushToConsumers(App.CreateScenarioConfig<CrNoMatchScenarioGenerator>(10, 3, arrivalDateRange: 0)) | ||
.GetAwaiter().GetResult(); | ||
|
||
// Create some more variable data over the rest of time | ||
App.PushToConsumers( | ||
App.CreateScenarioConfig<ChedASimpleMatchScenarioGenerator>(10, 7, arrivalDateRange: 10)) | ||
.GetAwaiter().GetResult(); | ||
|
||
App.PushToConsumers(App.CreateScenarioConfig<ChedANoMatchScenarioGenerator>(5, 3, arrivalDateRange: 10)) | ||
.GetAwaiter().GetResult(); | ||
|
||
App.PushToConsumers(App.CreateScenarioConfig<ChedPSimpleMatchScenarioGenerator>(1, 3, arrivalDateRange: 10)) | ||
.GetAwaiter().GetResult(); | ||
|
||
App.PushToConsumers(App.CreateScenarioConfig<CrNoMatchScenarioGenerator>(1, 3, arrivalDateRange: 10)) | ||
.GetAwaiter().GetResult(); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// ... clean up test data from the database ... | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...lytics.Tests/AggregationTestCollection.cs → ...s/Fixtures/MultiItemDataTestCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Btms.Analytics.Tests.Helpers; | ||
using Btms.Backend.Data; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using TestDataGenerator.Scenarios; | ||
|
||
namespace Btms.Analytics.Tests.Fixtures; | ||
|
||
#pragma warning disable S3881 | ||
public class MultiItemDataTestFixture : IDisposable | ||
#pragma warning restore S3881 | ||
{ | ||
public readonly IImportNotificationsAggregationService ImportNotificationsAggregationService; | ||
public readonly IMovementsAggregationService MovementsAggregationService; | ||
|
||
public IMongoDbContext MongoDbContext; | ||
public MultiItemDataTestFixture() | ||
{ | ||
var builder = TestContextHelper.CreateBuilder<MultiItemDataTestFixture>(); | ||
|
||
var app = builder.Build(); | ||
var rootScope = app.Services.CreateScope(); | ||
|
||
MongoDbContext = rootScope.ServiceProvider.GetRequiredService<IMongoDbContext>(); | ||
ImportNotificationsAggregationService = rootScope.ServiceProvider.GetRequiredService<IImportNotificationsAggregationService>(); | ||
MovementsAggregationService = rootScope.ServiceProvider.GetRequiredService<IMovementsAggregationService>(); | ||
|
||
// Would like to pick this up from env/config/DB state | ||
var insertToMongo = true; | ||
|
||
if (insertToMongo) | ||
{ | ||
MongoDbContext.ResetCollections().GetAwaiter().GetResult(); | ||
|
||
app.PushToConsumers(app.CreateScenarioConfig<ChedAManyCommoditiesScenarioGenerator>(10, 3, arrivalDateRange: 0)) | ||
.GetAwaiter().GetResult(); | ||
|
||
app.PushToConsumers(app.CreateScenarioConfig<CrNoMatchScenarioGenerator>(10, 3, arrivalDateRange: 0)) | ||
.GetAwaiter().GetResult(); | ||
|
||
app.PushToConsumers(app.CreateScenarioConfig<ChedASimpleMatchScenarioGenerator>(10, 3, arrivalDateRange: 0)) | ||
.GetAwaiter().GetResult(); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
// ... clean up test data from the database ... | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Btms.Analytics.Tests/Helpers/MultiSeriesDatasetAssertions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Btms.Common.Extensions; | ||
using FluentAssertions; | ||
using FluentAssertions.Collections; | ||
|
||
namespace Btms.Analytics.Tests.Helpers; | ||
|
||
public class MultiSeriesDatasetAssertions(List<MultiSeriesDataset>? test) | ||
: GenericCollectionAssertions<MultiSeriesDataset>(test) | ||
{ | ||
[CustomAssertion] | ||
public void BeSameLength(string because = "", params object[] becauseArgs) | ||
{ | ||
test!.Select(r => r.Results.Count) | ||
.Distinct() | ||
.Count() | ||
.Should() | ||
.Be(1); | ||
} | ||
|
||
[CustomAssertion] | ||
public void HaveResults(string because = "", params object[] becauseArgs) | ||
{ | ||
test!.Sum(d => d.Results.Sum(r => r.Value)) | ||
.Should().BeGreaterThan(0); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Btms.Analytics.Tests/Helpers/SingleSeriesDatasetAssertions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Btms.Common.Extensions; | ||
using FluentAssertions; | ||
using FluentAssertions.Collections; | ||
|
||
namespace Btms.Analytics.Tests.Helpers; | ||
|
||
public class SingleSeriesDatasetAssertions(SingeSeriesDataset? test) | ||
{ | ||
[CustomAssertion] | ||
public void HaveResults(string because = "", params object[] becauseArgs) | ||
{ | ||
test!.Values | ||
.Values.Sum() | ||
.Should().BeGreaterThan(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Btms.Analytics.Tests.Helpers; | ||
|
||
public static class TestAssertionExtensions | ||
{ | ||
public static MultiSeriesDatasetAssertions Should(this List<MultiSeriesDataset>? instance) | ||
{ | ||
return new MultiSeriesDatasetAssertions(instance); | ||
} | ||
public static SingleSeriesDatasetAssertions Should(this SingeSeriesDataset? instance) | ||
{ | ||
return new SingleSeriesDatasetAssertions(instance); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Btms.Analytics.Tests/ImportNotificationsByCommoditiesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Btms.Analytics.Extensions; | ||
using Btms.Common.Extensions; | ||
using FluentAssertions; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Btms.Analytics.Tests.Helpers; | ||
using Btms.Analytics.Tests.Fixtures; | ||
|
||
namespace Btms.Analytics.Tests; | ||
|
||
[Collection(nameof(MultiItemDataTestCollection))] | ||
public class ImportNotificationsByCommoditiesTests( | ||
MultiItemDataTestFixture multiItemDataTestFixture, | ||
ITestOutputHelper testOutputHelper) | ||
{ | ||
|
||
[Fact] | ||
public async Task WhenCalledLastWeek_ReturnExpectedAggregation() | ||
{ | ||
testOutputHelper.WriteLine("Querying for aggregated data"); | ||
var result = (await multiItemDataTestFixture.ImportNotificationsAggregationService | ||
.ByCommodityCount(DateTime.Today.WeekAgo(), DateTime.Today.Tomorrow())) | ||
.ToList();; | ||
|
||
testOutputHelper.WriteLine("{0} aggregated items found", result.Count); | ||
|
||
result.Count().Should().Be(8); | ||
result.Select(r => r.Name).Order().Should().Equal(AnalyticsHelpers.GetImportNotificationSegments().Order()); | ||
|
||
result.Should().AllSatisfy(r => | ||
{ | ||
r.Dimension.Should().Be("ItemCount"); | ||
r.Results.Count().Should().NotBe(0); | ||
}); | ||
|
||
result.Should().HaveResults(); | ||
|
||
result.Should().BeSameLength(); | ||
} | ||
} |
Oops, something went wrong.