Exemplo n.º 1
0
        public async Task ShouldFindSingleRouteMatch()
        {
            const string routeTag = "20";

            var agency = new Agency {
                Tag = "TTC",
            };
            var route = new AgencyRoute
            {
                Agency = agency,
                Tag    = routeTag,
            };
            var route2 = new AgencyRoute
            {
                Agency = agency,
                Tag    = routeTag + "a",
            };

            string[] results;

            using (BusVbotDbContext dbContext = DbContextProvider.CreateInMemoryDbContext(nameof(ShouldFindSingleRouteMatch)))
            {
                dbContext.AddRange(route, route2);
                dbContext.SaveChanges();

                IAgencyDataParser sut = new TtcDataParser(dbContext);
                results = await sut.FindMatchingRoutesAsync(routeTag);
            }

            Assert.Single(results);
            Assert.Equal(routeTag, results[0]);
        }
Exemplo n.º 2
0
        public async Task ShouldFindAllDirectionsForRoute(string routeTag, string[] directions, string directionText)
        {
            #region SeedData

            var agency = new Agency
            {
                Tag    = "TTC",
                Routes = new List <AgencyRoute>(),
            };

            var route = new AgencyRoute
            {
                Agency     = agency,
                Tag        = routeTag,
                Directions = directions.Select(dTag => new RouteDirection
                {
                    Tag  = dTag.ToUpper(),
                    Name = dTag.ToUpper(),
                }).ToList(),
            };

            agency.Routes.Add(route);

            #endregion

            string[] results;

            using (BusVbotDbContext dbContext = DbContextProvider.CreateInMemoryDbContext(nameof(ShouldFindAllDirectionsForRoute)))
            {
                dbContext.Add(agency);
                dbContext.SaveChanges();

                IAgencyDataParser sut = new TtcDataParser(dbContext);
                results = await sut.FindMatchingDirectionsForRouteAsync(routeTag, directionText);
            }

            Assert.Equal(directions.Length, results.Length);
            foreach (var result in results)
            {
                Assert.Contains(result, directions, StringComparer.OrdinalIgnoreCase);
            }
        }
Exemplo n.º 3
0
        private async Task SeedAgencyDataAsync(NextbusAgency nxtbAgency)
        {
            var nxtbRoutes = (await _nextBusClient.GetRoutesForAgency(nxtbAgency.Tag).ConfigureAwait(false)).ToArray();

            Agency agency = (Agency)nxtbAgency;

            {
                // Populate first agency coords
                var routeConfig = await _nextBusClient.GetRouteConfig(nxtbAgency.Tag, nxtbRoutes[0].Tag)
                                  .ConfigureAwait(false);

                agency.MinLatitude  = (double)routeConfig.LatMin;
                agency.MaxLatitude  = (double)routeConfig.LatMax;
                agency.MinLongitude = (double)routeConfig.LonMin;
                agency.MaxLongitude = (double)routeConfig.LonMax;
            }

            List <AgencyRoute> routes = new List <AgencyRoute>(90);

            foreach (var nxtbRoute in nxtbRoutes)
            {
                // for testing
                //if (
                //    (agency.Tag == "ttc" && !new[] { "57", "85", "190" }.Contains(nxtbRoute.Tag))
                //    || (agency.Tag == "jtafla" && !new[] { "53" }.Contains(nxtbRoute.Tag))
                //    )
                //{
                //    continue;
                //}

                var routeConfig = await _nextBusClient.GetRouteConfig(nxtbAgency.Tag, nxtbRoute.Tag)
                                  .ConfigureAwait(false);

                AgencyRoute route = (AgencyRoute)routeConfig;

                UpdateAgencyMinMaxCoordinates(ref agency,
                                              route.MaxLatitude,
                                              route.MinLatitude,
                                              route.MaxLongitude,
                                              route.MinLongitude);

                BusStop[] busStops = GetAllBusStopsPersistNew(routeConfig.Stops);

                List <RouteDirection> directions = new List <RouteDirection>(routeConfig.Directions.Length);

                foreach (NextbusDirection nextbusDir in routeConfig.Directions)
                {
                    RouteDirection dir = (RouteDirection)nextbusDir;
                    dir.RouteDirectionBusStops.Capacity = nextbusDir.StopTags.Length;

                    foreach (string stopTag in nextbusDir.StopTags)
                    {
//                        try
//                        {
                        BusStop stop = busStops.Single(s => s.Tag == stopTag);
                        dir.RouteDirectionBusStops.Add(new RouteDirectionBusStop(dir, stop));
//                        }
//                        catch (Exception e)
//                        {
//                            Console.WriteLine(e);
//                            throw;
//                        }
                    }
                    directions.Add(dir);
                }

                route.Directions = directions;
                routes.Add(route);
            }

            agency.Routes = routes;

            if (agency.Tag.Equals(TestAgencyTag, StringComparison.OrdinalIgnoreCase))
            {
                agency.Country = TestAgencyTag;
            }

            _dbContext.Agencies.Add(agency);

            await _dbContext.SaveChangesAsync().ConfigureAwait(false);
        }