public void WriteShouldCallRulesSectionManagerToWriteRuleOverrides() { ICalidusProject project = Mocker.DynamicMock <ICalidusProject>(); IRuleConfigurationOverride config = Mocker.DynamicMock <IRuleConfigurationOverride>(); Expect.Call(project.IgnoredFiles).Return(new String[] {}).Repeat.Once(); Expect.Call(project.GetProjectRuleConfigurationOverrides()).Return(new[] { config }).Repeat.Once(); Expect.Call(() => _rulesSectionManager.WriteTo(new[] { config }, null)).IgnoreArguments().Repeat.Once(); Mocker.ReplayAll(); MemoryStream stream = new MemoryStream(); XmlWriter writer = XmlTextWriter.Create(stream); _manager.WriteTo(project, writer); Mocker.VerifyAll(); }
/// <summary> /// Writes the calidus project to the specified xml writer /// </summary> /// <param name="project">The project to write</param> /// <param name="writer">The writer to write to</param> public void WriteTo(ICalidusProject project, XmlWriter writer) { if (writer.Settings == null || writer.Settings.Encoding != Encoding.UTF8) { throw new CalidusException("The target XmlWriter must be set to write to UTF8"); } XDocument doc = new XDocument(); //write root element XElement root = new XElement("calidusproject"); //write settings XElement ignoreAssemblyFiles = new XElement("IgnoreAssemblyFiles", project.IgnoreAssemblyFiles); XElement ignoreDesignerFiles = new XElement("IgnoreDesignerFiles", project.IgnoreDesignerFiles); XElement ignoreProgramFiles = new XElement("IgnoreProgramFiles", project.IgnoreProgramFiles); XElement settings = new XElement("settings"); settings.Add(ignoreAssemblyFiles); settings.Add(ignoreDesignerFiles); settings.Add(ignoreProgramFiles); root.Add(settings); //write full-file ignores XElement ignores = new XElement("ignore"); foreach (String aFile in project.IgnoredFiles) { XElement file = new XElement("file", new XAttribute("path", aFile)); ignores.Add(file); } root.Add(ignores); _rulesSectionManager.WriteTo(project.GetProjectRuleConfigurationOverrides(), root); //write document to file doc.Add(root); doc.WriteTo(writer); writer.Flush(); }