public void TryOrder_Unavailable_Returns_Empty() { // Execute var maybeProduct = OrderBehavior.TryOrder(new Product { AvailableUnits = 0 }, 1); // Check var result = maybeProduct.Match(p => p, null); Assert.Null(result); }
public async Task <IActionResult> Order(OrderCommand orderCommand) { return(await // Try to generate an order from maybeOrder in from product in _repository.FindByIdAsync(orderCommand.ProductId) select OrderBehavior.TryOrder(product, orderCommand.Quantity) // Update the DB from result in maybeOrder.AwaitSideEffect(_repository.UpdateAsync) // Return results select result.Match <IActionResult>( Ok, StatusCode(500, new { Error = "No available units." }))); }
public void TryOrder_Unavailable_Returns_Product() { // Prepare var sourceProduct = new Product { AvailableUnits = 1 }; // Execute var maybeProduct = OrderBehavior.TryOrder(sourceProduct, 1); // Check var result = maybeProduct.Match(p => p, null); Assert.NotNull(result); Assert.NotEqual(sourceProduct, result); Assert.Equal(0, result.AvailableUnits); }