public void UrlSafeStopId_Blanks()
        {
            string stopId   = "North Station";
            string expected = "NorthStation";
            string actual   = MbtaRtLoader.UrlSafeStopId(stopId);

            Assert.AreEqual(expected, actual);
        }
        public void UrlSafeStopId_SlashesAndBlanks()
        {
            string stopId   = "Littleton / Rte 495";
            string expected = "LittletonSlashRte495";
            string actual   = MbtaRtLoader.UrlSafeStopId(stopId);

            Assert.AreEqual(expected, actual);
        }
        public void UrlSafeStopId_NoFunnyCharacters()
        {
            string stopId   = "Belmont";
            string expected = stopId;
            string actual   = MbtaRtLoader.UrlSafeStopId(stopId);

            Assert.AreEqual(expected, actual);
        }
        public void UtcDateFromScheduledStopTime_TomorrowMidnight()
        {
            string   schedDateTxt = "24:00:00";
            DateTime expected     = MbtaLocalMidnightUtc.AddDays(1);
            DateTime actual       = MbtaRtLoader.UtcDateFromScheduledStopTime(schedDateTxt);

            Assert.AreEqual(expected, actual);
        }
        public void UtcDateFromScheduledStopTime_ThreeThirtyThreePeeEm()
        {
            string   schedDateTxt = "15:33:33";
            DateTime expected     = MbtaLocalMidnightUtc
                                    .AddHours(15).AddMinutes(33).AddSeconds(33);
            DateTime actual = MbtaRtLoader.UtcDateFromScheduledStopTime(schedDateTxt);

            Assert.AreEqual(expected, actual);
        }
        public void ReloadDenormalizedTables_OneScheduledTrip_OnePrediction()
        {
            TestEntitiesBuilder eb = new TestEntitiesBuilder();

            eb.DL1.Feed_Info.Add(eb.FI1);
            eb.DL1.Calendars.Add(eb.C1);
            eb.DL1.Routes.Add(eb.R1);
            eb.DL1.Trips.Add(eb.R1T1);
            eb.DL1.Stops.Add(eb.S1);
            eb.DL1.Stops.Add(eb.S2);
            eb.DL1.Stop_Times.Add(eb.R1T1S1);
            eb.DL1.Stop_Times.Add(eb.R1T1S2);
            eb.P1.PredictionTrips.Add(eb.PT1);
            eb.PT1.PredictionTripStops.Add(eb.PT1S2);
            eb.PT1.PredictionTripVehicles.Add(eb.PT1V1);

            TestBulkCopyHelper bch = new TestBulkCopyHelper();
            TestMbtaTrackerDb  db  = new TestMbtaTrackerDb();

            db.AddDownloadAndChildren(eb.DL1);
            db.AddPredictionAndChildren(eb.P1);

            string       connString = "test connection string";
            string       apiKey     = "test api key";
            MbtaRtLoader target     = new MbtaRtLoader
            {
                ApiKey           = apiKey,
                ConnectionString = connString
            };

            target.BulkHelper = bch;
            target.TrackerDb  = db;

            target.ReloadDenormalizedTables();

            // expecting only one result row: only one trip, and S1 stop is in past
            Assert.AreEqual(0, db.SaveChangesCallCount, "checking no calls to MbtaTrackerDb.SaveChanges()");
            Assert.AreEqual(1, bch.BulkLoadDataCallCount, "checking calls to BulkCopyHelper.BulkLoad()");
            Assert.AreEqual(connString, bch.ConnectionString, "checking ConnectionString");
            Assert.AreEqual("Display.TripsByStation", bch.TargetTable, "checking TargetTable");
            DataTable dt = bch.DataToLoad;

            Assert.AreEqual(1, dt.Rows.Count, "checking row count");
            Assert.AreEqual(eb.R1.route_id, dt.Rows[0]["route_id"], "checking row 0 route_id");
            Assert.AreEqual(eb.R1.route_long_name, dt.Rows[0]["route_name"], "checking row 0 route_name");
            Assert.AreEqual(eb.R1T1.trip_id, dt.Rows[0]["trip_id"], "checking row 0 trip_id");
            Assert.AreEqual(eb.R1T1.trip_shortname, dt.Rows[0]["trip_shortname"], "checking row 0 trip_shortname");
            Assert.AreEqual(eb.R1T1.trip_headsign, dt.Rows[0]["trip_headsign"], "checking row 0 trip_headsign");
            Assert.AreEqual(eb.R1T1.direction_id, dt.Rows[0]["trip_direction"], "checking row 0 trip_direction");
            Assert.AreEqual(eb.PT1V1.vehicle_id, dt.Rows[0]["vehicle_id"], "checking row 0 vehicle_id");
            Assert.AreEqual(eb.S2.stop_id, dt.Rows[0]["stop_id"], "checking row 0 stop_id");
            Assert.AreEqual(eb.S2UrlSafeStopId, dt.Rows[0]["url_safe_stop_id"], "checking row 0 url_safe_stop_id");
            Assert.AreEqual(eb.S2.stop_name, dt.Rows[0]["stop_name"], "checking row 0 stop_name");
            Assert.AreEqual(eb.R1T1S2_Time_Utc, dt.Rows[0]["sched_dep_dt"], "checking row 0 sched_dep_dt");
            Assert.AreEqual(eb.R1T1S2_Time_Utc, dt.Rows[0]["pred_dt"], "checking row 0 pred_dt");
            Assert.AreEqual(eb.PT1S2.pre_away, dt.Rows[0]["pred_away"], "checking row 0 pred_away");
        }
예제 #7
0
        private void LoadMbtaRtData()
        {
            string apiKey  = ConfigurationManager.AppSettings["MbtaRealtimeApiKey"];
            string connStr = ConfigurationManager.ConnectionStrings["MbtaTracker"].ConnectionString;

            MbtaRtLoader l = new MbtaRtLoader
            {
                ApiKey           = apiKey,
                ConnectionString = connStr
            };

            Trace.TraceInformation("MbtaRtLoader version " + l.Version);

            l.Load();
            l.ReloadDenormalizedTables();
        }