public void TestCalculateTotalPrice() { //Arange var boughtItem = new BoughtItem(); var calculationService = new CalculationService(); //Act calculationService.CalculateTotalPrice(boughtItem); //Assert boughtItem.TotalPrice.Should().Be(300); }
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(); } }