コード例 #1
0
        public IActionResult CreateBasket(DateTime arrivalDate)
        {
            basketUC = GetBasketUC();


            if (basketUC.shoppingMeals.Count() == 0)
            {
                return(RedirectToAction("Error", new { errorMessage = "Sorry, your basket is empty..." }));
            }
            if (!ModelState.IsValid)
            {
                return(View(basketUC));
            }
            var basketBTO = new BasketBTO();

            basketBTO.ArrivalDate = arrivalDate;

            RestaurantUC restoUC = new RestaurantUC(restoRepository);

            basketBTO.ShoppingMeals = basketUC.shoppingMeals
                                      .Select(x => x.ShoppingMealDomainToBTO())
                                      .ToList();

            basketBTO.UserId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? null;

            if (basketBTO.UserId == null)
            {
                return(RedirectToAction("Error", new { errorMessage = "You have to be logged to complete your order" }));
            }

            if (!restoUC.IsOpen(basketUC.restoId, basketBTO.ArrivalDate))
            {
                return(RedirectToAction("Error", new { errorMessage = "The restaurant will be closed at this hour" }));
            }
            var result = basketUC.AddBasket(basketBTO);

            basketUC.ClearShoppingMeals();
            if (basketUC.shoppingMeals.Count == 0)
            {
                HttpContext.Session.Clear();
            }
            if (result == null)
            {
                return(RedirectToAction("Error", new { errorMessage = "We can't add this basket, please contact support" }));
            }
            string email = restoUC.FindRestoMailByRestoId(basketUC.restoId);

            if (!String.IsNullOrEmpty(email))
            {
                _emailSender.SendEmailAsync(email,
                                            "You have a new order",
                                            "See your orders by clicking here");
            }

            return(View(result));
        }
コード例 #2
0
        public void IsOpen_Should_Return_False_When_ArrivalDate_Is_Before_Now()
        {
            //Arrange
            var mock = new Mock <IRestoRepository>();
            var date = DateTime.Now;

            date = date.AddMonths(-1);
            mock.Setup(x => x.RestaurantIsOpen(1, date)).Returns(true);
            RestaurantUC target = new RestaurantUC(mock.Object);

            //Act
            var result = target.IsOpen(1, date);

            //Assert
            Assert.IsFalse(result);
        }
コード例 #3
0
        public void IsOpen_Should_Return_True_When_Valid_Data()
        {
            //Arrange
            var mock = new Mock <IRestoRepository>();
            var date = DateTime.Now;

            date = date.AddMonths(1);
            mock.Setup(x => x.RestaurantIsOpen(1, date)).Returns(true);
            RestaurantUC target = new RestaurantUC(mock.Object);

            //Act
            var result = target.IsOpen(1, date);

            //Assert
            Assert.IsTrue(result);
        }