Exemple #1
0
        public async Task FlightAll_ValidQuery_Success()
        {
            // Arrange
            var query   = new FlightAll.Query();
            var handler = new FlightAll.Handler(_flightRepositoryMock.Object, _flightDomainServiceMock.Object);

            var expectedFlights = DomainHelpers.CreateManyValidFlights().ToList();

            _flightRepositoryMock
            .Setup(x => x.GetAllAsync())
            .ReturnsAsync(expectedFlights);

            _flightDomainServiceMock
            .Setup(x => x.GetDistanceBetweenAirportsAsync(It.IsAny <Flight>()))
            .ReturnsAsync(_fixture.Create <Distance>());

            // Act
            var result = await handler.Handle(query, CancellationToken.None);

            // Assert
            result.Count().Should().Be(expectedFlights.Count);
        }
Exemple #2
0
        public async Task <IActionResult> Index(int page = 1)
        {
            var airportsQuery = new AirportAll.Query();
            var airports      = (await _mediator.Send(airportsQuery)).ToList();

            var flightsQuery = new FlightAll.Query();
            var flights      = await _mediator.Send(flightsQuery);

            var onePageOfFLights = await flights
                                   .OrderByDescending(x => x.CreatedAt)
                                   .ToPagedListAsync(page, DefaultSettings.PageSize);

            var viewModels = onePageOfFLights.Select(flight => new FlightViewModel
            {
                Id = flight.Id,
                DepartureAirport     = airports.SingleOrDefault(x => x.Id == flight.DepartureAirportId)?.Name,
                DestinationAirport   = airports.SingleOrDefault(x => x.Id == flight.DestinationAirportId)?.Name,
                DistanceInKilometers = flight.DistanceInKilometers,
                FuelRequiredInLitres = flight.FuelRequiredInLitres,
                FlightDuration       = flight.FlightDuration
            });

            return(View(viewModels));
        }