예제 #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 void ShouldFailDirection(string directionText)
        {
            IAgencyDataParser sut = new TtcDataParser(null);

            var result = sut.TryParseToDirectionName(null, directionText);

            Assert.False(result.Success);
            Assert.Null(result.DirectionName);
        }
예제 #3
0
        public void ShouldParseDirection(string expectedDirection, string directionText)
        {
            IAgencyDataParser sut = new TtcDataParser(null);

            var result = sut.TryParseToDirectionName(null, directionText);

            Assert.True(result.Success);
            Assert.Equal(expectedDirection, result.DirectionName);
        }
예제 #4
0
        public void ShouldFailInvalidRoutes(string routeText)
        {
            IAgencyDataParser sut = new TtcDataParser(null);

            var result = sut.TryParseToRouteTag(routeText);

            Assert.False(result.Success);
            Assert.Null(result.RouteTag);
        }
예제 #5
0
        public void ShouldParseRouteTag(string routeText)
        {
            IAgencyDataParser sut = new TtcDataParser(null);

            var result = sut.TryParseToRouteTag(routeText);

            Assert.True(result.Success);
            Assert.NotEmpty(result.RouteTag);
        }
예제 #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);
            }
        }