Skip to content

Commit

Permalink
refactor: replaced ICommands with MediatR.NET
Browse files Browse the repository at this point in the history
moved command used classes in Shared namespace
  • Loading branch information
ericbrunner committed Nov 11, 2024
1 parent a018859 commit 652d8ea
Show file tree
Hide file tree
Showing 43 changed files with 210 additions and 215 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.Tests.Base;

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
global using static Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Constants.Resources;
global using static Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Constants.Resources;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.Tests.Base;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Readers;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Readers;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.Tests.Readers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.Tests.Base;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Readers;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Readers;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.Tests.Readers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Backbone.ConsumerApi.Sdk;
using Backbone.ConsumerApi.Sdk.Authentication;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;
using Backbone.Tooling;
using MediatR;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create.Mediator;
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create;

public record AddDevices
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Backbone.ConsumerApi.Sdk;
using Backbone.ConsumerApi.Sdk.Authentication;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;
using MediatR;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create.Mediator;
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create;

public record CreateChallenges
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Backbone.ConsumerApi.Sdk;
using Backbone.ConsumerApi.Sdk.Authentication;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;
using Backbone.Tooling;
using MediatR;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create.Mediator;
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create;

public record CreateIdentities
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Backbone.ConsumerApi.Sdk;
using Backbone.ConsumerApi.Sdk.Authentication;
using Backbone.ConsumerApi.Sdk.Endpoints.RelationshipTemplates.Types.Requests;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;
using Backbone.Tooling.Extensions;
using MediatR;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create.Mediator;
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create;

public record CreateRelationshipTemplates
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Backbone.ConsumerApi.Sdk;
using Backbone.ConsumerApi.Sdk.Authentication;
using Backbone.ConsumerApi.Sdk.Endpoints.Relationships.Types.Requests;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Enums;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Enums;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;
using MediatR;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create.Mediator;
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create;

public record CreateRelationships
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using Backbone.ConsumerApi.Sdk.Authentication;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Interfaces;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Create;

public record CreateSnapshot
{
public record Command(
string BaseAddress,
string ClientId,
string ClientSecret,
string JsonFilePath) : IRequest<StatusMessage>;

public record CommandHandler(
ILogger<CommandHandler> Logger,
IPerformanceTestConfigurationJsonReader PerformanceTestConfigurationJsonReader,
IMediator Mediator)
: IRequestHandler<Command, StatusMessage>
{
public async Task<StatusMessage> Handle(Command request, CancellationToken cancellationToken)
{
try
{
Logger.LogInformation("Creating pool configuration with relationships and messages ...");

var poolConfig = await PerformanceTestConfigurationJsonReader.Read(request.JsonFilePath);
var clientCredentials = new ClientCredentials(request.ClientId, request.ClientSecret);

var identities = await Mediator.Send(new CreateIdentities.Command(poolConfig.IdentityPoolConfigurations, request.BaseAddress, clientCredentials), cancellationToken);
Logger.LogInformation("Identities created");

identities = await Mediator.Send(new AddDevices.Command(identities, request.BaseAddress, clientCredentials), cancellationToken);
Logger.LogInformation("Devices added");

identities = await Mediator.Send(new CreateRelationshipTemplates.Command(identities, request.BaseAddress, clientCredentials), cancellationToken);
Logger.LogInformation("Relationship templates created");

identities = await Mediator.Send(new CreateRelationships.Command(poolConfig.RelationshipAndMessages, identities, request.BaseAddress, clientCredentials), cancellationToken);
Logger.LogInformation("Relationships created");

identities = await Mediator.Send(new CreateChallenges.Command(identities, request.BaseAddress, clientCredentials), cancellationToken);

// Create Messages

// Create DatawalletModifications


Logger.LogInformation("Pool configuration with relationships and messages created successfully.");
}
catch (Exception e)
{
return new StatusMessage(false, e.Message);
}


return new StatusMessage(true, "Pool configuration with relationships and messages created successfully.");
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Interfaces;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;
using MediatR;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Generate;

public record GenerateConfig
{
public record Command(string ExcelFilePath, string WorkSheetName) : IRequest<StatusMessage>;

public class CommandHandler(
IPerformanceTestConfigurationExcelReader performanceTestConfigurationExcelReader,
IRelationshipAndMessagesGenerator relationshipAndMessagesGenerator,
IPoolConfigurationJsonWriter poolConfigurationJsonWriter)
: IRequestHandler<Command, StatusMessage>
{
public async Task<StatusMessage> Handle(Command request, CancellationToken cancellationToken)
{
StatusMessage result;
try
{
var poolConfigFromExcel = await performanceTestConfigurationExcelReader.Read(request.ExcelFilePath, request.WorkSheetName);

var relationshipAndMessages = relationshipAndMessagesGenerator.Generate(poolConfigFromExcel);

poolConfigFromExcel.RelationshipAndMessages.Clear();
poolConfigFromExcel.RelationshipAndMessages.AddRange(relationshipAndMessages);

var path = Path.GetDirectoryName(request.ExcelFilePath);

var snapshotFolder = Path.Combine(path!, $"{DateTime.Now:yyyyMMddHHmmss}-snapshot-{request.WorkSheetName}");

if (Directory.Exists(snapshotFolder))
{
Directory.Delete(snapshotFolder, true);
}

Directory.CreateDirectory(snapshotFolder);

var poolConfigJsonFilePath = Path.Combine(snapshotFolder!, $"{POOL_CONFIG_JSON_WITH_RELATIONSHIP_AND_MESSAGES}.{request.WorkSheetName}.{JSON_FILE_EXT}");
result = await poolConfigurationJsonWriter.Write(poolConfigFromExcel, poolConfigJsonFilePath);
}
catch (Exception e)
{
return new StatusMessage(false, e.Message);
}

return result;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Generate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Generate;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Text.Json;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Generate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Enums;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Enums;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Generate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Constants;
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Constants;

public static class Resources
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Enums;
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Enums;

public enum IdentityPoolType
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Interfaces;
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Interfaces;

public interface IPerformanceTestConfigurationExcelReader
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Interfaces;
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Interfaces;

public interface IPerformanceTestConfigurationJsonReader
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Backbone.ConsumerApi.Sdk.Authentication;
using Backbone.ConsumerApi.Sdk.Endpoints.Challenges.Types;
using Backbone.ConsumerApi.Sdk.Endpoints.RelationshipTemplates.Types.Responses;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Enums;
using Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Enums;

namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Models;
namespace Backbone.ConsumerApi.Tests.Performance.SnapshotCreator.V2.Features.Shared.Models;

public record DomainIdentity(
UserCredentials UserCredentials,
Expand Down
Loading

0 comments on commit 652d8ea

Please sign in to comment.