public void MondayOrTuesday() { // Arrange Mock <BoekingVM> boekingVM = new Mock <BoekingVM>(); Mock <Beestje> animal1 = new Mock <Beestje>(); // If these are not initialized correctly, automatically takes the 2% discount animal1.Object.Name = "b"; animal1.Object.Price = 10.00m; animal1.Object.Type = "Boerderij"; // Datetime has to be Monday/Tuesday boekingVM.Object.Date = new DateTime(2020, 1, 6); boekingVM.Object.SelectedBeestjes.Add(animal1.Object); CalculateDiscount discount = new CalculateDiscount(); // Act var result = discount.CalculateTotalPrice(boekingVM.Object); // Assert Assert.AreEqual(8.50m, result); }
public void OneInSixDucks() { // Arrange Mock <BoekingVM> boekingVM = new Mock <BoekingVM>(); Mock <Beestje> animal1 = new Mock <Beestje>(); // If these are not initialized correctly, automatically takes the 2% discount animal1.Object.Name = "Eend"; animal1.Object.Price = 10.00m; animal1.Object.Type = "Boerderij"; // If no date is selected, takes date of today which could be Monday/Tuesday boekingVM.Object.Date = new DateTime(2020, 1, 8); boekingVM.Object.SelectedBeestjes.Add(animal1.Object); CalculateDiscount discount = new CalculateDiscount(); // Act var result = discount.CalculateTotalPrice(boekingVM.Object); // Assert Assert.IsTrue(discount.HasDuck); }
public void CatDog() { // Arrange Mock <BoekingVM> boekingVM = new Mock <BoekingVM>(); Mock <Beestje> animal1 = new Mock <Beestje>(); Mock <Beestje> animal2 = new Mock <Beestje>(); animal1.Object.Name = "Kat"; animal2.Object.Name = "Hond"; animal1.Object.Price = 10.00m; animal2.Object.Price = 10.00m; animal1.Object.Type = "Woestijn"; animal2.Object.Type = "Boerderij"; // If no date is selected, takes date of today which could be Monday/Tuesday boekingVM.Object.Date = new DateTime(2020, 1, 8); boekingVM.Object.SelectedBeestjes.Add(animal1.Object); boekingVM.Object.SelectedBeestjes.Add(animal2.Object); CalculateDiscount discount = new CalculateDiscount(); // Act var result = discount.CalculateTotalPrice(boekingVM.Object); // Assert Assert.AreEqual(17.60m, result); }
public void ContainsCharStartingFromA() { // Arrange Mock <BoekingVM> boekingVM = new Mock <BoekingVM>(); Mock <Beestje> animal1 = new Mock <Beestje>(); // If these are not initialized correctly, automatically takes the 2% discount // In this instance we take Baviaan for the 4% discount animal1.Object.Name = "Baviaan"; animal1.Object.Price = 10.00m; animal1.Object.Type = "Jungle"; // If no date is selected, takes date of today which could be Monday/Tuesday boekingVM.Object.Date = new DateTime(2020, 1, 8); boekingVM.Object.SelectedBeestjes.Add(animal1.Object); CalculateDiscount discount = new CalculateDiscount(); // Act var result = discount.CalculateTotalPrice(boekingVM.Object); // Assert Assert.AreEqual(9.60m, result); }
public async Task <ActionResult <IEnumerable <AllUserOrders> > > GetAllOrders(int statusId) { // Get all products var productsOrders = await _context.ProductOrders.Include(x => x.Order) .ThenInclude(x => x.User) .Where(x => x.Order.StatusId == statusId) .Select(x => new AllUserOrders { OrderId = x.Order.Id, OrderDate = x.Order.OrderDate, StatusId = x.Order.StatusId, CustomerName = x.Order.User.FirstName + " " + x.Order.User.LastName, CustomerEmail = x.Order.User.Email, Quantity = x.Amount, TotalCost = CalculateDiscount.NewPrice(x.Price * x.Amount, x.Discount) }) .OrderByDescending(x => x.OrderDate) .ToListAsync(); // Group orders by OrderId var orders = productsOrders.GroupBy(x => x.OrderId).Select(x => new AllUserOrders { OrderId = x.First().OrderId, OrderDate = x.First().OrderDate, StatusId = x.First().StatusId, CustomerName = x.First().CustomerName, CustomerEmail = x.First().CustomerEmail, Quantity = x.Sum(s => s.Quantity), TotalCost = x.Sum(s => s.TotalCost) }).ToList(); return(Ok(orders)); }
/** * Fourth step of the process, checks if tempdata is not empty to handle validation * User can see and confirm his booking * Also calculates the total price with discounts by using the CalculateDiscount class */ public ActionResult Stap4([Bind(Include = "Date,FirstName, Prefix, LastName, Adres, Email, Number, BeestjesIds, AccessoiresIds")] BoekingVM boekingVM) { if (boekingVM.Date < DateTime.Now) { TempData["nodateselected"] = "Selecteer een valide datum."; return(RedirectToAction("Index", "Home")); } calculateDiscount = new CalculateDiscount(); foreach (int i in boekingVM.BeestjesIds) { boekingVM.SelectedBeestjes.Add(boekingRepository.GetBeestjeById(i)); } foreach (int i in boekingVM.AccessoiresIds) { boekingVM.SelectedAccessoires.Add(boekingRepository.GetAccessoireById(i)); } boekingVM.FullName = boekingVM.FirstName + " " + boekingVM.Prefix + " " + boekingVM.LastName; boekingVM.TotalPrice = calculateDiscount.CalculateTotalPrice(boekingVM); boekingVM.DiscountList = calculateDiscount.DiscountList; return(View(boekingVM)); }
public void ThreeOfAKind() { // Arrange Mock <BoekingVM> boekingVM = new Mock <BoekingVM>(); Mock <Beestje> animal1 = new Mock <Beestje>(); Mock <Beestje> animal2 = new Mock <Beestje>(); Mock <Beestje> animal3 = new Mock <Beestje>(); // If these are not initialized correctly, automatically takes the 2% discount animal1.Object.Name = "b"; animal2.Object.Name = "c"; animal3.Object.Name = "d"; animal1.Object.Price = 10.00m; animal2.Object.Price = 10.00m; animal3.Object.Price = 10.00m; animal1.Object.Type = "Boerderij"; animal2.Object.Type = "Boerderij"; animal3.Object.Type = "Boerderij"; // If no date is selected, takes date of today which could be Monday/Tuesday boekingVM.Object.Date = new DateTime(2020, 1, 8); boekingVM.Object.SelectedBeestjes.Add(animal1.Object); boekingVM.Object.SelectedBeestjes.Add(animal2.Object); boekingVM.Object.SelectedBeestjes.Add(animal3.Object); CalculateDiscount discount = new CalculateDiscount(); // Act var result = discount.CalculateTotalPrice(boekingVM.Object); // Assert Assert.AreEqual(27.00m, result); }