diff --git a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/DomainEventHandlerResolverTests.cs b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/DomainEventHandlerResolverTests.cs index 488ea0fe..81bc95e9 100644 --- a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/DomainEventHandlerResolverTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/DomainEventHandlerResolverTests.cs @@ -3,8 +3,8 @@ using System; using System.Collections.Generic; using System.Linq; - using MessagingService.BusinessLogic.EventHandling; using Moq; + using Shared.EventStore.EventHandling; using Shouldly; using Testing; using Transaction.DomainEvents; @@ -17,7 +17,7 @@ public void DomainEventHandlerResolver_CanBeCreated_IsCreated() { Dictionary eventHandlerConfiguration = new Dictionary(); - eventHandlerConfiguration.Add("TestEventType1", new String[] { "TransactionProcessor.BusinessLogic.EventHandling.TransactionDomainEventHandler" }); + eventHandlerConfiguration.Add("TestEventType1", new String[] { "TransactionProcessor.BusinessLogic.EventHandling.TransactionDomainEventHandler, TransactionProcessor.BusinessLogic" }); Mock domainEventHandler = new Mock(); Func createDomainEventHandlerFunc = (type) => { return domainEventHandler.Object; }; @@ -31,7 +31,7 @@ public void DomainEventHandlerResolver_CanBeCreated_InvalidEventHandlerType_Erro { Dictionary eventHandlerConfiguration = new Dictionary(); - eventHandlerConfiguration.Add("TestEventType1", new String[] { "TransactionProcessor.BusinessLogic.EventHandling.NonExistantDomainEventHandler" }); + eventHandlerConfiguration.Add("TestEventType1", new String[] { "TransactionProcessor.BusinessLogic.EventHandling.NonExistantDomainEventHandler, TransactionProcessor.BusinessLogic" }); Mock domainEventHandler = new Mock(); Func createDomainEventHandlerFunc = (type) => { return domainEventHandler.Object; }; @@ -42,12 +42,12 @@ public void DomainEventHandlerResolver_CanBeCreated_InvalidEventHandlerType_Erro [Fact] public void DomainEventHandlerResolver_GetDomainEventHandlers_TransactionHasBeenCompletedEvent_EventHandlersReturned() { - String handlerTypeName = "TransactionProcessor.BusinessLogic.EventHandling.TransactionDomainEventHandler"; + String handlerTypeName = "TransactionProcessor.BusinessLogic.EventHandling.TransactionDomainEventHandler, TransactionProcessor.BusinessLogic"; Dictionary eventHandlerConfiguration = new Dictionary(); TransactionHasBeenCompletedEvent transactionHasBeenCompletedEvent = TestData.TransactionHasBeenCompletedEvent; - eventHandlerConfiguration.Add(transactionHasBeenCompletedEvent.GetType().FullName, new String[] { handlerTypeName }); + eventHandlerConfiguration.Add(transactionHasBeenCompletedEvent.GetType().Name, new String[] { handlerTypeName }); Mock domainEventHandler = new Mock(); Func createDomainEventHandlerFunc = (type) => { return domainEventHandler.Object; }; @@ -64,7 +64,7 @@ public void DomainEventHandlerResolver_GetDomainEventHandlers_TransactionHasBeen [Fact] public void DomainEventHandlerResolver_GetDomainEventHandlers_TransactionHasBeenCompletedEvent_EventNotConfigured_EventHandlersReturned() { - String handlerTypeName = "TransactionProcessor.BusinessLogic.EventHandling.TransactionDomainEventHandler"; + String handlerTypeName = "TransactionProcessor.BusinessLogic.EventHandling.TransactionDomainEventHandler, TransactionProcessor.BusinessLogic"; Dictionary eventHandlerConfiguration = new Dictionary(); TransactionHasBeenCompletedEvent transactionHasBeenCompletedEvent = TestData.TransactionHasBeenCompletedEvent; diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/TransactionAggregateManagerTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/TransactionAggregateManagerTests.cs index ce5d0d88..22d806b7 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/TransactionAggregateManagerTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/TransactionAggregateManagerTests.cs @@ -10,6 +10,8 @@ namespace TransactionProcessor.BusinessLogic.Tests.Services using BusinessLogic.Services; using Models; using Moq; + using Shared.DomainDrivenDesign.EventSourcing; + using Shared.EventStore.Aggregate; using Shared.EventStore.EventStore; using Shouldly; using Testing; @@ -21,7 +23,7 @@ public class TransactionAggregateManagerTests [Fact] public async Task TransactionAggregateManager_AuthoriseTransaction_TransactionAuthorised() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -37,7 +39,7 @@ await transactionAggregateManager.AuthoriseTransaction(TestData.EstateId, [Fact] public async Task TransactionAggregateManager_AuthoriseTransactionLocally_TransactionLocallyAuthorised() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -51,7 +53,7 @@ await transactionAggregateManager.AuthoriseTransactionLocally(TestData.EstateId, [Fact] public async Task TransactionAggregateManager_DeclineTransaction_TransactionDeclined() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -67,7 +69,7 @@ await transactionAggregateManager.DeclineTransaction(TestData.EstateId, [Fact] public async Task TransactionAggregateManager_DeclineTransactionLocally_TransactionLocallyDeclined() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -80,7 +82,7 @@ await transactionAggregateManager.DeclineTransactionLocally(TestData.EstateId, [Fact] public async Task TransactionAggregateManager_GetAggregate_AggregateReturned() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetCompletedLogonTransactionAggregate); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -94,7 +96,7 @@ public async Task TransactionAggregateManager_GetAggregate_AggregateReturned() [Fact] public async Task TransactionAggregateManager_RecordAdditionalRequestData_AdditionalRequestDataRecorded() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -108,7 +110,7 @@ await transactionAggregateManager.RecordAdditionalRequestData(TestData.EstateId, [Fact] public async Task TransactionAggregateManager_RecordAdditionalRequestData_NullAdditionalRequestData_NoActionPerformed() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -122,7 +124,7 @@ await transactionAggregateManager.RecordAdditionalRequestData(TestData.EstateId, [Fact] public async Task TransactionAggregateManager_RecordAdditionalRequestData_EmptyAdditionalRequestData_NoActionPerformed() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -136,7 +138,7 @@ await transactionAggregateManager.RecordAdditionalRequestData(TestData.EstateId, [Fact] public async Task TransactionAggregateManager_RecordAdditionalResponseData_AdditionalResponseDataRecorded() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -150,7 +152,7 @@ await transactionAggregateManager.RecordAdditionalResponseData(TestData.EstateId [Fact] public async Task TransactionAggregateManager_RecordAdditionalResponseData_NullAdditionalResponseData_NoActionPerformed() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -164,7 +166,7 @@ await transactionAggregateManager.RecordAdditionalResponseData(TestData.EstateId [Fact] public async Task TransactionAggregateManager_RecordAdditionalResponseData_EmptyAdditionalResponseData_NoActionPerformed() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -180,7 +182,7 @@ await transactionAggregateManager.RecordAdditionalResponseData(TestData.EstateId [InlineData(TransactionType.Sale)] public async Task TransactionAggregateManager_StartTransaction_TransactionStarted(TransactionType transactionType) { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetEmptyTransactionAggregate); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -199,7 +201,7 @@ await transactionAggregateManager.StartTransaction(TestData.TransactionId, [Fact] public async Task TransactionAggregateManager_CompleteTransaction_TransactionCompleted() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetLocallyAuthorisedTransactionAggregate); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -211,7 +213,7 @@ await transactionAggregateManager.CompleteTransaction(TestData.EstateId, [Fact] public async Task TransactionAggregateManager_RequestEmailReceipt_EmailRecieptRequested() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetCompletedLogonTransactionAggregate); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -224,7 +226,7 @@ await transactionAggregateManager.RequestEmailReceipt(TestData.EstateId, [Fact] public async Task TransactionAggregateManager_AddProductDetails_ProductDetailsAddedToTransaction() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetStartedTransactionAggregate()); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); @@ -238,7 +240,7 @@ await transactionAggregateManager.AddProductDetails(TestData.EstateId, [Fact] public async Task TransactionAggregateManager_AddFee_FeeAddedToTransaction() { - Mock> aggregateRepository = new Mock>(); + Mock> aggregateRepository = new Mock>(); aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny(), It.IsAny())).ReturnsAsync(TestData.GetCompletedAuthorisedSaleTransactionAggregate); TransactionAggregateManager transactionAggregateManager = new TransactionAggregateManager(aggregateRepository.Object); diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs index 09c81a63..e784d083 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs @@ -17,6 +17,8 @@ namespace TransactionProcessor.BusinessLogic.Tests.Services using ReconciliationAggregate; using SecurityService.Client; using SecurityService.DataTransferObjects.Responses; + using Shared.DomainDrivenDesign.EventSourcing; + using Shared.EventStore.Aggregate; using Shared.EventStore.EventStore; using Shared.General; using Shared.Logger; @@ -47,8 +49,8 @@ public async Task TransactionDomainService_ProcessReconciliationTransaction_Tran Mock operatorProxy = new Mock(); Func operatorProxyResolver = (operatorName) => { return operatorProxy.Object; }; - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); reconciliationAggregateRepository.Setup(r => r.GetLatestVersion(It.IsAny(), It.IsAny())) .ReturnsAsync(new ReconciliationAggregate()); @@ -88,8 +90,8 @@ public async Task TransactionDomainService_ProcessReconciliationTransaction_Inco estateClient.Setup(e => e.GetMerchant(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetMerchantResponseWithOperator1); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); reconciliationAggregateRepository.Setup(r => r.GetLatestVersion(It.IsAny(), It.IsAny())) .ReturnsAsync(new ReconciliationAggregate()); @@ -132,8 +134,8 @@ public async Task TransactionDomainService_ProcessReconciliationTransaction_Merc estateClient.Setup(e => e.GetMerchant(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(merchantResponse); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); reconciliationAggregateRepository.Setup(r => r.GetLatestVersion(It.IsAny(), It.IsAny())) .ReturnsAsync(new ReconciliationAggregate()); @@ -172,8 +174,8 @@ public async Task TransactionDomainService_ProcessReconciliationTransaction_Inva estateClient.Setup(e => e.GetMerchant(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetMerchantResponseWithOperator1); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); reconciliationAggregateRepository.Setup(r => r.GetLatestVersion(It.IsAny(), It.IsAny())) .ReturnsAsync(new ReconciliationAggregate()); @@ -212,8 +214,8 @@ public async Task TransactionDomainService_ProcessReconciliationTransaction_Inva estateClient.Setup(e => e.GetMerchant(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .ThrowsAsync(new Exception("Exception", new KeyNotFoundException("Invalid Merchant"))); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); reconciliationAggregateRepository.Setup(r => r.GetLatestVersion(It.IsAny(), It.IsAny())) .ReturnsAsync(new ReconciliationAggregate()); TransactionDomainService transactionDomainService = @@ -254,8 +256,8 @@ public async Task TransactionDomainService_ProcessLogonTransaction_TransactionIs Mock operatorProxy = new Mock(); Func operatorProxyResolver = (operatorName) => { return operatorProxy.Object; }; - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -294,8 +296,8 @@ public async Task TransactionDomainService_ProcessLogonTransaction_MerchantWithN transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetCompletedLogonTransactionAggregate); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -334,8 +336,8 @@ public async Task TransactionDomainService_ProcessLogonTransaction_MerchantWithN transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetCompletedLogonTransactionAggregate); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -373,8 +375,8 @@ public async Task TransactionDomainService_ProcessLogonTransaction_IncorrectDevi transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.InvalidDeviceIdentifier)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -412,8 +414,8 @@ public async Task TransactionDomainService_ProcessLogonTransaction_InvalidEstate transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.InvalidEstateId)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -451,8 +453,8 @@ public async Task TransactionDomainService_ProcessLogonTransaction_InvalidMercha transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.InvalidMerchantId)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -506,8 +508,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_SuccesfulOpera }); Func operatorProxyResolver = (operatorName) => { return operatorProxy.Object; }; - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -564,8 +566,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_FailedOperator }); Func operatorProxyResolver = (operatorName) => { return operatorProxy.Object; }; - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -608,8 +610,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_MerchantWithNu transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.NoValidDevices)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -653,8 +655,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_MerchantWithNo transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetDeclinedTransactionAggregate(TransactionResponseCode.NoValidDevices)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -697,8 +699,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_IncorrectDevic transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.InvalidDeviceIdentifier)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -741,8 +743,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_InvalidEstate_ transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.InvalidEstateId)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -785,8 +787,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_NotEnoughCredi transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.MerchantDoesNotHaveEnoughCredit)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -829,8 +831,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_InvalidMerchan transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.InvalidMerchantId)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -873,8 +875,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_EstateWithEmpt transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.NoEstateOperators)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -917,8 +919,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_EstateWithNull transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.NoEstateOperators)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -961,8 +963,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_OperatorNotSup transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetDeclinedTransactionAggregate(TransactionResponseCode.OperatorNotValidForEstate)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -1005,8 +1007,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_MerchantWithEm transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetDeclinedTransactionAggregate(TransactionResponseCode.NoMerchantOperators)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -1050,8 +1052,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_MerchantWithNu transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetDeclinedTransactionAggregate(TransactionResponseCode.NoMerchantOperators)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -1094,8 +1096,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_OperatorNotSup transactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.GetDeclinedTransactionAggregate(TransactionResponseCode.OperatorNotValidForMerchant)); - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, @@ -1147,8 +1149,8 @@ public async Task TransactionDomainService_ProcessSaleTransaction_ErrorInOperato It.IsAny())).ThrowsAsync(new Exception("Comms Error")); Func operatorProxyResolver = (operatorName) => { return operatorProxy.Object; }; - Mock> reconciliationAggregateRepository = - new Mock>(); + Mock> reconciliationAggregateRepository = + new Mock>(); TransactionDomainService transactionDomainService = new TransactionDomainService(transactionAggregateManager.Object, estateClient.Object, securityServiceClient.Object, diff --git a/TransactionProcessor.BusinessLogic/EventHandling/DomainEventHandlerResolver.cs b/TransactionProcessor.BusinessLogic/EventHandling/DomainEventHandlerResolver.cs deleted file mode 100644 index 393f014c..00000000 --- a/TransactionProcessor.BusinessLogic/EventHandling/DomainEventHandlerResolver.cs +++ /dev/null @@ -1,99 +0,0 @@ -namespace MessagingService.BusinessLogic.EventHandling -{ - using System; - using System.Collections.Generic; - using System.Linq; - using Shared.DomainDrivenDesign.EventSourcing; - - public class DomainEventHandlerResolver : IDomainEventHandlerResolver - { - #region Fields - - /// - /// The domain event handlers - /// - private readonly Dictionary DomainEventHandlers; - - /// - /// The event handler configuration - /// - private readonly Dictionary EventHandlerConfiguration; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of the class. - /// - /// The event handler configuration. - public DomainEventHandlerResolver(Dictionary eventHandlerConfiguration, Func createEventHandlerResolver) - { - this.EventHandlerConfiguration = eventHandlerConfiguration; - - this.DomainEventHandlers = new Dictionary(); - - List handlers = new List(); - - // Precreate the Event Handlers here - foreach (KeyValuePair handlerConfig in eventHandlerConfiguration) - { - handlers.AddRange(handlerConfig.Value); - } - - IEnumerable distinctHandlers = handlers.Distinct(); - - foreach (String handlerTypeString in distinctHandlers) - { - Type handlerType = Type.GetType(handlerTypeString); - - if (handlerType == null) - { - throw new NotSupportedException("Event handler configuration is not for a valid type"); - } - - IDomainEventHandler eventHandler = createEventHandlerResolver(handlerType); - this.DomainEventHandlers.Add(handlerTypeString, eventHandler); - } - } - - #endregion - - #region Methods - - /// - /// Gets the domain event handlers. - /// - /// The domain event. - /// - public List GetDomainEventHandlers(DomainEvent domainEvent) - { - // Get the type of the event passed in - String typeString = domainEvent.GetType().FullName; - - // Lookup the list - Boolean eventIsConfigured = this.EventHandlerConfiguration.ContainsKey(typeString); - - if (!eventIsConfigured) - { - // No handlers setup, return null and let the caller decide what to do next - return null; - } - - String[] handlers = this.EventHandlerConfiguration[typeString]; - - List handlersToReturn = new List(); - - foreach (String handler in handlers) - { - List> foundHandlers = this.DomainEventHandlers.Where(h => h.Key == handler).ToList(); - - handlersToReturn.AddRange(foundHandlers.Select(x => x.Value)); - } - - return handlersToReturn; - } - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic/EventHandling/IDomainEventHandler.cs b/TransactionProcessor.BusinessLogic/EventHandling/IDomainEventHandler.cs deleted file mode 100644 index 494f396e..00000000 --- a/TransactionProcessor.BusinessLogic/EventHandling/IDomainEventHandler.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace MessagingService.BusinessLogic.EventHandling -{ - using System.Threading; - using System.Threading.Tasks; - using Shared.DomainDrivenDesign.EventSourcing; - - public interface IDomainEventHandler - { - #region Methods - - /// - /// Handles the specified domain event. - /// - /// The domain event. - /// The cancellation token. - /// - Task Handle(DomainEvent domainEvent, - CancellationToken cancellationToken); - - #endregion - } -} \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic/EventHandling/IDomainEventHandlerResolver.cs b/TransactionProcessor.BusinessLogic/EventHandling/IDomainEventHandlerResolver.cs deleted file mode 100644 index 62db6f39..00000000 --- a/TransactionProcessor.BusinessLogic/EventHandling/IDomainEventHandlerResolver.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Collections.Generic; -using System.Text; - -namespace MessagingService.BusinessLogic.EventHandling -{ - using Shared.DomainDrivenDesign.EventSourcing; - - public interface IDomainEventHandlerResolver - { - #region Methods - - /// - /// Gets the domain event handlers. - /// - /// The domain event. - /// - List GetDomainEventHandlers(DomainEvent domainEvent); - - #endregion - } -} diff --git a/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs b/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs index b5680242..d02878bb 100644 --- a/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs +++ b/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs @@ -8,7 +8,6 @@ using EstateManagement.Client; using EstateManagement.DataTransferObjects.Responses; using Manager; - using MessagingService.BusinessLogic.EventHandling; using MessagingService.Client; using MessagingService.DataTransferObjects; using Models; @@ -16,6 +15,7 @@ using SecurityService.DataTransferObjects.Responses; using Services; using Shared.DomainDrivenDesign.EventSourcing; + using Shared.EventStore.EventHandling; using Shared.General; using Shared.Logger; using Transaction.DomainEvents; @@ -24,7 +24,8 @@ /// /// /// - /// + /// + /// public class TransactionDomainEventHandler : IDomainEventHandler { #region Fields @@ -44,8 +45,14 @@ public class TransactionDomainEventHandler : IDomainEventHandler /// private readonly ISecurityServiceClient SecurityServiceClient; + /// + /// The transaction receipt builder + /// private readonly ITransactionReceiptBuilder TransactionReceiptBuilder; + /// + /// The messaging service client + /// private readonly IMessagingServiceClient MessagingServiceClient; /// @@ -95,7 +102,7 @@ public TransactionDomainEventHandler(ITransactionAggregateManager transactionAgg /// /// The domain event. /// The cancellation token. - public async Task Handle(DomainEvent domainEvent, + public async Task Handle(IDomainEvent domainEvent, CancellationToken cancellationToken) { await this.HandleSpecificDomainEvent((dynamic)domainEvent, cancellationToken); diff --git a/TransactionProcessor.BusinessLogic/Services/TransactionAggregateManager.cs b/TransactionProcessor.BusinessLogic/Services/TransactionAggregateManager.cs index 8125dcb8..e9ad0fd6 100644 --- a/TransactionProcessor.BusinessLogic/Services/TransactionAggregateManager.cs +++ b/TransactionProcessor.BusinessLogic/Services/TransactionAggregateManager.cs @@ -9,6 +9,8 @@ using Microsoft.EntityFrameworkCore.Internal; using Models; using OperatorInterfaces; + using Shared.DomainDrivenDesign.EventSourcing; + using Shared.EventStore.Aggregate; using Shared.EventStore.EventStore; using TransactionAggregate; @@ -23,7 +25,7 @@ public class TransactionAggregateManager : ITransactionAggregateManager /// /// The transaction aggregate repository /// - private readonly IAggregateRepository TransactionAggregateRepository; + private readonly IAggregateRepository TransactionAggregateRepository; #endregion @@ -33,7 +35,7 @@ public class TransactionAggregateManager : ITransactionAggregateManager /// Initializes a new instance of the class. /// /// The transaction aggregate repository. - public TransactionAggregateManager(IAggregateRepository transactionAggregateRepository) + public TransactionAggregateManager(IAggregateRepository transactionAggregateRepository) { this.TransactionAggregateRepository = transactionAggregateRepository; } diff --git a/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs b/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs index d6a6ff87..f0786768 100644 --- a/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs @@ -15,6 +15,8 @@ using ReconciliationAggregate; using SecurityService.Client; using SecurityService.DataTransferObjects.Responses; + using Shared.DomainDrivenDesign.EventSourcing; + using Shared.EventStore.Aggregate; using Shared.EventStore.EventStore; using Shared.General; using Shared.Logger; @@ -56,7 +58,7 @@ public class TransactionDomainService : ITransactionDomainService /// /// The reconciliation aggregate repository /// - private readonly IAggregateRepository ReconciliationAggregateRepository; + private readonly IAggregateRepository ReconciliationAggregateRepository; #endregion @@ -74,7 +76,7 @@ public TransactionDomainService(ITransactionAggregateManager transactionAggregat IEstateClient estateClient, ISecurityServiceClient securityServiceClient, Func operatorProxyResolver, - IAggregateRepository reconciliationAggregateRepository) + IAggregateRepository reconciliationAggregateRepository) { this.TransactionAggregateManager = transactionAggregateManager; this.EstateClient = estateClient; diff --git a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj index c7cd6277..dd23e51c 100644 --- a/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj +++ b/TransactionProcessor.BusinessLogic/TransactionProcessor.BusinessLogic.csproj @@ -5,14 +5,14 @@ - - - - - + + + + + - + diff --git a/TransactionProcessor.Client/TransactionProcessor.Client.csproj b/TransactionProcessor.Client/TransactionProcessor.Client.csproj index 5ee03b47..91597f05 100644 --- a/TransactionProcessor.Client/TransactionProcessor.Client.csproj +++ b/TransactionProcessor.Client/TransactionProcessor.Client.csproj @@ -6,7 +6,7 @@ - + diff --git a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj index 16a52d5e..eba3bc04 100644 --- a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj +++ b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj @@ -7,15 +7,15 @@ - + - - + + - - + + diff --git a/TransactionProcessor.Reconciliation.DomainEvents/OverallTotalsRecordedEvent.cs b/TransactionProcessor.Reconciliation.DomainEvents/OverallTotalsRecordedEvent.cs index dbb4f20f..6208d6dc 100644 --- a/TransactionProcessor.Reconciliation.DomainEvents/OverallTotalsRecordedEvent.cs +++ b/TransactionProcessor.Reconciliation.DomainEvents/OverallTotalsRecordedEvent.cs @@ -9,19 +9,10 @@ /// /// /// - [JsonObject] - public class OverallTotalsRecordedEvent : DomainEvent + public record OverallTotalsRecordedEvent : DomainEventRecord.DomainEvent { #region Constructors - - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public OverallTotalsRecordedEvent() - { - } - + /// /// Initializes a new instance of the class. /// @@ -31,12 +22,11 @@ public OverallTotalsRecordedEvent() /// The merchant identifier. /// The transaction count. /// The transaction value. - private OverallTotalsRecordedEvent(Guid aggregateId, - Guid eventId, + public OverallTotalsRecordedEvent(Guid aggregateId, Guid estateId, Guid merchantId, Int32 transactionCount, - Decimal transactionValue) : base(aggregateId, eventId) + Decimal transactionValue) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -55,8 +45,7 @@ private OverallTotalsRecordedEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -64,8 +53,7 @@ private OverallTotalsRecordedEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the transaction count. @@ -73,8 +61,7 @@ private OverallTotalsRecordedEvent(Guid aggregateId, /// /// The transaction count. /// - [JsonProperty] - public Int32 TransactionCount { get; private set; } + public Int32 TransactionCount { get; init; } /// /// Gets the transaction value. @@ -82,39 +69,15 @@ private OverallTotalsRecordedEvent(Guid aggregateId, /// /// The transaction value. /// - [JsonProperty] - public Decimal TransactionValue { get; private set; } - + public Decimal TransactionValue { get; init; } + /// /// Gets the transaction identifier. /// /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The transaction count. - /// The transaction value. - /// - public static OverallTotalsRecordedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - Int32 transactionCount, - Decimal transactionValue) - { - return new OverallTotalsRecordedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, transactionCount, transactionValue); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasBeenLocallyAuthorisedEvent.cs b/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasBeenLocallyAuthorisedEvent.cs index 29b56062..6648480d 100644 --- a/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasBeenLocallyAuthorisedEvent.cs +++ b/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasBeenLocallyAuthorisedEvent.cs @@ -9,8 +9,8 @@ /// /// /// - [JsonObject] - public class ReconciliationHasBeenLocallyAuthorisedEvent : DomainEvent + + public record ReconciliationHasBeenLocallyAuthorisedEvent : DomainEventRecord.DomainEvent { #region Constructors @@ -23,12 +23,11 @@ public class ReconciliationHasBeenLocallyAuthorisedEvent : DomainEvent /// The merchant identifier. /// The response code. /// The response message. - private ReconciliationHasBeenLocallyAuthorisedEvent(Guid aggregateId, - Guid eventId, + public ReconciliationHasBeenLocallyAuthorisedEvent(Guid aggregateId, Guid estateId, Guid merchantId, String responseCode, - String responseMessage) : base(aggregateId, eventId) + String responseMessage) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -37,14 +36,6 @@ private ReconciliationHasBeenLocallyAuthorisedEvent(Guid aggregateId, this.ResponseMessage = responseMessage; } - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public ReconciliationHasBeenLocallyAuthorisedEvent() - { - } - #endregion #region Properties @@ -55,8 +46,7 @@ public ReconciliationHasBeenLocallyAuthorisedEvent() /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -64,8 +54,7 @@ public ReconciliationHasBeenLocallyAuthorisedEvent() /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the response code. @@ -73,8 +62,7 @@ public ReconciliationHasBeenLocallyAuthorisedEvent() /// /// The response code. /// - [JsonProperty] - public String ResponseCode { get; private set; } + public String ResponseCode { get; init; } /// /// Gets the response message. @@ -82,8 +70,7 @@ public ReconciliationHasBeenLocallyAuthorisedEvent() /// /// The response message. /// - [JsonProperty] - public String ResponseMessage { get; private set; } + public String ResponseMessage { get; init; } /// /// Gets the transaction identifier. @@ -91,30 +78,7 @@ public ReconciliationHasBeenLocallyAuthorisedEvent() /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The response code. - /// The response message. - /// - public static ReconciliationHasBeenLocallyAuthorisedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - String responseCode, - String responseMessage) - { - return new ReconciliationHasBeenLocallyAuthorisedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, responseCode, responseMessage); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasBeenLocallyDeclinedEvent.cs b/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasBeenLocallyDeclinedEvent.cs index 23eed486..c7d89e2e 100644 --- a/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasBeenLocallyDeclinedEvent.cs +++ b/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasBeenLocallyDeclinedEvent.cs @@ -4,9 +4,8 @@ using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; using Shared.DomainDrivenDesign.EventSourcing; - - [JsonObject] - public class ReconciliationHasBeenLocallyDeclinedEvent : DomainEvent + + public record ReconciliationHasBeenLocallyDeclinedEvent : DomainEventRecord.DomainEvent { #region Constructors @@ -19,12 +18,11 @@ public class ReconciliationHasBeenLocallyDeclinedEvent : DomainEvent /// The merchant identifier. /// The response code. /// The response message. - private ReconciliationHasBeenLocallyDeclinedEvent(Guid aggregateId, - Guid eventId, + public ReconciliationHasBeenLocallyDeclinedEvent(Guid aggregateId, Guid estateId, Guid merchantId, String responseCode, - String responseMessage) : base(aggregateId, eventId) + String responseMessage) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -33,14 +31,6 @@ private ReconciliationHasBeenLocallyDeclinedEvent(Guid aggregateId, this.ResponseMessage = responseMessage; } - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public ReconciliationHasBeenLocallyDeclinedEvent() - { - } - #endregion #region Properties @@ -51,8 +41,7 @@ public ReconciliationHasBeenLocallyDeclinedEvent() /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -60,8 +49,7 @@ public ReconciliationHasBeenLocallyDeclinedEvent() /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the response code. @@ -69,8 +57,7 @@ public ReconciliationHasBeenLocallyDeclinedEvent() /// /// The response code. /// - [JsonProperty] - public String ResponseCode { get; private set; } + public String ResponseCode { get; init; } /// /// Gets the response message. @@ -78,8 +65,7 @@ public ReconciliationHasBeenLocallyDeclinedEvent() /// /// The response message. /// - [JsonProperty] - public String ResponseMessage { get; private set; } + public String ResponseMessage { get; init; } /// /// Gets the transaction identifier. @@ -87,30 +73,7 @@ public ReconciliationHasBeenLocallyDeclinedEvent() /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The response code. - /// The response message. - /// - public static ReconciliationHasBeenLocallyDeclinedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - String responseCode, - String responseMessage) - { - return new ReconciliationHasBeenLocallyDeclinedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, responseCode, responseMessage); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasCompletedEvent.cs b/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasCompletedEvent.cs index 4d3f3b68..6f4e7302 100644 --- a/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasCompletedEvent.cs +++ b/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasCompletedEvent.cs @@ -9,19 +9,10 @@ /// /// /// - [JsonObject] - public class ReconciliationHasCompletedEvent : DomainEvent + public record ReconciliationHasCompletedEvent : DomainEventRecord.DomainEvent { #region Constructors - - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public ReconciliationHasCompletedEvent() - { - } - + /// /// Initializes a new instance of the class. /// @@ -29,10 +20,9 @@ public ReconciliationHasCompletedEvent() /// The event identifier. /// The estate identifier. /// The merchant identifier. - private ReconciliationHasCompletedEvent(Guid aggregateId, - Guid eventId, + public ReconciliationHasCompletedEvent(Guid aggregateId, Guid estateId, - Guid merchantId) : base(aggregateId, eventId) + Guid merchantId) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -49,8 +39,7 @@ private ReconciliationHasCompletedEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -58,8 +47,7 @@ private ReconciliationHasCompletedEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the transaction identifier. @@ -67,28 +55,8 @@ private ReconciliationHasCompletedEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } + public Guid TransactionId { get; init; } #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// - public static ReconciliationHasCompletedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId) - { - return new ReconciliationHasCompletedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId); - } - - #endregion - } } \ No newline at end of file diff --git a/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasStartedEvent.cs b/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasStartedEvent.cs index 02cff8e7..be976909 100644 --- a/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasStartedEvent.cs +++ b/TransactionProcessor.Reconciliation.DomainEvents/ReconciliationHasStartedEvent.cs @@ -12,19 +12,10 @@ namespace TransactionProcessor.Reconciliation.DomainEvents /// /// /// - [JsonObject] - public class ReconciliationHasStartedEvent : DomainEvent + public record ReconciliationHasStartedEvent : DomainEventRecord.DomainEvent { #region Constructors - - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public ReconciliationHasStartedEvent() - { - } - + /// /// Initializes a new instance of the class. /// @@ -33,11 +24,10 @@ public ReconciliationHasStartedEvent() /// The estate identifier. /// The merchant identifier. /// The transaction date time. - private ReconciliationHasStartedEvent(Guid aggregateId, - Guid eventId, + public ReconciliationHasStartedEvent(Guid aggregateId, Guid estateId, Guid merchantId, - DateTime transactionDateTime) : base(aggregateId, eventId) + DateTime transactionDateTime) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -55,8 +45,7 @@ private ReconciliationHasStartedEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -64,8 +53,7 @@ private ReconciliationHasStartedEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the transaction date time. @@ -73,8 +61,7 @@ private ReconciliationHasStartedEvent(Guid aggregateId, /// /// The transaction date time. /// - [JsonProperty] - public DateTime TransactionDateTime { get; private set; } + public DateTime TransactionDateTime { get; init; } /// /// Gets the transaction identifier. @@ -82,28 +69,7 @@ private ReconciliationHasStartedEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The transaction date time. - /// - public static ReconciliationHasStartedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - DateTime transactionDateTime) - { - return new ReconciliationHasStartedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, transactionDateTime); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Reconciliation.DomainEvents/TransactionProcessor.Reconciliation.DomainEvents.csproj b/TransactionProcessor.Reconciliation.DomainEvents/TransactionProcessor.Reconciliation.DomainEvents.csproj index 34bd507a..0100c470 100644 --- a/TransactionProcessor.Reconciliation.DomainEvents/TransactionProcessor.Reconciliation.DomainEvents.csproj +++ b/TransactionProcessor.Reconciliation.DomainEvents/TransactionProcessor.Reconciliation.DomainEvents.csproj @@ -5,6 +5,6 @@ - + diff --git a/TransactionProcessor.ReconciliationAggregate.Tests/DomainEventTests.cs b/TransactionProcessor.ReconciliationAggregate.Tests/DomainEventTests.cs index 405a933a..2b722da8 100644 --- a/TransactionProcessor.ReconciliationAggregate.Tests/DomainEventTests.cs +++ b/TransactionProcessor.ReconciliationAggregate.Tests/DomainEventTests.cs @@ -20,7 +20,7 @@ public class DomainEventTests [Fact] public void OverallTotalsRecordedEvent_CanBeCreated_IsCreated() { - OverallTotalsRecordedEvent overallTotalsRecordedEvent = OverallTotalsRecordedEvent.Create(TestData.TransactionId, + OverallTotalsRecordedEvent overallTotalsRecordedEvent = new OverallTotalsRecordedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.ReconciliationTransactionCount, @@ -28,7 +28,6 @@ public void OverallTotalsRecordedEvent_CanBeCreated_IsCreated() overallTotalsRecordedEvent.ShouldNotBeNull(); overallTotalsRecordedEvent.AggregateId.ShouldBe(TestData.TransactionId); - overallTotalsRecordedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); overallTotalsRecordedEvent.EventId.ShouldNotBe(Guid.Empty); overallTotalsRecordedEvent.TransactionId.ShouldBe(TestData.TransactionId); overallTotalsRecordedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -44,7 +43,7 @@ public void OverallTotalsRecordedEvent_CanBeCreated_IsCreated() public void ReconciliationHasBeenLocallyAuthorisedEvent_CanBeCreated_IsCreated() { ReconciliationHasBeenLocallyAuthorisedEvent reconciliationHasBeenLocallyAuthorisedEvent = - ReconciliationHasBeenLocallyAuthorisedEvent.Create(TestData.TransactionId, + new ReconciliationHasBeenLocallyAuthorisedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.ResponseCode, @@ -52,7 +51,6 @@ public void ReconciliationHasBeenLocallyAuthorisedEvent_CanBeCreated_IsCreated() reconciliationHasBeenLocallyAuthorisedEvent.ShouldNotBeNull(); reconciliationHasBeenLocallyAuthorisedEvent.AggregateId.ShouldBe(TestData.TransactionId); - reconciliationHasBeenLocallyAuthorisedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); reconciliationHasBeenLocallyAuthorisedEvent.EventId.ShouldNotBe(Guid.Empty); reconciliationHasBeenLocallyAuthorisedEvent.TransactionId.ShouldBe(TestData.TransactionId); reconciliationHasBeenLocallyAuthorisedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -68,11 +66,10 @@ public void ReconciliationHasBeenLocallyAuthorisedEvent_CanBeCreated_IsCreated() public void ReconciliationHasCompletedEvent_CanBeCreated_IsCreated() { ReconciliationHasCompletedEvent reconciliationHasCompletedEvent = - ReconciliationHasCompletedEvent.Create(TestData.TransactionId, TestData.EstateId, TestData.MerchantId); + new ReconciliationHasCompletedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId); reconciliationHasCompletedEvent.ShouldNotBeNull(); reconciliationHasCompletedEvent.AggregateId.ShouldBe(TestData.TransactionId); - reconciliationHasCompletedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); reconciliationHasCompletedEvent.EventId.ShouldNotBe(Guid.Empty); reconciliationHasCompletedEvent.TransactionId.ShouldBe(TestData.TransactionId); reconciliationHasCompletedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -85,13 +82,12 @@ public void ReconciliationHasCompletedEvent_CanBeCreated_IsCreated() [Fact] public void ReconciliationHasStartedEvent_CanBeCreated_IsCreated() { - ReconciliationHasStartedEvent reconciliationHasStartedEvent = ReconciliationHasStartedEvent.Create(TestData.TransactionId, + ReconciliationHasStartedEvent reconciliationHasStartedEvent = new ReconciliationHasStartedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.TransactionDateTime); reconciliationHasStartedEvent.ShouldNotBeNull(); reconciliationHasStartedEvent.AggregateId.ShouldBe(TestData.TransactionId); - reconciliationHasStartedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); reconciliationHasStartedEvent.EventId.ShouldNotBe(Guid.Empty); reconciliationHasStartedEvent.TransactionId.ShouldBe(TestData.TransactionId); reconciliationHasStartedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -105,7 +101,7 @@ public void ReconciliationHasStartedEvent_CanBeCreated_IsCreated() [Fact] public void TransactionHasBeenLocallyDeclinedEvent_CanBeCreated_IsCreated() { - ReconciliationHasBeenLocallyDeclinedEvent reconciliationHasBeenLocallyDeclinedEvent = ReconciliationHasBeenLocallyDeclinedEvent.Create(TestData.TransactionId, + ReconciliationHasBeenLocallyDeclinedEvent reconciliationHasBeenLocallyDeclinedEvent = new ReconciliationHasBeenLocallyDeclinedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.DeclinedResponseCode, @@ -113,7 +109,6 @@ public void TransactionHasBeenLocallyDeclinedEvent_CanBeCreated_IsCreated() reconciliationHasBeenLocallyDeclinedEvent.ShouldNotBeNull(); reconciliationHasBeenLocallyDeclinedEvent.AggregateId.ShouldBe(TestData.TransactionId); - reconciliationHasBeenLocallyDeclinedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); reconciliationHasBeenLocallyDeclinedEvent.EventId.ShouldNotBe(Guid.Empty); reconciliationHasBeenLocallyDeclinedEvent.TransactionId.ShouldBe(TestData.TransactionId); reconciliationHasBeenLocallyDeclinedEvent.EstateId.ShouldBe(TestData.EstateId); diff --git a/TransactionProcessor.ReconciliationAggregate/ReconciliationAggregate.cs b/TransactionProcessor.ReconciliationAggregate/ReconciliationAggregate.cs index 08a40de6..cc09182b 100644 --- a/TransactionProcessor.ReconciliationAggregate/ReconciliationAggregate.cs +++ b/TransactionProcessor.ReconciliationAggregate/ReconciliationAggregate.cs @@ -5,12 +5,21 @@ namespace TransactionProcessor.ReconciliationAggregate using System.Diagnostics.CodeAnalysis; using Reconciliation.DomainEvents; using Shared.DomainDrivenDesign.EventSourcing; + using Shared.EventStore.Aggregate; using Shared.EventStore.EventStore; using Shared.General; using Transaction.DomainEvents; + /// + /// + /// + /// public class ReconciliationAggregate : Aggregate { + /// + /// Gets the metadata. + /// + /// [ExcludeFromCodeCoverage] protected override Object GetMetadata() { @@ -20,7 +29,11 @@ protected override Object GetMetadata() }; } - protected override void PlayEvent(DomainEvent domainEvent) + /// + /// Plays the event. + /// + /// The domain event. + public override void PlayEvent(IDomainEvent domainEvent) { this.PlayEvent((dynamic)domainEvent); } @@ -46,12 +59,54 @@ private ReconciliationAggregate(Guid aggregateId) this.AggregateId = aggregateId; } + /// + /// Gets the estate identifier. + /// + /// + /// The estate identifier. + /// public Guid EstateId { get; private set; } + /// + /// Gets a value indicating whether this instance is started. + /// + /// + /// true if this instance is started; otherwise, false. + /// public Boolean IsStarted { get; private set; } + /// + /// Gets the merchant identifier. + /// + /// + /// The merchant identifier. + /// public Guid MerchantId { get; private set; } + /// + /// Gets the response code. + /// + /// + /// The response code. + /// public String ResponseCode { get; private set; } + /// + /// Gets a value indicating whether this instance is completed. + /// + /// + /// true if this instance is completed; otherwise, false. + /// public Boolean IsCompleted { get; private set; } + /// + /// Gets a value indicating whether this instance is authorised. + /// + /// + /// true if this instance is authorised; otherwise, false. + /// public Boolean IsAuthorised { get; private set; } + /// + /// Gets a value indicating whether this instance is declined. + /// + /// + /// true if this instance is declined; otherwise, false. + /// public Boolean IsDeclined { get; private set; } /// @@ -62,8 +117,20 @@ private ReconciliationAggregate(Guid aggregateId) /// public String ResponseMessage { get; private set; } + /// + /// Gets the transaction count. + /// + /// + /// The transaction count. + /// public Int32 TransactionCount { get; private set; } + /// + /// Gets the transaction value. + /// + /// + /// The transaction value. + /// public Decimal TransactionValue { get; private set; } /// @@ -76,6 +143,10 @@ public static ReconciliationAggregate Create(Guid aggregateId) return new ReconciliationAggregate(aggregateId); } + /// + /// Checks the reconciliation not already started. + /// + /// Reconciliation Id [{this.AggregateId}] has already been started private void CheckReconciliationNotAlreadyStarted() { if (this.IsStarted) @@ -84,6 +155,10 @@ private void CheckReconciliationNotAlreadyStarted() } } + /// + /// Checks the reconciliation not already completed. + /// + /// Reconciliation Id [{this.AggregateId}] has already been completed private void CheckReconciliationNotAlreadyCompleted() { if (this.IsCompleted) @@ -92,6 +167,12 @@ private void CheckReconciliationNotAlreadyCompleted() } } + /// + /// Starts the reconciliation. + /// + /// The transaction date time. + /// The estate identifier. + /// The merchant identifier. public void StartReconciliation(DateTime transactionDateTime, Guid estateId, Guid merchantId) @@ -105,11 +186,15 @@ public void StartReconciliation(DateTime transactionDateTime, this.CheckReconciliationNotAlreadyCompleted(); ReconciliationHasStartedEvent reconciliationHasStartedEvent = - ReconciliationHasStartedEvent.Create(this.AggregateId, estateId, merchantId, transactionDateTime); + new ReconciliationHasStartedEvent(this.AggregateId, estateId, merchantId, transactionDateTime); - this.ApplyAndPend(reconciliationHasStartedEvent); + this.ApplyAndAppend(reconciliationHasStartedEvent); } + /// + /// Checks the reconciliation has been started. + /// + /// Reconciliation [{this.AggregateId}] has not been started private void CheckReconciliationHasBeenStarted() { if (this.IsStarted == false) @@ -118,16 +203,26 @@ private void CheckReconciliationHasBeenStarted() } } + /// + /// Records the overall totals. + /// + /// The total count. + /// The total value. public void RecordOverallTotals(Int32 totalCount, Decimal totalValue) { // TODO: Rules this.CheckReconciliationHasBeenStarted(); this.CheckReconciliationNotAlreadyCompleted(); - OverallTotalsRecordedEvent overallTotalsRecordedEvent = OverallTotalsRecordedEvent.Create(this.AggregateId, this.EstateId,this.MerchantId, totalCount, totalValue); - this.ApplyAndPend(overallTotalsRecordedEvent); + OverallTotalsRecordedEvent overallTotalsRecordedEvent = new OverallTotalsRecordedEvent(this.AggregateId, this.EstateId,this.MerchantId, totalCount, totalValue); + this.ApplyAndAppend(overallTotalsRecordedEvent); } + /// + /// Authorises the specified response code. + /// + /// The response code. + /// The response message. public void Authorise(String responseCode, String responseMessage) { this.CheckReconciliationHasBeenStarted(); @@ -135,12 +230,16 @@ public void Authorise(String responseCode, String responseMessage) this.CheckReconciliationNotAlreadyAuthorised(); this.CheckReconciliationNotAlreadyDeclined(); - ReconciliationHasBeenLocallyAuthorisedEvent reconciliationHasBeenLocallyAuthorisedEvent = ReconciliationHasBeenLocallyAuthorisedEvent.Create(this.AggregateId, this.EstateId, this.MerchantId, + ReconciliationHasBeenLocallyAuthorisedEvent reconciliationHasBeenLocallyAuthorisedEvent = new ReconciliationHasBeenLocallyAuthorisedEvent(this.AggregateId, this.EstateId, this.MerchantId, responseCode, responseMessage); - this.ApplyAndPend(reconciliationHasBeenLocallyAuthorisedEvent); + this.ApplyAndAppend(reconciliationHasBeenLocallyAuthorisedEvent); } + /// + /// Checks the reconciliation not already authorised. + /// + /// Reconciliation [{this.AggregateId}] has already been authorised private void CheckReconciliationNotAlreadyAuthorised() { if (this.IsAuthorised) @@ -149,6 +248,10 @@ private void CheckReconciliationNotAlreadyAuthorised() } } + /// + /// Checks the reconciliation not already declined. + /// + /// Reconciliation [{this.AggregateId}] has already been declined private void CheckReconciliationNotAlreadyDeclined() { if (this.IsDeclined) @@ -157,6 +260,10 @@ private void CheckReconciliationNotAlreadyDeclined() } } + /// + /// Checks the reconciliation has been authorised or declined. + /// + /// Reconciliation [{this.AggregateId}] has not been authorised or declined private void CheckReconciliationHasBeenAuthorisedOrDeclined() { if (this.IsAuthorised == false && this.IsDeclined == false) @@ -165,6 +272,11 @@ private void CheckReconciliationHasBeenAuthorisedOrDeclined() } } + /// + /// Declines the specified response code. + /// + /// The response code. + /// The response message. public void Decline(String responseCode, String responseMessage) { this.CheckReconciliationHasBeenStarted(); @@ -172,12 +284,15 @@ public void Decline(String responseCode, String responseMessage) this.CheckReconciliationNotAlreadyAuthorised(); this.CheckReconciliationNotAlreadyDeclined(); - ReconciliationHasBeenLocallyDeclinedEvent reconciliationHasBeenLocallyDeclinedEvent = ReconciliationHasBeenLocallyDeclinedEvent.Create(this.AggregateId, this.EstateId, this.MerchantId, + ReconciliationHasBeenLocallyDeclinedEvent reconciliationHasBeenLocallyDeclinedEvent = new ReconciliationHasBeenLocallyDeclinedEvent(this.AggregateId, this.EstateId, this.MerchantId, responseCode, responseMessage); - this.ApplyAndPend(reconciliationHasBeenLocallyDeclinedEvent); + this.ApplyAndAppend(reconciliationHasBeenLocallyDeclinedEvent); } + /// + /// Completes the reconciliation. + /// public void CompleteReconciliation() { this.CheckReconciliationHasBeenStarted(); @@ -185,13 +300,17 @@ public void CompleteReconciliation() this.CheckReconciliationHasBeenAuthorisedOrDeclined(); ReconciliationHasCompletedEvent reconciliationHasCompletedEvent = - ReconciliationHasCompletedEvent.Create(this.AggregateId, this.EstateId, this.MerchantId); + new ReconciliationHasCompletedEvent(this.AggregateId, this.EstateId, this.MerchantId); - this.ApplyAndPend(reconciliationHasCompletedEvent); + this.ApplyAndAppend(reconciliationHasCompletedEvent); } #endregion + /// + /// Plays the event. + /// + /// The domain event. private void PlayEvent(ReconciliationHasStartedEvent domainEvent) { this.EstateId = domainEvent.EstateId; @@ -199,12 +318,20 @@ private void PlayEvent(ReconciliationHasStartedEvent domainEvent) this.IsStarted = true; } + /// + /// Plays the event. + /// + /// The domain event. private void PlayEvent(OverallTotalsRecordedEvent domainEvent) { this.TransactionCount = domainEvent.TransactionCount; this.TransactionValue = domainEvent.TransactionValue; } + /// + /// Plays the event. + /// + /// The domain event. private void PlayEvent(ReconciliationHasBeenLocallyAuthorisedEvent domainEvent) { this.ResponseCode = domainEvent.ResponseCode; @@ -212,6 +339,10 @@ private void PlayEvent(ReconciliationHasBeenLocallyAuthorisedEvent domainEvent) this.IsAuthorised = true; } + /// + /// Plays the event. + /// + /// The domain event. private void PlayEvent(ReconciliationHasBeenLocallyDeclinedEvent domainEvent) { this.ResponseCode = domainEvent.ResponseCode; @@ -219,6 +350,10 @@ private void PlayEvent(ReconciliationHasBeenLocallyDeclinedEvent domainEvent) this.IsDeclined = true; } + /// + /// Plays the event. + /// + /// The domain event. private void PlayEvent(ReconciliationHasCompletedEvent domainEvent) { this.IsStarted = false; diff --git a/TransactionProcessor.ReconciliationAggregate/TransactionProcessor.ReconciliationAggregate.csproj b/TransactionProcessor.ReconciliationAggregate/TransactionProcessor.ReconciliationAggregate.csproj index 75455d41..2e820027 100644 --- a/TransactionProcessor.ReconciliationAggregate/TransactionProcessor.ReconciliationAggregate.csproj +++ b/TransactionProcessor.ReconciliationAggregate/TransactionProcessor.ReconciliationAggregate.csproj @@ -5,7 +5,7 @@ - + diff --git a/TransactionProcessor.Testing/TestData.cs b/TransactionProcessor.Testing/TestData.cs index 8c5827c4..716a4860 100644 --- a/TransactionProcessor.Testing/TestData.cs +++ b/TransactionProcessor.Testing/TestData.cs @@ -683,9 +683,9 @@ public static TokenResponse TokenResponse() } public static CustomerEmailReceiptRequestedEvent CustomerEmailReceiptRequestedEvent = - CustomerEmailReceiptRequestedEvent.Create(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.CustomerEmailAddress); + new CustomerEmailReceiptRequestedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.CustomerEmailAddress); - public static TransactionHasBeenCompletedEvent TransactionHasBeenCompletedEvent = TransactionHasBeenCompletedEvent.Create(TestData.TransactionId, + public static TransactionHasBeenCompletedEvent TransactionHasBeenCompletedEvent = new TransactionHasBeenCompletedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.ResponseCode, diff --git a/TransactionProcessor.Transaction.DomainEvents/AdditionalRequestDataRecordedEvent.cs b/TransactionProcessor.Transaction.DomainEvents/AdditionalRequestDataRecordedEvent.cs index bd73d13e..78592285 100644 --- a/TransactionProcessor.Transaction.DomainEvents/AdditionalRequestDataRecordedEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/AdditionalRequestDataRecordedEvent.cs @@ -32,12 +32,11 @@ public AdditionalRequestDataRecordedEvent() /// The merchant identifier. /// The operator identifier. /// The additional transaction request metadata. - private AdditionalRequestDataRecordedEvent(Guid aggregateId, - Guid eventId, + public AdditionalRequestDataRecordedEvent(Guid aggregateId, Guid estateId, Guid merchantId, String operatorIdentifier, - Dictionary additionalTransactionRequestMetadata) : base(aggregateId, eventId) + Dictionary additionalTransactionRequestMetadata) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -56,8 +55,7 @@ private AdditionalRequestDataRecordedEvent(Guid aggregateId, /// /// The additional transaction request metadata. /// - [JsonProperty] - public Dictionary AdditionalTransactionRequestMetadata { get; private set; } + public Dictionary AdditionalTransactionRequestMetadata { get; init; } /// /// Gets the estate identifier. @@ -65,8 +63,7 @@ private AdditionalRequestDataRecordedEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -74,8 +71,7 @@ private AdditionalRequestDataRecordedEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the operator identifier. @@ -83,8 +79,7 @@ private AdditionalRequestDataRecordedEvent(Guid aggregateId, /// /// The operator identifier. /// - [JsonProperty] - public String OperatorIdentifier { get; private set; } + public String OperatorIdentifier { get; init; } /// /// Gets the transaction identifier. @@ -92,30 +87,7 @@ private AdditionalRequestDataRecordedEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The operator identifier. - /// The additional transaction request metadata. - /// - public static AdditionalRequestDataRecordedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - String operatorIdentifier, - Dictionary additionalTransactionRequestMetadata) - { - return new AdditionalRequestDataRecordedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, operatorIdentifier, additionalTransactionRequestMetadata); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/AdditionalResponseDataRecordedEvent.cs b/TransactionProcessor.Transaction.DomainEvents/AdditionalResponseDataRecordedEvent.cs index 4816aee8..4e4ce67a 100644 --- a/TransactionProcessor.Transaction.DomainEvents/AdditionalResponseDataRecordedEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/AdditionalResponseDataRecordedEvent.cs @@ -10,16 +10,10 @@ /// /// /// - public class AdditionalResponseDataRecordedEvent : DomainEvent + public record AdditionalResponseDataRecordedEvent : DomainEventRecord.DomainEvent { #region Constructors - [ExcludeFromCodeCoverage] - public AdditionalResponseDataRecordedEvent() - { - - } - /// /// Initializes a new instance of the class. /// @@ -29,12 +23,11 @@ public AdditionalResponseDataRecordedEvent() /// The merchant identifier. /// The operator identifier. /// The additional transaction response metadata. - private AdditionalResponseDataRecordedEvent(Guid aggregateId, - Guid eventId, + public AdditionalResponseDataRecordedEvent(Guid aggregateId, Guid estateId, Guid merchantId, String operatorIdentifier, - Dictionary additionalTransactionResponseMetadata) : base(aggregateId, eventId) + Dictionary additionalTransactionResponseMetadata) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -53,8 +46,7 @@ private AdditionalResponseDataRecordedEvent(Guid aggregateId, /// /// The additional transaction request metadata. /// - [JsonProperty] - public Dictionary AdditionalTransactionResponseMetadata { get; private set; } + public Dictionary AdditionalTransactionResponseMetadata { get; init; } /// /// Gets the estate identifier. @@ -62,8 +54,7 @@ private AdditionalResponseDataRecordedEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -71,8 +62,7 @@ private AdditionalResponseDataRecordedEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the operator identifier. @@ -80,8 +70,7 @@ private AdditionalResponseDataRecordedEvent(Guid aggregateId, /// /// The operator identifier. /// - [JsonProperty] - public String OperatorIdentifier { get; private set; } + public String OperatorIdentifier { get; init; } /// /// Gets the transaction identifier. @@ -89,30 +78,7 @@ private AdditionalResponseDataRecordedEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The operator identifier. - /// The additional transaction response metadata. - /// - public static AdditionalResponseDataRecordedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - String operatorIdentifier, - Dictionary additionalTransactionResponseMetadata) - { - return new AdditionalResponseDataRecordedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, operatorIdentifier, additionalTransactionResponseMetadata); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/CustomerEmailReceiptRequestedEvent.cs b/TransactionProcessor.Transaction.DomainEvents/CustomerEmailReceiptRequestedEvent.cs index dfa9a6f3..a43f3262 100644 --- a/TransactionProcessor.Transaction.DomainEvents/CustomerEmailReceiptRequestedEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/CustomerEmailReceiptRequestedEvent.cs @@ -9,18 +9,10 @@ /// /// /// - public class CustomerEmailReceiptRequestedEvent : DomainEvent + public record CustomerEmailReceiptRequestedEvent : DomainEventRecord.DomainEvent { #region Constructors - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public CustomerEmailReceiptRequestedEvent() - { - } - /// /// Initializes a new instance of the class. /// @@ -29,11 +21,10 @@ public CustomerEmailReceiptRequestedEvent() /// The estate identifier. /// The merchant identifier. /// The customer email address. - private CustomerEmailReceiptRequestedEvent(Guid aggregateId, - Guid eventId, + public CustomerEmailReceiptRequestedEvent(Guid aggregateId, Guid estateId, Guid merchantId, - String customerEmailAddress) : base(aggregateId, eventId) + String customerEmailAddress) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -51,8 +42,7 @@ private CustomerEmailReceiptRequestedEvent(Guid aggregateId, /// /// The customer email address. /// - [JsonProperty] - public String CustomerEmailAddress { get; private set; } + public String CustomerEmailAddress { get; init; } /// /// Gets the estate identifier. @@ -60,8 +50,7 @@ private CustomerEmailReceiptRequestedEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -69,8 +58,7 @@ private CustomerEmailReceiptRequestedEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the transaction identifier. @@ -78,28 +66,7 @@ private CustomerEmailReceiptRequestedEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The customer email address. - /// - public static CustomerEmailReceiptRequestedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - String customerEmailAddress) - { - return new CustomerEmailReceiptRequestedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, customerEmailAddress); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/MerchantFeeAddedToTransactionEvent.cs b/TransactionProcessor.Transaction.DomainEvents/MerchantFeeAddedToTransactionEvent.cs index 95740d29..bf0828c7 100644 --- a/TransactionProcessor.Transaction.DomainEvents/MerchantFeeAddedToTransactionEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/MerchantFeeAddedToTransactionEvent.cs @@ -1,46 +1,33 @@ namespace TransactionProcessor.Transaction.DomainEvents { using System; - using System.Diagnostics.CodeAnalysis; - using Newtonsoft.Json; using Shared.DomainDrivenDesign.EventSourcing; /// /// /// /// - [JsonObject] - public class MerchantFeeAddedToTransactionEvent : DomainEvent + public record MerchantFeeAddedToTransactionEvent : DomainEventRecord.DomainEvent { #region Constructors - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public MerchantFeeAddedToTransactionEvent() - { - } - /// /// Initializes a new instance of the class. /// /// The aggregate identifier. - /// The event identifier. /// The estate identifier. /// The merchant identifier. /// The calculated value. /// Type of the fee calculation. /// The fee identifier. /// The fee value. - private MerchantFeeAddedToTransactionEvent(Guid aggregateId, - Guid eventId, - Guid estateId, - Guid merchantId, - Decimal calculatedValue, - Int32 feeCalculationType, - Guid feeId, - Decimal feeValue) : base(aggregateId, eventId) + public MerchantFeeAddedToTransactionEvent(Guid aggregateId, + Guid estateId, + Guid merchantId, + Decimal calculatedValue, + Int32 feeCalculationType, + Guid feeId, + Decimal feeValue) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -61,8 +48,7 @@ private MerchantFeeAddedToTransactionEvent(Guid aggregateId, /// /// The calculated value. /// - [JsonProperty] - public Decimal CalculatedValue { get; private set; } + public Decimal CalculatedValue { get; init; } /// /// Gets the estate identifier. @@ -70,8 +56,7 @@ private MerchantFeeAddedToTransactionEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the type of the fee calculation. @@ -79,8 +64,7 @@ private MerchantFeeAddedToTransactionEvent(Guid aggregateId, /// /// The type of the fee calculation. /// - [JsonProperty] - public Int32 FeeCalculationType { get; private set; } + public Int32 FeeCalculationType { get; init; } /// /// Gets the fee identifier. @@ -88,8 +72,7 @@ private MerchantFeeAddedToTransactionEvent(Guid aggregateId, /// /// The fee identifier. /// - [JsonProperty] - public Guid FeeId { get; private set; } + public Guid FeeId { get; init; } /// /// Gets the fee value. @@ -97,8 +80,7 @@ private MerchantFeeAddedToTransactionEvent(Guid aggregateId, /// /// The fee value. /// - [JsonProperty] - public Decimal FeeValue { get; private set; } + public Decimal FeeValue { get; init; } /// /// Gets the merchant identifier. @@ -106,8 +88,7 @@ private MerchantFeeAddedToTransactionEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the transaction identifier. @@ -115,34 +96,7 @@ private MerchantFeeAddedToTransactionEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The calculated value. - /// Type of the fee calculation. - /// The fee identifier. - /// The fee value. - /// - public static MerchantFeeAddedToTransactionEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - Decimal calculatedValue, - Int32 feeCalculationType, - Guid feeId, - Decimal feeValue) - { - return new MerchantFeeAddedToTransactionEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, calculatedValue, feeCalculationType, feeId, feeValue); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/ProductDetailsAddedToTransactionEvent.cs b/TransactionProcessor.Transaction.DomainEvents/ProductDetailsAddedToTransactionEvent.cs index 32a7f3ca..f16dfd43 100644 --- a/TransactionProcessor.Transaction.DomainEvents/ProductDetailsAddedToTransactionEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/ProductDetailsAddedToTransactionEvent.cs @@ -9,38 +9,25 @@ /// /// /// - [JsonObject] - public class ProductDetailsAddedToTransactionEvent : DomainEvent + public record ProductDetailsAddedToTransactionEvent : DomainEventRecord.DomainEvent { #region Constructors - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public ProductDetailsAddedToTransactionEvent() - { - - } - /// /// Initializes a new instance of the class. /// /// The aggregate identifier. - /// The event identifier. /// The estate identifier. /// The merchant identifier. /// The contract identifier. /// The product identifier. - private ProductDetailsAddedToTransactionEvent(Guid aggregateId, - Guid eventId, + public ProductDetailsAddedToTransactionEvent(Guid aggregateId, Guid estateId, Guid merchantId, Guid contractId, - Guid productId) : base(aggregateId, eventId) + Guid productId) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; - this.EventId = eventId; this.EstateId = estateId; this.MerchantId = merchantId; this.ContractId = contractId; @@ -57,8 +44,7 @@ private ProductDetailsAddedToTransactionEvent(Guid aggregateId, /// /// The contract identifier. /// - [JsonProperty] - public Guid ContractId { get; private set; } + public Guid ContractId { get; init; } /// /// Gets the estate identifier. @@ -66,8 +52,7 @@ private ProductDetailsAddedToTransactionEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -75,8 +60,7 @@ private ProductDetailsAddedToTransactionEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the product identifier. @@ -84,8 +68,7 @@ private ProductDetailsAddedToTransactionEvent(Guid aggregateId, /// /// The product identifier. /// - [JsonProperty] - public Guid ProductId { get; private set; } + public Guid ProductId { get; init; } /// /// Gets the transaction identifier. @@ -93,32 +76,7 @@ private ProductDetailsAddedToTransactionEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - public Guid EventId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The contract identifier. - /// The product identifier. - /// - public static ProductDetailsAddedToTransactionEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - Guid contractId, - Guid productId) - { - return new ProductDetailsAddedToTransactionEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, contractId, productId); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/ServiceProviderFeeAddedToTransactionEvent.cs b/TransactionProcessor.Transaction.DomainEvents/ServiceProviderFeeAddedToTransactionEvent.cs index e27e58ae..4aebc0ec 100644 --- a/TransactionProcessor.Transaction.DomainEvents/ServiceProviderFeeAddedToTransactionEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/ServiceProviderFeeAddedToTransactionEvent.cs @@ -9,38 +9,27 @@ /// /// /// - [JsonObject] - public class ServiceProviderFeeAddedToTransactionEvent : DomainEvent + public record ServiceProviderFeeAddedToTransactionEvent : DomainEventRecord.DomainEvent { #region Constructors - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public ServiceProviderFeeAddedToTransactionEvent() - { - } - /// /// Initializes a new instance of the class. /// /// The aggregate identifier. - /// The event identifier. /// The estate identifier. /// The merchant identifier. /// The calculated value. /// Type of the fee calculation. /// The fee identifier. /// The fee value. - private ServiceProviderFeeAddedToTransactionEvent(Guid aggregateId, - Guid eventId, + public ServiceProviderFeeAddedToTransactionEvent(Guid aggregateId, Guid estateId, Guid merchantId, Decimal calculatedValue, Int32 feeCalculationType, Guid feeId, - Decimal feeValue) : base(aggregateId, eventId) + Decimal feeValue) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -61,8 +50,7 @@ private ServiceProviderFeeAddedToTransactionEvent(Guid aggregateId, /// /// The calculated value. /// - [JsonProperty] - public Decimal CalculatedValue { get; private set; } + public Decimal CalculatedValue { get; init; } /// /// Gets the estate identifier. @@ -70,8 +58,7 @@ private ServiceProviderFeeAddedToTransactionEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the type of the fee calculation. @@ -79,8 +66,7 @@ private ServiceProviderFeeAddedToTransactionEvent(Guid aggregateId, /// /// The type of the fee calculation. /// - [JsonProperty] - public Int32 FeeCalculationType { get; private set; } + public Int32 FeeCalculationType { get; init; } /// /// Gets the fee identifier. @@ -88,8 +74,7 @@ private ServiceProviderFeeAddedToTransactionEvent(Guid aggregateId, /// /// The fee identifier. /// - [JsonProperty] - public Guid FeeId { get; private set; } + public Guid FeeId { get; init; } /// /// Gets the fee value. @@ -97,8 +82,7 @@ private ServiceProviderFeeAddedToTransactionEvent(Guid aggregateId, /// /// The fee value. /// - [JsonProperty] - public Decimal FeeValue { get; private set; } + public Decimal FeeValue { get; init; } /// /// Gets the merchant identifier. @@ -106,8 +90,7 @@ private ServiceProviderFeeAddedToTransactionEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the transaction identifier. @@ -115,34 +98,7 @@ private ServiceProviderFeeAddedToTransactionEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The calculated value. - /// Type of the fee calculation. - /// The fee identifier. - /// The fee value. - /// - public static ServiceProviderFeeAddedToTransactionEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - Decimal calculatedValue, - Int32 feeCalculationType, - Guid feeId, - Decimal feeValue) - { - return new ServiceProviderFeeAddedToTransactionEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, calculatedValue, feeCalculationType, feeId, feeValue); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/TransactionAuthorisedByOperatorEvent.cs b/TransactionProcessor.Transaction.DomainEvents/TransactionAuthorisedByOperatorEvent.cs index 97a539a7..de3b0f74 100644 --- a/TransactionProcessor.Transaction.DomainEvents/TransactionAuthorisedByOperatorEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/TransactionAuthorisedByOperatorEvent.cs @@ -4,22 +4,15 @@ using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; using Shared.DomainDrivenDesign.EventSourcing; - - [JsonObject] - public class TransactionAuthorisedByOperatorEvent : DomainEvent + + public record TransactionAuthorisedByOperatorEvent : DomainEventRecord.DomainEvent { #region Constructors - [ExcludeFromCodeCoverage] - public TransactionAuthorisedByOperatorEvent() - { - } - /// /// Initializes a new instance of the class. /// /// The aggregate identifier. - /// The event identifier. /// The estate identifier. /// The merchant identifier. /// The operator identifier. @@ -29,8 +22,7 @@ public TransactionAuthorisedByOperatorEvent() /// The operator transaction identifier. /// The response code. /// The response message. - private TransactionAuthorisedByOperatorEvent(Guid aggregateId, - Guid eventId, + public TransactionAuthorisedByOperatorEvent(Guid aggregateId, Guid estateId, Guid merchantId, String operatorIdentifier, @@ -39,7 +31,7 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, String operatorResponseMessage, String operatorTransactionId, String responseCode, - String responseMessage) : base(aggregateId, eventId) + String responseMessage) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -63,8 +55,7 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, /// /// The authorisation code. /// - [JsonProperty] - public String AuthorisationCode { get; private set; } + public String AuthorisationCode { get; init; } /// /// Gets the estate identifier. @@ -72,8 +63,7 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -81,8 +71,7 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the operator identifier. @@ -90,8 +79,7 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, /// /// The operator identifier. /// - [JsonProperty] - public String OperatorIdentifier { get; private set; } + public String OperatorIdentifier { get; init; } /// /// Gets the operator response code. @@ -99,8 +87,7 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, /// /// The operator response code. /// - [JsonProperty] - public String OperatorResponseCode { get; private set; } + public String OperatorResponseCode { get; init; } /// /// Gets the operator response message. @@ -108,8 +95,7 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, /// /// The operator response message. /// - [JsonProperty] - public String OperatorResponseMessage { get; private set; } + public String OperatorResponseMessage { get; init; } /// /// Gets or sets the operator transaction identifier. @@ -117,8 +103,7 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, /// /// The operator transaction identifier. /// - [JsonProperty] - public String OperatorTransactionId { get; set; } + public String OperatorTransactionId { get; init; } /// /// Gets the response code. @@ -126,8 +111,7 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, /// /// The response code. /// - [JsonProperty] - public String ResponseCode { get; private set; } + public String ResponseCode { get; init; } /// /// Gets the response message. @@ -135,8 +119,7 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, /// /// The response message. /// - [JsonProperty] - public String ResponseMessage { get; private set; } + public String ResponseMessage { get; init; } /// /// Gets the transaction identifier. @@ -144,51 +127,8 @@ private TransactionAuthorisedByOperatorEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The operator identifier. - /// The authorisation code. - /// The operator response code. - /// The operator response message. - /// The operator transaction identifier. - /// The response code. - /// The response message. - /// - public static TransactionAuthorisedByOperatorEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - String operatorIdentifier, - String authorisationCode, - String operatorResponseCode, - String operatorResponseMessage, - String operatorTransactionId, - String responseCode, - String responseMessage) - { - return new TransactionAuthorisedByOperatorEvent(aggregateId, - Guid.NewGuid(), - estateId, - merchantId, - operatorIdentifier, - authorisationCode, - operatorResponseCode, - operatorResponseMessage, - operatorTransactionId, - responseCode, - responseMessage); - } - + public Guid TransactionId { get; init; } + #endregion } } \ No newline at end of file diff --git a/TransactionProcessor.Transaction.DomainEvents/TransactionDeclinedByOperatorEvent.cs b/TransactionProcessor.Transaction.DomainEvents/TransactionDeclinedByOperatorEvent.cs index b70ebd96..1bf27a92 100644 --- a/TransactionProcessor.Transaction.DomainEvents/TransactionDeclinedByOperatorEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/TransactionDeclinedByOperatorEvent.cs @@ -5,21 +5,14 @@ using Newtonsoft.Json; using Shared.DomainDrivenDesign.EventSourcing; - [JsonObject] - public class TransactionDeclinedByOperatorEvent : DomainEvent + public record TransactionDeclinedByOperatorEvent : DomainEventRecord.DomainEvent { #region Constructors - [ExcludeFromCodeCoverage] - public TransactionDeclinedByOperatorEvent() - { - } - /// /// Initializes a new instance of the class. /// /// The aggregate identifier. - /// The event identifier. /// The estate identifier. /// The merchant identifier. /// The operator identifier. @@ -27,15 +20,15 @@ public TransactionDeclinedByOperatorEvent() /// The operator response message. /// The response code. /// The response message. - private TransactionDeclinedByOperatorEvent(Guid aggregateId, - Guid eventId, - Guid estateId, - Guid merchantId, - String operatorIdentifier, - String operatorResponseCode, - String operatorResponseMessage, - String responseCode, - String responseMessage) : base(aggregateId, eventId) + public TransactionDeclinedByOperatorEvent(Guid aggregateId, + + Guid estateId, + Guid merchantId, + String operatorIdentifier, + String operatorResponseCode, + String operatorResponseMessage, + String responseCode, + String responseMessage) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -57,8 +50,7 @@ private TransactionDeclinedByOperatorEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -66,8 +58,7 @@ private TransactionDeclinedByOperatorEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the operator identifier. @@ -75,8 +66,7 @@ private TransactionDeclinedByOperatorEvent(Guid aggregateId, /// /// The operator identifier. /// - [JsonProperty] - public String OperatorIdentifier { get; private set; } + public String OperatorIdentifier { get; init; } /// /// Gets the operator response code. @@ -84,8 +74,7 @@ private TransactionDeclinedByOperatorEvent(Guid aggregateId, /// /// The operator response code. /// - [JsonProperty] - public String OperatorResponseCode { get; private set; } + public String OperatorResponseCode { get; init; } /// /// Gets the operator response message. @@ -93,8 +82,7 @@ private TransactionDeclinedByOperatorEvent(Guid aggregateId, /// /// The operator response message. /// - [JsonProperty] - public String OperatorResponseMessage { get; private set; } + public String OperatorResponseMessage { get; init; } /// /// Gets the response code. @@ -102,8 +90,7 @@ private TransactionDeclinedByOperatorEvent(Guid aggregateId, /// /// The response code. /// - [JsonProperty] - public String ResponseCode { get; private set; } + public String ResponseCode { get; init; } /// /// Gets the response message. @@ -111,8 +98,7 @@ private TransactionDeclinedByOperatorEvent(Guid aggregateId, /// /// The response message. /// - [JsonProperty] - public String ResponseMessage { get; private set; } + public String ResponseMessage { get; init; } /// /// Gets the transaction identifier. @@ -120,44 +106,7 @@ private TransactionDeclinedByOperatorEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The operator identifier. - /// The operator response code. - /// The operator response message. - /// The response code. - /// The response message. - /// - public static TransactionDeclinedByOperatorEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - String operatorIdentifier, - String operatorResponseCode, - String operatorResponseMessage, - String responseCode, - String responseMessage) - { - return new TransactionDeclinedByOperatorEvent(aggregateId, - Guid.NewGuid(), - estateId, - merchantId, - operatorIdentifier, - operatorResponseCode, - operatorResponseMessage, - responseCode, - responseMessage); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenCompletedEvent.cs b/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenCompletedEvent.cs index 880f309d..22ba79a0 100644 --- a/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenCompletedEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenCompletedEvent.cs @@ -9,24 +9,14 @@ /// /// /// - [JsonObject] - public class TransactionHasBeenCompletedEvent : DomainEvent + public record TransactionHasBeenCompletedEvent : DomainEventRecord.DomainEvent { #region Constructors - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public TransactionHasBeenCompletedEvent() - { - } - /// /// Initializes a new instance of the class. /// /// The aggregate identifier. - /// The event identifier. /// The estate identifier. /// The merchant identifier. /// The response code. @@ -34,15 +24,14 @@ public TransactionHasBeenCompletedEvent() /// if set to true [is authorised]. /// The completed date time. /// The transaction amount. - private TransactionHasBeenCompletedEvent(Guid aggregateId, - Guid eventId, + public TransactionHasBeenCompletedEvent(Guid aggregateId, Guid estateId, Guid merchantId, String responseCode, String responseMessage, Boolean isAuthorised, DateTime completedDateTime, - Decimal? transactionAmount) : base(aggregateId, eventId) + Decimal? transactionAmount) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -58,8 +47,13 @@ private TransactionHasBeenCompletedEvent(Guid aggregateId, #region Properties - [JsonProperty] - public DateTime CompletedDateTime { get; private set; } + /// + /// Gets or sets the completed date time. + /// + /// + /// The completed date time. + /// + public DateTime CompletedDateTime { get; init; } /// /// Gets the estate identifier. @@ -67,8 +61,7 @@ private TransactionHasBeenCompletedEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets a value indicating whether this instance is authorised. @@ -76,8 +69,7 @@ private TransactionHasBeenCompletedEvent(Guid aggregateId, /// /// true if this instance is authorised; otherwise, false. /// - [JsonProperty] - public Boolean IsAuthorised { get; private set; } + public Boolean IsAuthorised { get; init; } /// /// Gets the transaction amount. @@ -86,7 +78,7 @@ private TransactionHasBeenCompletedEvent(Guid aggregateId, /// The transaction amount. /// [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] - public Decimal? TransactionAmount { get; private set; } + public Decimal? TransactionAmount { get; init; } /// /// Gets the merchant identifier. @@ -94,8 +86,7 @@ private TransactionHasBeenCompletedEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the response code. @@ -103,8 +94,7 @@ private TransactionHasBeenCompletedEvent(Guid aggregateId, /// /// The response code. /// - [JsonProperty] - public String ResponseCode { get; private set; } + public String ResponseCode { get; init; } /// /// Gets the response message. @@ -112,8 +102,7 @@ private TransactionHasBeenCompletedEvent(Guid aggregateId, /// /// The response message. /// - [JsonProperty] - public String ResponseMessage { get; private set; } + public String ResponseMessage { get; init; } /// /// Gets the transaction identifier. @@ -121,36 +110,7 @@ private TransactionHasBeenCompletedEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The response code. - /// The response message. - /// if set to true [is authorised]. - /// The completed date time. - /// The transaction amount. - /// - public static TransactionHasBeenCompletedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - String responseCode, - String responseMessage, - Boolean isAuthorised, - DateTime completedDateTime, - Decimal? transactionAmount) - { - return new TransactionHasBeenCompletedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, responseCode, responseMessage, isAuthorised, completedDateTime, transactionAmount); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenLocallyAuthorisedEvent.cs b/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenLocallyAuthorisedEvent.cs index 583210d0..55dfff5c 100644 --- a/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenLocallyAuthorisedEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenLocallyAuthorisedEvent.cs @@ -9,8 +9,7 @@ /// /// /// - [JsonObject] - public class TransactionHasBeenLocallyAuthorisedEvent : DomainEvent + public record TransactionHasBeenLocallyAuthorisedEvent : DomainEventRecord.DomainEvent { #region Constructors @@ -18,19 +17,17 @@ public class TransactionHasBeenLocallyAuthorisedEvent : DomainEvent /// Initializes a new instance of the class. /// /// The aggregate identifier. - /// The event identifier. /// The estate identifier. /// The merchant identifier. /// The authorisation code. /// The response code. /// The response message. - private TransactionHasBeenLocallyAuthorisedEvent(Guid aggregateId, - Guid eventId, + public TransactionHasBeenLocallyAuthorisedEvent(Guid aggregateId, Guid estateId, Guid merchantId, String authorisationCode, String responseCode, - String responseMessage) : base(aggregateId, eventId) + String responseMessage) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -40,14 +37,6 @@ private TransactionHasBeenLocallyAuthorisedEvent(Guid aggregateId, this.ResponseMessage = responseMessage; } - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public TransactionHasBeenLocallyAuthorisedEvent() - { - } - #endregion #region Properties @@ -58,8 +47,7 @@ public TransactionHasBeenLocallyAuthorisedEvent() /// /// The authorisation code. /// - [JsonProperty] - public String AuthorisationCode { get; private set; } + public String AuthorisationCode { get; init; } /// /// Gets the estate identifier. @@ -67,8 +55,7 @@ public TransactionHasBeenLocallyAuthorisedEvent() /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -76,8 +63,7 @@ public TransactionHasBeenLocallyAuthorisedEvent() /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the response code. @@ -85,8 +71,7 @@ public TransactionHasBeenLocallyAuthorisedEvent() /// /// The response code. /// - [JsonProperty] - public String ResponseCode { get; private set; } + public String ResponseCode { get; init; } /// /// Gets the response message. @@ -94,8 +79,7 @@ public TransactionHasBeenLocallyAuthorisedEvent() /// /// The response message. /// - [JsonProperty] - public String ResponseMessage { get; private set; } + public String ResponseMessage { get; init; } /// /// Gets the transaction identifier. @@ -103,32 +87,7 @@ public TransactionHasBeenLocallyAuthorisedEvent() /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The authorisation code. - /// The response code. - /// The response message. - /// - public static TransactionHasBeenLocallyAuthorisedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - String authorisationCode, - String responseCode, - String responseMessage) - { - return new TransactionHasBeenLocallyAuthorisedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, authorisationCode, responseCode, responseMessage); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenLocallyDeclinedEvent.cs b/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenLocallyDeclinedEvent.cs index 496f119c..5ea0f0aa 100644 --- a/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenLocallyDeclinedEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/TransactionHasBeenLocallyDeclinedEvent.cs @@ -5,8 +5,7 @@ using Newtonsoft.Json; using Shared.DomainDrivenDesign.EventSourcing; - [JsonObject] - public class TransactionHasBeenLocallyDeclinedEvent : DomainEvent + public record TransactionHasBeenLocallyDeclinedEvent : DomainEventRecord.DomainEvent { #region Constructors @@ -14,17 +13,15 @@ public class TransactionHasBeenLocallyDeclinedEvent : DomainEvent /// Initializes a new instance of the class. /// /// The aggregate identifier. - /// The event identifier. /// The estate identifier. /// The merchant identifier. /// The response code. /// The response message. - private TransactionHasBeenLocallyDeclinedEvent(Guid aggregateId, - Guid eventId, + public TransactionHasBeenLocallyDeclinedEvent(Guid aggregateId, Guid estateId, Guid merchantId, String responseCode, - String responseMessage) : base(aggregateId, eventId) + String responseMessage) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -33,14 +30,6 @@ private TransactionHasBeenLocallyDeclinedEvent(Guid aggregateId, this.ResponseMessage = responseMessage; } - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public TransactionHasBeenLocallyDeclinedEvent() - { - } - #endregion #region Properties @@ -51,8 +40,7 @@ public TransactionHasBeenLocallyDeclinedEvent() /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the merchant identifier. @@ -60,8 +48,7 @@ public TransactionHasBeenLocallyDeclinedEvent() /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the response code. @@ -69,8 +56,7 @@ public TransactionHasBeenLocallyDeclinedEvent() /// /// The response code. /// - [JsonProperty] - public String ResponseCode { get; private set; } + public String ResponseCode { get; init; } /// /// Gets the response message. @@ -78,8 +64,7 @@ public TransactionHasBeenLocallyDeclinedEvent() /// /// The response message. /// - [JsonProperty] - public String ResponseMessage { get; private set; } + public String ResponseMessage { get; init; } /// /// Gets the transaction identifier. @@ -87,30 +72,7 @@ public TransactionHasBeenLocallyDeclinedEvent() /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } - - #endregion - - #region Methods - - /// - /// Creates the specified aggregate identifier. - /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The response code. - /// The response message. - /// - public static TransactionHasBeenLocallyDeclinedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - String responseCode, - String responseMessage) - { - return new TransactionHasBeenLocallyDeclinedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, responseCode, responseMessage); - } + public Guid TransactionId { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/TransactionHasStartedEvent.cs b/TransactionProcessor.Transaction.DomainEvents/TransactionHasStartedEvent.cs index 7342af3f..021bb2f1 100644 --- a/TransactionProcessor.Transaction.DomainEvents/TransactionHasStartedEvent.cs +++ b/TransactionProcessor.Transaction.DomainEvents/TransactionHasStartedEvent.cs @@ -9,24 +9,14 @@ /// /// /// - [JsonObject] - public class TransactionHasStartedEvent : DomainEvent + public record TransactionHasStartedEvent : DomainEventRecord.DomainEvent { #region Constructors - /// - /// Initializes a new instance of the class. - /// - [ExcludeFromCodeCoverage] - public TransactionHasStartedEvent() - { - } - /// /// Initializes a new instance of the class. /// /// The aggregate identifier. - /// The event identifier. /// The estate identifier. /// The merchant identifier. /// The transaction date time. @@ -35,8 +25,7 @@ public TransactionHasStartedEvent() /// The transaction reference. /// The device identifier. /// The transaction amount. - private TransactionHasStartedEvent(Guid aggregateId, - Guid eventId, + public TransactionHasStartedEvent(Guid aggregateId, Guid estateId, Guid merchantId, DateTime transactionDateTime, @@ -44,7 +33,7 @@ private TransactionHasStartedEvent(Guid aggregateId, String transactionType, String transactionReference, String deviceIdentifier, - Decimal? transactionAmount) : base(aggregateId, eventId) + Decimal? transactionAmount) : base(aggregateId, Guid.NewGuid()) { this.TransactionId = aggregateId; this.EstateId = estateId; @@ -67,8 +56,7 @@ private TransactionHasStartedEvent(Guid aggregateId, /// /// The estate identifier. /// - [JsonProperty] - public Guid EstateId { get; private set; } + public Guid EstateId { get; init; } /// /// Gets the device identifier. @@ -76,8 +64,7 @@ private TransactionHasStartedEvent(Guid aggregateId, /// /// The device identifier. /// - [JsonProperty] - public String DeviceIdentifier { get; private set; } + public String DeviceIdentifier { get; init; } /// /// Gets the transaction amount. @@ -86,7 +73,7 @@ private TransactionHasStartedEvent(Guid aggregateId, /// The transaction amount. /// [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] - public Decimal? TransactionAmount { get; private set; } + public Decimal? TransactionAmount { get; init; } /// /// Gets the merchant identifier. @@ -94,8 +81,7 @@ private TransactionHasStartedEvent(Guid aggregateId, /// /// The merchant identifier. /// - [JsonProperty] - public Guid MerchantId { get; private set; } + public Guid MerchantId { get; init; } /// /// Gets the transaction date time. @@ -103,8 +89,7 @@ private TransactionHasStartedEvent(Guid aggregateId, /// /// The transaction date time. /// - [JsonProperty] - public DateTime TransactionDateTime { get; private set; } + public DateTime TransactionDateTime { get; init; } /// /// Gets the transaction identifier. @@ -112,8 +97,7 @@ private TransactionHasStartedEvent(Guid aggregateId, /// /// The transaction identifier. /// - [JsonProperty] - public Guid TransactionId { get; private set; } + public Guid TransactionId { get; init; } /// /// Gets the transaction number. @@ -121,8 +105,7 @@ private TransactionHasStartedEvent(Guid aggregateId, /// /// The transaction number. /// - [JsonProperty] - public String TransactionNumber { get; private set; } + public String TransactionNumber { get; init; } /// /// Gets the type of the transaction. @@ -130,41 +113,15 @@ private TransactionHasStartedEvent(Guid aggregateId, /// /// The type of the transaction. /// - [JsonProperty] - public String TransactionType { get; private set; } - - [JsonProperty] - public String TransactionReference { get; private set; } - - #endregion - - #region Methods - + public String TransactionType { get; init; } + /// - /// Creates the specified aggregate identifier. + /// Gets or sets the transaction reference. /// - /// The aggregate identifier. - /// The estate identifier. - /// The merchant identifier. - /// The transaction date time. - /// The transaction number. - /// Type of the transaction. - /// The transaction reference. - /// The device identifier. - /// The transaction amount. - /// - public static TransactionHasStartedEvent Create(Guid aggregateId, - Guid estateId, - Guid merchantId, - DateTime transactionDateTime, - String transactionNumber, - String transactionType, - String transactionReference, - String deviceIdentifier, - Decimal? transactionAmount) - { - return new TransactionHasStartedEvent(aggregateId, Guid.NewGuid(), estateId, merchantId, transactionDateTime, transactionNumber, transactionType, transactionReference, deviceIdentifier, transactionAmount); - } + /// + /// The transaction reference. + /// + public String TransactionReference { get; init; } #endregion } diff --git a/TransactionProcessor.Transaction.DomainEvents/TransactionProcessor.Transaction.DomainEvents.csproj b/TransactionProcessor.Transaction.DomainEvents/TransactionProcessor.Transaction.DomainEvents.csproj index 8fe400e5..d85afbc3 100644 --- a/TransactionProcessor.Transaction.DomainEvents/TransactionProcessor.Transaction.DomainEvents.csproj +++ b/TransactionProcessor.Transaction.DomainEvents/TransactionProcessor.Transaction.DomainEvents.csproj @@ -5,7 +5,7 @@ - + diff --git a/TransactionProcessor.TransactionAggregate.Tests/DomainEventTests.cs b/TransactionProcessor.TransactionAggregate.Tests/DomainEventTests.cs index 3e75d800..fd41cbbb 100644 --- a/TransactionProcessor.TransactionAggregate.Tests/DomainEventTests.cs +++ b/TransactionProcessor.TransactionAggregate.Tests/DomainEventTests.cs @@ -19,7 +19,7 @@ public class DomainEventTests [InlineData(TransactionType.Sale)] public void TransactionHasStartedEvent_CanBeCreated_IsCreated(TransactionType transactionType) { - TransactionHasStartedEvent transactionHasStartedEvent = TransactionHasStartedEvent.Create(TestData.TransactionId, + TransactionHasStartedEvent transactionHasStartedEvent = new TransactionHasStartedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.TransactionDateTime, @@ -31,7 +31,6 @@ public void TransactionHasStartedEvent_CanBeCreated_IsCreated(TransactionType tr transactionHasStartedEvent.ShouldNotBeNull(); transactionHasStartedEvent.AggregateId.ShouldBe(TestData.TransactionId); transactionHasStartedEvent.TransactionAmount.ShouldBe(TestData.TransactionAmount); - transactionHasStartedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); transactionHasStartedEvent.EventId.ShouldNotBe(Guid.Empty); transactionHasStartedEvent.TransactionId.ShouldBe(TestData.TransactionId); transactionHasStartedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -47,7 +46,7 @@ public void TransactionHasStartedEvent_CanBeCreated_IsCreated(TransactionType tr public void TransactionHasBeenLocallyAuthorisedEvent_CanBeCreated_IsCreated() { TransactionHasBeenLocallyAuthorisedEvent transactionHasBeenLocallyAuthorisedEvent = - TransactionHasBeenLocallyAuthorisedEvent.Create(TestData.TransactionId, + new TransactionHasBeenLocallyAuthorisedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.AuthorisationCode, @@ -56,7 +55,6 @@ public void TransactionHasBeenLocallyAuthorisedEvent_CanBeCreated_IsCreated() transactionHasBeenLocallyAuthorisedEvent.ShouldNotBeNull(); transactionHasBeenLocallyAuthorisedEvent.AggregateId.ShouldBe(TestData.TransactionId); - transactionHasBeenLocallyAuthorisedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); transactionHasBeenLocallyAuthorisedEvent.EventId.ShouldNotBe(Guid.Empty); transactionHasBeenLocallyAuthorisedEvent.TransactionId.ShouldBe(TestData.TransactionId); transactionHasBeenLocallyAuthorisedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -69,7 +67,7 @@ public void TransactionHasBeenLocallyAuthorisedEvent_CanBeCreated_IsCreated() [Fact] public void TransactionHasBeenCompletedEvent_CanBeCreated_IsCreated() { - TransactionHasBeenCompletedEvent transactionHasBeenCompletedEvent = TransactionHasBeenCompletedEvent.Create(TestData.TransactionId, + TransactionHasBeenCompletedEvent transactionHasBeenCompletedEvent = new TransactionHasBeenCompletedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.ResponseCode, @@ -80,7 +78,6 @@ public void TransactionHasBeenCompletedEvent_CanBeCreated_IsCreated() transactionHasBeenCompletedEvent.ShouldNotBeNull(); transactionHasBeenCompletedEvent.AggregateId.ShouldBe(TestData.TransactionId); - transactionHasBeenCompletedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); transactionHasBeenCompletedEvent.EventId.ShouldNotBe(Guid.Empty); transactionHasBeenCompletedEvent.TransactionId.ShouldBe(TestData.TransactionId); transactionHasBeenCompletedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -95,7 +92,7 @@ public void TransactionHasBeenCompletedEvent_CanBeCreated_IsCreated() [Fact] public void TransactionHasBeenLocallyDeclinedEvent_CanBeCreated_IsCreated() { - TransactionHasBeenLocallyDeclinedEvent transactionHasBeenLocallyDeclinedEvent = TransactionHasBeenLocallyDeclinedEvent.Create(TestData.TransactionId, + TransactionHasBeenLocallyDeclinedEvent transactionHasBeenLocallyDeclinedEvent = new TransactionHasBeenLocallyDeclinedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.DeclinedResponseCode, @@ -104,7 +101,6 @@ public void TransactionHasBeenLocallyDeclinedEvent_CanBeCreated_IsCreated() transactionHasBeenLocallyDeclinedEvent.ShouldNotBeNull(); transactionHasBeenLocallyDeclinedEvent.AggregateId.ShouldBe(TestData.TransactionId); - transactionHasBeenLocallyDeclinedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); transactionHasBeenLocallyDeclinedEvent.EventId.ShouldNotBe(Guid.Empty); transactionHasBeenLocallyDeclinedEvent.TransactionId.ShouldBe(TestData.TransactionId); transactionHasBeenLocallyDeclinedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -116,7 +112,7 @@ public void TransactionHasBeenLocallyDeclinedEvent_CanBeCreated_IsCreated() [Fact] public void TransactionAuthorisedByOperatorEvent_CanBeCreated_IsCreated() { - TransactionAuthorisedByOperatorEvent transactionAuthorisedByOperatorEvent = TransactionAuthorisedByOperatorEvent.Create(TestData.TransactionId, + TransactionAuthorisedByOperatorEvent transactionAuthorisedByOperatorEvent = new TransactionAuthorisedByOperatorEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.OperatorIdentifier1, @@ -129,7 +125,6 @@ public void TransactionAuthorisedByOperatorEvent_CanBeCreated_IsCreated() transactionAuthorisedByOperatorEvent.ShouldNotBeNull(); transactionAuthorisedByOperatorEvent.AggregateId.ShouldBe(TestData.TransactionId); - transactionAuthorisedByOperatorEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); transactionAuthorisedByOperatorEvent.EventId.ShouldNotBe(Guid.Empty); transactionAuthorisedByOperatorEvent.TransactionId.ShouldBe(TestData.TransactionId); transactionAuthorisedByOperatorEvent.EstateId.ShouldBe(TestData.EstateId); @@ -146,7 +141,7 @@ public void TransactionAuthorisedByOperatorEvent_CanBeCreated_IsCreated() [Fact] public void TransactionDeclinedByOperatorEvent_CanBeCreated_IsCreated() { - TransactionDeclinedByOperatorEvent transactionDeclinedByOperatorEvent = TransactionDeclinedByOperatorEvent.Create(TestData.TransactionId, + TransactionDeclinedByOperatorEvent transactionDeclinedByOperatorEvent = new TransactionDeclinedByOperatorEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.OperatorIdentifier1, @@ -157,7 +152,6 @@ public void TransactionDeclinedByOperatorEvent_CanBeCreated_IsCreated() transactionDeclinedByOperatorEvent.ShouldNotBeNull(); transactionDeclinedByOperatorEvent.AggregateId.ShouldBe(TestData.TransactionId); - transactionDeclinedByOperatorEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); transactionDeclinedByOperatorEvent.EventId.ShouldNotBe(Guid.Empty); transactionDeclinedByOperatorEvent.TransactionId.ShouldBe(TestData.TransactionId); transactionDeclinedByOperatorEvent.EstateId.ShouldBe(TestData.EstateId); @@ -172,7 +166,7 @@ public void TransactionDeclinedByOperatorEvent_CanBeCreated_IsCreated() [Fact] public void AdditionalResponseDataRecordedEvent_CanBeCreated_IsCreated() { - AdditionalResponseDataRecordedEvent additionalResponseDataRecordedEvent = AdditionalResponseDataRecordedEvent.Create(TestData.TransactionId, + AdditionalResponseDataRecordedEvent additionalResponseDataRecordedEvent = new AdditionalResponseDataRecordedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.OperatorIdentifier1, @@ -180,7 +174,6 @@ public void AdditionalResponseDataRecordedEvent_CanBeCreated_IsCreated() additionalResponseDataRecordedEvent.ShouldNotBeNull(); additionalResponseDataRecordedEvent.AggregateId.ShouldBe(TestData.TransactionId); - additionalResponseDataRecordedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); additionalResponseDataRecordedEvent.EventId.ShouldNotBe(Guid.Empty); additionalResponseDataRecordedEvent.TransactionId.ShouldBe(TestData.TransactionId); additionalResponseDataRecordedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -197,7 +190,7 @@ public void AdditionalResponseDataRecordedEvent_CanBeCreated_IsCreated() [Fact] public void AdditionalRequestDataRecordedEvent_CanBeCreated_IsCreated() { - AdditionalRequestDataRecordedEvent additionalRequestDataRecordedEvent = AdditionalRequestDataRecordedEvent.Create(TestData.TransactionId, + AdditionalRequestDataRecordedEvent additionalRequestDataRecordedEvent = new AdditionalRequestDataRecordedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.OperatorIdentifier1, @@ -205,7 +198,6 @@ public void AdditionalRequestDataRecordedEvent_CanBeCreated_IsCreated() additionalRequestDataRecordedEvent.ShouldNotBeNull(); additionalRequestDataRecordedEvent.AggregateId.ShouldBe(TestData.TransactionId); - additionalRequestDataRecordedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); additionalRequestDataRecordedEvent.EventId.ShouldNotBe(Guid.Empty); additionalRequestDataRecordedEvent.TransactionId.ShouldBe(TestData.TransactionId); additionalRequestDataRecordedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -222,14 +214,13 @@ public void AdditionalRequestDataRecordedEvent_CanBeCreated_IsCreated() [Fact] public void CustomerEmailReceiptRequestedEvent_CanBeCreated_IsCreated() { - CustomerEmailReceiptRequestedEvent customerEmailReceiptRequestedEvent = CustomerEmailReceiptRequestedEvent.Create(TestData.TransactionId, + CustomerEmailReceiptRequestedEvent customerEmailReceiptRequestedEvent = new CustomerEmailReceiptRequestedEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.CustomerEmailAddress); customerEmailReceiptRequestedEvent.ShouldNotBeNull(); customerEmailReceiptRequestedEvent.AggregateId.ShouldBe(TestData.TransactionId); - customerEmailReceiptRequestedEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); customerEmailReceiptRequestedEvent.EventId.ShouldNotBe(Guid.Empty); customerEmailReceiptRequestedEvent.TransactionId.ShouldBe(TestData.TransactionId); customerEmailReceiptRequestedEvent.EstateId.ShouldBe(TestData.EstateId); @@ -240,11 +231,10 @@ public void CustomerEmailReceiptRequestedEvent_CanBeCreated_IsCreated() [Fact] public void ProductDetailsAddedToTransactionEvent_CanBeCreated_IsCreated() { - ProductDetailsAddedToTransactionEvent productDetailsAddedToTransactionEvent = ProductDetailsAddedToTransactionEvent.Create(TestData.TransactionId, TestData.EstateId,TestData.MerchantId, TestData.ContractId, TestData.ProductId); + ProductDetailsAddedToTransactionEvent productDetailsAddedToTransactionEvent = new ProductDetailsAddedToTransactionEvent(TestData.TransactionId, TestData.EstateId,TestData.MerchantId, TestData.ContractId, TestData.ProductId); productDetailsAddedToTransactionEvent.ShouldNotBeNull(); productDetailsAddedToTransactionEvent.AggregateId.ShouldBe(TestData.TransactionId); - productDetailsAddedToTransactionEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); productDetailsAddedToTransactionEvent.EventId.ShouldNotBe(Guid.Empty); productDetailsAddedToTransactionEvent.TransactionId.ShouldBe(TestData.TransactionId); productDetailsAddedToTransactionEvent.EstateId.ShouldBe(TestData.EstateId); @@ -256,7 +246,7 @@ public void ProductDetailsAddedToTransactionEvent_CanBeCreated_IsCreated() [Fact] public void MerchantFeeAddedToTransactionEvent_CanBeCreated_IsCreated() { - MerchantFeeAddedToTransactionEvent merchantFeeAddedToTransactionEvent = MerchantFeeAddedToTransactionEvent.Create(TestData.TransactionId, + MerchantFeeAddedToTransactionEvent merchantFeeAddedToTransactionEvent = new MerchantFeeAddedToTransactionEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.CalculatedFeeValue, @@ -266,7 +256,6 @@ public void MerchantFeeAddedToTransactionEvent_CanBeCreated_IsCreated() merchantFeeAddedToTransactionEvent.ShouldNotBeNull(); merchantFeeAddedToTransactionEvent.AggregateId.ShouldBe(TestData.TransactionId); - merchantFeeAddedToTransactionEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); merchantFeeAddedToTransactionEvent.EventId.ShouldNotBe(Guid.Empty); merchantFeeAddedToTransactionEvent.TransactionId.ShouldBe(TestData.TransactionId); merchantFeeAddedToTransactionEvent.EstateId.ShouldBe(TestData.EstateId); @@ -281,7 +270,7 @@ public void MerchantFeeAddedToTransactionEvent_CanBeCreated_IsCreated() [Fact] public void ServiceProviderFeeAddedToTransactionEvent_CanBeCreated_IsCreated() { - ServiceProviderFeeAddedToTransactionEvent serviceProviderFeeAddedToTransactionEvent = ServiceProviderFeeAddedToTransactionEvent.Create(TestData.TransactionId, + ServiceProviderFeeAddedToTransactionEvent serviceProviderFeeAddedToTransactionEvent = new ServiceProviderFeeAddedToTransactionEvent(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.CalculatedFeeValue, @@ -291,7 +280,6 @@ public void ServiceProviderFeeAddedToTransactionEvent_CanBeCreated_IsCreated() serviceProviderFeeAddedToTransactionEvent.ShouldNotBeNull(); serviceProviderFeeAddedToTransactionEvent.AggregateId.ShouldBe(TestData.TransactionId); - serviceProviderFeeAddedToTransactionEvent.EventCreatedDateTime.ShouldNotBe(DateTime.MinValue); serviceProviderFeeAddedToTransactionEvent.EventId.ShouldNotBe(Guid.Empty); serviceProviderFeeAddedToTransactionEvent.TransactionId.ShouldBe(TestData.TransactionId); serviceProviderFeeAddedToTransactionEvent.EstateId.ShouldBe(TestData.EstateId); diff --git a/TransactionProcessor.TransactionAgrgegate/TransactionAggregate.cs b/TransactionProcessor.TransactionAgrgegate/TransactionAggregate.cs index 68cee9d7..32df2cb2 100644 --- a/TransactionProcessor.TransactionAgrgegate/TransactionAggregate.cs +++ b/TransactionProcessor.TransactionAgrgegate/TransactionAggregate.cs @@ -7,6 +7,7 @@ using System.Text.RegularExpressions; using Models; using Shared.DomainDrivenDesign.EventSourcing; + using Shared.EventStore.Aggregate; using Shared.EventStore.EventStore; using Shared.General; using Transaction.DomainEvents; @@ -14,7 +15,7 @@ /// /// /// - /// + /// /// public class TransactionAggregate : Aggregate { @@ -288,11 +289,11 @@ public void AddFee(CalculatedFee calculatedFee) this.CheckTransactionHasBeenCompleted(); this.CheckTransactionCanAttractFees(); - DomainEvent @event = null; + DomainEventRecord.DomainEvent @event = null; if (calculatedFee.FeeType == FeeType.Merchant) { // This is a merchant fee - @event = MerchantFeeAddedToTransactionEvent.Create(this.AggregateId, + @event = new MerchantFeeAddedToTransactionEvent(this.AggregateId, this.EstateId, this.MerchantId, calculatedFee.CalculatedValue, @@ -303,7 +304,7 @@ public void AddFee(CalculatedFee calculatedFee) else if (calculatedFee.FeeType == FeeType.ServiceProvider) { // This is an operational (service provider) fee - @event = ServiceProviderFeeAddedToTransactionEvent.Create(this.AggregateId, + @event = new ServiceProviderFeeAddedToTransactionEvent(this.AggregateId, this.EstateId, this.MerchantId, calculatedFee.CalculatedValue, @@ -318,7 +319,7 @@ public void AddFee(CalculatedFee calculatedFee) if (@event != null) { - this.ApplyAndPend(@event); + this.ApplyAndAppend(@event); } } @@ -338,9 +339,9 @@ public void AddProductDetails(Guid contractId, this.CheckProductDetailsNotAlreadyAdded(); ProductDetailsAddedToTransactionEvent productDetailsAddedToTransactionEvent = - ProductDetailsAddedToTransactionEvent.Create(this.AggregateId, this.EstateId, this.MerchantId, contractId, productId); + new ProductDetailsAddedToTransactionEvent(this.AggregateId, this.EstateId, this.MerchantId, contractId, productId); - this.ApplyAndPend(productDetailsAddedToTransactionEvent); + this.ApplyAndAppend(productDetailsAddedToTransactionEvent); } /// @@ -364,7 +365,7 @@ public void AuthoriseTransaction(String operatorIdentifier, this.CheckTransactionHasBeenStarted(); this.CheckTransactionNotAlreadyAuthorised(); - TransactionAuthorisedByOperatorEvent transactionAuthorisedByOperatorEvent = TransactionAuthorisedByOperatorEvent.Create(this.AggregateId, + TransactionAuthorisedByOperatorEvent transactionAuthorisedByOperatorEvent = new TransactionAuthorisedByOperatorEvent(this.AggregateId, this.EstateId, this.MerchantId, operatorIdentifier, @@ -374,7 +375,7 @@ public void AuthoriseTransaction(String operatorIdentifier, operatorTransactionId, responseCode, responseMessage); - this.ApplyAndPend(transactionAuthorisedByOperatorEvent); + this.ApplyAndAppend(transactionAuthorisedByOperatorEvent); } /// @@ -391,9 +392,9 @@ public void AuthoriseTransactionLocally(String authorisationCode, this.CheckTransactionNotAlreadyAuthorised(); this.CheckTransactionCanBeLocallyAuthorised(); TransactionHasBeenLocallyAuthorisedEvent transactionHasBeenLocallyAuthorisedEvent = - TransactionHasBeenLocallyAuthorisedEvent.Create(this.AggregateId, this.EstateId, this.MerchantId, authorisationCode, responseCode, responseMessage); + new TransactionHasBeenLocallyAuthorisedEvent(this.AggregateId, this.EstateId, this.MerchantId, authorisationCode, responseCode, responseMessage); - this.ApplyAndPend(transactionHasBeenLocallyAuthorisedEvent); + this.ApplyAndAppend(transactionHasBeenLocallyAuthorisedEvent); } /// @@ -406,7 +407,7 @@ public void CompleteTransaction() this.CheckTransactionNotAlreadyCompleted(); TransactionHasBeenCompletedEvent transactionHasBeenCompletedEvent = - TransactionHasBeenCompletedEvent.Create(this.AggregateId, + new TransactionHasBeenCompletedEvent(this.AggregateId, this.EstateId, this.MerchantId, this.ResponseCode, @@ -415,7 +416,7 @@ public void CompleteTransaction() this.TransactionDateTime, this.TransactionType != TransactionType.Logon ? this.TransactionAmount : null); - this.ApplyAndPend(transactionHasBeenCompletedEvent); + this.ApplyAndAppend(transactionHasBeenCompletedEvent); } /// @@ -447,7 +448,7 @@ public void DeclineTransaction(String operatorIdentifier, this.CheckTransactionNotAlreadyDeclined(); TransactionDeclinedByOperatorEvent transactionDeclinedByOperatorEvent = - TransactionDeclinedByOperatorEvent.Create(this.AggregateId, + new TransactionDeclinedByOperatorEvent(this.AggregateId, this.EstateId, this.MerchantId, operatorIdentifier, @@ -455,7 +456,7 @@ public void DeclineTransaction(String operatorIdentifier, operatorResponseMessage, responseCode, responseMessage); - this.ApplyAndPend(transactionDeclinedByOperatorEvent); + this.ApplyAndAppend(transactionDeclinedByOperatorEvent); } /// @@ -470,9 +471,9 @@ public void DeclineTransactionLocally(String responseCode, this.CheckTransactionNotAlreadyAuthorised(); this.CheckTransactionNotAlreadyDeclined(); TransactionHasBeenLocallyDeclinedEvent transactionHasBeenLocallyDeclinedEvent = - TransactionHasBeenLocallyDeclinedEvent.Create(this.AggregateId, this.EstateId, this.MerchantId, responseCode, responseMessage); + new TransactionHasBeenLocallyDeclinedEvent(this.AggregateId, this.EstateId, this.MerchantId, responseCode, responseMessage); - this.ApplyAndPend(transactionHasBeenLocallyDeclinedEvent); + this.ApplyAndAppend(transactionHasBeenLocallyDeclinedEvent); } /// @@ -499,9 +500,9 @@ public void RecordAdditionalRequestData(String operatorIdentifier, this.CheckAdditionalRequestDataNotAlreadyRecorded(); AdditionalRequestDataRecordedEvent additionalRequestDataRecordedEvent = - AdditionalRequestDataRecordedEvent.Create(this.AggregateId, this.EstateId, this.MerchantId, operatorIdentifier, additionalTransactionRequestMetadata); + new AdditionalRequestDataRecordedEvent(this.AggregateId, this.EstateId, this.MerchantId, operatorIdentifier, additionalTransactionRequestMetadata); - this.ApplyAndPend(additionalRequestDataRecordedEvent); + this.ApplyAndAppend(additionalRequestDataRecordedEvent); } /// @@ -516,9 +517,9 @@ public void RecordAdditionalResponseData(String operatorIdentifier, this.CheckAdditionalResponseDataNotAlreadyRecorded(); AdditionalResponseDataRecordedEvent additionalResponseDataRecordedEvent = - AdditionalResponseDataRecordedEvent.Create(this.AggregateId, this.EstateId, this.MerchantId, operatorIdentifier, additionalTransactionResponseMetadata); + new AdditionalResponseDataRecordedEvent(this.AggregateId, this.EstateId, this.MerchantId, operatorIdentifier, additionalTransactionResponseMetadata); - this.ApplyAndPend(additionalResponseDataRecordedEvent); + this.ApplyAndAppend(additionalResponseDataRecordedEvent); } /// @@ -531,9 +532,9 @@ public void RequestEmailReceipt(String customerEmailAddress) this.CheckCustomerHasNotAlreadyRequestedEmailReceipt(); CustomerEmailReceiptRequestedEvent customerEmailReceiptRequestedEvent = - CustomerEmailReceiptRequestedEvent.Create(this.AggregateId, this.EstateId, this.MerchantId, customerEmailAddress); + new CustomerEmailReceiptRequestedEvent(this.AggregateId, this.EstateId, this.MerchantId, customerEmailAddress); - this.ApplyAndPend(customerEmailReceiptRequestedEvent); + this.ApplyAndAppend(customerEmailReceiptRequestedEvent); } /// @@ -589,7 +590,7 @@ public void StartTransaction(DateTime transactionDateTime, this.CheckTransactionNotAlreadyStarted(); this.CheckTransactionNotAlreadyCompleted(); - TransactionHasStartedEvent transactionHasStartedEvent = TransactionHasStartedEvent.Create(this.AggregateId, + TransactionHasStartedEvent transactionHasStartedEvent = new TransactionHasStartedEvent(this.AggregateId, estateId, merchantId, transactionDateTime, @@ -599,7 +600,7 @@ public void StartTransaction(DateTime transactionDateTime, deviceIdentifier, transactionAmount); - this.ApplyAndPend(transactionHasStartedEvent); + this.ApplyAndAppend(transactionHasStartedEvent); } /// @@ -619,7 +620,7 @@ protected override Object GetMetadata() /// Plays the event. /// /// The domain event. - protected override void PlayEvent(DomainEvent domainEvent) + public override void PlayEvent(IDomainEvent domainEvent) { this.PlayEvent((dynamic)domainEvent); } diff --git a/TransactionProcessor.TransactionAgrgegate/TransactionProcessor.TransactionAggregate.csproj b/TransactionProcessor.TransactionAgrgegate/TransactionProcessor.TransactionAggregate.csproj index 2adff2ac..b7a856a9 100644 --- a/TransactionProcessor.TransactionAgrgegate/TransactionProcessor.TransactionAggregate.csproj +++ b/TransactionProcessor.TransactionAgrgegate/TransactionProcessor.TransactionAggregate.csproj @@ -5,7 +5,7 @@ - + diff --git a/TransactionProcessor/Controllers/DomainEventController.cs b/TransactionProcessor/Controllers/DomainEventController.cs index ac2e8ca8..bba0c707 100644 --- a/TransactionProcessor/Controllers/DomainEventController.cs +++ b/TransactionProcessor/Controllers/DomainEventController.cs @@ -7,24 +7,44 @@ namespace TransactionProcessor.Controllers { using System.Diagnostics.CodeAnalysis; using System.Threading; - using MessagingService.BusinessLogic.EventHandling; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Shared.DomainDrivenDesign.EventSourcing; + using Shared.EventStore.Aggregate; + using Shared.EventStore.EventHandling; + using Shared.General; using Shared.Logger; + using Shared.Serialisation; [Route(DomainEventController.ControllerRoute)] [ApiController] [ExcludeFromCodeCoverage] public class DomainEventController : ControllerBase { + #region Fields + + /// + /// The domain event handler resolver + /// private readonly IDomainEventHandlerResolver DomainEventHandlerResolver; + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The domain event handler resolver. public DomainEventController(IDomainEventHandlerResolver domainEventHandlerResolver) { this.DomainEventHandlerResolver = domainEventHandlerResolver; } + #endregion + + #region Methods + /// /// Posts the event asynchronous. /// @@ -32,9 +52,11 @@ public DomainEventController(IDomainEventHandlerResolver domainEventHandlerResol /// The cancellation token. /// [HttpPost] - public async Task PostEventAsync([FromBody] DomainEvent domainEvent, + public async Task PostEventAsync([FromBody] Object request, CancellationToken cancellationToken) { + var domainEvent = await this.GetDomainEvent(request); + cancellationToken.Register(() => this.Callback(cancellationToken, domainEvent.EventId)); try @@ -86,6 +108,51 @@ private void Callback(CancellationToken cancellationToken, } } + /// + /// Gets the domain event. + /// + /// The domain event. + /// + private async Task GetDomainEvent(Object domainEvent) + { + String eventType = this.Request.Query["eventType"].ToString(); + + var type = TypeMap.GetType(eventType); + + if (type == null) + throw new Exception($"Failed to find a domain event with type {eventType}"); + + JsonIgnoreAttributeIgnorerContractResolver jsonIgnoreAttributeIgnorerContractResolver = new JsonIgnoreAttributeIgnorerContractResolver(); + var jsonSerialiserSettings = new JsonSerializerSettings + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore, + TypeNameHandling = TypeNameHandling.All, + Formatting = Formatting.Indented, + DateTimeZoneHandling = DateTimeZoneHandling.Utc, + ContractResolver = jsonIgnoreAttributeIgnorerContractResolver + }; + + if (type.IsSubclassOf(typeof(DomainEventRecord.DomainEvent))) + { + var json = JsonConvert.SerializeObject(domainEvent, jsonSerialiserSettings); + DomainEventRecordFactory domainEventFactory = new(); + + return domainEventFactory.CreateDomainEvent(json, type); + } + + if (type.IsSubclassOf(typeof(DomainEvent))) + { + var json = JsonConvert.SerializeObject(domainEvent, jsonSerialiserSettings); + DomainEventFactory domainEventFactory = new(); + + return domainEventFactory.CreateDomainEvent(json, type); + } + + return null; + } + + #endregion + #region Others /// @@ -99,6 +166,5 @@ private void Callback(CancellationToken cancellationToken, private const String ControllerRoute = "api/" + DomainEventController.ControllerName; #endregion - } } diff --git a/TransactionProcessor/Program.cs b/TransactionProcessor/Program.cs index 5c4a8828..6c632305 100644 --- a/TransactionProcessor/Program.cs +++ b/TransactionProcessor/Program.cs @@ -11,6 +11,11 @@ namespace TransactionProcessor { using System.Diagnostics.CodeAnalysis; using System.IO; + using Microsoft.Extensions.DependencyInjection; + using Reconciliation.DomainEvents; + using Shared.EventStore.Aggregate; + using Shared.EventStore.Subscriptions; + using Transaction.DomainEvents; [ExcludeFromCodeCoverage] public class Program @@ -36,7 +41,19 @@ public static IHostBuilder CreateHostBuilder(string[] args) webBuilder.UseStartup(); webBuilder.UseConfiguration(config); webBuilder.UseKestrel(); - }); + }) + .ConfigureServices(services => + { + TransactionHasStartedEvent t = new TransactionHasStartedEvent(Guid.Parse("2AA2D43B-5E24-4327-8029-1135B20F35CE"), Guid.NewGuid(),Guid.NewGuid(), + DateTime.Now, "","","","",null); + + ReconciliationHasStartedEvent r = + new ReconciliationHasStartedEvent(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), DateTime.Now); + + TypeProvider.LoadDomainEventsTypeDynamically(); + + services.AddHostedService(); + }); return hostBuilder; } diff --git a/TransactionProcessor/Startup.cs b/TransactionProcessor/Startup.cs index cc804abf..5aa126e6 100644 --- a/TransactionProcessor/Startup.cs +++ b/TransactionProcessor/Startup.cs @@ -30,7 +30,6 @@ namespace TransactionProcessor using EventStore.Client; using HealthChecks.UI.Client; using MediatR; - using MessagingService.BusinessLogic.EventHandling; using MessagingService.Client; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Diagnostics.HealthChecks; @@ -45,8 +44,12 @@ namespace TransactionProcessor using NLog.Extensions.Logging; using SecurityService.Client; using Shared.DomainDrivenDesign.CommandHandling; + using Shared.DomainDrivenDesign.EventSourcing; using Shared.EntityFramework.ConnectionStringConfiguration; + using Shared.EventStore.Aggregate; + using Shared.EventStore.EventHandling; using Shared.EventStore.EventStore; + using Shared.EventStore.Extensions; using Shared.Extensions; using Shared.General; using Shared.Logger; @@ -142,13 +145,14 @@ public void ConfigureServices(IServiceCollection services) else { services.AddEventStoreClient(Startup.ConfigureEventStoreSettings); - services.AddEventStoreProjectionManagerClient(Startup.ConfigureEventStoreSettings); + services.AddEventStoreProjectionManagementClient(Startup.ConfigureEventStoreSettings); + services.AddEventStorePersistentSubscriptionsClient(Startup.ConfigureEventStoreSettings); } services.AddTransient(); services.AddSingleton(); - services.AddSingleton, AggregateRepository>(); - services.AddSingleton, AggregateRepository>(); + services.AddSingleton, AggregateRepository>(); + services.AddSingleton, AggregateRepository>(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); @@ -371,6 +375,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF Logger.Initialise(logger); + foreach (KeyValuePair type in TypeMap.Map) + { + Logger.LogInformation($"Type name {type.Value} mapped to {type.Key.Name}"); + } + app.AddRequestLogging(); app.AddResponseLogging(); app.AddExceptionHandler(); diff --git a/TransactionProcessor/TransactionProcessor.csproj b/TransactionProcessor/TransactionProcessor.csproj index 3fc1c957..900aa5bd 100644 --- a/TransactionProcessor/TransactionProcessor.csproj +++ b/TransactionProcessor/TransactionProcessor.csproj @@ -11,6 +11,8 @@ + + @@ -25,7 +27,7 @@ - + diff --git a/TransactionProcessor/appsettings.json b/TransactionProcessor/appsettings.json index 2fbb1942..e507aa29 100644 --- a/TransactionProcessor/appsettings.json +++ b/TransactionProcessor/appsettings.json @@ -12,12 +12,15 @@ "UserName": "admin", "Password": "changeit", "START_PROJECTIONS": false, - "ContinuousProjectionsFolder": "" + "ContinuousProjectionsFolder": "", + "TcpPort": 1113, + "PersistentSubscriptionPollingInSeconds": 30 }, "ConnectionStrings": { //"ConnectionStringConfiguration": "server=192.168.1.133;database=ConnectionStringConfiguration;user id=sa;password=Sc0tland" }, "AppSettings": { + "SubscriptionFilter": "Transaction Processor", "HandlerEventTypesToSilentlyHandle": { }, "UseConnectionStringConfig": false, @@ -29,10 +32,10 @@ "ClientSecret": "d192cbc46d834d0da90e8a9d50ded543", "EventHandlerConfiguration": { "TransactionProcessor.Transaction.DomainEvents.TransactionHasBeenCompletedEvent": [ - "TransactionProcessor.BusinessLogic.EventHandling.TransactionDomainEventHandler" + "TransactionProcessor.BusinessLogic.EventHandling.TransactionDomainEventHandler,TransactionProcessor.BusinessLogic" ], "TransactionProcessor.Transaction.DomainEvents.CustomerEmailReceiptRequestedEvent": [ - "TransactionProcessor.BusinessLogic.EventHandling.TransactionDomainEventHandler" + "TransactionProcessor.BusinessLogic.EventHandling.TransactionDomainEventHandler,TransactionProcessor.BusinessLogic" ] } },