public void ConfigurationIsLoadedCorrectly() { var reader = new NetReflectorConfigurationReader(); var xml = new XmlDocument(); xml.LoadXml(@" <cruisecontrol> <project name=""WebTrunkTest""> <tasks> <merge target=""somewhere""> <files> <file>File 1</file> <file action=""Copy"">File 2</file> <file action=""Merge"">File 3</file> </files> </merge> </tasks> </project> </cruisecontrol> "); var configuration = reader.Read(xml, null); Assert.IsNotNull(configuration, "Configuration not loaded"); var project = configuration.Projects["WebTrunkTest"] as Project; Assert.IsNotNull(project, "Project not loaded"); Assert.AreNotEqual(0, project.Tasks.Length, "Tasks not loaded"); var task = project.Tasks[0] as MergeFilesTask; Assert.IsNotNull(task, "Task not correctly loaded"); Assert.AreEqual("somewhere", task.TargetFolder, "TargetFolder is incorrect"); var expected = new MergeFileInfo[] { new MergeFileInfo{FileName = "File 1", MergeAction = MergeFileInfo.MergeActionType.Merge}, new MergeFileInfo{FileName = "File 2", MergeAction = MergeFileInfo.MergeActionType.Copy}, new MergeFileInfo{FileName = "File 3", MergeAction = MergeFileInfo.MergeActionType.Merge} }; Assert.AreEqual(task.MergeFiles.Length, expected.Length, "File count incorrect"); for (var loop = 0; loop < expected.Length; loop++) { Assert.AreEqual(expected[loop].FileName, task.MergeFiles[loop].FileName, string.Format(System.Globalization.CultureInfo.CurrentCulture,"FileName on {0} does not match", loop)); Assert.AreEqual(expected[loop].MergeAction, task.MergeFiles[loop].MergeAction, string.Format(System.Globalization.CultureInfo.CurrentCulture,"MergeAction on {0} does not match", loop)); } }
/// <summary> /// Read a node. /// </summary> /// <param name="node"></param> /// <param name="table"></param> /// <returns></returns> public override object Read(XmlNode node, NetReflectorTypeTable table) { var fileList = new List <MergeFileInfo>(); if (node != null) { // Validate the attributes if (node.Attributes.Count > 0) { throw new NetReflectorException(string.Concat("A file list cannot directly contain attributes.", Environment.NewLine, "XML: ", node.OuterXml)); } // Check each element var subNodes = node.SelectNodes("*"); if (subNodes != null) { foreach (XmlElement fileElement in subNodes) { if (fileElement.Name == "file") { // Make sure there are no child elements var fileSubNodes = fileElement.SelectNodes("*"); if (fileSubNodes != null && fileSubNodes.Count > 0) { throw new NetReflectorException(string.Concat("file cannot contain any sub-items.", Environment.NewLine, "XML: ", fileElement.OuterXml)); } // Load the filename var newFile = new MergeFileInfo(); newFile.FileName = fileElement.InnerText; // Load the merge action var typeAttribute = fileElement.GetAttribute("action"); if (string.IsNullOrEmpty(typeAttribute)) { newFile.MergeAction = MergeFileInfo.MergeActionType.Merge; } else { try { newFile.MergeAction = (MergeFileInfo.MergeActionType)Enum.Parse( typeof(MergeFileInfo.MergeActionType), typeAttribute); } catch (Exception error) { throw new NetReflectorConverterException(string.Concat( "Unknown action :'", typeAttribute, Environment.NewLine, "'XML: " + fileElement.InnerXml), error); } } Log.Debug(string.Concat("MergeFilesTask: Add '", newFile.FileName, "' to '", newFile.MergeAction.ToString(), "' file list.")); fileList.Add(newFile); } else { // Unknown sub-item throw new NetReflectorException(string.Concat(fileElement.Name, " is not a valid sub-item.", Environment.NewLine, "XML: ", fileElement.OuterXml)); } } } } return(fileList.ToArray()); }
/// <summary> /// Read a node. /// </summary> /// <param name="node"></param> /// <param name="table"></param> /// <returns></returns> public override object Read(XmlNode node, NetReflectorTypeTable table) { var fileList = new List<MergeFileInfo>(); if (node != null) { // Validate the attributes if (node.Attributes.Count > 0) throw new NetReflectorException(string.Concat("A file list cannot directly contain attributes.", Environment.NewLine, "XML: ", node.OuterXml)); // Check each element var subNodes = node.SelectNodes("*"); if (subNodes != null) { foreach (XmlElement fileElement in subNodes) { if (fileElement.Name == "file") { // Make sure there are no child elements var fileSubNodes = fileElement.SelectNodes("*"); if (fileSubNodes != null && fileSubNodes.Count > 0) throw new NetReflectorException(string.Concat("file cannot contain any sub-items.", Environment.NewLine, "XML: ", fileElement.OuterXml)); // Load the filename var newFile = new MergeFileInfo(); newFile.FileName = fileElement.InnerText; // Load the merge action var typeAttribute = fileElement.GetAttribute("action"); if (string.IsNullOrEmpty(typeAttribute)) { newFile.MergeAction = MergeFileInfo.MergeActionType.Merge; } else { try { newFile.MergeAction = (MergeFileInfo.MergeActionType) Enum.Parse( typeof (MergeFileInfo.MergeActionType), typeAttribute); } catch (Exception error) { throw new NetReflectorConverterException(string.Concat( "Unknown action :'", typeAttribute, Environment.NewLine, "'XML: " + fileElement.InnerXml), error); } } Log.Debug(string.Concat("MergeFilesTask: Add '", newFile.FileName, "' to '", newFile.MergeAction.ToString(), "' file list.")); fileList.Add(newFile); } else { // Unknown sub-item throw new NetReflectorException(string.Concat(fileElement.Name, " is not a valid sub-item.", Environment.NewLine, "XML: ", fileElement.OuterXml)); } } } } return fileList.ToArray(); }