public async Task ReceiptEngine_GenerateReceiptAsync_InputOne_StringReturnedAsExpected() { var productList = CreateCompleteProductList(); var receiptRequest = CreateRequestForInputOne(); var expectedResponse = CreateResponseStringForInputOne(); SetupStrategyMockForInputOne(productList); _productRepositoryMock.Setup(x => x.GetAllProductsAsync()).ReturnsAsync(productList); var actualResponse = await _receiptEngine.GenerateReceiptAsync(receiptRequest).ConfigureAwait(false); Assert.AreEqual(expectedResponse, actualResponse, "Expected strings to be the same."); }
public async Task <ActionResult <string> > GetReceiptForCheckOutAsync(IEnumerable <ReceiptRequest> receiptRequest) { try { if (receiptRequest == null || !receiptRequest.Any()) { return(BadRequest("There must be at least on product in order to generate receipt")); } if (receiptRequest.Any(r => r.ProductId <= 0)) { return(BadRequest("Product id needs to be greater than 0 in order to generate a receipt")); } if (receiptRequest.Any(r => r.Quantity <= 0)) { return(BadRequest("Product need quantity greater than 0 in order to generate a receipt")); } return(StatusCode(201, await _receiptEngine.GenerateReceiptAsync(receiptRequest).ConfigureAwait(false))); } catch (Exception exception) when(exception is SqlException || exception is ArgumentNullException || exception is InvalidOperationException || exception is InvalidCastException || exception is ArgumentOutOfRangeException) { Logger.LogError(exception, "An error occurred while retrieving receipt."); return(StatusCode(500, "Sorry an error occurred processing your request.")); } }