示例#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]);
        }
示例#2
0
 public DataSeeder(BusVbotDbContext dbContext,
                   INextBusClient nextBusClient,
                   ILogger <DataSeeder> logger)
 {
     _nextBusClient = nextBusClient;
     _logger        = logger;
     _dbContext     = dbContext;
 }
示例#3
0
 protected AgencyDataParserBase(
     BusVbotDbContext dbContext,
     string agencyTag            = null,
     string sampleRoutesMarkdown = null
     )
 {
     DbContext = dbContext;
     AgencyTag = agencyTag;
     SampleRoutesMarkdownText = sampleRoutesMarkdown ?? Constants.SampleRoutesText;
 }
示例#4
0
 public PredictionsManager(
     INextBusClient nextBusClient,
     ICachingService cachingService,
     ILocationsManager locationsManager,
     BusVbotDbContext dbContext,
     IAgencyServiceAccessor agencyServiceAccessor
     )
 {
     _nextBusClient         = nextBusClient;
     _cachingService        = cachingService;
     _locationsManager      = locationsManager;
     _dbContext             = dbContext;
     _agencyServiceAccessor = agencyServiceAccessor;
 }
示例#5
0
        internal static BusVbotDbContext CreateInMemoryDbContext(string dbName = "", bool deleteIfExists = true)
        {
            var options = new DbContextOptionsBuilder <BusVbotDbContext>()
                          .UseInMemoryDatabase(dbName)
                          .Options;

            var dbContext = new BusVbotDbContext(options);

            if (deleteIfExists)
            {
                dbContext.Database.EnsureDeleted();
                dbContext.Database.EnsureCreated();
            }

            return(dbContext);
        }
示例#6
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);
            }
        }
示例#7
0
 public CachingService(IMemoryCache cache, BusVbotDbContext dbContext)
 {
     _cache     = cache;
     _dbContext = dbContext;
 }
 public DefaultAgencyDataParser(BusVbotDbContext dbContext)
     : base(dbContext)
 {
 }
示例#9
0
 public UserContextManager(BusVbotDbContext dbContext, IMemoryCache cache)
 {
     _dbContext = dbContext;
     _cache     = cache;
 }
示例#10
0
 public TtcDataParser(BusVbotDbContext dbContext)
     :  base(dbContext, Constants.Tag, Constants.SampleRoutesText)
 {
 }