public TestingTrackModel(ISimulationEnvironment env)
        {
            _env = env;
            _redBlocks = new List<IBlock>();
            _greenBlocks = new List<IBlock>();

            IBlock r0 = new TestingBlock("Red", 0, 6, 100, null, true, false, false, false, false, false, StateEnum.Healthy);
            IBlock r1 = new TestingBlock("Red", 1, 0, 100, null, true, false, false, false, false, false, StateEnum.Healthy);
            IBlock r2 = new TestingBlock("Red", 2, 1, 100, null, false, true, false, false, false, false, StateEnum.Healthy);
            IBlock r3 = new TestingBlock("Red", 3, 2, 100, null, false, false, true, false, false, false, StateEnum.Healthy);
            IBlock r4 = new TestingBlock("Red", 4, 3, 100, null, false, false, false, true, false, false, StateEnum.Healthy);
            IBlock r5 = new TestingBlock("Red", 5, 4, 100, null, false, false, false, false, true, false, StateEnum.Healthy);
            IBlock r6 = new TestingBlock("Red", 6, 5, 100, null, false, false, false, false, false, true, StateEnum.Healthy);

            _redBlocks.Add(r0);
            _redBlocks.Add(r1);
            _redBlocks.Add(r2);
            _redBlocks.Add(r3);
            _redBlocks.Add(r4);
            _redBlocks.Add(r5);
            _redBlocks.Add(r6);

            _redLineLayout = new IBlock[1, 7];
            _redLineLayout[0, 0] = r0;
            _redLineLayout[0, 1] = r1;
            _redLineLayout[0, 2] = r2;
            _redLineLayout[0, 3] = r3;
            _redLineLayout[0, 4] = r4;
            _redLineLayout[0, 5] = r5;
            _redLineLayout[0, 6] = r6;

            _redPath = _redBlocks.ToArray();

            IBlock g0 = new TestingBlock("Green", 0, 6, 100, null, true, false, false, false, false, false, StateEnum.Healthy);
            IBlock g1 = new TestingBlock("Green", 1, 0, 100, null, true, false, false, false, false, false, StateEnum.Healthy);
            IBlock g2 = new TestingBlock("Green", 2, 1, 100, null, false, true, false, false, false, false, StateEnum.Healthy);
            IBlock g3 = new TestingBlock("Green", 3, 2, 100, null, false, false, true, false, false, false, StateEnum.Healthy);
            IBlock g4 = new TestingBlock("Green", 4, 3, 100, null, false, false, false, true, false, false, StateEnum.Healthy);
            IBlock g5 = new TestingBlock("Green", 5, 4, 100, null, false, false, false, false, true, false, StateEnum.Healthy);
            IBlock g6 = new TestingBlock("Green", 6, 5, 100, null, false, false, false, false, false, true, StateEnum.Healthy);

            _greenBlocks.Add(g0);
            _greenBlocks.Add(g1);
            _greenBlocks.Add(g2);
            _greenBlocks.Add(g3);
            _greenBlocks.Add(g4);
            _greenBlocks.Add(g5);
            _greenBlocks.Add(g6);

            _greenLineLayout = new IBlock[1, 7];
            _greenLineLayout[0, 0] = g0;
            _greenLineLayout[0, 1] = g1;
            _greenLineLayout[0, 2] = g2;
            _greenLineLayout[0, 3] = g3;
            _greenLineLayout[0, 4] = g4;
            _greenLineLayout[0, 5] = g5;
            _greenLineLayout[0, 6] = g6;

            _greenPath = _greenBlocks.ToArray();
        }
예제 #2
0
        public TestingTrackModel(ISimulationEnvironment env)
        {
            _env         = env;
            _redBlocks   = new List <IBlock>();
            _greenBlocks = new List <IBlock>();

            IBlock r0 = new TestingBlock("Red", 0, 6, 100, null, true, false, false, false, false, false, StateEnum.Healthy);
            IBlock r1 = new TestingBlock("Red", 1, 0, 100, null, true, false, false, false, false, false, StateEnum.Healthy);
            IBlock r2 = new TestingBlock("Red", 2, 1, 100, null, false, true, false, false, false, false, StateEnum.Healthy);
            IBlock r3 = new TestingBlock("Red", 3, 2, 100, null, false, false, true, false, false, false, StateEnum.Healthy);
            IBlock r4 = new TestingBlock("Red", 4, 3, 100, null, false, false, false, true, false, false, StateEnum.Healthy);
            IBlock r5 = new TestingBlock("Red", 5, 4, 100, null, false, false, false, false, true, false, StateEnum.Healthy);
            IBlock r6 = new TestingBlock("Red", 6, 5, 100, null, false, false, false, false, false, true, StateEnum.Healthy);

            _redBlocks.Add(r0);
            _redBlocks.Add(r1);
            _redBlocks.Add(r2);
            _redBlocks.Add(r3);
            _redBlocks.Add(r4);
            _redBlocks.Add(r5);
            _redBlocks.Add(r6);

            _redLineLayout       = new IBlock[1, 7];
            _redLineLayout[0, 0] = r0;
            _redLineLayout[0, 1] = r1;
            _redLineLayout[0, 2] = r2;
            _redLineLayout[0, 3] = r3;
            _redLineLayout[0, 4] = r4;
            _redLineLayout[0, 5] = r5;
            _redLineLayout[0, 6] = r6;

            _redPath = _redBlocks.ToArray();

            IBlock g0 = new TestingBlock("Green", 0, 6, 100, null, true, false, false, false, false, false, StateEnum.Healthy);
            IBlock g1 = new TestingBlock("Green", 1, 0, 100, null, true, false, false, false, false, false, StateEnum.Healthy);
            IBlock g2 = new TestingBlock("Green", 2, 1, 100, null, false, true, false, false, false, false, StateEnum.Healthy);
            IBlock g3 = new TestingBlock("Green", 3, 2, 100, null, false, false, true, false, false, false, StateEnum.Healthy);
            IBlock g4 = new TestingBlock("Green", 4, 3, 100, null, false, false, false, true, false, false, StateEnum.Healthy);
            IBlock g5 = new TestingBlock("Green", 5, 4, 100, null, false, false, false, false, true, false, StateEnum.Healthy);
            IBlock g6 = new TestingBlock("Green", 6, 5, 100, null, false, false, false, false, false, true, StateEnum.Healthy);

            _greenBlocks.Add(g0);
            _greenBlocks.Add(g1);
            _greenBlocks.Add(g2);
            _greenBlocks.Add(g3);
            _greenBlocks.Add(g4);
            _greenBlocks.Add(g5);
            _greenBlocks.Add(g6);

            _greenLineLayout       = new IBlock[1, 7];
            _greenLineLayout[0, 0] = g0;
            _greenLineLayout[0, 1] = g1;
            _greenLineLayout[0, 2] = g2;
            _greenLineLayout[0, 3] = g3;
            _greenLineLayout[0, 4] = g4;
            _greenLineLayout[0, 5] = g5;
            _greenLineLayout[0, 6] = g6;

            _greenPath = _greenBlocks.ToArray();
        }
예제 #3
0
        public bool DoTest(out int pass, out int fail, out List <string> message)
        {
            //local
            pass    = 0;
            fail    = 0;
            message = new List <string>();

            //global for events
            _pass    = 0;
            _fail    = 0;
            _message = new List <string>();

            redRequests = new bool[7] {
                false, false, false, false, false, false, false
            };
            greenRequests = new bool[7] {
                false, false, false, false, false, false, false
            };


            //create environment instance
            _env = new SimulationEnvironment.SimulationEnvironment();

            //create testing track model
            _trackMod = new TestingTrackModel(_env);

            //creating testing track controllers
            _red   = new TestingTrackController(0, _trackMod, _env, false);
            _green = new TestingTrackController(1, _trackMod, _env, false);

            //hook to environment
            _env.PrimaryTrackControllerRed   = _red;
            _red.TransferRequest            += new EventHandler <EventArgs>(_red_TransferRequest);
            _env.PrimaryTrackControllerGreen = _green;
            _green.TransferRequest          += new EventHandler <EventArgs>(_green_TransferRequest);
            _env.TrackModel = _trackMod;

            //creating office instance
            _ctc = new CTCOffice.CTCOffice(_env, _red, _green);
            if (_ctc != null)
            {
                pass++;
                message.Add("CTC Object Secessfully Created");
            }
            else
            {
                fail++;
                message.Add("CTC Object Not Secessfully Created");
            }

            _env.CTCOffice        = _ctc;
            _ctc.StartAutomation += new EventHandler <EventArgs>(_ctc_StartAutomation);
            _ctc.StopAutomation  += new EventHandler <EventArgs>(_ctc_StopAutomation);
            _ctc.LoadData        += new EventHandler <EventArgs>(_ctc_LoadData);
            _ctc.MessagesReady   += new EventHandler <EventArgs>(_ctc_MessagesReady);
            _ctc.UnlockLogin     += new EventHandler <EventArgs>(_ctc_UnlockLogin);
            _ctc.UpdatedData     += new EventHandler <EventArgs>(_ctc_UpdatedData);
            _env.StartTick();

            _trackMod.ThrowTrackChanged();



            if (_env.CTCOffice != null)
            {
                pass++;
                message.Add("CTC Office Added to Environment");

                #region Login Testing
                //Test Improper Login
                if (!_ctc.Login("me", "42"))
                {
                    pass++;
                    message.Add("PASS: Operator has invalid credentials");
                }
                else
                {
                    fail--;
                    message.Add("FAIL: Operator has invlaid credentials");
                }

                //Test Operator Auth (invalid creds)
                if (!_ctc.IsAuth())
                {
                    pass++;
                    message.Add("PASS: Op Auth (Lockout)");
                }
                else
                {
                    fail++;
                    message.Add("FAIL: Op Auth (Lockout)");
                }

                //Test Proper Login
                if (_ctc.Login("root", "admin"))
                {
                    pass++;
                    message.Add("PASS: Operator Login");
                }
                else
                {
                    fail--;
                    message.Add("FAIL: Operator Login");
                }

                //Test Operator Auth (invalid creds)
                if (_ctc.IsAuth())
                {
                    pass++;
                    message.Add("PASS: Op Auth");
                }
                else
                {
                    fail++;
                    message.Add("FAIL: Op Auth");
                }

                //Logout
                //Always returns true
                pass++;
                message.Add("PASS: Logout (always true)");

                #endregion

                //Populate Track -> void function.. always passes unit test
                pass++;
                message.Add("PASS: PopulateTrack() (always true unless exception is generated)");

                //call for start scheduling
                _ctc.StartScheduling();
                _ctc.StopScheduling();

                #region Test Get Line
                if (_ctc.GetLine(0) != null)
                {
                    pass++;
                    message.Add("PASS: GetLine(0) -> Red.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(0) -> Red.");
                }

                if (_ctc.GetLine(1) != null)
                {
                    pass++;
                    message.Add("PASS: GetLine(1) -> Green.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(1) -> Green.");
                }

                if (_ctc.GetLine(2) == null)
                {
                    pass++;
                    message.Add("PASS: GetLine(2) -> null.");
                }
                else
                {
                    fail++;
                    message.Add("Fail: GetLine(0) -> null.");
                }
                #endregion

                //Cannot test private functions (including Line ID functions)

                //RequestTypes.AssignTrainRoute
                //RequestTypes.SetTrainAuthority
                //RequestTypes.SetTrainOOS
                //RequestTypes.SetTrainSpeed
                ////RequestTypes.TrackControllerData
                //RequestTypes.TrackMaintenanceClose
                //RequestTypes.TrackMaintenanceOpen

                TestingBlock redBlock   = new TestingBlock("Red", 0, 0, 0, null, true, false, false, false, false, false, StateEnum.Healthy);
                TestingBlock greenBlock = new TestingBlock("Green", 0, 0, 0, null, true, false, false, false, false, false, StateEnum.Healthy);

                _ctc.assignTrainRouteRequest(1, 0, null, redBlock);
                _ctc.setTrainAuthorityRequest(1, 0, 50, redBlock);
                _ctc.setTrainOutOfServiceRequest(1, 0, redBlock);
                _ctc.setTrainSpeedRequest(1, 0, 50, redBlock);
                _ctc.closeTrackBlockRequest(0, redBlock);
                _ctc.openTrackBlockRequest(0, redBlock);

                _ctc.assignTrainRouteRequest(1, 1, null, greenBlock);
                _ctc.setTrainAuthorityRequest(1, 1, 50, greenBlock);
                _ctc.setTrainOutOfServiceRequest(1, 1, greenBlock);
                _ctc.setTrainSpeedRequest(1, 1, 50, greenBlock);
                _ctc.closeTrackBlockRequest(1, greenBlock);
                _ctc.openTrackBlockRequest(1, greenBlock);

                //dispatch train handled in GUI Tester

                //cannot test handleResponse.  No actual case to test
            }
            else
            {
                fail++;
                message.Add("CTC Office Not Added to Environment");
            }



            //add event handler tests
            pass = pass + _pass;
            fail = fail + _fail;
            message.AddRange(_message);
            return(true);
        }