public void HaveTemDataWithKeyTicketAndValueExpectedFlightViewModel()
        {
            // 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
            flightController.Search(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <int>());

            // Assert
            flightController.ShouldHaveTempDataProperty <IEnumerable <DetailsFlightViewModel> >("Ticket", m => m.Count() == 3);
        }
示例#2
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);
            });
        }
        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);
                }
            });
        }