Exemplo n.º 1
0
        public async Task GetRestaurantDetails_RestaurantNotAvailable_UserIsNotRestaurantOwner()
        {
            //Arrange
            int    restaurantId = 1;
            string userId       = "475c5e32-049c-4d7b-a963-02ebdc15a94b";

            var restaurantRepository = new Mock <IRestaurantRepository>();

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

            userRepository.Setup(u => u.UserHasRestaurant(userId))
            .ReturnsAsync(false);
            var foodRepository = new Mock <IFoodRepository>();
            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.GetRestaurantDetails(restaurantId)
                );

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

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

            restaurantRepository.Setup(r => r.IsRestaurantAvailableForUsers(restaurantId))
            .ReturnsAsync(true);
            restaurantRepository.Setup(r => r.GetRestaurantDetails(restaurantId))
            .ReturnsAsync(expectedRestaurantDetails);
            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
            var restaurantDetails = await manager.GetRestaurantDetails(restaurantId);

            //Assert
            Assert.Equal(expectedRestaurantDetails, restaurantDetails);
        }
Exemplo n.º 3
0
 public async Task <ActionResult <RestaurantDetailsDto> > GetRestaurantDetails(int restaurantId)
 {
     return(await restaurantManager.GetRestaurantDetails(restaurantId));
 }