public void When_Quantity_IsMoreThanStock() { GetProductInfoOutput getProductInfoOutput = new GetProductInfoOutput { Price = 100, Stock = 10 }; mockProductService.Setup(x => x.GetProductInfo("P1")).Returns(getProductInfoOutput); CreateOrderInput createOrderInput = new CreateOrderInput { ProductCode = "P1", Quantity = 20 }; Assert.Throws <InsufficientProductInStockException>(() => orderService.CreateOrder(createOrderInput)); }
private GetProductInfoOutput ParseGetProductInfoResponse(Product product) { var getProductInfoOutput = new GetProductInfoOutput(); var campaignInfo = _campaignService.GetCampaignInfoByProductCode(product.Code); if (campaignInfo != null && campaignInfo.Status == (int)Dto.CampaignStatusEnum.Active) { getProductInfoOutput.Price = product.Price + product.Discount; getProductInfoOutput.CampaignId = campaignInfo.Id; } else { getProductInfoOutput.Price = product.Price; } getProductInfoOutput.Stock = product.Stock; return(getProductInfoOutput); }
public void When_CreateOrder_IsSuccessful() { Product product = new Product("P1", 100, 1000); GetProductInfoOutput getProductInfoOutput = new GetProductInfoOutput { Price = 100, Stock = 1000 }; mockProductService.Setup(x => x.GetProductInfo("P1")).Returns(getProductInfoOutput); CreateOrderInput createOrderInput = new CreateOrderInput { ProductCode = "P1", Quantity = 10 }; Assert.DoesNotThrow(() => orderService.CreateOrder(createOrderInput)); mockOrderRepository.Verify(x => x.CreateOrder(It.IsAny <Order>()), Times.Once()); }