-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e459a9
commit 31c7ce8
Showing
173 changed files
with
2,428 additions
and
573 deletions.
There are no files selected for viewing
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
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
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,15 @@ | ||
using Application.Interfaces; | ||
using Common; | ||
|
||
namespace AncillaryApplication; | ||
|
||
public interface IRecordingApplication | ||
{ | ||
Task<Result<Error>> RecordMeasurementAsync(ICallerContext context, string eventName, | ||
Dictionary<string, object?>? additional, | ||
CancellationToken cancellationToken); | ||
|
||
Task<Result<Error>> RecordUsageAsync(ICallerContext context, string eventName, | ||
Dictionary<string, object?>? additional, | ||
CancellationToken cancellationToken); | ||
} |
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,43 @@ | ||
using Application.Common; | ||
using Application.Interfaces; | ||
using Common; | ||
using Common.Extensions; | ||
using Task = System.Threading.Tasks.Task; | ||
|
||
namespace AncillaryApplication; | ||
|
||
public class RecordingApplication : IRecordingApplication | ||
{ | ||
private readonly IRecorder _recorder; | ||
|
||
public RecordingApplication(IRecorder recorder) | ||
{ | ||
_recorder = recorder; | ||
} | ||
|
||
public Task<Result<Error>> RecordMeasurementAsync(ICallerContext context, string eventName, | ||
Dictionary<string, object?>? additional, | ||
CancellationToken cancellationToken) | ||
{ | ||
_recorder.Measure(context.ToCall(), eventName, (additional.Exists() | ||
? additional | ||
.Where(pair => pair.Value.Exists()) | ||
.ToDictionary(pair => pair.Key, pair => pair.Value) | ||
: null)!); | ||
|
||
return Task.FromResult(Result.Ok); | ||
} | ||
|
||
public Task<Result<Error>> RecordUsageAsync(ICallerContext context, string eventName, | ||
Dictionary<string, object?>? additional, | ||
CancellationToken cancellationToken) | ||
{ | ||
_recorder.TrackUsage(context.ToCall(), eventName, (additional.Exists() | ||
? additional | ||
.Where(pair => pair.Value.Exists()) | ||
.ToDictionary(pair => pair.Key, pair => pair.Value) | ||
: null)!); | ||
|
||
return Task.FromResult(Result.Ok); | ||
} | ||
} |
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,11 @@ | ||
using Domain.Interfaces.Validations; | ||
|
||
namespace AncillaryDomain; | ||
|
||
public static class Validations | ||
{ | ||
public static class Recording | ||
{ | ||
public static readonly Validation AdditionalStringValue = CommonValidations.DescriptiveName(1, 300); | ||
} | ||
} |
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
89 changes: 89 additions & 0 deletions
89
src/AncillaryInfrastructure.IntegrationTests/RecordingApiSpec.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,89 @@ | ||
using System.Text.Json; | ||
using AncillaryInfrastructure.IntegrationTests.Stubs; | ||
using ApiHost1; | ||
using Common; | ||
using FluentAssertions; | ||
using Infrastructure.Web.Api.Common.Extensions; | ||
using Infrastructure.Web.Api.Operations.Shared.Ancillary; | ||
using IntegrationTesting.WebApi.Common; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
using Task = System.Threading.Tasks.Task; | ||
|
||
namespace AncillaryInfrastructure.IntegrationTests; | ||
|
||
[Trait("Category", "Integration.Web")] | ||
public class RecordingApiSpec : WebApiSpec<Program> | ||
{ | ||
private readonly StubRecorder _recorder; | ||
|
||
public RecordingApiSpec(WebApiSetup<Program> setup) : base(setup, OverrideDependencies) | ||
{ | ||
EmptyAllRepositories(setup); | ||
_recorder = setup.GetRequiredService<IRecorder>().As<StubRecorder>(); | ||
_recorder.Reset(); | ||
} | ||
|
||
[Fact] | ||
public async Task WhenRecordUseWithNoAdditional_ThenRecords() | ||
{ | ||
var request = new RecordUseRequest | ||
{ | ||
EventName = "aneventname", | ||
Additional = null | ||
}; | ||
await Api.PostAsync(request, req => req.SetHmacAuth(request, "asecret")); | ||
|
||
_recorder.LastUsageEventName.Should().Be("aneventname"); | ||
_recorder.LastUsageAdditional.Should().BeNull(); | ||
} | ||
|
||
[Fact] | ||
public async Task WhenRecordUse_ThenRecords() | ||
{ | ||
var request = new RecordUseRequest | ||
{ | ||
EventName = "aneventname", | ||
Additional = new Dictionary<string, object?> | ||
{ | ||
{ "aname1", "avalue" }, | ||
{ "aname2", 25 }, | ||
{ "aname3", true } | ||
} | ||
}; | ||
await Api.PostAsync(request, req => req.SetHmacAuth(request, "asecret")); | ||
|
||
_recorder.LastUsageEventName.Should().Be("aneventname"); | ||
_recorder.LastUsageAdditional!.Count.Should().Be(3); | ||
_recorder.LastUsageAdditional!["aname1"].As<JsonElement>().GetString().Should().Be("avalue"); | ||
_recorder.LastUsageAdditional!["aname2"].As<JsonElement>().GetInt32().Should().Be(25); | ||
_recorder.LastUsageAdditional!["aname3"].As<JsonElement>().GetBoolean().Should().Be(true); | ||
} | ||
|
||
[Fact] | ||
public async Task WhenRecordMeasure_ThenRecords() | ||
{ | ||
var request = new RecordMeasureRequest | ||
{ | ||
EventName = "aneventname", | ||
Additional = new Dictionary<string, object?> | ||
{ | ||
{ "aname1", "avalue" }, | ||
{ "aname2", 25 }, | ||
{ "aname3", true } | ||
} | ||
}; | ||
await Api.PostAsync(request, req => req.SetHmacAuth(request, "asecret")); | ||
|
||
_recorder.LastMeasureEventName.Should().Be("aneventname"); | ||
_recorder.LastMeasureAdditional!.Count.Should().Be(3); | ||
_recorder.LastMeasureAdditional!["aname1"].As<JsonElement>().GetString().Should().Be("avalue"); | ||
_recorder.LastMeasureAdditional!["aname2"].As<JsonElement>().GetInt32().Should().Be(25); | ||
_recorder.LastMeasureAdditional!["aname3"].As<JsonElement>().GetBoolean().Should().Be(true); | ||
} | ||
|
||
private static void OverrideDependencies(IServiceCollection services) | ||
{ | ||
services.AddSingleton<IRecorder, StubRecorder>(); | ||
} | ||
} |
Oops, something went wrong.