Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions CallbackHander.Testing/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,49 @@
using CallbackHandlers.Models;
using Xunit;

namespace CallbackHander.Testing
{
using CallbackHandler.BusinessLogic.Requests;
using CallbackHandler.CallbackMessageAggregate;
namespace CallbackHander.Testing;

public class TestData
{
public static Guid CallbackId = Guid.Parse("E82DF060-5717-4F79-B99B-E14C702C8F0E");
using CallbackHandler.BusinessLogic.Requests;
using CallbackHandler.CallbackMessageAggregate;

public static Int32 MessageFormat = 1;
public class TestData
{
public static Guid CallbackId = Guid.Parse("E82DF060-5717-4F79-B99B-E14C702C8F0E");

public static String TypeString = "TestTypeString";
public static Int32 MessageFormat = 1;

public static String CallbackMessage = "Callback message";
public static String TypeString = "TestTypeString";

public static String[] Destinations = new[] {"A", "B"};
public static String CallbackMessage = "Callback message";

public static String Reference = "640E863C23E244BDB9717C92733FFD4C-9D20A3961CF645EDAA7BDD436318BA29";
public static Guid EstateReference = Guid.Parse("640E863C-23E2-44BD-B971-7C92733FFD4C");
public static Guid MerchantReference = Guid.Parse("9D20A396-1CF6-45ED-AA7B-DD436318BA29");
public static String[] Destinations = {"A", "B"};

public static CallbackCommands.RecordCallbackRequest RecordCallbackRequest =>
new CallbackCommands.RecordCallbackRequest(TestData.CallbackId,
TestData.CallbackMessage,
TestData.Destinations,
(MessageFormat)TestData.MessageFormat,
TestData.TypeString,
TestData.Reference);
public static String Reference = "640E863C23E244BDB9717C92733FFD4C-9D20A3961CF645EDAA7BDD436318BA29";
public static Guid EstateReference = Guid.Parse("640E863C-23E2-44BD-B971-7C92733FFD4C");
public static Guid MerchantReference = Guid.Parse("9D20A396-1CF6-45ED-AA7B-DD436318BA29");

public static CallbackQueries.GetCallbackQuery GetCallbackQuery =>
new CallbackQueries.GetCallbackQuery(TestData.CallbackId);
public static CallbackCommands.RecordCallbackRequest RecordCallbackRequest =>
new CallbackCommands.RecordCallbackRequest(TestData.CallbackId,
TestData.CallbackMessage,
TestData.Destinations,
(MessageFormat)TestData.MessageFormat,
TestData.TypeString,
TestData.Reference);

public static CallbackMessageAggregate EmptyCallbackMessageAggregate()
{
return new CallbackMessageAggregate();
}
public static CallbackQueries.GetCallbackQuery GetCallbackQuery =>
new CallbackQueries.GetCallbackQuery(TestData.CallbackId);

public static CallbackMessageAggregate RecordedCallbackMessageAggregate()
{
CallbackMessageAggregate aggregate = new();
aggregate.RecordCallback(TestData.CallbackId, TestData.TypeString, (MessageFormat)TestData.MessageFormat,
TestData.CallbackMessage, TestData.Reference, TestData.Destinations, EstateReference, MerchantReference);
public static CallbackMessageAggregate EmptyCallbackMessageAggregate()
{
return new CallbackMessageAggregate();
}

public static CallbackMessageAggregate RecordedCallbackMessageAggregate()
{
CallbackMessageAggregate aggregate = new();
aggregate.RecordCallback(TestData.CallbackId, TestData.TypeString, (MessageFormat)TestData.MessageFormat,
TestData.CallbackMessage, TestData.Reference, TestData.Destinations, EstateReference, MerchantReference);

return aggregate;
}
return aggregate;
}
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
namespace CallbackHandler.BusinessLogic.Common
namespace CallbackHandler.BusinessLogic.Common;

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Shared.DomainDrivenDesign.EventSourcing;

[ExcludeFromCodeCoverage]
public class DomainEventTypesToSilentlyHandle : IDomainEventTypesToSilentlyHandle
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Shared.DomainDrivenDesign.EventSourcing;

[ExcludeFromCodeCoverage]
public class DomainEventTypesToSilentlyHandle : IDomainEventTypesToSilentlyHandle
{
#region Fields
#region Fields

/// <summary>
/// The handler event types to silently handle
/// </summary>
private readonly Dictionary<String, String[]> HandlerEventTypesToSilentlyHandle;
/// <summary>
/// The handler event types to silently handle
/// </summary>
private readonly Dictionary<String, String[]> HandlerEventTypesToSilentlyHandle;

#endregion
#endregion

#region Constructors
#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="DomainEventTypesToSilentlyHandle" /> class.
/// </summary>
/// <param name="handlerEventTypesToSilentlyHandle">The handler event types to silently handle.</param>
public DomainEventTypesToSilentlyHandle(Dictionary<String, String[]> handlerEventTypesToSilentlyHandle)
{
this.HandlerEventTypesToSilentlyHandle = handlerEventTypesToSilentlyHandle;
}
/// <summary>
/// Initializes a new instance of the <see cref="DomainEventTypesToSilentlyHandle" /> class.
/// </summary>
/// <param name="handlerEventTypesToSilentlyHandle">The handler event types to silently handle.</param>
public DomainEventTypesToSilentlyHandle(Dictionary<String, String[]> handlerEventTypesToSilentlyHandle)
{
this.HandlerEventTypesToSilentlyHandle = handlerEventTypesToSilentlyHandle;
}

#endregion
#endregion

#region Methods
#region Methods

/// <summary>
/// Handles the silently.
/// </summary>
/// <param name="handlerName">Name of the handler.</param>
/// <param name="domainEvent">The domain event.</param>
/// <returns></returns>
public Boolean HandleSilently(String handlerName,
DomainEvent domainEvent)
/// <summary>
/// Handles the silently.
/// </summary>
/// <param name="handlerName">Name of the handler.</param>
/// <param name="domainEvent">The domain event.</param>
/// <returns></returns>
public Boolean HandleSilently(String handlerName,
DomainEvent domainEvent)
{
if (this.HandlerEventTypesToSilentlyHandle.TryGetValue(handlerName, out var eventTypes)
&& eventTypes.Contains(domainEvent.GetType().FullName))
{
if (this.HandlerEventTypesToSilentlyHandle.TryGetValue(handlerName, out var eventTypes)
&& eventTypes.Contains(domainEvent.GetType().FullName))
{
return true;
}
return true;
}

return false;
return false;
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
namespace CallbackHandler.BusinessLogic.Common
{
using System;
using Shared.DomainDrivenDesign.EventSourcing;
namespace CallbackHandler.BusinessLogic.Common;

using System;
using Shared.DomainDrivenDesign.EventSourcing;

public interface IDomainEventTypesToSilentlyHandle
{
#region Methods
public interface IDomainEventTypesToSilentlyHandle
{
#region Methods

/// <summary>
/// Handles the silently.
/// </summary>
/// <param name="handlerName">Name of the handler.</param>
/// <param name="domainEvent">The domain event.</param>
/// <returns></returns>
Boolean HandleSilently(String handlerName,
DomainEvent domainEvent);
/// <summary>
/// Handles the silently.
/// </summary>
/// <param name="handlerName">Name of the handler.</param>
/// <param name="domainEvent">The domain event.</param>
/// <returns></returns>
Boolean HandleSilently(String handlerName,
DomainEvent domainEvent);

#endregion
}
#endregion
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
using Shared.Results;
using SimpleResults;

namespace CallbackHandler.BusinessLogic.RequestHandler
namespace CallbackHandler.BusinessLogic.RequestHandler;

using System.Threading;
using System.Threading.Tasks;
using CallbackHandler.BusinessLogic.Services;
using CallbackMessageAggregate;
using MediatR;
using Requests;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;

public class CallbackHandlerRequestHandler : IRequestHandler<CallbackCommands.RecordCallbackRequest, Result>,
IRequestHandler<CallbackQueries.GetCallbackQuery, Result<CallbackHandlers.Models.CallbackMessage>>
{
using System.Threading;
using System.Threading.Tasks;
using CallbackHandler.BusinessLogic.Services;
using CallbackMessageAggregate;
using MediatR;
using Requests;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;

public class CallbackHandlerRequestHandler : IRequestHandler<CallbackCommands.RecordCallbackRequest, Result>,
IRequestHandler<CallbackQueries.GetCallbackQuery, Result<CallbackHandlers.Models.CallbackMessage>>
private readonly ICallbackDomainService CallbackDomainService;
private readonly IAggregateRepository<CallbackMessageAggregate, DomainEvent> CallbackAggregateRepository;

public CallbackHandlerRequestHandler(ICallbackDomainService callbackDomainService,
IAggregateRepository<CallbackMessageAggregate, DomainEvent> callbackAggregateRepository)
{
this.CallbackDomainService = callbackDomainService;
CallbackAggregateRepository = callbackAggregateRepository;
}

public async Task<Result> Handle(CallbackCommands.RecordCallbackRequest request,
CancellationToken cancellationToken) {

return await this.CallbackDomainService.RecordCallback(request.CallbackId,
request.TypeString,
request.MessageFormat,
request.CallbackMessage,
request.Reference,
request.Destinations,
cancellationToken);
}

public async Task<Result<CallbackHandlers.Models.CallbackMessage>> Handle(CallbackQueries.GetCallbackQuery request, CancellationToken cancellationToken)
{
private readonly ICallbackDomainService CallbackDomainService;
private readonly IAggregateRepository<CallbackMessageAggregate, DomainEvent> CallbackAggregateRepository;

public CallbackHandlerRequestHandler(ICallbackDomainService callbackDomainService,
IAggregateRepository<CallbackMessageAggregate, DomainEvent> callbackAggregateRepository)
{
this.CallbackDomainService = callbackDomainService;
CallbackAggregateRepository = callbackAggregateRepository;
}

public async Task<Result> Handle(CallbackCommands.RecordCallbackRequest request,
CancellationToken cancellationToken) {

return await this.CallbackDomainService.RecordCallback(request.CallbackId,
request.TypeString,
request.MessageFormat,
request.CallbackMessage,
request.Reference,
request.Destinations,
cancellationToken);
}

public async Task<Result<CallbackHandlers.Models.CallbackMessage>> Handle(CallbackQueries.GetCallbackQuery request, CancellationToken cancellationToken)
{
Result<CallbackMessageAggregate> callbackAggregate =
await this.CallbackAggregateRepository.GetLatestVersion(request.CallbackId, cancellationToken);
if (callbackAggregate.IsFailed)
return ResultHelpers.CreateFailure(callbackAggregate);

return Result.Success(callbackAggregate.Data.GetCallbackMessage());
}
Result<CallbackMessageAggregate> callbackAggregate =
await this.CallbackAggregateRepository.GetLatestVersion(request.CallbackId, cancellationToken);
if (callbackAggregate.IsFailed)
return ResultHelpers.CreateFailure(callbackAggregate);

return Result.Success(callbackAggregate.Data.GetCallbackMessage());
}
}
21 changes: 10 additions & 11 deletions CallbackHandler.BusinessLogic/Services/ICallbackDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
using System.Threading.Tasks;
using SimpleResults;

namespace CallbackHandler.BusinessLogic.Services
namespace CallbackHandler.BusinessLogic.Services;

public interface ICallbackDomainService
{
public interface ICallbackDomainService
{
Task<Result> RecordCallback(Guid callbackId,
String typeString,
MessageFormat messageFormat,
String callbackMessage,
String reference,
String[] destinations,
CancellationToken cancellationToken);
}
Task<Result> RecordCallback(Guid callbackId,
String typeString,
MessageFormat messageFormat,
String callbackMessage,
String reference,
String[] destinations,
CancellationToken cancellationToken);
}
Loading
Loading