Exemple #1
0
        public void ReturnNotFoundWhenGivenAIncorrectFlightId()
        {
            // Arrange
            var mockFlightRepo = new Mock <IFlightRepository>();

            mockFlightRepo.Setup(repo => repo.Items)
            .Returns(MoqRepositories.GetFlights());
            var mockReservationRepo = new Mock <IReservationRepository>();
            int flightId            = 3;
            var controller          = new FlightsController(mockFlightRepo.Object, mockReservationRepo.Object, _mapper);

            // Act
            var result = controller.Details(flightId);

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }
        public void ReturnAViewResultWhenModelStateIsInvalid()
        {
            // Arrange
            var mockFlightRepo = new Mock <IFlightRepository>();

            mockFlightRepo.Setup(repo => repo.Items)
            .Returns(MoqRepositories.GetFlights());
            var mockPassengerRepo   = new Mock <IPassengerRepository>();
            var mockReservationRepo = new Mock <IReservationRepository>();
            var controller          = new FlightsAdminController(mockFlightRepo.Object, mockReservationRepo.Object, mockPassengerRepo.Object, _mapper);

            controller.ModelState.AddModelError("test", "test");
            // Act
            var result = controller.Edit(new FlightAdminViewModel()).Result;

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <FlightAdminViewModel>(viewResult.ViewData.Model);
        }
        public void ReturnARedirectToActionResultWhenModelStateIsValid()
        {
            // Arrange
            var mockFlightRepo = new Mock <IFlightRepository>();

            mockFlightRepo.Setup(repo => repo.Items)
            .Returns(MoqRepositories.GetFlights());
            var mockPassengerRepo   = new Mock <IPassengerRepository>();
            var mockReservationRepo = new Mock <IReservationRepository>();
            var controller          = new FlightsAdminController(mockFlightRepo.Object, mockReservationRepo.Object, mockPassengerRepo.Object, _mapper);

            controller.ModelState.Clear();
            // Act
            var result = controller.Edit(new FlightAdminViewModel()).Result;

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
        public void ReturnARedirectToActionResult()
        {
            // Arrange
            var mockFlightRepo = new Mock <IFlightRepository>();

            mockFlightRepo.Setup(repo => repo.Items)
            .Returns(MoqRepositories.GetFlights());
            var mockPassengerRepo   = new Mock <IPassengerRepository>();
            var mockReservationRepo = new Mock <IReservationRepository>();
            var controller          = new FlightsAdminController(mockFlightRepo.Object, mockReservationRepo.Object, mockPassengerRepo.Object, _mapper);
            int flightId            = 1;

            // Act
            var result = controller.Delete(flightId);

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result.Result);

            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
        public void ReturnAViewModelWithAListOfFlights()
        {
            // Arrange
            var mockFlightRepo = new Mock <IFlightRepository>();

            mockFlightRepo.Setup(repo => repo.Items)
            .Returns(MoqRepositories.GetFlights());
            var mockReservationRepo = new Mock <IReservationRepository>();

            var controller = new FlightsController(mockFlightRepo.Object, mockReservationRepo.Object, _mapper);

            // Act
            var result = controller.Index(new FlightListViewModel());

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <FlightListViewModel>(
                viewResult.ViewData.Model);

            Assert.Equal(2, model.Items.Count());
        }
        public void ReturnAViewResultWithAnEmptyModelWhenFlightIdIsIncorrect()
        {
            // Arrange
            var mockFlightRepo = new Mock <IFlightRepository>();

            mockFlightRepo.Setup(repo => repo.Items)
            .Returns(MoqRepositories.GetFlights());
            var mockPassengerRepo   = new Mock <IPassengerRepository>();
            var mockReservationRepo = new Mock <IReservationRepository>();
            var controller          = new FlightsAdminController(mockFlightRepo.Object, mockReservationRepo.Object, mockPassengerRepo.Object, _mapper);
            int flightId            = 3;

            // Act
            var result = controller.Edit(flightId);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <FlightAdminViewModel>(viewResult.ViewData.Model);

            Assert.Null(model.ArrivalCity);
        }
        public void ReturnNotFoundWhenGivenAIncorrectReservationId()
        {
            // Arrange
            var mockFlightRepo = new Mock <IFlightRepository>();

            mockFlightRepo.Setup(repo => repo.Items)
            .Returns(MoqRepositories.GetFlights());
            var mockPassengerRepo   = new Mock <IPassengerRepository>();
            var mockReservationRepo = new Mock <IReservationRepository>();

            mockReservationRepo.Setup(repo => repo.Items)
            .Returns(MoqRepositories.GetReservationWithPassengers().AsQueryable());
            var controller    = new FlightsAdminController(mockFlightRepo.Object, mockReservationRepo.Object, mockPassengerRepo.Object, _mapper);
            int reservationId = 3;

            // Act
            var result = controller.PassengersDetails(reservationId);

            // Assert
            Assert.IsType <NotFoundResult>(result);
        }
        public void ReturnAViewResult()
        {
            // Arrange
            var mockFlightRepo = new Mock <IFlightRepository>();

            mockFlightRepo.Setup(repo => repo.Items)
            .Returns(MoqRepositories.GetFlights());
            var mockPassengerRepo   = new Mock <IPassengerRepository>();
            var mockReservationRepo = new Mock <IReservationRepository>();

            mockReservationRepo.Setup(repo => repo.Items)
            .Returns(MoqRepositories.GetReservationWithPassengers().AsQueryable());
            var controller    = new FlightsAdminController(mockFlightRepo.Object, mockReservationRepo.Object, mockPassengerRepo.Object, _mapper);
            int reservationId = 1;
            // Act
            var result = controller.PassengersDetails(reservationId);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <PassengerListViewModel>(
                viewResult.ViewData.Model);

            Assert.Equal(3, model.Items.Count());
        }