public void CancelMissionInvalidElementId()
        {
            AvailableElementData elementData = null;
            Guid requestId = Guid.NewGuid();

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._existingMissionCode,
                this._elementId,
                null,
                1);

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(true);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);
            this._train2groundClientMock.Setup(y => y.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData)).Returns(T2GManagerErrorEnum.eElementNotFound);

            MissionCancelMissionResult result = this._missionService.CancelMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.Timeout);

            this._train2groundClientMock.Verify(a => a.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData), Times.Once());

            Assert.AreEqual(MissionServiceErrorCodeEnum.ErrorInvalidElementId, result.ResultCode);
            Assert.AreEqual(requestId, result.RequestId);
            Assert.AreEqual(result.MissionCode, missionParams.MissionCode);
        }
        public void CancelMissionInvalidRequestTimeout()
        {
            AvailableElementData elementData = null;
            Guid requestId = Guid.NewGuid();

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._existingMissionCode,
                this._elementId,
                null,
                50000);

            MissionCancelMissionResult result = this._missionService.CancelMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.Timeout);

            this._sessionManagerMock.Verify(a => a.IsSessionValid(It.IsAny <Guid>()), Times.Never());
            this._sessionManagerMock.Verify(b => b.GenerateRequestID(It.IsAny <Guid>(), out requestId), Times.Never());
            this._train2groundClientMock.Verify(c => c.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData), Times.Never());

            Assert.AreEqual(MissionServiceErrorCodeEnum.ErrorInvalidRequestTimeout, result.ResultCode);
            Assert.AreEqual(Guid.Empty, result.RequestId);
            Assert.AreEqual(result.MissionCode, missionParams.MissionCode);
        }
        public void InitializeMissionErrorOpeningLMTDb()
        {
            AvailableElementData elementData = InitTrainElement();
            Guid requestId = Guid.NewGuid();

            File.Copy(this._dbSourcePath, Path.Combine(this._dbWorkingPath, "file.db"));

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._existingMissionCode,
                this._elementId,
                null,
                1);

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(true);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);
            this._train2groundClientMock.Setup(y => y.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData)).Returns(T2GManagerErrorEnum.eSuccess);
            this._remoteDataStoreFactoryMock.Setup(z => z.GetRemoteDataStoreInstance()).Returns(new RemoteDataStoreSimulator.RemoteDataStore(this._dbWorkingPath, "1.1.1.1"));

            MissionInitializeMissionResult result = this._missionService.InitializeMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.StationList,
                missionParams.Timeout);

            Assert.AreEqual(MissionServiceErrorCodeEnum.ErrorOpeningLMTDb, result.ResultCode);
            Assert.AreEqual(result.RequestId, requestId);
            Assert.AreEqual(result.MissionCode, missionParams.MissionCode);
        }
        public void InitializeMissionInvalidMissionCode()
        {
            AvailableElementData elementData = null;
            Guid requestId = Guid.NewGuid();

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                string.Empty,
                this._elementId,
                null,
                1);

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(true);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);
            this._train2groundClientMock.Setup(y => y.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData)).Returns(T2GManagerErrorEnum.eSuccess);

            MissionInitializeMissionResult result = this._missionService.InitializeMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.StationList,
                missionParams.Timeout);

            Assert.AreEqual(MissionServiceErrorCodeEnum.ErrorInvalidMissionCode, result.ResultCode);
            Assert.AreEqual(requestId, result.RequestId);
            Assert.IsNullOrEmpty(result.MissionCode);
            Assert.IsNull(result.InvalidStationList);
        }
        public void InitializeMissionInvalidSessionId()
        {
            Guid requestId = Guid.NewGuid();
            AvailableElementData elementData = null;

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._existingMissionCode,
                this._elementId,
                null,
                1);

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(false);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);

            MissionInitializeMissionResult result = this._missionService.InitializeMission(
                Guid.NewGuid(),
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.StationList,
                missionParams.Timeout);

            this._train2groundClientMock.Verify(a => a.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData), Times.Never());

            Assert.AreEqual(MissionServiceErrorCodeEnum.ErrorInvalidSessionId, result.ResultCode);
            Assert.AreEqual(Guid.Empty, result.RequestId);
            Assert.AreEqual(result.MissionCode, missionParams.MissionCode);
            Assert.IsNull(result.InvalidStationList);
        }
        /// <summary>Initializes the mission params.</summary>
        /// <returns>An instance of MissionParams for testing purpose.</returns>
        private MissionParams InitMissionParams(
            Guid sessionId,
            string missionCode,
            string elementId,
            List <string> stationList,
            int?timeout)
        {
            MissionParams missionParams = new MissionParams(
                sessionId,
                missionCode,
                elementId,
                stationList,
                timeout);

            return(missionParams);
        }
        public void InitializeMissionNewMissionRequestAccepted()
        {
            AvailableElementData elementData = InitTrainElement();
            Guid requestId = Guid.NewGuid();

            File.Copy(this._dbSourcePath, Path.Combine(this._dbWorkingPath, "file.db"));
            List <string> inputStationList = InitStationList(StationListTypeEnum.VALID_ONLY);

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._newMissionCode,
                this._elementId,
                inputStationList,
                1);

            ServiceInfo serviceInfo = this.InitServiceInfo();

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(true);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);
            this._train2groundClientMock.Setup(y => y.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData)).Returns(T2GManagerErrorEnum.eSuccess);
            this._remoteDataStoreFactoryMock.Setup(z => z.GetRemoteDataStoreInstance()).Returns(new RemoteDataStoreSimulator.RemoteDataStore(this._dbWorkingPath, "3.0.13.0"));

            T2GManagerErrorEnum rslt = T2GManagerErrorEnum.eSuccess;

            this._train2groundClientMock.Setup(x => x.GetAvailableServiceData(
                                                   missionParams.ElementId,
                                                   (int)eServiceID.eSrvSIF_MissionServer,
                                                   out serviceInfo)).Returns(rslt);

            MissionInitializeMissionResult result = this._missionService.InitializeMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.StationList,
                missionParams.Timeout);

            Assert.AreEqual(MissionServiceErrorCodeEnum.RequestAccepted, result.ResultCode);
            Assert.AreEqual(result.RequestId, requestId);
            Assert.AreEqual(result.MissionCode, this._newMissionCode);
        }
        public void CancelMissionRequestAccepted()
        {
            AvailableElementData elementData = null;
            Guid requestId = Guid.NewGuid();

            MissionParams missionParams = InitMissionParams(
                this._sessionId,
                this._existingMissionCode,
                this._elementId,
                null,
                1);

            ServiceInfo serviceInfo = this.InitServiceInfo();

            T2GManagerErrorEnum rslt = T2GManagerErrorEnum.eSuccess;

            this._train2groundClientMock.Setup(x => x.GetAvailableServiceData(
                                                   missionParams.ElementId,
                                                   (int)eServiceID.eSrvSIF_MissionServer,
                                                   out serviceInfo)).Returns(rslt);

            this._sessionManagerMock.Setup(x => x.IsSessionValid(It.IsAny <Guid>())).Returns(true);
            this._sessionManagerMock.Setup(x => x.GenerateRequestID(It.IsAny <Guid>(), out requestId)).Returns(string.Empty);
            this._train2groundClientMock.Setup(y => y.GetAvailableElementDataByElementNumber(missionParams.ElementId, out elementData)).Returns(T2GManagerErrorEnum.eSuccess);
            this._remoteDataStoreFactoryMock.Setup(z => z.GetRemoteDataStoreInstance()).Returns(new RemoteDataStoreSimulator.RemoteDataStore(this._dbWorkingPath, "3.0.13.0"));

            MissionCancelMissionResult result = this._missionService.CancelMission(
                missionParams.SessionId,
                missionParams.MissionCode,
                missionParams.ElementId,
                missionParams.Timeout);

            Assert.AreEqual(MissionServiceErrorCodeEnum.RequestAccepted, result.ResultCode);
            Assert.AreEqual(result.RequestId, requestId);
            Assert.AreEqual(result.MissionCode, this._existingMissionCode);
        }