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
27 changes: 1 addition & 26 deletions .github/workflows/nightlybuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,14 @@ on:
- cron: "10 23 * * *"
repository_dispatch:

jobs:
check:
runs-on: ubuntu-latest
name: Check latest commit
outputs:
commitcount: ${{ steps.commitswithintime.outputs.number-of-commits-within-time }}
steps:
- uses: actions/checkout@v2
#with:
#fetch-depth: 0

- name: Check for commits within time
uses: TransactionProcessing/CommitsWithinTime@1.0.0
id: commitswithintime
with:
hours: 24

- name: Get the output from CommitsWithinTime
run: |
echo "The 'has-new-commits-within-time' value is ${{ steps.commitswithintime.outputs.has-new-commits-within-time }}"
echo "The 'number-of-commits-within-time' value is ${{ steps.commitswithintime.outputs.number-of-commits-within-time }}"
echo "The 'total-commits' value is ${{ steps.commitswithintime.outputs.total-commits }}"

jobs:
build:
name: "Nightly Build"
env:
ASPNETCORE_ENVIRONMENT: "Production"

runs-on: ubuntu-latest

needs: check
if: ${{ needs.check.outputs.commitcount > 0 }}

steps:
- uses: actions/checkout@v2.3.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using EstateManagement.DataTransferObjects;
using EstateManagement.DataTransferObjects.Responses;
using EventHandling;
using FloatAggregate;
using MessagingService.Client;
using MessagingService.DataTransferObjects;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -45,12 +46,15 @@ public class TransactionDomainEventHandlerTests

private Mock<IMessagingServiceClient> MessagingServiceClient;

private Mock<IAggregateRepository<FloatAggregate, DomainEvent>> FloatAggregateRepository;

private TransactionDomainEventHandler TransactionDomainEventHandler;

public TransactionDomainEventHandlerTests()
{
this.SettlementAggregateRepository = new Mock<IAggregateRepository<SettlementAggregate, DomainEvent>>();
this.TransactionAggregateRepository = new Mock<IAggregateRepository<TransactionAggregate, DomainEvent>>();
this.FloatAggregateRepository = new Mock<IAggregateRepository<FloatAggregate, DomainEvent>>();
this.FeeCalculationManager = new Mock<IFeeCalculationManager>();
this.EstateClient = new Mock<IEstateClient>();
this.SecurityServiceClient = new Mock<ISecurityServiceClient>();
Expand All @@ -62,12 +66,13 @@ public TransactionDomainEventHandlerTests()
Logger.Initialise(NullLogger.Instance);

this.TransactionDomainEventHandler = new TransactionDomainEventHandler(this.TransactionAggregateRepository.Object,
this.FeeCalculationManager.Object,
this.EstateClient.Object,
this.SecurityServiceClient.Object,
this.TransactionReceiptBuilder.Object,
this.MessagingServiceClient.Object,
this.SettlementAggregateRepository.Object);
this.FeeCalculationManager.Object,
this.EstateClient.Object,
this.SecurityServiceClient.Object,
this.TransactionReceiptBuilder.Object,
this.MessagingServiceClient.Object,
this.SettlementAggregateRepository.Object,
this.FloatAggregateRepository.Object);
}

[Theory]
Expand All @@ -76,6 +81,8 @@ public TransactionDomainEventHandlerTests()
[InlineData(SettlementSchedule.Monthly)]
public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenCompletedEvent_SuccessfulSale_EventIsHandled(SettlementSchedule settlementSchedule)
{
this.FloatAggregateRepository.Setup(f => f.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetFloatAggregateWithCostValues);

TransactionAggregate transactionAggregate = TestData.GetCompletedAuthorisedSaleTransactionAggregate();
this.TransactionAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(transactionAggregate);
Expand Down Expand Up @@ -125,6 +132,8 @@ public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenComplet
[Fact]
public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenCompletedEvent_SuccessfulSale_MerchantWithNotSetSettlementSchedule_ErrorThrown()
{
this.FloatAggregateRepository.Setup(f => f.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetFloatAggregateWithCostValues);

TransactionAggregate transactionAggregate = TestData.GetCompletedAuthorisedSaleTransactionAggregate();
this.TransactionAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(transactionAggregate);
Expand Down Expand Up @@ -158,6 +167,8 @@ public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenComplet
[Fact]
public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenCompletedEvent_UnsuccessfulSale_EventIsHandled()
{
this.FloatAggregateRepository.Setup(f => f.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetFloatAggregateWithCostValues);

this.TransactionAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetCompletedDeclinedSaleTransactionAggregate);

Expand All @@ -167,6 +178,8 @@ public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenComplet
[Fact]
public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenCompletedEvent_IncompleteSale_EventIsHandled()
{
this.FloatAggregateRepository.Setup(f => f.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetFloatAggregateWithCostValues);

this.TransactionAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetIncompleteAuthorisedSaleTransactionAggregate);
await this.TransactionDomainEventHandler.Handle(TestData.TransactionHasBeenCompletedEvent, CancellationToken.None);
Expand All @@ -175,15 +188,18 @@ public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenComplet
[Fact]
public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenCompletedEvent_SaleWithNoProductDetails_EventIsHandled()
{
this.FloatAggregateRepository.Setup(f => f.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetFloatAggregateWithCostValues);

this.TransactionAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetCompletedAuthorisedSaleWithNoProductDetailsTransactionAggregate);

await this.TransactionDomainEventHandler.Handle(TestData.TransactionHasBeenCompletedEvent, CancellationToken.None);
}

[Fact]
public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenCompletedEvent_AuthorisedLogon_EventIsHandled()
{
public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenCompletedEvent_AuthorisedLogon_EventIsHandled(){
this.FloatAggregateRepository.Setup(f => f.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetFloatAggregateWithCostValues);

this.TransactionAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetCompletedAuthorisedLogonTransactionAggregate);

Expand Down Expand Up @@ -213,6 +229,43 @@ public async Task TransactionDomainEventHandler_Handle_CustomerEmailReceiptResen
It.IsAny<CancellationToken>()), Times.Once);
}

[Fact]
public async Task TransactionDomainEventHandler_Handle_TransactionCostInformationRecordedEvent_EventIsHandled(){
this.TransactionAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetCompletedAuthorisedSaleTransactionAggregate);

this.FloatAggregateRepository.Setup(f => f.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetFloatAggregateWithCostValues);

await this.TransactionDomainEventHandler.Handle(TestData.TransactionCostInformationRecordedEvent, CancellationToken.None);

this.FloatAggregateRepository.Verify(f => f.SaveChanges(It.IsAny<FloatAggregate>(), It.IsAny<CancellationToken>()), Times.Once);
}

[Fact]
public async Task TransactionDomainEventHandler_Handle_TransactionCostInformationRecordedEvent_TransactionNotAuthorised_EventIsHandled()
{
this.TransactionAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetCompletedDeclinedSaleTransactionAggregate);

this.FloatAggregateRepository.Setup(f => f.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetFloatAggregateWithCostValues);

await this.TransactionDomainEventHandler.Handle(TestData.TransactionCostInformationRecordedEvent, CancellationToken.None);

this.FloatAggregateRepository.Verify(f => f.SaveChanges(It.IsAny<FloatAggregate>(), It.IsAny<CancellationToken>()), Times.Never);
}

[Fact]
public async Task TransactionDomainEventHandler_Handle_TransactionCostInformationRecordedEvent_TransactionNotCompleted_EventIsHandled()
{
this.TransactionAggregateRepository.Setup(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetIncompleteAuthorisedSaleTransactionAggregate);

this.FloatAggregateRepository.Setup(f => f.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetFloatAggregateWithCostValues);

await this.TransactionDomainEventHandler.Handle(TestData.TransactionCostInformationRecordedEvent, CancellationToken.None);

this.FloatAggregateRepository.Verify(f => f.SaveChanges(It.IsAny<FloatAggregate>(), It.IsAny<CancellationToken>()), Times.Never);
}

//[Fact]
//public async Task TransactionDomainEventHandler_Handle_MerchantFeeAddedToTransactionEvent_EventIsHandled()
Expand Down
93 changes: 2 additions & 91 deletions TransactionProcessor.BusinessLogic/Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace TransactionProcessor.BusinessLogic.Common
{
using Google.Protobuf.WellKnownTypes;
using System.Diagnostics.CodeAnalysis;
using Shared.General;
using Type = System.Type;

public static class Helpers
Expand All @@ -20,97 +21,7 @@ public static Guid CalculateSettlementAggregateId(DateTime settlementDate,
return aggregateId;
}
}

public static class GuidCalculator
{
#region Methods

/// <summary>
/// Combines the specified GUIDs into a new GUID.
/// </summary>
/// <param name="firstGuid">The first unique identifier.</param>
/// <param name="secondGuid">The second unique identifier.</param>
/// <param name="offset">The offset.</param>
/// <returns>Guid.</returns>
public static Guid Combine(Guid firstGuid,
Guid secondGuid,
Byte offset)
{
Byte[] firstAsBytes = firstGuid.ToByteArray();
Byte[] secondAsBytes = secondGuid.ToByteArray();

Byte[] newBytes = new Byte[16];

for (Int32 i = 0; i < 16; i++)
{
// Add and truncate any overflow
newBytes[i] = (Byte)(firstAsBytes[i] + secondAsBytes[i] + offset);
}

return new Guid(newBytes);
}

/// <summary>
/// Combines the specified GUIDs into a new GUID.
/// </summary>
/// <param name="firstGuid">The first unique identifier.</param>
/// <param name="secondGuid">The second unique identifier.</param>
/// <returns>Guid.</returns>
public static Guid Combine(Guid firstGuid,
Guid secondGuid)
{
return GuidCalculator.Combine(firstGuid,
secondGuid,
0);
}

/// <summary>
/// Combines the specified first unique identifier.
/// </summary>
/// <param name="firstGuid">The first unique identifier.</param>
/// <param name="secondGuid">The second unique identifier.</param>
/// <param name="thirdGuid">The third unique identifier.</param>
/// <param name="offset">The offset.</param>
/// <returns>Guid.</returns>
public static Guid Combine(Guid firstGuid,
Guid secondGuid,
Guid thirdGuid,
Byte offset)
{
Byte[] firstAsBytes = firstGuid.ToByteArray();
Byte[] secondAsBytes = secondGuid.ToByteArray();
Byte[] thirdAsBytes = thirdGuid.ToByteArray();

Byte[] newBytes = new Byte[16];

for (Int32 i = 0; i < 16; i++)
{
// Add and truncate any overflow
newBytes[i] = (Byte)(firstAsBytes[i] + secondAsBytes[i] + thirdAsBytes[i] + offset);
}

return new Guid(newBytes);
}

/// <summary>
/// Combines the specified first unique identifier.
/// </summary>
/// <param name="firstGuid">The first unique identifier.</param>
/// <param name="secondGuid">The second unique identifier.</param>
/// <param name="thirdGuid">The third unique identifier.</param>
/// <returns>Guid.</returns>
public static Guid Combine(Guid firstGuid,
Guid secondGuid,
Guid thirdGuid)
{
return GuidCalculator.Combine(firstGuid,
secondGuid,
thirdGuid,
0);
}

#endregion
}

public static class Extensions
{
/// <summary>
Expand Down
Loading