public void PaySelectedSoldProducts_ShouldWork() { List <ISoldProductModel> inputList = Factory.InstanceISoldProductModelList(); ISoldProductModel product1 = Factory.InstanceSoldProductModel(); ISoldProductModel product2 = Factory.InstanceSoldProductModel(); product1.ID = 23; product1.Name = "product1"; product1.Price = 1.5M; product1.Detail = ""; product2.ID = 12; product2.Name = "product2"; product2.Price = 3.5M; product2.Detail = "algo"; inputList.Add(product1); inputList.Add(product2); int[] elements = { 0 }; Mock <ISoldProductDataAccess> soldproductData = new Mock <ISoldProductDataAccess>(); Mock <ISoldProductAccomplishedDataAccess> soldproductDataAccomplished = new Mock <ISoldProductAccomplishedDataAccess>(); MainMenuHelper.PaySelectedSoldProducts(inputList, elements, soldproductData.Object, soldproductDataAccomplished.Object); Assert.NotEmpty(inputList); Assert.Single(inputList); inputList[0].Should().BeEquivalentTo(product2); }
public void PaySelectedSoldProducts_ShouldGiveException() { List <ISoldProductModel> inputList = Factory.InstanceISoldProductModelList(); ISoldProductModel product1 = Factory.InstanceSoldProductModel(); ISoldProductModel product2 = Factory.InstanceSoldProductModel(); product1.ID = 23; product1.Name = "product1"; product1.Price = 1.5M; product1.Detail = ""; product2.ID = 12; product2.Name = "product2"; product2.Price = 3.5M; product2.Detail = "algo"; inputList.Add(product1); inputList.Add(product2); int[] elements = { 0, 3 }; Mock <ISoldProductDataAccess> soldproductData = new Mock <ISoldProductDataAccess>(); Mock <ISoldProductAccomplishedDataAccess> soldproductDataAccomplished = new Mock <ISoldProductAccomplishedDataAccess>(); Action act = () => MainMenuHelper.PaySelectedSoldProducts(inputList, elements, soldproductData.Object, soldproductDataAccomplished.Object); Assert.Throws <ArgumentOutOfRangeException>(act); }
public ActionResult PayPartial(int id, int[] Paid, string order) { if (Paid != null) { try { // Finding the sold products from the table that are selected to be paid List <ISoldProductModel> fullList = soldProductData.GetByTable(id); // Selection of the order of the list fullList = MainMenuHelper.OrderListSoldProducts(fullList, order); // Moving in the database the selected sold products to a table of all sold products accomplished MainMenuHelper.PaySelectedSoldProducts(fullList, Paid, soldProductData, soldProductAccomplishedData); //if the table is without any product set it to empty if (fullList.Count() < 1) { ITableModel table = tableData.FindById(id); table.Occupied = false; tableData.Update(table); } } catch (Exception ex) { log.Error("Could't load sold products or tables from Database", ex); return(View("ErrorRetriveData")); } } return(RedirectToAction("Tables")); }