-
-
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 3019d51
Showing
216 changed files
with
3,753 additions
and
653 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
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="AllHosts" type="CompoundRunConfigurationType"> | ||
<toRun name="ApiHost1: ApiHost1-Development" type="LaunchSettings" /> | ||
<toRun name="TestingStubApiHost: TestingStubApiHost-Development" type="LaunchSettings" /> | ||
<method v="2" /> | ||
</configuration> | ||
<configuration default="false" name="AllHosts" type="CompoundRunConfigurationType"> | ||
<toRun name="ApiHost1: ApiHost1-Development" type="LaunchSettings" /> | ||
<toRun name="TestingStubApiHost: TestingStubApiHost-Development" type="LaunchSettings" /> | ||
<toRun name="WebsiteHost: WebsiteHost-Development" type="LaunchSettings" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
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,5 @@ | ||
namespace AncillaryDomain; | ||
|
||
public static class Validations | ||
{ | ||
} |
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 ApiHost1; | ||
using Common; | ||
using FluentAssertions; | ||
using Infrastructure.Web.Api.Common.Extensions; | ||
using Infrastructure.Web.Api.Operations.Shared.Ancillary; | ||
using IntegrationTesting.WebApi.Common; | ||
using IntegrationTesting.WebApi.Common.Stubs; | ||
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>(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/AncillaryInfrastructure.IntegrationTests/Stubs/StubUsageReportingService.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
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
Oops, something went wrong.