public void TestApplyDiscount(decimal priceShouldBe, int quantity) { var boughtItem = new BoughtItem(); var calculationService = new CalculationService(); boughtItem.Quantity = quantity; calculationService.ApplyDiscount(boughtItem); boughtItem.Price.Should().Be(priceShouldBe); }
public void BuyItem(T item, int id, int qty) { var itemWantToBuy = _context.Set <T>().Where(i => i.Id == id).SingleOrDefault(); if (itemWantToBuy != null) { var boughtItem = _mapper.Map <BoughtItem>(itemWantToBuy); boughtItem.Quantity = qty; _calculationService.ApplyDiscount(boughtItem); _calculationService.CalculateTotalPrice(boughtItem); _context.BoughtItems.Add(boughtItem); _context.SaveChanges(); } else { throw new Exception(); } }