public void StreamToXMLFullConstructorTest() { string projectName = "full test"; string category = "categ1"; ProjectActivity activity = ProjectActivity.Building; IntegrationStatus buildStatus = IntegrationStatus.Failure; ProjectIntegratorState status = ProjectIntegratorState.Stopped; string webURL = "someurl"; DateTime lastBuildDate = DateTime.Now; string lastBuildLabel = "lastLabel"; string lastSuccessfulBuildLabel = "lastSuccess"; DateTime nextBuildTime = DateTime.Now.AddDays(2); string buildStage = "some stage"; string queue = "someQueue"; int queuePriority = 25; List <ParameterBase> parameters = new List <ParameterBase>(); ProjectStatus projectStatus = new ProjectStatus(projectName, category, activity, buildStatus, status, webURL, lastBuildDate, lastBuildLabel, lastSuccessfulBuildLabel, nextBuildTime, buildStage, queue, queuePriority, parameters); XmlSerializer serializer = new XmlSerializer(typeof(ProjectStatus)); TextWriter writer = new StringWriter(); XmlSerializerNamespaces nmsp = new XmlSerializerNamespaces(); nmsp.Add("", ""); serializer.Serialize(writer, projectStatus, nmsp); Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?>" + Environment.NewLine + "<projectStatus " + "stage=\"" + buildStage + "\" " + "showForceBuildButton=\"true\" " + "showStartStopButton=\"true\" " + "serverName=\"" + Environment.MachineName + "\" " + "status=\"" + status.ToString() + "\" " + "buildStatus=\"" + buildStatus.ToString() + "\" " + "name=\"" + projectName + "\" " + "category=\"" + category + "\" " + "queueName=\"" + queue + "\" " + "queuePriority=\"" + queuePriority.ToString() + "\" " + "url=\"" + webURL + "\" " + "lastBuildDate=\"" + lastBuildDate.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFF") + "\" " + "lastBuildLabel=\"" + lastBuildLabel + "\" " + "lastSuccessfulBuildLabel=\"" + lastSuccessfulBuildLabel + "\" " + "nextBuildTime=\"" + nextBuildTime.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFF") + "\"" + ">" + Environment.NewLine + " <activity type=\"" + activity.ToString() + "\" />" + Environment.NewLine + " <parameters />" + Environment.NewLine + "</projectStatus>", writer.ToString()); }
public void StreamToXMLFullConstructorWithParametersTest() { string projectName = "full test"; string category = "categ1"; ProjectActivity activity = ProjectActivity.Building; IntegrationStatus buildStatus = IntegrationStatus.Failure; ProjectIntegratorState status = ProjectIntegratorState.Stopped; string webURL = "someurl"; DateTime lastBuildDate = DateTime.Now; string lastBuildLabel = "lastLabel"; string lastSuccessfulBuildLabel = "lastSuccess"; DateTime nextBuildTime = DateTime.Now.AddDays(2); string buildStage = "some stage"; string queue = "someQueue"; int queuePriority = 25; List <ParameterBase> parameters = new List <ParameterBase> { new TextParameter("textParam"), new BooleanParameter("boolParam") }; ProjectStatus projectStatus = new ProjectStatus(projectName, category, activity, buildStatus, status, webURL, lastBuildDate, lastBuildLabel, lastSuccessfulBuildLabel, nextBuildTime, buildStage, queue, queuePriority, parameters); string streamedParameters = String.Empty; foreach (ParameterBase parameter in parameters) { XmlSerializerNamespaces parameternmsp = new XmlSerializerNamespaces(); parameternmsp.Add("", ""); XmlSerializer parameterSerializer = new XmlSerializer(parameter.GetType()); TextWriter parameterWriter = new StringWriter(); XmlWriterSettings writerSettings = new XmlWriterSettings(); writerSettings.OmitXmlDeclaration = true; using (XmlWriter xmlWriter = XmlWriter.Create(parameterWriter, writerSettings)) { parameterSerializer.Serialize(xmlWriter, parameter, parameternmsp); } string streamedParameter = parameterWriter.ToString(); streamedParameter = Regex.Replace(streamedParameter, parameter.GetType().Name, "parameter d3p1:type=\"" + parameter.GetType().Name + "\"", RegexOptions.IgnoreCase); streamedParameter = Regex.Replace(streamedParameter, "/>", "xmlns:d3p1=\"http://www.w3.org/2001/XMLSchema-instance\" />", RegexOptions.IgnoreCase); streamedParameters += " " + streamedParameter + "" + Environment.NewLine; } XmlSerializerNamespaces nmsp = new XmlSerializerNamespaces(); nmsp.Add("", ""); XmlSerializer serializer = new XmlSerializer(typeof(ProjectStatus)); TextWriter writer = new StringWriter(); serializer.Serialize(writer, projectStatus, nmsp); Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-16\"?>" + Environment.NewLine + "<projectStatus " + "stage=\"" + buildStage + "\" " + "showForceBuildButton=\"true\" " + "showStartStopButton=\"true\" " + "serverName=\"" + Environment.MachineName + "\" " + "status=\"" + status.ToString() + "\" " + "buildStatus=\"" + buildStatus.ToString() + "\" " + "name=\"" + projectName + "\" " + "category=\"" + category + "\" " + "queueName=\"" + queue + "\" " + "queuePriority=\"" + queuePriority.ToString() + "\" " + "url=\"" + webURL + "\" " + "lastBuildDate=\"" + lastBuildDate.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFF") + "\" " + "lastBuildLabel=\"" + lastBuildLabel + "\" " + "lastSuccessfulBuildLabel=\"" + lastSuccessfulBuildLabel + "\" " + "nextBuildTime=\"" + nextBuildTime.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFF") + "\"" + ">" + Environment.NewLine + " <activity type=\"" + activity.ToString() + "\" />" + Environment.NewLine + " <parameters>" + Environment.NewLine + streamedParameters + " </parameters>" + Environment.NewLine + "</projectStatus>", writer.ToString()); }