/// <summary> /// Constructs message by given xml string /// </summary> /// <param name="xmlString"> /// xml in string /// </param> /// <returns> /// Message constructed by the xml /// </returns> public static Message Construct(string xmlString) { xmlString = concCompabilityIssuesStringWojtekIsGay(xmlString); if (GetMessageName(xmlString) == RegisterMessage.ELEMENT_NAME) { return(RegisterMessage.Construct(xmlString)); } if (GetMessageName(xmlString) == DivideProblemMessage.ELEMENT_NAME) { return(DivideProblemMessage.Construct(xmlString)); } if (GetMessageName(xmlString) == NoOperationMessage.ELEMENT_NAME) { return(NoOperationMessage.Construct(xmlString)); } if (GetMessageName(xmlString) == RegisterResponseMessage.ELEMENT_NAME) { return(RegisterResponseMessage.Construct(xmlString)); } if (GetMessageName(xmlString) == SolutionRequestMessage.ELEMENT_NAME) { return(SolutionRequestMessage.Construct(xmlString)); } if (GetMessageName(xmlString) == SolutionsMessage.ELEMENT_NAME) { return(SolutionsMessage.Construct(xmlString)); } if (GetMessageName(xmlString) == SolvePartialProblemsMessage.ELEMENT_NAME) { try { //return SolvePartialProblemsMessage.Construct(xmlString); } catch (InvalidOperationException e) { return(null); } Console.WriteLine("******** SOLVE PARTIAL PROBLEM MESSAGE **************"); return(SolvePartialProblemsMessage.Construct(xmlString)); } if (GetMessageName(xmlString) == SolveRequestMessage.ELEMENT_NAME) { return(SolveRequestMessage.Construct(xmlString)); } if (GetMessageName(xmlString) == SolveRequestResponseMessage.ELEMENT_NAME) { return(SolveRequestResponseMessage.Construct(xmlString)); } if (GetMessageName(xmlString) == StatusMessage.ELEMENT_NAME) { return(StatusMessage.Construct(xmlString)); } return(null); }
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); }