public async Task Add_WhenModelIsValid_ShouldRedirectToConfirm()
        {
            var input       = new ReservationViewModel();
            var reservation = new Reservation {
                ReservationId = 1
            };

            reservationServiceMock.Setup(s => s.AddAsync(input.Reservation))
            .ReturnsAsync(reservation);
            var controllerContext = ControllerContextProvider.GetDefault();
            var controller        = new ReservationsController(reservationServiceMock.Object, roomServiceMock.Object)
            {
                ControllerContext = controllerContext
            };

            var result = await controller.Add(input);

            var redirectResult      = Assert.IsType <RedirectToActionResult>(result);
            int resultReservationId = (int)redirectResult.RouteValues[nameof(reservation.ReservationId)];

            Assert.Null(redirectResult.ControllerName);
            Assert.Equal(nameof(controller.Confirm), redirectResult.ActionName);
            Assert.Equal(reservation.ReservationId, resultReservationId);
            reservationServiceMock.Verify(s => s.AddAsync(input.Reservation), Times.Once);
        }
Пример #2
0
        public async Task StartGame_WithInvalidHostId_ReturnsBadRequest()
        {
            // Arrange
            var gameServiceMock   = new Mock <IGameService>();
            var controllerContext = ControllerContextProvider.GetDefault();
            var controller        = new GameController(gameServiceMock.Object)
            {
                ControllerContext = controllerContext
            };
            var gameId = 1;
            var userId = "test-userid";

            gameServiceMock.Setup(x => x.CheckHostIdAsync(gameId, userId))
            .Returns(Task.FromResult(true));

            // Act
            var result = await controller.StartGame(gameId);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }
        public async Task AddReview_WhenValid_ShouldCallServiceAndRedirect()
        {
            var controllerContext = ControllerContextProvider.GetDefault();
            var controller        = new HotelsController(hotelServiceMock.Object,
                                                         imageServiceMock.Object, thumbnailServiceMock.Object, propertyServiceMock.Object)
            {
                ControllerContext = controllerContext
            };
            var hotelId = 1;
            var review  = new Review();

            var result = await controller.AddReview(hotelId, review);

            var redirectResult = Assert.IsType <RedirectToActionResult>(result);
            int resultHotelId  = (int)redirectResult.RouteValues["id"];

            Assert.Null(redirectResult.ControllerName);
            Assert.Equal(nameof(controller.Hotel), redirectResult.ActionName);
            Assert.Equal(hotelId, resultHotelId);
            Assert.Equal(controllerContext.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier), review.ApplicationUserId);
            hotelServiceMock.Verify(s => s.AddReviewAsync(review), Times.Once);
        }
Пример #4
0
        public async Task StartGame_WithNotExistingInput_ReturnsBadRequest()
        {
            // Arrange
            var gameServiceMock   = new Mock <IGameService>();
            var controllerContext = ControllerContextProvider.GetDefault();
            var controller        = new GameController(gameServiceMock.Object)
            {
                ControllerContext = controllerContext
            };
            var gameId = 1;
            var userId = "userid";

            gameServiceMock.Setup(x => x.CheckHostIdAsync(gameId, userId))
            .Returns(Task.FromResult(true));
            gameServiceMock.Setup(x => x.StartGameAsync(gameId, userId))
            .Throws(new ItemNotFoundException());

            // Act
            var result = await controller.StartGame(gameId);

            // Assert
            Assert.IsType <BadRequestObjectResult>(result);
        }