public void TrainBaselineStatusScenario_OnSystemChangedNotificationUpdateTrainNumber()
        {
            TrainBaselineStatusData valueTrain1 = new TrainBaselineStatusData(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, DEFAULT_BASELINE, BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            TrainBaselineStatusData valueTrain2 = new TrainBaselineStatusData(TRAIN_NAME_2, TRAIN_VEHICLE_ID_2, false, "5.4.3.3", BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            TrainBaselineStatusData valueTrain3 = new TrainBaselineStatusData(TRAIN_NAME_0, TRAIN_VEHICLE_ID_0, false, "1.0.0.0", BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            Dictionary <string, TrainBaselineStatusData> expectedStatuses = new Dictionary <string, TrainBaselineStatusData>();

            expectedStatuses.Add(valueTrain1.TrainId, valueTrain1.Clone());
            expectedStatuses.Add(valueTrain2.TrainId, valueTrain2.Clone());
            expectedStatuses.Add(valueTrain3.TrainId, valueTrain3.Clone());


            // Initialize the history log database
            valueTrain1.OnlineStatus = false;
            valueTrain3.OnlineStatus = true;
            UpdateHistoryLog(valueTrain1);
            UpdateHistoryLog(valueTrain2);
            UpdateHistoryLog(valueTrain3);
            valueTrain1.OnlineStatus = true;
            valueTrain3.OnlineStatus = false;

            // Initialize services
            CreateT2GServicesStub();

            _dataStoreServiceStub.InitializeRemoteDataStoreMockWithDefaultBehavior();
            InitializeTrain(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, TRAIN_IP_1, TRAIN_DATA_PACKAGE_PORT_1, commLinkEnum._2G3G, true);
            InitializeTrain(TRAIN_NAME_2, TRAIN_VEHICLE_ID_2, false, TRAIN_IP_2, TRAIN_DATA_PACKAGE_PORT_2, commLinkEnum._2G3G, false, "5.4.3.3");
            InitializeTrain(TRAIN_NAME_0, TRAIN_VEHICLE_ID_0, false, TRAIN_IP_0, TRAIN_DATA_PACKAGE_PORT_0, commLinkEnum.wifi, false, "1.0.0.0");

            InitializeDataPackageService(false);
            InitializePISGroundSession();

            // Wait that history log was on expected status.
            WaitTrainBaselineStatusesEquals(expectedStatuses, "Online statuses of train not updated in train baseline status when PIS-Ground connect with T2G");


            // TRAIN-1 become train number 100
            valueTrain1.TrainNumber = "100";
            expectedStatuses[valueTrain1.TrainId] = valueTrain1.Clone();
            expectedStatuses[valueTrain2.TrainId] = valueTrain2.Clone();
            expectedStatuses[valueTrain3.TrainId] = valueTrain3.Clone();

            _identificationServiceStub.UpdateSystem(valueTrain1.TrainId, Convert.ToInt32(valueTrain1.TrainNumber, CultureInfo.InvariantCulture), valueTrain1.OnlineStatus, 0, DEFAULT_MISSION, commLinkEnum.wifi, TRAIN_IP_1);

            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnSystemChanged does not update the train number field in train baseline statuses database.");

            // TRAIN-2 become train number 200
            // TRAIN-1 become train number 1000
            valueTrain1.TrainNumber = "1000";
            valueTrain2.TrainNumber = "200";
            expectedStatuses[valueTrain1.TrainId] = valueTrain1.Clone();
            expectedStatuses[valueTrain2.TrainId] = valueTrain2.Clone();
            expectedStatuses[valueTrain3.TrainId] = valueTrain3.Clone();

            _identificationServiceStub.UpdateSystem(valueTrain1.TrainId, Convert.ToInt32(valueTrain1.TrainNumber, CultureInfo.InvariantCulture), valueTrain1.OnlineStatus, 0, DEFAULT_MISSION, commLinkEnum.wifi, TRAIN_IP_1);
            _identificationServiceStub.UpdateSystem(valueTrain2.TrainId, Convert.ToInt32(valueTrain2.TrainNumber, CultureInfo.InvariantCulture), valueTrain2.OnlineStatus, 0, DEFAULT_MISSION, commLinkEnum.wifi, TRAIN_IP_2);

            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnSystemChanged does not update the train number field in train baseline statuses database.");
        }
        public void TrainBaselineStatusScenario_OnMessageChangedUpdateThePisSoftwareVersion()
        {
            TrainBaselineStatusData valueTrain1 = new TrainBaselineStatusData(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, DEFAULT_BASELINE, BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            TrainBaselineStatusData valueTrain2 = new TrainBaselineStatusData(TRAIN_NAME_2, TRAIN_VEHICLE_ID_2, true, "5.4.3.3", BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            TrainBaselineStatusData valueTrain3 = new TrainBaselineStatusData(TRAIN_NAME_0, TRAIN_VEHICLE_ID_0, false, "1.0.0.0", BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            Dictionary <string, TrainBaselineStatusData> expectedStatuses = new Dictionary <string, TrainBaselineStatusData>();

            expectedStatuses.Add(valueTrain1.TrainId, valueTrain1.Clone());
            expectedStatuses.Add(valueTrain2.TrainId, valueTrain2.Clone());
            expectedStatuses.Add(valueTrain3.TrainId, valueTrain3.Clone());

            // Initialize services
            CreateT2GServicesStub();

            _dataStoreServiceStub.InitializeRemoteDataStoreMockWithDefaultBehavior();

            InitializeTrain(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, TRAIN_IP_1, TRAIN_DATA_PACKAGE_PORT_1, commLinkEnum._2G3G, true);
            InitializeTrain(TRAIN_NAME_0, TRAIN_VEHICLE_ID_0, false, TRAIN_IP_0, TRAIN_DATA_PACKAGE_PORT_0, commLinkEnum.wifi, false, "1.0.0.0");
            InitializeTrain(TRAIN_NAME_2, TRAIN_VEHICLE_ID_2, true, TRAIN_IP_2, TRAIN_DATA_PACKAGE_PORT_2, commLinkEnum._2G3G, false, "5.4.3.3");

            InitializeDataPackageService(false);
            InitializePISGroundSession();

            // Wait that history log was on expected status.
            WaitTrainBaselineStatusesEquals(expectedStatuses, "Online statuses of train not updated in train baseline status when PIS-Ground connect with T2G");


            // Update pis.version message of TRAIN-0
            valueTrain3.PisOnBoardVersion         = "5.16.3.2";
            expectedStatuses[valueTrain1.TrainId] = valueTrain1.Clone();
            expectedStatuses[valueTrain2.TrainId] = valueTrain2.Clone();
            expectedStatuses[valueTrain3.TrainId] = valueTrain3.Clone();
            _vehicleInfoServiceStub.UpdateMessageData(new VersionMessage(valueTrain3.TrainId, valueTrain3.PisOnBoardVersion));

            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnMessageChanged does not update the pis onboard software version in train baseline statuses database.");

            // Update pis.version message of TRAIN-1
            valueTrain1.PisOnBoardVersion         = "5.18.0.0";
            expectedStatuses[valueTrain1.TrainId] = valueTrain1.Clone();
            expectedStatuses[valueTrain2.TrainId] = valueTrain2.Clone();
            expectedStatuses[valueTrain3.TrainId] = valueTrain3.Clone();
            _vehicleInfoServiceStub.UpdateMessageData(new VersionMessage(valueTrain1.TrainId, valueTrain1.PisOnBoardVersion));

            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnMessageChanged does not update the pis onboard software version in train baseline statuses database.");

            // Update pis.version message of TRAIN-2
            valueTrain2.PisOnBoardVersion         = "5.20.0.0";
            expectedStatuses[valueTrain1.TrainId] = valueTrain1.Clone();
            expectedStatuses[valueTrain2.TrainId] = valueTrain2.Clone();
            expectedStatuses[valueTrain3.TrainId] = valueTrain3.Clone();
            _vehicleInfoServiceStub.UpdateMessageData(new VersionMessage(valueTrain2.TrainId, valueTrain2.PisOnBoardVersion));

            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnMessageChanged does not update the pis onboard software version in train baseline statuses database.");
        }
        public void TrainBaselineStatusScenario_OnStartupAllTrainAreOffline()
        {
            TrainBaselineStatusData valueTrain1 = new TrainBaselineStatusData(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, false, DEFAULT_BASELINE);
            TrainBaselineStatusData valueTrain2 = new TrainBaselineStatusData("TRAIN-2", 2, false, "5.4.3.3");
            TrainBaselineStatusData valueTrain3 = new TrainBaselineStatusData("TRAIN-0", 0, false, "1.0.0.0");
            Dictionary <string, TrainBaselineStatusData> expectedStatuses = new Dictionary <string, TrainBaselineStatusData>();

            expectedStatuses.Add(valueTrain1.TrainId, valueTrain1.Clone());
            expectedStatuses.Add(valueTrain2.TrainId, valueTrain2.Clone());
            expectedStatuses.Add(valueTrain3.TrainId, valueTrain3.Clone());


            // Initialize the history log database
            valueTrain1.OnlineStatus = true;
            valueTrain3.OnlineStatus = true;
            UpdateHistoryLog(valueTrain1);
            UpdateHistoryLog(valueTrain2);
            UpdateHistoryLog(valueTrain3);
            valueTrain1.OnlineStatus = false;
            valueTrain3.OnlineStatus = false;

            // Initialize services
            _dataStoreServiceStub.InitializeRemoteDataStoreMockWithDefaultBehavior();
            InitializeDataPackageService(false);
            InitializePISGroundSession();

            // Wait that history log was updated.
            WaitTrainBaselineStatusesEquals(expectedStatuses, "On startup of PIS-Ground, train baselines status are not set to state offline");
        }
        public void TrainBaselineStatusScenario_OnSystemDeletedNotificationNominal()
        {
            TrainBaselineStatusData valueTrain1 = new TrainBaselineStatusData(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, DEFAULT_BASELINE, BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            TrainBaselineStatusData valueTrain2 = new TrainBaselineStatusData(TRAIN_NAME_2, TRAIN_VEHICLE_ID_2, true, "5.4.3.3", BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            TrainBaselineStatusData valueTrain3 = new TrainBaselineStatusData(TRAIN_NAME_0, TRAIN_VEHICLE_ID_0, false, "1.0.0.0", BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            Dictionary <string, TrainBaselineStatusData> expectedStatuses = new Dictionary <string, TrainBaselineStatusData>();

            expectedStatuses.Add(valueTrain1.TrainId, valueTrain1.Clone());
            expectedStatuses.Add(valueTrain2.TrainId, valueTrain2.Clone());
            expectedStatuses.Add(valueTrain3.TrainId, valueTrain3.Clone());


            // Initialize the history log database
            valueTrain1.OnlineStatus = false;
            valueTrain3.OnlineStatus = true;
            UpdateHistoryLog(valueTrain1);
            UpdateHistoryLog(valueTrain2);
            UpdateHistoryLog(valueTrain3);
            valueTrain1.OnlineStatus = true;
            valueTrain3.OnlineStatus = false;

            // Initialize services
            CreateT2GServicesStub();

            _dataStoreServiceStub.InitializeRemoteDataStoreMockWithDefaultBehavior();
            InitializeTrain(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, TRAIN_IP_1, TRAIN_DATA_PACKAGE_PORT_1, commLinkEnum._2G3G, true);
            InitializeTrain(TRAIN_NAME_2, TRAIN_VEHICLE_ID_2, true, TRAIN_IP_2, TRAIN_DATA_PACKAGE_PORT_2, commLinkEnum._2G3G, false, "5.4.3.3");
            InitializeTrain(TRAIN_NAME_0, TRAIN_VEHICLE_ID_0, false, TRAIN_IP_0, TRAIN_DATA_PACKAGE_PORT_0, commLinkEnum.wifi, false, "1.0.0.0");

            InitializeDataPackageService(false);
            InitializePISGroundSession();

            // Wait that history log was on expected status.
            WaitTrainBaselineStatusesEquals(expectedStatuses, "Online statuses of train not updated in train baseline status when PIS-Ground connect with T2G");


            // Remove TRAIN-0
            expectedStatuses.Remove(valueTrain3.TrainId);
            _identificationServiceStub.DeleteSystem(valueTrain3.TrainId);

            WaitNotificationSend(NotificationIdEnum.DeletedElement, valueTrain3.TrainId);
            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnSystemDeleted does not remove the deleted train in train baseline statuses database.");

            // Delete TRAIN-2
            expectedStatuses.Remove(valueTrain2.TrainId);
            _identificationServiceStub.DeleteSystem(valueTrain2.TrainId);

            WaitNotificationSend(NotificationIdEnum.DeletedElement, valueTrain2.TrainId);
            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnSystemDeleted does not remove the deleted train in train baseline statuses database.");

            // Delete TRAIN-1
            expectedStatuses.Remove(valueTrain1.TrainId);
            _identificationServiceStub.DeleteSystem(valueTrain1.TrainId);

            WaitNotificationSend(NotificationIdEnum.DeletedElement, valueTrain1.TrainId);
            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnSystemDeleted does not remove the deleted train in train baseline statuses database.");
        }
        public void TrainBaselineStatusScenario_OnSystemChangedNotificationAddNewTrain()
        {
            TrainBaselineStatusData valueTrain1 = new TrainBaselineStatusData(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, DEFAULT_BASELINE, BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            TrainBaselineStatusData valueTrain2 = new TrainBaselineStatusData(TRAIN_NAME_2, TRAIN_VEHICLE_ID_2, true, "5.4.3.3", BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            TrainBaselineStatusData valueTrain3 = new TrainBaselineStatusData(TRAIN_NAME_0, TRAIN_VEHICLE_ID_0, false, "1.0.0.0", BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            Dictionary <string, TrainBaselineStatusData> expectedStatuses = new Dictionary <string, TrainBaselineStatusData>();


            // Initialize services
            CreateT2GServicesStub();

            _dataStoreServiceStub.InitializeRemoteDataStoreMockWithDefaultBehavior();

            InitializeDataPackageService(false);
            InitializePISGroundSession();

            // Wait that history log was on expected status.
            WaitTrainBaselineStatusesEquals(expectedStatuses, "Online statuses of train not updated in train baseline status when PIS-Ground connect with T2G");


            // TRAIN-1 become train online
            expectedStatuses.Add(valueTrain1.TrainId, valueTrain1.Clone());
            InitializeTrain(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, TRAIN_IP_1, TRAIN_DATA_PACKAGE_PORT_1, commLinkEnum._2G3G, true);

            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnSystemChanged does not update the train number field in train baseline statuses database.");

            // TRAIN-0 added
            expectedStatuses.Add(valueTrain3.TrainId, valueTrain3.Clone());
            InitializeTrain(TRAIN_NAME_0, TRAIN_VEHICLE_ID_0, false, TRAIN_IP_0, TRAIN_DATA_PACKAGE_PORT_0, commLinkEnum.wifi, false, "1.0.0.0");

            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnSystemChanged does not update the train number field in train baseline statuses database.");

            // TRAIN-2 added
            expectedStatuses.Add(valueTrain2.TrainId, valueTrain2.Clone());
            InitializeTrain(TRAIN_NAME_2, TRAIN_VEHICLE_ID_2, true, TRAIN_IP_2, TRAIN_DATA_PACKAGE_PORT_2, commLinkEnum._2G3G, false, "5.4.3.3");

            WaitTrainBaselineStatusesEquals(expectedStatuses, "T2G - OnSystemChanged does not update the train number field in train baseline statuses database.");
        }
        public void TrainBaselineStatusScenario_OnlineStatusOfTrainBaselineUpdateWhenCommunicationIsEstablishedWithT2G()
        {
            TrainBaselineStatusData valueTrain1 = new TrainBaselineStatusData(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, DEFAULT_BASELINE, BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            TrainBaselineStatusData valueTrain2 = new TrainBaselineStatusData(TRAIN_NAME_2, TRAIN_VEHICLE_ID_2, true, "5.4.3.3", BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            TrainBaselineStatusData valueTrain3 = new TrainBaselineStatusData(TRAIN_NAME_0, TRAIN_VEHICLE_ID_0, false, "1.0.0.0", BaselineStatusUpdater.NoBaselineVersion, DEFAULT_PIS_VERSION, BaselineProgressStatusEnum.UNKNOWN);
            Dictionary <string, TrainBaselineStatusData> expectedStatuses = new Dictionary <string, TrainBaselineStatusData>();

            expectedStatuses.Add(valueTrain1.TrainId, valueTrain1.Clone());
            expectedStatuses.Add(valueTrain2.TrainId, valueTrain2.Clone());
            expectedStatuses.Add(valueTrain3.TrainId, valueTrain3.Clone());


            // Initialize the history log database
            valueTrain1.OnlineStatus = false;
            valueTrain3.OnlineStatus = true;
            UpdateHistoryLog(valueTrain1);
            UpdateHistoryLog(valueTrain2);
            UpdateHistoryLog(valueTrain3);
            valueTrain1.OnlineStatus = true;
            valueTrain3.OnlineStatus = false;

            // Initialize services
            CreateT2GServicesStub();
            _hostIdentificationService.Close();

            _dataStoreServiceStub.InitializeRemoteDataStoreMockWithDefaultBehavior();
            InitializeTrain(TRAIN_NAME_1, TRAIN_VEHICLE_ID_1, true, TRAIN_IP_1, TRAIN_DATA_PACKAGE_PORT_1, commLinkEnum._2G3G, true);
            InitializeTrain(TRAIN_NAME_2, TRAIN_VEHICLE_ID_2, true, TRAIN_IP_2, TRAIN_DATA_PACKAGE_PORT_2, commLinkEnum._2G3G, false, "5.4.3.3");
            InitializeTrain(TRAIN_NAME_0, TRAIN_VEHICLE_ID_0, false, TRAIN_IP_0, TRAIN_DATA_PACKAGE_PORT_0, commLinkEnum.wifi, false, "1.0.0.0");

            InitializeDataPackageService(false);
            InitializePISGroundSession();
            ReopenIdentificationService();
            WaitPisGroundIsConnectedWithT2G(true);

            // Wait that history log was updated.
            WaitTrainBaselineStatusesEquals(expectedStatuses, "Online statuses of train not updated in train baseline status when PIS-Ground connect with T2G");
        }