private BusStop[] GetAllBusStopsPersistNew(NextbusStop[] nxtbsStops) { var stops = new List <BusStop>(); foreach (NextbusStop nxtbsStop in nxtbsStops) { //var cc = _dbContext.BusStops.Local.Where(s => // s.Tag == nxtbsStop.Tag && // Math.Abs(s.Latitude - (double)nxtbsStop.Lat) < 0.000_1 && // Math.Abs(s.Longitude - (double)nxtbsStop.Lon) < 0.000_1 //).ToArray(); //{ } // try // { //BusStop stop = _dbContext.BusStops.Local.SingleOrDefault(s => // s.Tag == nxtbsStop.Tag && // //s.StopId == nxtbsStop.StopId // Math.Abs(s.Latitude - (double)nxtbsStop.Lat) < 0.0001 && // Math.Abs(s.Longitude - (double)nxtbsStop.Lon) < 0.0001 //); var q = _dbContext.BusStops.Local.Where(s => s.Tag == nxtbsStop.Tag && //s.StopId == nxtbsStop.StopId Math.Abs(s.Latitude - (double)nxtbsStop.Lat) < 0.00001 && Math.Abs(s.Longitude - (double)nxtbsStop.Lon) < 0.00001 ).ToArray(); BusStop stop = q.SingleOrDefault(); if (stop == null) { stop = (BusStop)nxtbsStop; _dbContext.Add(stop); } stops.Add(stop); // } // catch (Exception e) // { // Console.WriteLine(e); // throw; // } } return(stops.ToArray()); }
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); } }