public async Task ShouldMakeCustomersPreferredStatusToGold() { var customerId = Guid.NewGuid(); var flightPlanWasAdded = new FlightPlanWasAdded { CustomerId = customerId, MilesFlown = 25000 }; var customerWasBilled = new CustomerWasBilled { CustomerId = customerId, DollarsPaid = 3000 }; await saga.Handle(flightPlanWasAdded, context); await saga.Handle(customerWasBilled, context); await saga.Timeout(new CalendarYearHasStarted(), context); await Verifier.Verify( new { context, saga.Data }); }
public async Task WaitForCalendarYearBeforeUpgradingPreferredStatusToGold() { var customerId = Guid.NewGuid(); var flightPlanWasAdded = new FlightPlanWasAdded { CustomerId = customerId, MilesFlown = 25000 }; var customerWasBilled = new CustomerWasBilled { CustomerId = customerId, DollarsPaid = 3000 }; await saga.Handle(flightPlanWasAdded, context); await saga.Handle(customerWasBilled, context); // also test how long the timeout was supposed to be. await Verifier.Verify( new { context, saga.Data }); }
public async Task Handle(CustomerWasBilled message, IMessageHandlerContext context) { Console.WriteLine($"New billing info was received for {message.CustomerId}, dollars = {message.DollarsPaid}"); Data.CustomerId = message.CustomerId; Data.TotalDollarsPaid += message.DollarsPaid; if (CanCustomerBePromotedToGold()) { Console.WriteLine($"Customer {message.CustomerId} can be promoted in the next calendar year...Waiting..."); await RequestTimeout(context, TimeSpan.FromSeconds(15), new CalendarYearHasStarted()).ConfigureAwait(false); } }
public async Task Handle(CustomerWasBilled message, IMessageHandlerContext context) { Console.WriteLine($"New billing info was received for {message.CustomerId}, dollars = {message.DollarsPaid}"); Data.CustomerId = message.CustomerId; Data.TotalDollarsPaid += message.DollarsPaid; if (CanCustomerBePromotedToGold()) { await context.Publish( new CustomerWasPromotedToGold { CustomerId = message.CustomerId }) .ConfigureAwait(false); MarkAsComplete(); } }
public async Task ShouldNotMakeCustomersPreferredStatusToGoldWhenNotEnoughMilesHasBeenFlown() { var customerId = Guid.NewGuid(); var flightPlanWasAdded = new FlightPlanWasAdded { CustomerId = customerId, MilesFlown = 2500 }; var customerWasBilled = new CustomerWasBilled { CustomerId = customerId, DollarsPaid = 3500 }; await saga.Handle(flightPlanWasAdded, context); await saga.Handle(customerWasBilled, context); await Verifier.Verify( new { context, saga.Data }); }
static async Task Main() { LogManager.Use <DefaultFactory>() .Level(LogLevel.Info); var endpointConfiguration = new EndpointConfiguration("PreferredCustomerPolicy"); endpointConfiguration.UseSerialization <NewtonsoftSerializer>(); endpointConfiguration.Recoverability().Delayed(c => c.NumberOfRetries(0)); endpointConfiguration.UseTransport <LearningTransport>(); endpointConfiguration.UsePersistence <InMemoryPersistence>(); endpointConfiguration.SendFailedMessagesTo("error"); endpointConfiguration.AuditProcessedMessagesTo("audit"); endpointConfiguration.EnableInstallers(); // Send saga state change and heartbeats to ServiceControl for visualization and monitoring. endpointConfiguration.AuditSagaStateChanges("Particular.ServiceControl"); endpointConfiguration.SendHeartbeatTo("Particular.ServiceControl"); // start the endpoint var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false); Console.WriteLine("Press f to publish flight plan added."); Console.WriteLine("Press b to publish customer was billed added."); Console.WriteLine("Press ENTER to exit"); var guid = Guid.NewGuid(); while (true) { var key = Console.ReadKey(); Console.WriteLine(); if (key.Key == ConsoleKey.Enter) { break; } if (key.Key == ConsoleKey.F) { Console.WriteLine($"Publishing flight plan for CustomerId id: {guid:N}"); var message = new FlightPlanWasAdded { CustomerId = guid, MilesFlown = 10000 }; await endpointInstance.Publish(message) .ConfigureAwait(false); } if (key.Key == ConsoleKey.B) { Console.WriteLine($"Publishing CustomerWasBilled for CustomerId id: {guid:N}"); var billedEvent = new CustomerWasBilled { CustomerId = guid, DollarsPaid = 2500 }; await endpointInstance.Publish(billedEvent) .ConfigureAwait(false); } } await endpointInstance.Stop() .ConfigureAwait(false); }