Skip to content

Commit a6786e0

Browse files
committed
Adding test
1 parent 60d0781 commit a6786e0

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

src/Particular.LicensingComponent.UnitTests/Infrastructure/DataStoreBuilder.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,33 @@ public DataStoreBuilder WithThroughput(ThroughputSource? source = null, DateOnly
9191
return this;
9292
}
9393

94+
public DataStoreBuilder WithThroughput(ThroughputData throughput)
95+
{
96+
Endpoint endpoint = endpoints.LastOrDefault() ??
97+
throw new InvalidOperationException(
98+
$"Need to add an endpoint before calling {nameof(WithThroughput)}");
99+
100+
var source = endpoint.Id.ThroughputSource;
101+
if (endpoints.SingleOrDefault(e => e.Id.Name == endpoint.Id.Name && e.Id.ThroughputSource == source) == null)
102+
{
103+
throw new InvalidOperationException(
104+
$"Need to add endpoint {endpoint.Id.Name}:{source} before calling {nameof(WithThroughput)}");
105+
}
106+
107+
var idForThroughput = new EndpointIdentifier(endpoint.Id.Name, source);
108+
109+
if (endpointThroughput.TryGetValue(idForThroughput, out List<ThroughputData> throughputList))
110+
{
111+
throughputList.Add(throughput);
112+
}
113+
else
114+
{
115+
endpointThroughput.Add(idForThroughput, [throughput]);
116+
}
117+
118+
return this;
119+
}
120+
94121
public async Task Build()
95122
{
96123
foreach (Endpoint endpoint in endpoints)

src/Particular.LicensingComponent.UnitTests/ThroughputCollector/ThroughputCollector_ThroughputSummary_Tests.cs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
namespace Particular.LicensingComponent.UnitTests;
22

3+
using System;
34
using System.Linq;
5+
using System.Threading;
46
using System.Threading.Tasks;
57
using NUnit.Framework;
68
using Particular.LicensingComponent.Contracts;
@@ -81,7 +83,7 @@ await DataStore.CreateBuilder()
8183
[TestCase(ThroughputSource.Audit)]
8284
[TestCase(ThroughputSource.Broker)]
8385
[TestCase(ThroughputSource.Monitoring)]
84-
public async Task Should_return_correct_max_throughput_in_summary_when_data_only_from_one_source(ThroughputSource source)
86+
public async Task Should_return_correct_max_daily_throughput_in_summary_when_data_only_from_one_source(ThroughputSource source)
8587
{
8688
// Arrange
8789
await DataStore.CreateBuilder()
@@ -106,7 +108,7 @@ await DataStore.CreateBuilder()
106108
}
107109

108110
[Test]
109-
public async Task Should_return_correct_max_throughput_in_summary_when_multiple_sources()
111+
public async Task Should_return_correct_max_daily_throughput_in_summary_when_multiple_sources()
110112
{
111113
// Arrange
112114
await DataStore.CreateBuilder()
@@ -138,7 +140,44 @@ await DataStore.CreateBuilder()
138140
}
139141

140142
[Test]
141-
public async Task Should_return_correct_max_throughput_in_summary_when_endpoint_has_no_throughput()
143+
public async Task Should_return_correct_max_monthly_throughput_in_summary_when_multiple_sources()
144+
{
145+
// Arrange
146+
await DataStore.CreateBuilder()
147+
.AddEndpoint("Endpoint1", sources: [ThroughputSource.Broker])
148+
.WithThroughput(new ThroughputData([
149+
new EndpointDailyThroughput(new DateOnly(2025, 1, 10), 50),
150+
new EndpointDailyThroughput(new DateOnly(2025, 1, 15), 50),
151+
new EndpointDailyThroughput(new DateOnly(2025, 1, 16), 150),
152+
new EndpointDailyThroughput(new DateOnly(2025, 2, 20), 160),
153+
new EndpointDailyThroughput(new DateOnly(2025, 3, 25), 65),
154+
new EndpointDailyThroughput(new DateOnly(2025, 4, 30), 70),
155+
new EndpointDailyThroughput(new DateOnly(2025, 5, 1), 75)]))
156+
.AddEndpoint("Endpoint2", sources: [ThroughputSource.Broker])
157+
.WithThroughput(new ThroughputData([
158+
new EndpointDailyThroughput(new DateOnly(2025, 1, 10), 60),
159+
new EndpointDailyThroughput(new DateOnly(2025, 1, 15), 65),
160+
new EndpointDailyThroughput(new DateOnly(2025, 5, 20), 165),
161+
new EndpointDailyThroughput(new DateOnly(2025, 3, 25), 65),
162+
new EndpointDailyThroughput(new DateOnly(2025, 9, 30), 70)]))
163+
.Build();
164+
165+
// Act
166+
var summary = await ThroughputCollector.GetThroughputSummary(CancellationToken.None);
167+
168+
// Assert
169+
Assert.That(summary, Is.Not.Null);
170+
Assert.That(summary, Has.Count.EqualTo(2));
171+
172+
Assert.Multiple(() =>
173+
{
174+
Assert.That(summary.First(w => w.Name == "Endpoint1").MaxMonthlyThroughput, Is.EqualTo(250), $"Incorrect MaxDailyThroughput recorded for Endpoint1");
175+
Assert.That(summary.First(w => w.Name == "Endpoint2").MaxMonthlyThroughput, Is.EqualTo(165), $"Incorrect MaxDailyThroughput recorded for Endpoint2");
176+
});
177+
}
178+
179+
[Test]
180+
public async Task Should_return_correct_max_daily_throughput_in_summary_when_endpoint_has_no_throughput()
142181
{
143182
// Arrange
144183
await DataStore.CreateBuilder().AddEndpoint().Build();
@@ -153,7 +192,7 @@ public async Task Should_return_correct_max_throughput_in_summary_when_endpoint_
153192
}
154193

155194
[Test]
156-
public async Task Should_return_correct_max_throughput_in_summary_when_data_from_multiple_sources_and_name_is_different()
195+
public async Task Should_return_correct_max_daily_throughput_in_summary_when_data_from_multiple_sources_and_name_is_different()
157196
{
158197
// Arrange
159198
await DataStore.CreateBuilder()

0 commit comments

Comments
 (0)