public void CreateReceipt_CheckProperties_ShouldReturnCorrectValueProperties() { // Assemble _cart.Products[0].Discount = Discount.Bonus; _cart.Products[0].Amount = 3; // Assign var expectedMessage = "Bedankt dat u bij de Boni bent geweest!"; var expectedProductName = "Kaas"; var expectedOriginalPrice = 4.99M; var expectedDiscount = Discount.Bonus; var expectedDiscountPrice = 3.99M; var expectedTotal = 11.98M; // Act var receipt = ReceiptService.CreateReceipt(_cart); // Assert Assert.Multiple(() => { Assert.AreEqual(expectedMessage, receipt.Message); Assert.AreEqual(expectedProductName, receipt.BoughtProducts[0].ProductName); Assert.AreEqual(expectedOriginalPrice, receipt.BoughtProducts[0].ProductPrice); Assert.AreEqual(expectedDiscount, receipt.BoughtProducts[0].Discount); Assert.AreEqual(expectedDiscountPrice, receipt.BoughtProducts[0].ProductPriceWithDiscount); Assert.AreEqual(expectedTotal, receipt.BoughtProducts[0].Total); }); }
public void CreateReceipt_NoDiscount_ShouldBeCorrectPrice() { // Act var receipt = ReceiptService.CreateReceipt(_cart); // Assert Assert.AreEqual(13.18M, receipt.TotalPrice); }
public async Task <IActionResult> Create(Receipt receipt) { ReceiptService service = new ReceiptService(_config, _httpContextAccessor); await service.CreateReceipt(receipt); var AllReceipts = await service.GetAll(); ViewBag.YourEnums = new Microsoft.AspNetCore.Mvc.Rendering.SelectList(Enum.GetValues(typeof(Currency))); return(View("Index", AllReceipts)); }
public void CreateReceipt_WithBonusAndExpiryDiscount_ShouldBeCorrectPrice() { _cart.Products[0].Discount = Discount.Bonus; _cart.Products[2].Discount = Discount.Expiry; _cart.Products[4].Discount = Discount.Bonus; // Act var receipt = ReceiptService.CreateReceipt(_cart); // Assert Assert.AreEqual(11.61M, receipt.TotalPrice); }
public ActionResult Create() { var orders = receiptService.ChangeOrderStatus(); var receipt = receiptService.CreateReceipt(User.Username, orders); var receiptOrder = receiptService.CreateReceiptOrder(receipt, orders); var userReceipt = receiptService.CreateUserReceipt(receipt); //TODO: Fix it!!! //var products = productService.GetAllProducts(); ; //receiptService.context.Entry(receiptOrder).Reload(); //Thread.Sleep(3000); var orderViewModels = receiptOrder.Orders .Select(o => new OrderViewModel { Id = o.Id, Product = o.Product.Name, Quantity = o.Quantity, Price = o.Product.Price }) .ToList(); var receiptViewModel = new ReceiptDetailsViewModel { Id = receipt.Id, Orders = orderViewModels, IssuedOn = receipt.IssuedOn.ToString("dd/MM/yyyy"), Cashier = receipt.Cashier.Username }; var total = orderViewModels.Sum(ovm => ovm.Quantity * ovm.Price); receiptViewModel.Total = total; return(View(receiptViewModel, "Details")); }
public void CreateReceipt_MultipleAmountsAndDiscount_ShouldBeCorrectPrice() { // Assemble _cart.Products[0].Discount = Discount.Bonus; _cart.Products[2].Discount = Discount.Expiry; _cart.Products[4].Discount = Discount.Bonus; _cart.Products[0].Amount = 3; _cart.Products[2].Amount = 2; _cart.Products[4].Amount = 3; // Assign var expectedTotal = 22.04M; // Act var receipt = ReceiptService.CreateReceipt(_cart); // Assert Assert.AreEqual(expectedTotal, receipt.TotalPrice); }
public void CreateReceipt_ShouldReturnCorrectDouble_WhenGivenCartNoDiscount() { // Assemble _calculateProductPriceMock.Setup(mock => mock.Calculate(_cart.Products[0], 1)).Returns(_cart.Products[0].Price); _calculateProductPriceMock.Setup(mock => mock.Calculate(_cart.Products[1], 1)).Returns(_cart.Products[1].Price); _calculateProductPriceMock.Setup(mock => mock.Calculate(_cart.Products[2], 1)).Returns(_cart.Products[2].Price); _calculateProductPriceMock.Setup(mock => mock.Calculate(_cart.Products[3], 1)).Returns(_cart.Products[3].Price); _calculateProductPriceMock.Setup(mock => mock.Calculate(_cart.Products[4], 1)).Returns(_cart.Products[4].Price); _mapperServiceMock.Setup(mock => mock.MapReceiptProduct(_cart.Products[0])). Returns(new ReceiptProduct { Amount = 1, Barcode = 123, Discount = Discount.NoDiscount, ProductName = "Kaas", ProductPrice = 4.99M, Total = 4.99M }); _mapperServiceMock.Setup(mock => mock.MapReceipt(It.IsAny <List <ReceiptProduct> >())).Returns(new Receipt { Message = "hooooiii test", TimePrinted = DateTime.Now, TotalPrice = 4.99M }); var receiptService = new ReceiptService(_mapperServiceMock.Object); // Assign var expectedPrice = 4.99; // Act var receipt = receiptService.CreateReceipt(_cart); // Assert Assert.AreEqual(expectedPrice, receipt.TotalPrice); }
public async Task <IActionResult> CreateReceipt([FromBody] ReceiptForCreateDto receipt) { var result = await _receiptService.CreateReceipt(receipt); return(new ObjectResult(ApiResponse.Create(result))); }