Beispiel #1
0
        public void GetAirportByCodeNotFoundTest()
        {
            AirportRepository repository = new AirportRepository(new TestDbFactory());
            var airport = repository.GetAirportByCode("KOD");

            Assert.IsNull(airport);
        }
        public AirportControllerTest()
        {
            this.fixture = new Fixture();
            this.airportAppServiceMock = new Mock <IAirportAppService>();
            this.airportServiceMock    = new Mock <IAirportService>();
            this.airportRepositoryMock = new Mock <IAirportRepository>();
            this.imapperMock           = new Mock <IMapper>();
            this.ihttpClientMock       = new Mock <IHttpClientFactory>();

            //auto mapper configuration
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperConfig());
            });
            var mapper = mockMapper.CreateMapper();

            this.airportController = new AirportController(
                this.airportAppServiceMock.Object,
                mapper: mapper);

            this.airportAppService = new AirportAppService(
                this.airportServiceMock.Object);

            this.airportService = new AirportService(
                this.airportRepositoryMock.Object);

            this.airportRepository = new AirportRepository(
                this.ihttpClientMock.Object);
        }
        /// <summary>
        /// Get the coordination information of airport asynchronously
        /// Firstly, the method checks if airport informations exist in database.
        /// If exist, directly returns coordinates from database.
        /// If not exist, it calls external api and parse informations to get coordinations
        /// On the last step, it saves informations to database for get it on the next request and avoid api calls
        /// </summary>
        /// <param name="airportIataCode">Iata code of airport</param>
        /// <returns>coordination informations in Tuple: (Item1:latitude, Item2:longitude)</returns>
        private async Task <Tuple <double, double> > GetAirportCoordinations(string airportIataCode)
        {
            using (var con = new AppDbContext(new DbContextOptions <AppDbContext>()))
            {
                var    repository   = new AirportRepository(con);
                double latitude     = 0.0;
                double longitude    = 0.0;
                var    savedAirport = await repository.GetAirport(airportIataCode);

                // If airport exist in db, no need to call external api
                if (savedAirport != null)
                {
                    SetCoordinates(savedAirport, out latitude, out longitude);
                }
                else
                {
                    IRestResponse response = AirportHelper.CallApi(airportIataCode);
                    if (response.IsSuccessful == false)
                    {
                        throw new Exception(AirportHelper.ParseApiError(response));
                    }
                    var airport = AirportHelper.GetAirportFromResponse(response);
                    if (airport != null)
                    {
                        SetCoordinates(airport, out latitude, out longitude);
                        // Save airport to in-memory database using by repository
                        await repository.AddAirport(airport);
                    }
                }
                return(Tuple.Create(latitude, longitude));
            }
        }
Beispiel #4
0
        public static void Register(HttpConfiguration config)
        {
            //// Web API configuration and services

            //// Web API routes
            //config.MapHttpAttributeRoutes();

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);

            // Web API configuration and services

            // Web API routes
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            DB.Initialize();
            AirCraftRepository.Init();
            FlightRepository.Init();
            AirportRepository.Init();
        }
        public void Search()
        {
            var repository = AirportRepository.Instance();

            var result = repository.Search("seattle");

            Assert.IsTrue(result.First().Code == "SEA");
        }
        private void viewAirportBtn_Click(object sender, EventArgs e)
        {
            AirportRepository airRepo = new AirportRepository();

            List <Airport> airList = airRepo.GetAllAirports();

            this.dataGridView2.DataSource = airList;
        }
        public void GetAllSorted()
        {
            var repository = AirportRepository.Instance();

            var airports = repository.GetAll();

            Assert.IsTrue(airports.First().Code == "LAS");
            Assert.IsTrue(airports.Last().Code == "SEA");
        }
 public WingsOnDbContext()
 {
     AirportRepository = new AirportRepository();
     AirportRepository = new AirportRepository();
     BookingRepository = new BookingRepository();
     FlightRepository  = new FlightRepository();
     PersonRepository  = new PersonRepository();
     AirlineRepository = new AirlineRepository();
 }
        public void TestJsonResource()
        {
            var repository = new AirportRepository
            {
                AirportSourceUrl = "https://raw.githubusercontent.com/jbrooksuk/JSON-Airports/master/airports.json"
            };
            var airports = repository.GetAirportInfoList().Result;

            Assert.IsTrue(airports.Count > 1000);
        }
        public async Task TestInitialize()
        {
            DbContextOptions <FlyingDutchmanAirlinesContext> dbContextOptions =
                new DbContextOptionsBuilder <FlyingDutchmanAirlinesContext>().UseInMemoryDatabase("FlyingDutchman")
                .Options;

            _context = new FlyingDutchmanAirlinesContext_Stub(dbContextOptions);


            SortedList <string, Airport> airports = new SortedList <string, Airport>
            {
                {
                    "GOH",
                    new Airport
                    {
                        AirportId = 0,
                        City      = "Nuuk",
                        Iata      = "GOH"
                    }
                },
                {
                    "PHX",
                    new Airport
                    {
                        AirportId = 1,
                        City      = "Phoenix",
                        Iata      = "PHX"
                    }
                },
                {
                    "DDH",
                    new Airport
                    {
                        AirportId = 2,
                        City      = "Bennington",
                        Iata      = "DDH"
                    }
                },
                {
                    "RDU",
                    new Airport
                    {
                        AirportId = 3,
                        City      = "Raleigh-Durham",
                        Iata      = "RDU"
                    }
                }
            };

            _context.Airport.AddRange(airports.Values);
            await _context.SaveChangesAsync();

            _repository = new AirportRepository(_context);
            Assert.IsNotNull(_repository);
        }
Beispiel #11
0
        public async Task <HttpResponseMessage> GetAllAirports()
        {
            List <Airport> airports = await AirportRepository.GetAllAirports();

            if (airports.Count >= 0)
            {
                return(Request.CreateResponse <List <Airport> >(HttpStatusCode.OK, airports));
            }

            return(Request.CreateResponse(HttpStatusCode.NotFound, "While retrieving all Airports, error occured!"));
        }
Beispiel #12
0
        public void GetAirportByCodeTest()
        {
            AirportRepository repository = new AirportRepository(new TestDbFactory());
            var airport = repository.GetAirportByCode("Code");

            Assert.IsNotNull(airport);
            Assert.AreEqual(airport.Code, "Code");
            Assert.AreEqual(airport.City, "City");
            Assert.AreEqual(airport.Name, "Name");
            Assert.AreEqual(airport.TimeZone, 999);
        }
        public void GetReturnsIEnumerableAirportViewModelObject()
        {
            // Arrange
            var airportRepository = new AirportRepository(airportServiceMock.Object, mapper);
            var airportController = new AirportController(airportRepository);

            // Act
            var results = airportController.Get();

            // Assert
            Assert.IsInstanceOfType(results, typeof(IEnumerable <AirportViewModel>));
        }
        public void GetAirportsReturnsMultipleAirportViewModelObjects()
        {
            // Arrange
            var airportRepository = new AirportRepository(airportServiceMock.Object, mapper);

            // Act
            var airports = airportRepository.GetAirports();

            // Assert
            Assert.IsInstanceOfType(airports, typeof(List <AirportViewModel>));
            Assert.AreEqual(2, airports.Count());
        }
 public FlightsController(
     FlightRepository flights,
     AviaCompanyRepository companies,
     AirportRepository airports,
     AirplaneRepository airplanes
     )
 {
     _flights   = flights;
     _companies = companies;
     _airports  = airports;
     _airplanes = airplanes;
 }
Beispiel #16
0
        protected void Application_Start()
        {
            // Create unity container
            UnityConfig.RegisterContainer(new UnityContainer());

            GlobalConfiguration.Configuration.DependencyResolver = new UnityResolver(UnityConfig.Container);

            // Here your usual Web API configuration stuff.
            GlobalConfiguration.Configure(WebApiConfig.Register);

            //Load airports to memory
            AirportRepository.LoadAirports();
        }
        public void GetReturnsMultipleAirportViewModelObjects()
        {
            // Arrange
            var airportRepository = new AirportRepository(airportServiceMock.Object, mapper);
            var airportController = new AirportController(airportRepository);

            // Act
            var results     = airportController.Get();
            var resultsData = results as List <AirportViewModel>;

            // Assert
            Assert.AreEqual(2, resultsData.Count);
        }
Beispiel #18
0
        public BillionMutation(AirportRepository airportRepository, CityRepository cityRepository)
        {
            _cityRepository    = cityRepository;
            _airportRepository = airportRepository;

            FieldAsync <CityType>(
                name: "city",
                description: "Add or edit an exiting city entry",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <CityInputType> >
            {
                Name        = "city",
                Description = "Set the cityID on the input object to edit, leave it blank or set to an empty Guid to add."
            }),
                resolve: City);

            FieldAsync <CityType>(
                name: "deleteCity",
                description: "Delete a city",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name        = "cityID",
                Description = "The ID of the city to delete"
            }),
                resolve: DeleteCity
                );

            FieldAsync <AirportType>(
                name: "airport",
                description: "Add or edit an exiting airport entry",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <AirportInputType> >
            {
                Name        = "airport",
                Description = "Set the airportID on the input object to edit, leave it blank or set to an empty Guid to add."
            }),
                resolve: Airport);

            FieldAsync <AirportType>(
                name: "deleteAirport",
                description: "Delete an airport",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name        = "airportID",
                Description = "The ID of the airport to delete"
            }),
                resolve: DeleteAirport);
        }
Beispiel #19
0
 public FlightService(
     AirportRepository airportRepository,
     FlightEntryRepository flightRepository,
     AirportApiService airportApiService,
     FlightApiService flightApiService,
     SearchEntryRepository searchEntryRepository, ItineraryEntryRepository itineraryEntryRepository)
 {
     this._itineraryEntryRepository = itineraryEntryRepository;
     this._searchEntryRepository    = searchEntryRepository;
     this._flightApiService         = flightApiService;
     this._airportApiService        = airportApiService;
     this._flightRepository         = flightRepository;
     this._airportRepository        = airportRepository;
 }
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            using (var conn = new NpgsqlConnection(conString))
            {
                conn.Open();
                foreach (var row in rows)
                {
                    AirportRepository.Add(conn, (string)row["OriginAirportName"], (string)row["OriginCityName"], (string)row["OriginState"], _dictAirport, _dictCity, _dictState);
                    AirportRepository.Add(conn, (string)row["DestAirportName"], (string)row["DestCityName"], (string)row["DestState"], _dictAirport, _dictCity, _dictState);

                    yield return(row);
                }
            }
        }
Beispiel #21
0
 public UnitOfWork(AppDbContext context)
 {
     Users                  = new UserRepository(context);
     Airports               = new AirportRepository(context);
     Airlines               = new AirlineRepository(context);
     Luggages               = new LuggageRepository(context);
     Customers              = new CustomerRepository(context);
     Orders                 = new OrderRepository(context);
     Flights                = new FlightRepository(context);
     Dates                  = new DateRepository(context);
     DateFlights            = new DateFlightRepository(context);
     TicketCategories       = new TicketCategoryRepository(context);
     FlightTicketCategories = new FlightTicketCategoryRepository(context);
     Tickets                = new TicketRepository(context);
     _context               = context;
 }
        public async void GetAllAirportsReturnNotNull()
        {
            ICachingService cache = new CachingService();

            DbContextOptions <AirportDbContext> options = new DbContextOptionsBuilder <AirportDbContext>().
                                                          UseSqlServer("data source=.;initial catalog=test_Local;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;")
                                                          .Options;

            AirportDbContext   context           = new AirportDbContext(options);
            IAirportRepository airportRepository = new AirportRepository(context);
            IAirportConnector  airport           = new AirportConnector(cache, airportRepository);


            var airports = await airport.GetAllAirports();

            Assert.NotNull(airports);
        }
        public async void GetAllAirportsCount()
        {
            ICachingService cache = new CachingService();

            DbContextOptions <AirportDbContext> options = new DbContextOptionsBuilder <AirportDbContext>().
                                                          UseSqlServer("data source=.;initial catalog=test_Local;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;")
                                                          .Options;

            AirportDbContext   context           = new AirportDbContext(options);
            IAirportRepository airportRepository = new AirportRepository(context);
            IAirportConnector  airport           = new AirportConnector(cache, airportRepository);

            int expectedValue = 1062;

            var airports = await airport.GetAllAirports();

            int actualValue = airports.Airports.ToList().Count();

            Assert.Equal(expectedValue, actualValue);
        }
Beispiel #24
0
        public BillionQuery(CityRepository cityRepository, AirportRepository airportRepository, CountryRepository countryRepository)
        {
            Field <ListGraphType <CityType> >("cityList", description: "Query to get a list of cities", resolve: fieldContext => cityRepository.GetAll());

            Field <CityType>()
            .Name("city")
            .Argument <NonNullGraphType <IdGraphType> >("cityID", "The ID of the city to fetch")
            .Resolve(context =>
            {
                var cityId = context.GetArgument <Guid>("cityID");
                return(cityRepository.GetOne(cityId));
            });

            Field <ListGraphType <AirportType> >("airportList", description: "Query to get a list of airports", resolve: fieldContext => airportRepository.GetAll());

            Field <AirportType>()
            .Name("airport")
            .Argument <NonNullGraphType <IdGraphType> >("airportID", "The ID of the airport to fetch")
            .Resolve(context =>
            {
                var airportId = context.GetArgument <Guid>("airportID");
                return(airportRepository.GetOne(airportId));
            });


            Field <ListGraphType <CountryType> >("countryList", description: "Query to get a list of countries", resolve: fieldContext => countryRepository.GetAll());

            Field <ListGraphType <CountryType> >("countryListWithChildren", description: "Query to get a list of countries, with all child objects", resolve: fieldContext => countryRepository.GetAllWithChildren());

            Field <CountryType>()
            .Name("country")
            .Argument <NonNullGraphType <IdGraphType> >("countryID", "The ID of the country to fetch")
            .Resolve(context =>
            {
                var countryId = context.GetArgument <Guid>("countryID");
                return(countryRepository.GetOne(countryId));
            });
        }
 public FlightService(FlightRepository flightRepository, AirportRepository airportRepository)
 {
     _flightRepository  = flightRepository;
     _airportRepository = airportRepository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AirportService"/> class.
 /// </summary>
 /// <param name="airportRepository">The airport repository.</param>
 public AirportService(AirportRepository airportRepository)
     : base(airportRepository)
 {
     _airportRepository = airportRepository;
 }
Beispiel #27
0
 public MapController(AirportRepository airport)
 {
     this.Repository = airport;
 }
 public ScheduleManager()
 {
     _scheduleRepository = new ScheduleRepository();
     _airportRepository  = new AirportRepository();
     _session2DbContext  = new Session2Entities();
 }