public static void LoadTypes() { VoucherIssuedEvent v = new VoucherIssuedEvent(Guid.NewGuid(), Guid.NewGuid(), DateTime.Now, "", ""); 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); EstateCreatedEvent e = new EstateCreatedEvent(Guid.NewGuid(), ""); MerchantCreatedEvent m = new MerchantCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), "", DateTime.Now); ContractCreatedEvent c = new ContractCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), ""); MerchantBalanceChangedEvent mb = new MerchantBalanceChangedEvent(Guid.NewGuid(), Guid.NewGuid(), DateTime.Now, Guid.NewGuid(), Guid.NewGuid(), 0, 0, 0, ""); ImportLogCreatedEvent i = new ImportLogCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), DateTime.MinValue); FileCreatedEvent f = new FileCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), String.Empty, DateTime.MinValue); SettlementCreatedForDateEvent s = new SettlementCreatedForDateEvent(Guid.NewGuid(), Guid.NewGuid(), DateTime.Now); StatementCreatedEvent ms = new StatementCreatedEvent(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), DateTime.Now); TypeProvider.LoadDomainEventsTypeDynamically(); }
/// <summary> /// Plays the event. /// </summary> /// <param name="domainEvent">The domain event.</param> private void PlayEvent(VoucherIssuedEvent domainEvent) { this.IsIssued = true; this.IssuedDateTime = domainEvent.IssuedDateTime; this.RecipientEmail = domainEvent.RecipientEmail; this.RecipientMobile = domainEvent.RecipientMobile; this.Balance = this.Value; }
public void TransactionDomainEventHandler_VoucherIssuedEvent_EventIsHandled() { VoucherIssuedEvent voucherIssuedEvent = TestData.VoucherIssuedEvent; Mock <IEstateReportingRepository> estateReportingRepository = new Mock <IEstateReportingRepository>(); TransactionDomainEventHandler eventHandler = new TransactionDomainEventHandler(estateReportingRepository.Object); Logger.Initialise(NullLogger.Instance); Should.NotThrow(async() => { await eventHandler.Handle(voucherIssuedEvent, CancellationToken.None); }); }
public void VoucherIssuedEvent_CanBeCreated_IsCreated() { VoucherIssuedEvent voucherIssuedEvent = new VoucherIssuedEvent(TestData.VoucherId, TestData.EstateId, TestData.IssuedDateTime, TestData.RecipientEmail, TestData.RecipientMobile); voucherIssuedEvent.ShouldNotBeNull(); voucherIssuedEvent.AggregateId.ShouldBe(TestData.VoucherId); voucherIssuedEvent.EventId.ShouldNotBe(Guid.Empty); voucherIssuedEvent.VoucherId.ShouldBe(TestData.VoucherId); voucherIssuedEvent.EstateId.ShouldBe(TestData.EstateId); voucherIssuedEvent.RecipientEmail.ShouldBe(TestData.RecipientEmail); voucherIssuedEvent.RecipientMobile.ShouldBe(TestData.RecipientMobile); voucherIssuedEvent.IssuedDateTime.ShouldBe(TestData.IssuedDateTime); }
/// <summary> /// Handles the specific domain event. /// </summary> /// <param name="domainEvent">The domain event.</param> /// <param name="cancellationToken">The cancellation token.</param> private async Task HandleSpecificDomainEvent(VoucherIssuedEvent domainEvent, CancellationToken cancellationToken) { // Get the voucher aggregate VoucherAggregate voucherAggregate = await this.VoucherAggregateRepository.GetLatestVersion(domainEvent.AggregateId, cancellationToken); Voucher voucherModel = voucherAggregate.GetVoucher(); this.TokenResponse = await this.GetToken(cancellationToken); if (string.IsNullOrEmpty(voucherModel.RecipientEmail) == false) { String message = await this.GetEmailVoucherMessage(voucherModel, cancellationToken); SendEmailRequest request = new SendEmailRequest { Body = message, ConnectionIdentifier = domainEvent.EstateId, FromAddress = "*****@*****.**", // TODO: lookup from config IsHtml = true, MessageId = domainEvent.EventId, Subject = "Voucher Issue", ToAddresses = new List <String> { voucherModel.RecipientEmail } }; await this.MessagingServiceClient.SendEmail(this.TokenResponse.AccessToken, request, cancellationToken); } if (String.IsNullOrEmpty(voucherModel.RecipientMobile) == false) { String message = await this.GetSMSVoucherMessage(voucherModel, cancellationToken); SendSMSRequest request = new SendSMSRequest { ConnectionIdentifier = domainEvent.EstateId, Destination = domainEvent.RecipientMobile, Message = message, MessageId = domainEvent.EventId, Sender = "Your Voucher" }; await this.MessagingServiceClient.SendSMS(this.TokenResponse.AccessToken, request, cancellationToken); } }
/// <summary> /// Issues the specified recipient email. /// </summary> /// <param name="recipientEmail">The recipient email.</param> /// <param name="recipientMobile">The recipient mobile.</param> /// <param name="issuedDateTime">The issued date time.</param> /// <exception cref="ArgumentNullException"></exception> public void Issue(String recipientEmail, String recipientMobile, DateTime issuedDateTime) { this.CheckIfVoucherHasBeenGenerated(); if (string.IsNullOrEmpty(recipientEmail) && string.IsNullOrEmpty(recipientMobile)) { throw new ArgumentNullException(message: "Either Recipient Email Address or Recipient Mobile number must be set to issue a voucher", innerException: null); } this.CheckIfVoucherAlreadyIssued(); VoucherIssuedEvent voucherIssuedEvent = new VoucherIssuedEvent(this.AggregateId, this.EstateId, issuedDateTime, recipientEmail, recipientMobile); this.ApplyAndAppend(voucherIssuedEvent); }
public void DomainEventHandlerResolver_GetDomainEventHandlers_TransactionHasBeenCompletedEvent_EventHandlersReturned() { String handlerTypeName = "VoucherManagement.BusinessLogic.EventHandling.VoucherDomainEventHandler, VoucherManagement.BusinessLogic"; Dictionary <String, String[]> eventHandlerConfiguration = new Dictionary <String, String[]>(); VoucherIssuedEvent voucherIssuedEvent = TestData.VoucherIssuedEvent; eventHandlerConfiguration.Add(voucherIssuedEvent.GetType().Name, new String[] { handlerTypeName }); Mock <IDomainEventHandler> domainEventHandler = new Mock <IDomainEventHandler>(); Func <Type, IDomainEventHandler> createDomainEventHandlerFunc = (type) => { return(domainEventHandler.Object); }; DomainEventHandlerResolver resolver = new DomainEventHandlerResolver(eventHandlerConfiguration, createDomainEventHandlerFunc); List <IDomainEventHandler> handlers = resolver.GetDomainEventHandlers(voucherIssuedEvent); handlers.ShouldNotBeNull(); handlers.Any().ShouldBeTrue(); handlers.Count.ShouldBe(1); }
public static void LoadTypes() { VoucherIssuedEvent i = new VoucherIssuedEvent(Guid.NewGuid(), Guid.NewGuid(), DateTime.Now, "", ""); TypeProvider.LoadDomainEventsTypeDynamically(); }
/// <summary> /// Handles the specific domain event. /// </summary> /// <param name="domainEvent">The domain event.</param> /// <param name="cancellationToken">The cancellation token.</param> private async Task HandleSpecificDomainEvent(VoucherIssuedEvent domainEvent, CancellationToken cancellationToken) { await this.EstateReportingRepository.UpdateVoucherIssueDetails(domainEvent, cancellationToken); }