public void Test_Order_CancelProducesProductReleaseEvents() { OrderAggregate oa = new OrderAggregate("order-1-1"); var productAggs = FakeAggs(); var evts = oa.Cancel("tester", productAggs); Assert.Equal(3, evts.Count); Assert.IsType <OrderCanceledEvent>(evts[0]); Assert.IsType <InventoryReleasedEvent>(evts[1]); Assert.IsType <InventoryReleasedEvent>(evts[2]); }
public override Task <CancelOrderResponse> CancelOrder(CancelOrderRequest request, grpc::ServerCallContext context) { logger.LogInformation("Handling Order cancellation request"); var result = new CancelOrderResponse(); try { var agg = new OrderAggregate(request.OrderID); // TODO: load aggregate with order events var exists = orderManagementClient.OrderExists(new GetOrderRequest { OrderID = request.OrderID }); if (!exists.Exists) { result.Canceled = false; return(Task.FromResult(result)); } var originalOrder = orderManagementClient.GetOrder(new GetOrderRequest { OrderID = request.OrderID }); var productAggregates = GetProductAggregates(originalOrder.LineItems.ToArray()); IList <DomainEvent> evts = agg.Cancel(request.UserID, productAggregates); foreach (var evt in evts) { this.eventEmitter.Emit(evt); } result.Canceled = true; result.ConfirmationCode = Guid.NewGuid().ToString(); // unused return(Task.FromResult(result)); } catch (Exception ex) { logger.LogError(ex, "Failed to cancel order"); result.Canceled = false; return(Task.FromResult(result)); } }