Example #1
0
        public void ReturnViewWithEmptyModel_WhenThereNoModelWithThePassedId()
        {
            // Arrange
            var flightServiceMock  = new Mock <IFlightService>();
            var airlineServiceMock = new Mock <IAirlineService>();

            var flightViewModel = new FlightViewModel();

            Guid?flightId  = Guid.NewGuid();
            Guid?airlineId = Guid.NewGuid();

            flightServiceMock.Setup(m => m.GetById(flightId.Value)).Returns((FlightModel)null);
            //airlineServiceMock.Setup(m => m.GetById(airlineId.Value)).Returns((AirlineModel)null);

            var flightController = new FlightController(flightServiceMock.Object, airlineServiceMock.Object);

            // Act & Assert
            flightController
            .WithCallTo(b => b.Details(flightId.Value))
            .ShouldRenderDefaultView()
            .WithModel <FlightViewModel>(viewModel =>
            {
                Assert.AreEqual(null, viewModel.Title);
                Assert.AreEqual(0, viewModel.Price);
                Assert.AreEqual(TimeSpan.Zero, viewModel.Duration);
                Assert.AreEqual((TravelClass)0, viewModel.TravelClass);
            });
        }
Example #2
0
        public void ReturnViewWithModelWithCorrectProperties_WhenThereIsAModelWithThePassedId()
        {
            // Arrange
            var flightServiceMock  = new Mock <IFlightService>();
            var airlineServiceMock = new Mock <IAirlineService>();
            var flightModel        = new FlightModel()
            {
                Id          = Guid.NewGuid(),
                Title       = "BA123",
                Price       = 50,
                Duration    = TimeSpan.Parse("01:10:00"),
                TravelClass = TravelClass.First
            };

            var flightViewModel = new FlightViewModel(flightModel);

            flightServiceMock.Setup(m => m.GetById(flightModel.Id)).Returns(flightModel);

            var flightController = new FlightController(flightServiceMock.Object, airlineServiceMock.Object);

            // Act & Assert
            flightController
            .WithCallTo(b => b.Details(flightModel.Id))
            .ShouldRenderDefaultView()
            .WithModel <FlightViewModel>(viewModel =>
            {
                Assert.AreEqual(flightModel.Title, viewModel.Title);
                Assert.AreEqual(flightModel.Price, viewModel.Price);
                Assert.AreEqual(flightModel.Duration, viewModel.Duration);
                Assert.AreEqual(flightModel.TravelClass, viewModel.TravelClass);
            });
        }
Example #3
0
        public void RenderDetailsFlightPartialViewWithExpectedMappedFlight()
        {
            // Arrange
            var countryService   = new Mock <ICountryService>();
            var flightService    = new Mock <IFlightService>();
            var mappingService   = new Mock <IMappingService>();
            var airportService   = new Mock <IAirportService>();
            var cityService      = new Mock <ICityService>();
            var flightController = new FlightController(flightService.Object, mappingService.Object, countryService.Object, airportService.Object, cityService.Object);

            var flight = new Flight()
            {
                Id = It.IsAny <int>()
            };

            flightService.Setup(f => f.GetDetailedFlight(It.IsAny <int>())).Returns(flight);

            var expectedFlight = new DetailsFlightViewModel()
            {
                Id = It.IsAny <int>()
            };

            mappingService.Setup(m => m.Map <DetailsFlightViewModel>(flight)).Returns(expectedFlight);

            // Act and Assert
            flightController.WithCallTo(f => f.Details(10))
            .ShouldRenderPartialView("_DetailFlight")
            .WithModel <DetailsFlightViewModel>(m =>
            {
                Assert.AreEqual(expectedFlight, m);
            });
        }
Example #4
0
        public void RenderDefaultViewWithExpectedViewModel()
        {
            // Arrange
            var countryService   = new Mock <ICountryService>();
            var flightService    = new Mock <IFlightService>();
            var mappingService   = new Mock <IMappingService>();
            var airportService   = new Mock <IAirportService>();
            var cityService      = new Mock <ICityService>();
            var flightController = new FlightController(flightService.Object, mappingService.Object, countryService.Object, airportService.Object, cityService.Object);

            var countries = new List <Country>()
            {
                new Country()
                {
                    Id = 1, Name = It.IsAny <string>()
                },
                new Country()
                {
                    Id = 2, Name = It.IsAny <string>()
                },
                new Country()
                {
                    Id = 3, Name = It.IsAny <string>()
                },
                new Country()
                {
                    Id = 4, Name = It.IsAny <string>()
                }
            };

            countryService.Setup(c => c.GetAllCountries()).Returns(countries);

            var countryViewModel = new CountryViewModel()
            {
                Id = 1, Name = "First"
            };

            mappingService.Setup(m => m.Map <CountryViewModel>(It.IsAny <Country>())).Returns(countryViewModel);

            // Act and Assert
            flightController.WithCallTo(f => f.Search())
            .ShouldRenderDefaultView()
            .WithModel <SearchViewModel>(m =>
            {
                foreach (var country in m.Countries)
                {
                    Assert.AreEqual("First", country.Text);
                    Assert.AreEqual("1", country.Value);
                }
            });
        }
Example #5
0
        public void ReturnHomeVIew_WhenIdIsNull()
        {
            // Arrange
            var countryService   = new Mock <ICountryService>();
            var flightService    = new Mock <IFlightService>();
            var mappingService   = new Mock <IMappingService>();
            var airportService   = new Mock <IAirportService>();
            var cityService      = new Mock <ICityService>();
            var flightController = new FlightController(flightService.Object, mappingService.Object, countryService.Object, airportService.Object, cityService.Object);

            // Act and Assert
            flightController
            .WithCallTo(f => f.Details(null))
            .ShouldRenderView("Home");
        }
        public void Render_FlightSearchResult_WithExpectedViewModel()
        {
            // Arrange
            var countryService   = new Mock <ICountryService>();
            var flightService    = new Mock <IFlightService>();
            var mappingService   = new Mock <IMappingService>();
            var airportService   = new Mock <IAirportService>();
            var cityService      = new Mock <ICityService>();
            var flightController = new FlightController(flightService.Object, mappingService.Object, countryService.Object, airportService.Object, cityService.Object);

            var flights = new List <PresentationFlight>()
            {
                new PresentationFlight(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <decimal>(), It.IsAny <string>(), It.IsAny <int>()),
                new PresentationFlight(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <decimal>(), It.IsAny <string>(), It.IsAny <int>()),
                new PresentationFlight(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <decimal>(), It.IsAny <string>(), It.IsAny <int>())
            };

            flightService.Setup(f => f.GetFlights(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <int>())).Returns(flights);

            var detailsFlightViewModel = new DetailsFlightViewModel()
            {
                Id = 1
            };

            mappingService.Setup(m => m.Map <DetailsFlightViewModel>(It.IsAny <PresentationFlight>())).Returns(detailsFlightViewModel);

            // Act ans Assert
            flightController.WithCallTo(f => f.Search(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <int>()))
            .ShouldRenderPartialView("_FlightSearchResult")
            .WithModel <IEnumerable <DetailsFlightViewModel> >(m =>
            {
                Assert.AreEqual(flights.Count, m.Count());
                foreach (var item in m)
                {
                    Assert.AreEqual(1, item.Id);
                }
            });
        }