public void SpecialsAppliedForMultipleProductsAndProductPricesAppliedCorrectlyForItemsMoreThanOne() { // Arrange var calculateTrolleyQuery = new CalculateTrolleyQuery { Products = new List <Product> { new Product("Product 1", 14.5), new Product("Product 2", 29.6), new Product("Product 3", 24) }, Specials = new List <Special> { new Special(new List <Quantity> { new Quantity("Product 1", 3), new Quantity("Product 2", 3) }, 20) }, Quantities = new List <Quantity> { new Quantity("Product 1", 5), new Quantity("Product 2", 5) } }; // Act var total = new CalculateTrolleyQueryHandler().Handle(calculateTrolleyQuery); // Assert total.Should().Be(108.2); }
public void SpecialsAppliedForMultipleProducts() { // Arrange var calculateTrolleyQuery = new CalculateTrolleyQuery { Products = new List <Product> { new Product("Product 1", 14.5), new Product("Product 2", 29.6), new Product("Product 3", 24) }, Specials = new List <Special> { new Special(new List <Quantity> { new Quantity("Product 1", 3), new Quantity("Product 2", 3) }, 20) }, Quantities = new List <Quantity> { new Quantity("Product 1", 4), new Quantity("Product 2", 4) } }; // Act var total = new CalculateTrolleyQueryHandler().Handle(calculateTrolleyQuery); // Assert total.Should().Be(64.1d); }
public void InValidPurchasedQuantities() { // Arrange var calculateTrolleyQuery = new CalculateTrolleyQuery { Products = new List <Product> { new Product("Product 1", 14.5), new Product("Product 2", 29.6), new Product("Product 3", 24) }, Specials = new List <Special> { new Special(new List <Quantity> { new Quantity("Product 1", 3), new Quantity("Product 2", 3) }, 20) }, Quantities = new List <Quantity> { new Quantity("Product 3", 1), new Quantity("Product 3", 1), } }; // Act // Assert Assert.Throws <ArgumentException>(() => new CalculateTrolleyQueryHandler().Handle(calculateTrolleyQuery)); }
public void ShouldApplySpecialForOneProduct() { // Arrange var calculateTrolleyQuery = new CalculateTrolleyQuery { Products = new List <Product> { new Product("Product 1", 14.5), new Product("Product 2", 29.6) }, Specials = new List <Special> { new Special(new List <Quantity> { new Quantity("Product 1", 3) }, 20) }, Quantities = new List <Quantity> { new Quantity("Product 1", 3) } }; // Act var total = new CalculateTrolleyQueryHandler().Handle(calculateTrolleyQuery); // Assert total.Should().Be(20.0d); }
public async Task <decimal> GetTotal(CalculateTrolleyQuery request) { var uri = API.GetTotal(_userOption.Token); var response = await _httpClient.PostAsync(uri, new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json")); if (!response.IsSuccessStatusCode) { throw new HttpRequestException($"Post to calculate trolley fails. Msg:{response.ReasonPhrase}"); } var total = Convert.ToDecimal(await response.Content.ReadAsStringAsync()); return(total); }
public async Task <ActionResult> GetTotal(CalculateTrolleyQuery query) { var totalAmount = await Mediator.Send(query); return(Ok(totalAmount)); }
public ActionResult <double> TrolleyTotal([FromBody] CalculateTrolleyQuery query) { return(Ok(_calculateTrolleyQueryHandler.Handle(query))); }