示例#1
0
        public void CreateBasket_Should_Return_Null_If_Dto_Is_Null()
        {
            //Arrange
            var mock     = new Mock <IBasketRepository>();
            var myBasket = new BasketDTO
            {
                Id     = 1,
                UserId = "25"
            };

            mock.Setup(x => x.Create(myBasket)).Returns(
                new BasketDTO
            {
                Id     = 1,
                UserId = "25"
            }
                );

            BasketUC target = new BasketUC(mock.Object);

            //Act
            var result = target.AddBasket(null);

            //Assert
            Assert.IsNull(result);
        }
示例#2
0
        public void CreateBasket_Should_Return_Valid_Data()
        {
            //Arrange
            var mock     = new Mock <IBasketRepository>();
            var myBasket = new BasketDTO
            {
                Id     = 1,
                UserId = "25"
            };

            mock.Setup(x => x.Create(myBasket)).Returns(
                new BasketDTO
            {
                Id     = 1,
                UserId = "25"
            }
                );

            BasketUC target = new BasketUC(mock.Object);

            //Act
            var result = target.AddBasket(new BasketBTO
            {
                Id     = 1,
                UserId = "25"
            });

            //Assert
            mock.Verify(u => u.Create(It.IsAny <BasketDTO>()), Times.Once());
        }
示例#3
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));
        }