public void TestRevertOrder() { var incomeSumBefore = _incomesForProduct.Sum(x => x.QuantityCurrent); var outcome1 = new Outcome(_product.Price, 10, _incomesForProduct[0], 0); var outcome2 = new Outcome(_product.Price, 5, _incomesForProduct[1], 0); var outcomes = new List<Outcome>() {outcome1, outcome2}; var orderLine = new OrderLine(_product, 15, outcomes); _incomesForProduct[0].QuantityCurrent -= 10; _incomesForProduct[0].QuantityCurrent -= 5; Order order = new Order(outcomes, new List<OrderLine>(){orderLine}); Assert.True(order.Outcomes().Sum(x => x.Quantity) == 15); _orderService.RevertOrder(order); Assert.True(_incomesForProduct.Sum(x => x.QuantityCurrent) == incomeSumBefore); Assert.True(order.Outcomes().Count() == 0); Assert.True(order.Status.Equals(OrderStatus.Revoked)); }
public void RevertOrder(Order order) { IEnumerable<Outcome> outcomes = order.Outcomes(); foreach (Outcome outcome in outcomes) { outcome.Income.QuantityCurrent += outcome.Quantity; } order.ClearOutcomes(); order.Status = OrderStatus.Revoked; }