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
6 changes: 4 additions & 2 deletions CallbackHander.Testing/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

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

public static String Reference = "TestRef";
public static String Reference = "640E863C23E244BDB9717C92733FFD4C-9D20A3961CF645EDAA7BDD436318BA29";
public static Guid EstateReference = Guid.Parse("640E863C-23E2-44BD-B971-7C92733FFD4C");

Check warning on line 23 in CallbackHander.Testing/TestData.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

CallbackHander.Testing/TestData.cs#L23

Change the visibility of 'EstateReference' or make it 'const' or 'readonly'.

Check warning on line 23 in CallbackHander.Testing/TestData.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

CallbackHander.Testing/TestData.cs#L23

Make this field 'private' and encapsulate it in a 'public' property.
public static Guid MerchantReference = Guid.Parse("9D20A396-1CF6-45ED-AA7B-DD436318BA29");

Check warning on line 24 in CallbackHander.Testing/TestData.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

CallbackHander.Testing/TestData.cs#L24

Change the visibility of 'MerchantReference' or make it 'const' or 'readonly'.

Check warning on line 24 in CallbackHander.Testing/TestData.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

CallbackHander.Testing/TestData.cs#L24

Make this field 'private' and encapsulate it in a 'public' property.

public static CallbackCommands.RecordCallbackRequest RecordCallbackRequest =>
new CallbackCommands.RecordCallbackRequest(TestData.CallbackId,
Expand All @@ -41,7 +43,7 @@
{
CallbackMessageAggregate aggregate = new CallbackMessageAggregate();
aggregate.RecordCallback(TestData.CallbackId, TestData.TypeString, (MessageFormat)TestData.MessageFormat,
TestData.CallbackMessage, TestData.Reference, TestData.Destinations);
TestData.CallbackMessage, TestData.Reference, TestData.Destinations, EstateReference, MerchantReference);

return aggregate;
}
Expand Down
18 changes: 16 additions & 2 deletions CallbackHandler.BusinessLogic/Services/CallbackDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,26 @@ public async Task<Result> RecordCallback(Guid callbackId,
String reference,
String[] destinations,
CancellationToken cancellationToken) {
var getResult = await this.AggregateRepository.GetLatestVersion(callbackId, cancellationToken);

// split the reference string into an array of strings
String[] referenceData = reference?.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
if (referenceData.Length == 0)
{
return Result.Failure("Reference cannot be empty.");
}
// Element 0 is estate reference, Element 1 is merchant reference
String estateReference = referenceData[0];
String merchantReference = referenceData[1];

// TODO: Validate the reference data

Result<CallbackMessageAggregate> getResult = await this.AggregateRepository.GetLatestVersion(callbackId, cancellationToken);
Result<CallbackMessageAggregate> callbackMessageAggregateResult =
DomainServiceHelper.HandleGetAggregateResult(getResult, callbackId, false);

CallbackMessageAggregate aggregate = callbackMessageAggregateResult.Data;
aggregate.RecordCallback(callbackId, typeString, messageFormat, callbackMessage, reference, destinations);
aggregate.RecordCallback(callbackId, typeString, messageFormat, callbackMessage, reference, destinations,
Guid.Parse(estateReference), Guid.Parse(merchantReference));

return await this.AggregateRepository.SaveChanges(aggregate, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,12 @@
using System;
using Shared.DomainDrivenDesign.EventSourcing;

public record CallbackReceivedEvent : DomainEvent
{
public CallbackReceivedEvent(Guid aggregateId, String typeString,
Int32 messageFormat,
String callbackMessage,
String reference,
String destination) : base(aggregateId, Guid.NewGuid())
{
this.TypeString = typeString;
this.MessageFormat = messageFormat;
this.CallbackMessage = callbackMessage;
this.Destination = destination;
this.Reference = reference;
}

public String TypeString { get; init; }
public Int32 MessageFormat { get; init; }
public String CallbackMessage { get; init; }

public String Reference { get; init; }

public String Destination { get; init; }
}
public record CallbackReceivedEvent(Guid AggregateId,
String TypeString,
Int32 MessageFormat,
String CallbackMessage,
String Reference,
String Destination,
Guid EstateId,
Guid MerchantId) : DomainEvent(AggregateId, Guid.NewGuid());
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public void CallbackMessageAggregate_RecordCallback_CallbackIsRecorded()
{
CallbackMessageAggregate aggregate = new CallbackMessageAggregate();

aggregate.RecordCallback(TestData.CallbackId, TestData.TypeString, MessageFormat.JSON, TestData.CallbackMessage, TestData.Reference, TestData.Destinations);
aggregate.RecordCallback(TestData.CallbackId, TestData.TypeString, MessageFormat.JSON, TestData.CallbackMessage, TestData.Reference, TestData.Destinations,
TestData.EstateReference, TestData.MerchantReference);

aggregate.ShouldSatisfyAllConditions(() => aggregate.CallbackMessage.ShouldBe(TestData.CallbackMessage),
() => aggregate.TypeString.ShouldBe(TestData.TypeString),
Expand Down
25 changes: 0 additions & 25 deletions CallbackHandler.CallbackMessageAggregate.Tests/DomainEventTests.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ public static void RecordCallback(this CallbackMessageAggregate aggregate,
MessageFormat messageFormat,
String callbackMessage,
String reference,
String[] destinations)
String[] destinations,
Guid estateId,Guid merchantId)
{
foreach (String destination in destinations)
{
DomainEvent callbackReceivedEvent = CreateCallbackReceivedEvent(aggregate,aggregateId, typeString,
messageFormat, callbackMessage, reference, destination);
messageFormat, callbackMessage, reference, destination,
estateId, merchantId);

aggregate.ApplyAndAppend(callbackReceivedEvent);
}
Expand All @@ -72,12 +74,13 @@ internal static DomainEvent CreateCallbackReceivedEvent(this CallbackMessageAggr
MessageFormat messageFormat,
String callbackMessage,
String reference,
String destination)
String destination,
Guid estateId, Guid merchantId)
{
return new CallbackReceivedEvent(aggregateId, typeString, (Int32) messageFormat,
callbackMessage,
reference,
destination);
destination, estateId, merchantId);
}

public static String[] GetDestinations(this CallbackMessageAggregate aggregate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Feature: BankDepositCallback
Scenario: Process a Bank Deposit Callback
Given I have the following Bank Deposit Callbacks
| Amount | DateTime | DepositId | HostIdentifier | Reference | SortCode | AccountNumber |
| 100.00 | Today | 6AE04AFC-D7F8-4936-A3A2-DCA177CAA106 | DC4A7DDA-45A1-4D5B-8D46-21FA99A3868E | Deposit1 | 11-22-33 | 12345678 |
| 100.00 | Today | 6AE04AFC-D7F8-4936-A3A2-DCA177CAA106 | DC4A7DDA-45A1-4D5B-8D46-21FA99A3868E | DC4A7DDA45A14D5B8D4621FA99A3868E-6AE04AFCD7F84936A3A2DCA177CAA106 | 11-22-33 | 12345678 |
When I send the requests to the callback handler for deposits
Then the deposit records are recorded

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CallbackHandler.Tests/CallbackHandler.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Lamar" Version="15.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="Moq" Version="4.20.72" />
Expand Down
Loading