Exemple #1
0
        public async Task ShowMyRestaurantForUsers_RestaurantNameIsNotValid_UserIsRestaurantOwner()
        {
            //Arrange
            int restaurantId = 1;
            var notValidRestaurantDetails = helper.GetRestaurantDetailsDto();

            notValidRestaurantDetails.Name = "";
            string userId = "475c5e32-049c-4d7b-a963-02ebdc15a94b";

            var foodRepository       = new Mock <IFoodRepository>();
            var restaurantRepository = new Mock <IRestaurantRepository>();

            restaurantRepository.Setup(r => r.GetRestaurantDetails(restaurantId))
            .ReturnsAsync(notValidRestaurantDetails);
            var userRepository = new Mock <IUserRepository>();

            userRepository.Setup(u => u.GetMyRestaurantId(userId))
            .ReturnsAsync(restaurantId);
            var httpContext = new Mock <IHttpContextAccessor>();

            httpContext.SetupGet(h => h.HttpContext.User)
            .Returns(helper.GetUserClaimPrinciple(userId));

            var manager = new RestaurantManager(restaurantRepository.Object, userRepository.Object, foodRepository.Object, httpContext.Object);

            //Act

            //Assert
            var exception = await Assert.ThrowsAsync <ProblemDetailsException>(
                async() => await manager.ShowMyRestaurantForUsers()
                );

            Assert.Equal(StatusCodes.Status400BadRequest, exception.Details.Status);
        }
Exemple #2
0
        public async Task ShowMyRestaurantForUsers_RestaurantDataIsValid_UserIsRestaurantOwner()
        {
            //Arrange
            int    restaurantId      = 1;
            var    restaurantDetails = helper.GetRestaurantDetailsDto();
            string userId            = "475c5e32-049c-4d7b-a963-02ebdc15a94b";

            var foodRepository       = new Mock <IFoodRepository>();
            var restaurantRepository = new Mock <IRestaurantRepository>();

            restaurantRepository.Setup(r => r.GetRestaurantDetails(restaurantId))
            .ReturnsAsync(restaurantDetails);
            restaurantRepository.Setup(r => r.ChangeShowForUsersStatus(restaurantId, true))
            .Verifiable();
            var userRepository = new Mock <IUserRepository>();

            userRepository.Setup(u => u.GetMyRestaurantId(userId))
            .ReturnsAsync(restaurantId);
            var httpContext = new Mock <IHttpContextAccessor>();

            httpContext.SetupGet(h => h.HttpContext.User)
            .Returns(helper.GetUserClaimPrinciple(userId));

            var manager = new RestaurantManager(restaurantRepository.Object, userRepository.Object, foodRepository.Object, httpContext.Object);

            //Act
            await manager.ShowMyRestaurantForUsers();

            //Assert
            restaurantRepository.Verify();
        }
Exemple #3
0
        public async Task <ActionResult> ShowMyRestaurantForUsers()
        {
            await restaurantManager.ShowMyRestaurantForUsers();

            return(Ok());
        }