Ejemplo n.º 1
0
        public static StatusMessage CreateStatusMessage()
        {
            ulong id = 12;

            StatusThread statusThread1 = new StatusThread(StatusThreadState.Idle);
            StatusThread statusThread2 = new StatusThread(StatusThreadState.Idle);

            ulong howLong = 1000;
            ulong problemInstanceId = 2;
            ulong taskId = 1;
            string problemType = "TCP";

            StatusThread statusThread3 = new StatusThread(StatusThreadState.Busy, howLong, problemInstanceId, taskId, problemType);

            StatusThread[] statusThreads = { statusThread1, statusThread2, statusThread3 };

            StatusMessage expectedMessage = new StatusMessage(id, statusThreads);
            return expectedMessage;
        }
        public void Parse_XMLString_StatusMessage()
        {
            /*********** Actual message ***********/
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"xml_samples\Status.xml");

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(path);
            string xmlStr = xmlDoc.OuterXml;

            string name = Message.GetMessageName(xmlStr);
            StatusMessage actualMessage = null;

            if(name == StatusMessage.ELEMENT_NAME)
                actualMessage = StatusMessage.Construct(xmlStr);

            /*********** Expected message ***********/
            ulong id = 12;

            StatusThread statusThread1 = new StatusThread(StatusThreadState.Idle);
            StatusThread statusThread2 = new StatusThread(StatusThreadState.Idle);

            ulong howLong = 1000;
            ulong problemInstanceId = 2;
            ulong taskId = 1;
            string problemType = "TCP";

            StatusThread statusThread3 = new StatusThread(StatusThreadState.Busy, howLong, problemInstanceId, taskId, problemType);

            StatusThread[] statusThreads = { statusThread1, statusThread2, statusThread3 };

            StatusMessage expectedMessage = new StatusMessage(id, statusThreads);

            Assert.AreEqual(expectedMessage, actualMessage);
        }
        public void Parse_StatusMessage_XMLString()
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"xml_samples\Status.xml");

            ulong id = 12;

            StatusThread statusThread1 = new StatusThread(StatusThreadState.Idle);
            StatusThread statusThread2 = new StatusThread(StatusThreadState.Idle);

            ulong howLong = 1000;
            ulong problemInstanceId = 2;
            ulong taskId = 1;
            string problemType = "TCP";

            StatusThread statusThread3 = new StatusThread(StatusThreadState.Busy, howLong, problemInstanceId, taskId, problemType);

            StatusThread[] statusThreads = { statusThread1, statusThread2, statusThread3 };

            StatusMessage message = new StatusMessage(id, statusThreads);

            string actualXmlStr = message.ToXmlString();

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(path);
            string expectedXmlStr = xmlDoc.OuterXml;

            Assert.AreEqual(expectedXmlStr, actualXmlStr);
        }
 /// <summary>
 /// function updating status of each thread
 /// </summary>
 /// <param name="node"></param>
 /// <param name="message"></param>
 private void UpdateThreadsStatus(NetworkNode node, StatusMessage message){
     for (int i = 0; i < node.TaskThreads.Count(); i++)
     {
         node.TaskThreads[i].StatusThread.State = message.Threads[i].State;
     }
 }