public void Simple() { var root = new GeneralTree<int>(5); var child1 = new GeneralTree<int>(2); var child2 = new GeneralTree<int>(3); var child3 = new GeneralTree<int>(1); root.Add(child1); root.Add(child2); root.Add(child3); var child4 = new GeneralTree<int>(9); var child5 = new GeneralTree<int>(12); var child6 = new GeneralTree<int>(13); child1.Add(child4); child1.Add(child5); child2.Add(child6); Assert.AreEqual(root.FindNode(target => target == 13), child6); Assert.AreEqual(root.FindNode(target => target == 2), child1); Assert.AreEqual(root.FindNode(target => target == 9), child4); Assert.AreEqual(root.FindNode(target => target == 57), null); }
private XElement AddNodeForFile(XNamespace xmlns, Uri file, GeneralTree<INode> childNode) { var xElement = new XElement(xmlns + "li", new XAttribute("class", "file")); string nodeText = childNode.Data.Name; if (childNode.Data.OriginalLocationUrl == file) { xElement.Add(new XElement(xmlns + "span", new XAttribute("class", "current"), nodeText)); } else { xElement.Add(new XElement(xmlns + "a", new XAttribute("href", childNode.Data.GetRelativeUriTo(file)), nodeText)); } var featureNode = childNode.Data as FeatureNode; if (featureNode != null && this.imageResultFormatter != null) { Feature feature = featureNode.Feature; XElement formatForToC = this.imageResultFormatter.FormatForToC(feature); if (formatForToC != null) { xElement.Add(formatForToC); } } return xElement; }
private static void ApplyTestResultsToFeatures(IContainer container, IConfiguration configuration, GeneralTree<INode> features) { var testResults = container.Resolve<ITestResults>(); var actionVisitor = new ActionVisitor<INode>(node => { var featureTreeNode = node as FeatureNode; if (featureTreeNode == null) { return; } if (configuration.HasTestResults) { SetResultsAtFeatureLevel(featureTreeNode, testResults); SetResultsForIndividualScenariosUnderFeature(featureTreeNode, testResults); } else { featureTreeNode.Feature.Result = TestResult.Inconclusive; } }); features.AcceptVisitor(actionVisitor); }
private void VisitNodes(GeneralTree<INode> features, INode node) { if (node.IsIndexMarkDownNode()) { return; } string nodePath = this.fileSystem.Path.Combine(this.configuration.OutputFolder.FullName, node.RelativePathFromRoot); string htmlFilePath; if (node.NodeType == NodeType.Content) { htmlFilePath = nodePath.Replace(this.fileSystem.Path.GetExtension(nodePath), ".html"); this.WriteContentNode(features, node, htmlFilePath); } else if (node.NodeType == NodeType.Structure) { this.fileSystem.Directory.CreateDirectory(nodePath); htmlFilePath = this.fileSystem.Path.Combine(nodePath, "index.html"); this.WriteContentNode(features, node, htmlFilePath); } else { // copy file from source to output this.fileSystem.File.Copy(node.OriginalLocation.FullName, nodePath, overwrite: true); } }
private XElement BuildListItems(XNamespace xmlns, Uri file, GeneralTree<FeatureNode> features) { var ul = new XElement(xmlns + "ul", new XAttribute("class", "features")); foreach (var childNode in features.ChildNodes) { if (childNode.Data.IsContent) { ul.Add(new XElement(xmlns + "div", new XAttribute("class", "file"), new XElement(xmlns + "li", new XElement(xmlns + "a", new XAttribute("href", childNode.Data.GetRelativeUriTo(file)), childNode.Data.Name.ExpandWikiWord())))); } else { ul.Add(new XElement(xmlns + "li", new XElement(xmlns + "div", new XAttribute("class", "directory"), new XText(childNode.Data.Name.ExpandWikiWord()) ), BuildListItems(xmlns, file, childNode))); } } return ul; }
private XElement BuildListItems(GeneralTree<IDirectoryTreeNode> features) { XElement container; if (features.Data.IsContent) { container = new XElement("topicref", new XAttribute("href", this.ditaMapPathGenerator.GeneratePathToFeature(features.Data))); } else { container = new XElement("topichead", new XAttribute("navtitle", features.Data.Name)); } foreach (var childNode in features.ChildNodes) { if (childNode.Data.IsContent) { container.Add(new XElement("topicref", new XAttribute("href", this.ditaMapPathGenerator.GeneratePathToFeature(childNode.Data)))); } else { container.Add(this.BuildListItems(childNode)); } } return container; }
public void Build(GeneralTree<INode> features) { if (Log.IsInfoEnabled) { Log.Info("Writing Excel workbook to {0}", this.configuration.OutputFolder.FullName); } string spreadsheetPath = this.fileSystem.Path.Combine(this.configuration.OutputFolder.FullName, "features.xlsx"); using (var workbook = new XLWorkbook()) { var actionVisitor = new ActionVisitor<INode>(node => { var featureDirectoryTreeNode = node as FeatureNode; if (featureDirectoryTreeNode != null) { IXLWorksheet worksheet = workbook.AddWorksheet( this.excelSheetNameGenerator.GenerateSheetName( workbook, featureDirectoryTreeNode .Feature)); this.excelFeatureFormatter.Format( worksheet, featureDirectoryTreeNode.Feature); } }); features.AcceptVisitor(actionVisitor); this.excelTableOfContentsFormatter.Format(workbook, features); workbook.SaveAs(spreadsheetPath); } }
private GeneralTree<IDirectoryTreeNode> Crawl(DirectoryInfo directory, IDirectoryTreeNode rootNode) { IDirectoryTreeNode currentNode = featureNodeFactory.Create(rootNode != null ? rootNode.OriginalLocation : null, directory); if (rootNode == null) { rootNode = currentNode; } var tree = new GeneralTree<IDirectoryTreeNode>(currentNode); bool isRelevantFileFound = false; foreach (FileInfo file in directory.GetFiles().Where(file => relevantFileDetector.IsRelevant(file))) { isRelevantFileFound = true; IDirectoryTreeNode node = featureNodeFactory.Create(rootNode.OriginalLocation, file); tree.Add(node); } bool isRelevantDirectoryFound = false; foreach (DirectoryInfo subDirectory in directory.GetDirectories()) { GeneralTree<IDirectoryTreeNode> subTree = Crawl(subDirectory, rootNode); if (subTree != null) { isRelevantDirectoryFound = true; tree.Add(subTree); } } if (!isRelevantFileFound && !isRelevantDirectoryFound) return null; return tree; }
public XDocument Format(FeatureNode featureNode, GeneralTree<FeatureNode> features) { var xmlns = XNamespace.Get("http://www.w3.org/1999/xhtml"); var featureNodeOutputPath = Path.Combine(this.configuration.OutputFolder.FullName, featureNode.RelativePathFromRoot); var featureNodeOutputUri = new Uri(featureNodeOutputPath); var container = new XElement(xmlns + "div", new XAttribute("id", "container")); container.Add(this.htmlHeaderFormatter.Format()); container.Add(this.htmlTableOfContentsFormatter.Format(featureNode.Url, features)); container.Add(this.htmlContentFormatter.Format(featureNode)); container.Add(this.htmlFooterFormatter.Format()); var body = new XElement(xmlns + "body"); body.Add(container); var head = new XElement(xmlns + "head"); head.Add(new XElement(xmlns + "title", string.Format("{0}", featureNode.Name))); head.Add(new XElement(xmlns + "link", new XAttribute("rel", "stylesheet"), new XAttribute("href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.MasterStylesheet)), new XAttribute("type", "text/css"))); var html = new XElement(xmlns + "html", new XAttribute(XNamespace.Xml + "lang", "en"), head, body); var document = new XDocument( new XDeclaration("1.0", "UTF-8", null), new XDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", string.Empty), html); return document; }
public void Build(GeneralTree<IDirectoryTreeNode> features) { if (log.IsInfoEnabled) { log.InfoFormat("Writing DHTML files to {0}", this.configuration.OutputFolder.FullName); } var resource = new DhtmlResourceSet(configuration); log.Info("DeployZippedDhtmlResourcesForExtraction"); DeployZippedDhtmlResourcesForExtraction(resource); log.Info("UnzipDhtmlResources"); UnzipDhtmlResources(resource); log.Info("UtilizeJsonBuilderToDumpJsonFeatureFileNextToDthmlResources"); UtilizeJsonBuilderToDumpJsonFeatureFileNextToDthmlResources(features); log.Info("Tweak Json file"); TweakJsonFile(); log.Info("CleanupZippedDhtmlResources"); CleanupZippedDhtmlResources(resource); }
public XDocument Format(IDirectoryTreeNode featureNode, GeneralTree<IDirectoryTreeNode> features, DirectoryInfo rootFolder) { var xmlns = HtmlNamespace.Xhtml; var featureNodeOutputPath = Path.Combine(this.configuration.OutputFolder.FullName, featureNode.RelativePathFromRoot); var featureNodeOutputUri = new Uri(featureNodeOutputPath); var container = new XElement(xmlns + "div", new XAttribute("id", "container")); container.Add(this.htmlHeaderFormatter.Format()); container.Add(this.htmlTableOfContentsFormatter.Format(featureNode.OriginalLocationUrl, features, rootFolder)); container.Add(this.htmlContentFormatter.Format(featureNode, features)); container.Add(this.htmlFooterFormatter.Format()); var body = new XElement(xmlns + "body"); body.Add(container); var head = new XElement(xmlns + "head"); head.Add(new XElement(xmlns + "title", string.Format("{0}", featureNode.Name))); head.Add(new XElement(xmlns + "link", new XAttribute("rel", "stylesheet"), new XAttribute("href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.MasterStylesheet)), new XAttribute("type", "text/css"))); head.Add(new XElement(xmlns + "link", new XAttribute("rel", "stylesheet"), new XAttribute("href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.PrintStylesheet)), new XAttribute("type", "text/css"), new XAttribute("media", "print"))); head.Add(new XElement(xmlns + "script", new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.jQueryScript)), new XAttribute("type", "text/javascript"), new XText(string.Empty))); head.Add(new XElement(xmlns + "script", new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.jQueryDataTablesScript)), new XAttribute("type", "text/javascript"), new XText(string.Empty))); head.Add(new XElement(xmlns + "script", new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.AdditionalScripts)), new XAttribute("type", "text/javascript"), new XText(string.Empty))); head.Add(new XElement(xmlns + "script", new XAttribute("type", "text/javascript"), documentReady)); var html = new XElement(xmlns + "html", new XAttribute(XNamespace.Xml + "lang", "en"), head, body); var document = new XDocument( new XDeclaration("1.0", "UTF-8", null), new XDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", string.Empty), html); return document; }
public void Simple() { var generalTree = new GeneralTree<int>(4); Assert.IsFalse(generalTree.IsReadOnly); generalTree = GetTestTree(); Assert.IsFalse(generalTree.IsReadOnly); }
public void Build(GeneralTree<IDirectoryTreeNode> features) { var map = new XElement("map", new XAttribute("title", "Features"), new XAttribute("id", "features"), this.BuildListItems(features)); var document = new XDocument( new XDocumentType("map", "-//OASIS//DTD DITA Map//EN", "map.dtd", string.Empty), map); document.Save(Path.Combine(this.configuration.OutputFolder.FullName, "features.ditamap")); }
public void ExceptionInvalidSubTreeNegative() { var root = new GeneralTree<int>(5); var child1 = new GeneralTree<int>(2); root.Add(child1); root.GetChild(-1); }
public void IHaveThisFeatureDescription(string featureDescription) { FeatureParser parser = new FeatureParser(this.FileSystem); var feature = parser.Parse(new StringReader(featureDescription)); this.nodes = new GeneralTree<INode>(new FeatureNode(this.FileSystem.DirectoryInfo.FromDirectoryName(@"c:\output\"), string.Empty, feature)); }
public void Get() { var root = new GeneralTree<int>(5) { 2, 3 }; root.GetChild(0).Parent = root.GetChild(1); Assert.AreSame(((ITree<int>)root.GetChild(0)).Parent, root); }
public void IHaveThisFeatureDescription(string featureDescription) { var configuration = this.Container.Resolve<IConfiguration>(); FeatureParser parser = new FeatureParser(this.FileSystem, configuration); var feature = parser.Parse(new StringReader(featureDescription)); this.nodes = new GeneralTree<INode>(new FeatureNode(this.FileSystem.DirectoryInfo.FromDirectoryName(@"c:\output\"), string.Empty, feature)); }
public XElement Format(Uri file, GeneralTree<FeatureNode> features) { var xmlns = XNamespace.Get("http://www.w3.org/1999/xhtml"); return new XElement(xmlns + "div", new XAttribute("id", "toc"), BuildListItems(xmlns, file, features) ); }
public void Simple() { var root = new GeneralTree<int>(5); var child1 = new GeneralTree<int>(2); var child2 = new GeneralTree<int>(3); var child3 = new GeneralTree<int>(5); var child4 = new GeneralTree<int>(7); root.Add(child1); root.Add(child2); Assert.AreEqual(root.Count, 2); Assert.AreEqual(root.Degree, 2); root.RemoveAt(0); Assert.IsNull(child1.Parent); Assert.AreEqual(root.Count, 1); Assert.AreEqual(root.Degree, 1); Assert.AreEqual(root.GetChild(0), child2); Assert.AreEqual(root.GetChild(0).Data, 3); root.Add(child1); Assert.AreEqual(child1.Parent, root); Assert.AreEqual(root.Count, 2); Assert.AreEqual(root.Degree, 2); Assert.IsTrue(root.Remove(child1)); Assert.IsNull(child1.Parent); Assert.AreEqual(root.Count, 1); Assert.AreEqual(root.Degree, 1); Assert.AreEqual(root.GetChild(0), child2); Assert.AreEqual(root.GetChild(0).Data, 3); Assert.IsFalse(root.Remove(child3)); root.Add(child3); root.Add(child4); Assert.AreEqual(root.Count, 3); Assert.AreEqual(root.Degree, 3); var fiveNode = root.FindNode(target => target == 5); Assert.IsTrue(root.Remove(5)); Assert.IsNull(fiveNode.Parent); Assert.AreEqual(root.Count, 2); Assert.AreEqual(root.Degree, 2); Assert.AreEqual(root.GetChild(1).Data, 7); Assert.IsFalse(root.Remove(13)); }
public void Build(GeneralTree<INode> features) { if (log.IsInfoEnabled) { log.InfoFormat("Writing HTML to {0}", this.configuration.OutputFolder.FullName); } this.htmlResourceWriter.WriteTo(this.configuration.OutputFolder.FullName); var actionVisitor = new ActionVisitor<INode>(node => { if (node.IsIndexMarkDownNode()) { return; } string nodePath = this.fileSystem.Path.Combine( this.configuration.OutputFolder. FullName, node.RelativePathFromRoot); string htmlFilePath; if (node.IsContent) { htmlFilePath = nodePath.Replace( this.fileSystem.Path.GetExtension(nodePath), ".html"); } else { this.fileSystem.Directory.CreateDirectory(nodePath); htmlFilePath = this.fileSystem.Path.Combine(nodePath, "index.html"); } using ( var writer = new System.IO.StreamWriter(htmlFilePath, false, Encoding.UTF8)) { XDocument document = this.htmlDocumentFormatter.Format( node, features, this.configuration.FeatureFolder); document.Save(writer); writer.Close(); } }); if (features != null) features.AcceptVisitor(actionVisitor); }
public void Simple() { var tree = new GeneralTree<int>(2); Assert.AreEqual(tree.Data, 2); tree.Data = 5; Assert.AreEqual(tree.Data, 5); }
public void Simple() { var generalTree = new GeneralTree<int>(5); Assert.AreEqual(generalTree.Count, 0); Assert.AreEqual(generalTree.Degree, 0); Assert.AreEqual(generalTree.Height, 0); Assert.IsTrue(generalTree.IsEmpty); Assert.IsTrue(generalTree.IsLeafNode); Assert.IsNull(generalTree.Parent); }
public void Build(GeneralTree<IDirectoryTreeNode> features) { string filename = string.IsNullOrEmpty(this.configuration.SystemUnderTestName) ? "features.docx" : this.configuration.SystemUnderTestName + ".docx"; string documentFileName = Path.Combine(this.configuration.OutputFolder.FullName, filename); if (File.Exists(documentFileName)) File.Delete(documentFileName); using ( WordprocessingDocument wordProcessingDocument = WordprocessingDocument.Create(documentFileName, WordprocessingDocumentType .Document)) { MainDocumentPart mainDocumentPart = wordProcessingDocument.AddMainDocumentPart(); this.wordStyleApplicator.AddStylesPartToPackage(wordProcessingDocument); this.wordStyleApplicator.AddStylesWithEffectsPartToPackage(wordProcessingDocument); this.wordFontApplicator.AddFontTablePartToPackage(wordProcessingDocument); var documentSettingsPart = mainDocumentPart.AddNewPart<DocumentSettingsPart>(); documentSettingsPart.Settings = new Settings(); this.wordHeaderFooterFormatter.ApplyHeaderAndFooter(wordProcessingDocument); var document = new Document(); var body = new Body(); document.Append(body); var actionVisitor = new ActionVisitor<IDirectoryTreeNode>(node => { var featureDirectoryTreeNode = node as FeatureDirectoryTreeNode; if (featureDirectoryTreeNode != null) { this.wordFeatureFormatter.Format(body, featureDirectoryTreeNode); } }); features.AcceptVisitor(actionVisitor); mainDocumentPart.Document = document; mainDocumentPart.Document.Save(); } // HACK - Add the table of contents using (WordprocessingDocument wordProcessingDocument = WordprocessingDocument.Open(documentFileName, true)) { XElement firstPara = wordProcessingDocument .MainDocumentPart .GetXDocument() .Descendants(W.p) .FirstOrDefault(); TocAdder.AddToc(wordProcessingDocument, firstPara, @"TOC \o '1-2' \h \z \u", null, 4); } }
public void Build(GeneralTree<INode> features) { if (Log.IsInfoEnabled) { Log.Info("Writing HTML to {0}", this.configuration.OutputFolder.FullName); } this.htmlResourceWriter.WriteTo(this.configuration.OutputFolder.FullName); var actionVisitor = new ActionVisitor<INode>(node => this.VisitNodes(features, node)); features?.AcceptVisitor(actionVisitor); }
public void ExceptionInvalidIndex1() { var root = new GeneralTree<int>(5); var child1 = new GeneralTree<int>(2); var child2 = new GeneralTree<int>(3); root.Add(child1); root.Add(child2); var i = root[3].Data; }
public XElement Format(Uri file, GeneralTree<INode> features, DirectoryInfoBase outputFolder) { XNamespace xmlns = HtmlNamespace.Xhtml; XElement ul = this.BuildListItems(xmlns, file, features); ul.AddFirst(AddNodeForHome(xmlns, file, outputFolder)); return new XElement( xmlns + "div", new XAttribute("id", "toc"), this.BuildCollapser(xmlns), ul); }
private XElement AddNodeForDirectory(XNamespace xmlns, Uri file, GeneralTree<IDirectoryTreeNode> childNode) { var xElement = new XElement( xmlns + "li", new XElement(xmlns + "div", new XAttribute("class", "directory"), new XElement(xmlns + "a", new XAttribute("href", childNode.Data.GetRelativeUriTo(file) + "index.html"), new XText(childNode.Data.Name))), this.BuildListItems(xmlns, file, childNode)); return xElement; }
public void Build(GeneralTree<INode> features) { if (log.IsInfoEnabled) { log.Info("Writing DHTML files to {0}", this.configuration.OutputFolder.FullName); } log.Info("WriteResources"); this.WriteResources(); log.Info("UtilizeJsonBuilderToDumpJsonFeatureFileNextToDthmlResources"); UtilizeJsonBuilderToDumpJsonFeatureFileNextToDthmlResources(features); log.Info("Tweak Json file"); TweakJsonFile(); }
public void Build(GeneralTree<IDirectoryTreeNode> features) { this.ditaMapBuilder.Build(features); var actionVisitor = new ActionVisitor<IDirectoryTreeNode>(node => { var featureDirectoryTreeNode = node as FeatureDirectoryTreeNode; if (featureDirectoryTreeNode != null) { this.ditaFeatureFormatter.Format( featureDirectoryTreeNode); } }); features.AcceptVisitor(actionVisitor); }
public void Set() { var root = new GeneralTree <int>(5) { 2, 3 }; Assert.AreEqual(root.GetChild(0).Data, 2); Assert.AreEqual(root.GetChild(1).Data, 3); Assert.AreEqual(root.GetChild(0).Parent, root); Assert.AreEqual(root.GetChild(1).Parent, root); root.GetChild(0).Parent = root.GetChild(1); Assert.AreEqual(root.ChildNodes.Count, 1); Assert.AreEqual(root.GetChild(0).ChildNodes.Count, 1); Assert.AreEqual(root.GetChild(0).GetChild(0).Data, 2); Assert.AreEqual(root.GetChild(0).Data, 3); Assert.AreSame(root.GetChild(0).GetChild(0).Parent, root.GetChild(0)); Assert.AreSame(root.GetChild(0).Parent, root); }
public void Setup() { GeneralTree <INode> features = Container.Resolve <DirectoryTreeCrawler>().Crawl(ROOT_PATH); var outputDirectory = RealFileSystem.DirectoryInfo.FromDirectoryName(OUTPUT_DIRECTORY); if (!outputDirectory.Exists) { outputDirectory.Create(); } var configuration = new Configuration { OutputFolder = RealFileSystem.DirectoryInfo.FromDirectoryName(OUTPUT_DIRECTORY), DocumentationFormat = DocumentationFormat.JSON }; var jsonDocumentationBuilder = new JSONDocumentationBuilder(configuration, null, RealFileSystem); jsonDocumentationBuilder.Build(features); }
internal static GeneralTree <int> GetMixedTestTree() { var root = new GeneralTree <int>(5); var child1 = new GeneralTree <int>(2); var child2 = new GeneralTree <int>(3); var child3 = new GeneralTree <int>(1); root.Add(child1); root.Add(child2); root.Add(child3); var child4 = new GeneralTree <int>(15); var child5 = new GeneralTree <int>(11); var child6 = new GeneralTree <int>(13); child1.Add(child4); child1.Add(child5); child2.Add(child6); return(root); }
public void TestAncestors() { GeneralTree <int> tree = GetTestTree(); GeneralTree <int>[] ancestors = tree.GetChild(0).GetChild(0).Ancestors; Assert.AreEqual(ancestors.Length, 2); Assert.AreEqual(ancestors[0], tree.GetChild(0)); Assert.AreEqual(ancestors[1], tree); GeneralTree <int> root = new GeneralTree <int>(5); GeneralTree <int> child1 = new GeneralTree <int>(2); GeneralTree <int> child2 = new GeneralTree <int>(3); GeneralTree <int> child3 = new GeneralTree <int>(1); root.Add(child1); root.Add(child2); root.Add(child3); GeneralTree <int> child4 = new GeneralTree <int>(9); GeneralTree <int> child5 = new GeneralTree <int>(12); GeneralTree <int> child6 = new GeneralTree <int>(13); GeneralTree <int> child7 = new GeneralTree <int>(15); child1.Add(child4); child1.Add(child5); child2.Add(child6); child4.Add(child7); ancestors = child7.Ancestors; Assert.AreEqual(ancestors.Length, 3); Assert.AreEqual(ancestors[0], child4); Assert.AreEqual(ancestors[1], child1); Assert.AreEqual(ancestors[2], root); }
public void Simple() { var tree = GetTestTree(); var ancestors = tree.GetChild(0).GetChild(0).Ancestors; Assert.AreEqual(ancestors.Count, 2); Assert.AreEqual(ancestors[1], tree.GetChild(0)); Assert.AreEqual(ancestors[0], tree); var root = new GeneralTree <int>(5); var child1 = new GeneralTree <int>(2); var child2 = new GeneralTree <int>(3); var child3 = new GeneralTree <int>(1); root.Add(child1); root.Add(child2); root.Add(child3); var child4 = new GeneralTree <int>(9); var child5 = new GeneralTree <int>(12); var child6 = new GeneralTree <int>(13); var child7 = new GeneralTree <int>(15); child1.Add(child4); child1.Add(child5); child2.Add(child6); child4.Add(child7); ancestors = child7.Ancestors; Assert.AreEqual(ancestors.Count, 3); Assert.AreEqual(ancestors[0], root); Assert.AreEqual(ancestors[1], child1); Assert.AreEqual(ancestors[2], child4); }
public void Build(GeneralTree <IDirectoryTreeNode> features) { if (log.IsInfoEnabled) { log.InfoFormat("Writing Excel workbook to {0}", configuration.OutputFolder.FullName); } string spreadsheetPath = Path.Combine(configuration.OutputFolder.FullName, "features.xlsx"); using (var workbook = new XLWorkbook()) { var actionVisitor = new ActionVisitor <IDirectoryTreeNode>(node => { var featureDirectoryTreeNode = node as FeatureDirectoryTreeNode; if (featureDirectoryTreeNode != null) { IXLWorksheet worksheet = workbook.AddWorksheet( excelSheetNameGenerator. GenerateSheetName( workbook, featureDirectoryTreeNode .Feature)); excelFeatureFormatter.Format( worksheet, featureDirectoryTreeNode. Feature); } }); features.AcceptVisitor(actionVisitor); excelTableOfContentsFormatter.Format(workbook, features); workbook.SaveAs(spreadsheetPath); } }
public void Build(GeneralTree <INode> features) { if (log.IsInfoEnabled) { log.Info("Writing JSON to {0}", this.configuration.OutputFolder.FullName); } var featuresToFormat = new List <FeatureWithMetaInfo>(); var actionVisitor = new ActionVisitor <INode>(node => { var featureTreeNode = node as FeatureNode; if (featureTreeNode != null) { if (this.configuration.HasTestResults) { featuresToFormat.Add( new FeatureWithMetaInfo( featureTreeNode, this.testResults. GetFeatureResult( featureTreeNode. Feature))); } else { featuresToFormat.Add( new FeatureWithMetaInfo( featureTreeNode)); } } }); features.AcceptVisitor(actionVisitor); CreateFile(this.OutputFilePath, GenerateJSON(featuresToFormat)); }
private XElement BuildListItems(XNamespace xmlns, Uri file, GeneralTree <INode> features) { var ul = new XElement(xmlns + "ul", new XAttribute("class", "features")); foreach (var childNode in features.ChildNodes) { if (childNode.Data.NodeType == NodeType.Content) { if (childNode.Data.IsIndexMarkDownNode()) { continue; } ul.Add(this.AddNodeForFile(xmlns, file, childNode)); } else if (childNode.Data.NodeType == NodeType.Structure) { ul.Add(this.AddNodeForDirectory(xmlns, file, childNode)); } } return(ul); }
public void TestHeight() { GeneralTree <int> t = new GeneralTree <int>(5); Assert.AreEqual(t.Height, 0); GeneralTree <int> s1 = new GeneralTree <int>(3); t.Add(s1); Assert.AreEqual(t.Height, 1); s1.Add(new GeneralTree <int>(6)); Assert.AreEqual(t.Height, 2); t.Add(new GeneralTree <int>(4)); Assert.AreEqual(t.Height, 2); t = GetTestTree(); Assert.AreEqual(t.Height, 2); }
private GeneralTree <INode> Crawl(DirectoryInfoBase directory, INode rootNode) { INode currentNode = this.featureNodeFactory.Create(rootNode != null ? rootNode.OriginalLocation : null, directory); if (rootNode == null) { rootNode = currentNode; } var tree = new GeneralTree <INode>(currentNode); var filesAreFound = this.CollectFiles(directory, rootNode, tree); var directoriesAreFound = this.CollectDirectories(directory, rootNode, tree); if (!filesAreFound && !directoriesAreFound) { return(null); } return(tree); }
public void Simple() { var generalTree = new GeneralTree <int>(5); Assert.AreEqual(generalTree.Height, 0); var s1 = new GeneralTree <int>(3); generalTree.Add(s1); Assert.AreEqual(generalTree.Height, 1); s1.Add(new GeneralTree <int>(6)); Assert.AreEqual(generalTree.Height, 2); generalTree.Add(new GeneralTree <int>(4)); Assert.AreEqual(generalTree.Height, 2); generalTree = GetTestTree(); Assert.AreEqual(generalTree.Height, 2); }
public void Setup() { this.AddFakeFolderStructures(); GeneralTree <INode> features = Container.Resolve <DirectoryTreeCrawler>().Crawl(FileSystemPrefix); var outputDirectory = FileSystem.DirectoryInfo.FromDirectoryName(OutputDirectory); if (!outputDirectory.Exists) { outputDirectory.Create(); } var configuration = new Configuration { OutputFolder = FileSystem.DirectoryInfo.FromDirectoryName(OutputDirectory), DocumentationFormat = DocumentationFormat.Json }; var jsonDocumentationBuilder = new JsonDocumentationBuilder(configuration, null, FileSystem); jsonDocumentationBuilder.Build(features); }
private bool CollectFiles(DirectoryInfoBase directory, INode rootNode, GeneralTree <INode> tree) { List <INode> collectedNodes = new List <INode>(); foreach (FileInfoBase file in directory.GetFiles().Where(file => this.relevantFileDetector.IsRelevant(file)) ) { INode node = null; try { node = this.featureNodeFactory.Create(rootNode.OriginalLocation, file); } catch (Exception) { if (log.IsWarnEnabled) { // retrieving the name as file.FullName may trigger an exception if the FullName is too long // so we retreive Name and DirectoryName separately // https://github.com/picklesdoc/pickles/issues/199 var fullName = file.Name + " in directory " + file.DirectoryName; log.Warn("The file {0} will be ignored because it could not be read in properly", fullName); } } if (node != null) { collectedNodes.Add(node); } } foreach (var node in OrderFileNodes(collectedNodes)) { tree.Add(node); } return(collectedNodes.Count > 0); }
public void Build(GeneralTree <INode> features) { if (log.IsInfoEnabled) { log.Info("Writing DHTML files to {0}", this.configuration.OutputFolder.FullName); } var resource = new DhtmlResourceSet(configuration, this.fileSystem); log.Info("DeployZippedDhtmlResourcesForExtraction"); DeployZippedDhtmlResourcesForExtraction(resource); log.Info("UnzipDhtmlResources"); UnzipDhtmlResources(resource); log.Info("UtilizeJsonBuilderToDumpJsonFeatureFileNextToDthmlResources"); UtilizeJsonBuilderToDumpJsonFeatureFileNextToDthmlResources(features); log.Info("Tweak Json file"); TweakJsonFile(); log.Info("CleanupZippedDhtmlResources"); CleanupZippedDhtmlResources(resource); }
private void UtilizeJsonBuilderToDumpJsonFeatureFileNextToDthmlResources(GeneralTree <INode> features) { var jsonBuilder = new JSONDocumentationBuilder(configuration, testResults, this.fileSystem); jsonBuilder.Build(features); }
public void TestNullVisitor() { GeneralTree <int> t = GetTestTree(); t.Accept(null); }
public void TestInvalidIndex2() { GeneralTree <int> root = new GeneralTree <int>(5); int i = root[0].Data; }
public void TestInterfaceNullFind() { GeneralTree <int> tree = GetTestTree(); ((ITree <int>)tree).FindNode(null); }
public void TestNullCopyTo() { GeneralTree <int> t = GetTestTree(); t.CopyTo(null, 1); }
public XDocument Format(INode featureNode, GeneralTree <INode> features, DirectoryInfoBase rootFolder) { XNamespace xmlns = HtmlNamespace.Xhtml; string featureNodeOutputPath = this.fileSystem.Path.Combine( this.configuration.OutputFolder.FullName, featureNode.RelativePathFromRoot); var featureNodeOutputUri = new Uri(featureNodeOutputPath); var container = new XElement(xmlns + "div", new XAttribute("id", "container")); container.Add(this.htmlHeaderFormatter.Format()); container.Add(this.htmlTableOfContentsFormatter.Format(featureNode.OriginalLocationUrl, features, rootFolder)); container.Add(this.htmlContentFormatter.Format(featureNode, features)); container.Add(this.htmlFooterFormatter.Format()); var body = new XElement(xmlns + "body"); body.Add(container); var head = new XElement(xmlns + "head"); head.Add(new XElement(xmlns + "title", featureNode.Name)); head.Add( new XElement( xmlns + "link", new XAttribute("rel", "stylesheet"), new XAttribute( "href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.MasterStylesheet)), new XAttribute("type", "text/css"))); head.Add( new XElement( xmlns + "link", new XAttribute("rel", "stylesheet"), new XAttribute( "href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.PrintStylesheet)), new XAttribute("type", "text/css"), new XAttribute("media", "print"))); head.Add( new XElement( xmlns + "script", new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.JQueryScript)), new XAttribute("type", "text/javascript"), new XText(string.Empty))); head.Add( new XElement( xmlns + "script", new XAttribute( "src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.AdditionalScripts)), new XAttribute("type", "text/javascript"), new XText(string.Empty))); head.Add( new XElement( xmlns + "script", new XAttribute("type", "text/javascript"), DocumentReady)); head.Add(new XComment(" We are using Font Awesome - http://fortawesome.github.com/Font-Awesome - licensed under CC BY 3.0 ")); var html = new XElement( xmlns + "html", new XAttribute(XNamespace.Xml + "lang", "en"), head, body); var document = new XDocument( new XDeclaration("1.0", "UTF-8", null), new XDocumentType( "html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", string.Empty), html); return(document); }
public void BuildTableOfContents(XLWorkbook workbook, IXLWorksheet worksheet, ref int row, int column, GeneralTree <INode> features) { foreach (var childNode in features.ChildNodes) { var featureChildNode = childNode.Data as FeatureNode; if (featureChildNode != null) { var featureWorksheet = FindFirstMatchingA1TitleUsingFeatureName(workbook, featureChildNode); this.WriteFileCell(worksheet, ref row, column, featureWorksheet); } else if (childNode.Data.NodeType == NodeType.Structure) { this.WriteDirectoryCell(worksheet, ref row, column, childNode.Data.Name); this.BuildTableOfContents(workbook, worksheet, ref row, column + 1, childNode); } } }
private static void ApplyTestResultsToFeatures(IContainer container, IConfiguration configuration, GeneralTree <INode> features) { var testResults = container.Resolve <ITestResults>(); var actionVisitor = new ActionVisitor <INode>(node => { var featureTreeNode = node as FeatureNode; if (featureTreeNode == null) { return; } if (configuration.HasTestResults) { SetResultsAtFeatureLevel(featureTreeNode, testResults); SetResultsForIndividualScenariosUnderFeature(featureTreeNode, testResults); } else { featureTreeNode.Feature.Result = TestResult.Inconclusive; } }); features.AcceptVisitor(actionVisitor); }
public void TestFindNull() { GeneralTree <int> tree = GetTestTree(); tree.FindNode(null); }
public void TestSortNullComparison() { GeneralTree <int> tree = GetTestTree(); tree.Sort(new InsertionSorter <GeneralTree <int> >(), (Comparison <GeneralTree <int> >)null); }
public void ExcepionInvalidIndex1() { var generalTree = new GeneralTree <int>(3); generalTree.RemoveAt(1); }
public int Compare(GeneralTree <T> x, GeneralTree <T> y) { return(x.Data.CompareTo(y.Data)); }
public void Then_can_crawl_all_folders_including_subfolders_for_features_successfully() { string rootPath = @"FakeFolderStructures\FeatureCrawlerTests"; GeneralTree <INode> features = Container.Resolve <DirectoryTreeCrawler>().Crawl(rootPath); Assert.NotNull(features); INode indexMd = features.ChildNodes[0].Data; indexMd.ShouldNotBeNull(); indexMd.Name.ShouldEqual("This is an index written in Markdown"); indexMd.RelativePathFromRoot.ShouldEqual("index.md"); indexMd.ShouldBeType <MarkdownNode>(); INode levelOneFeature = features.ChildNodes[1].Data; levelOneFeature.ShouldNotBeNull(); levelOneFeature.Name.ShouldEqual("Addition"); levelOneFeature.RelativePathFromRoot.ShouldEqual("LevelOne.feature"); levelOneFeature.ShouldBeType <FeatureNode>(); INode subLevelOneDirectory = features.ChildNodes[2].Data; subLevelOneDirectory.ShouldNotBeNull(); subLevelOneDirectory.Name.ShouldEqual("Sub Level One"); subLevelOneDirectory.RelativePathFromRoot.ShouldEqual(@"SubLevelOne\"); subLevelOneDirectory.ShouldBeType <FolderNode>(); GeneralTree <INode> subLevelOneNode = features.ChildNodes[2]; subLevelOneNode.ChildNodes.Count.ShouldEqual(3); INode levelOneSublevelOneFeature = subLevelOneNode.ChildNodes[0].Data; levelOneSublevelOneFeature.ShouldNotBeNull(); levelOneSublevelOneFeature.Name.ShouldEqual("Addition"); levelOneSublevelOneFeature.RelativePathFromRoot.ShouldEqual(@"SubLevelOne\LevelOneSublevelOne.feature"); levelOneSublevelOneFeature.ShouldBeType <FeatureNode>(); INode levelOneSublevelTwoFeature = subLevelOneNode.ChildNodes[1].Data; levelOneSublevelTwoFeature.ShouldNotBeNull(); levelOneSublevelTwoFeature.Name.ShouldEqual("Addition"); levelOneSublevelTwoFeature.RelativePathFromRoot.ShouldEqual(@"SubLevelOne\LevelOneSublevelTwo.feature"); levelOneSublevelTwoFeature.ShouldBeType <FeatureNode>(); GeneralTree <INode> subLevelTwoNode = subLevelOneNode.ChildNodes[2]; subLevelTwoNode.ChildNodes.Count.ShouldEqual(1); INode subLevelTwoDirectory = subLevelOneNode.ChildNodes[2].Data; subLevelTwoDirectory.ShouldNotBeNull(); subLevelTwoDirectory.Name.ShouldEqual("Sub Level Two"); subLevelTwoDirectory.RelativePathFromRoot.ShouldEqual(@"SubLevelOne\SubLevelTwo\"); subLevelTwoDirectory.ShouldBeType <FolderNode>(); INode levelOneSublevelOneSubLevelTwoDirectory = subLevelOneNode.ChildNodes[2].ChildNodes[0].Data; levelOneSublevelOneSubLevelTwoDirectory.ShouldNotBeNull(); levelOneSublevelOneSubLevelTwoDirectory.Name.ShouldEqual("Addition"); levelOneSublevelOneSubLevelTwoDirectory.RelativePathFromRoot.ShouldEqual(@"SubLevelOne\SubLevelTwo\LevelOneSublevelOneSubLevelTwo.feature"); levelOneSublevelOneSubLevelTwoDirectory.ShouldBeType <FeatureNode>(); }
public void TestInvalidIndexRemoveAt2() { GeneralTree <int> t = GetTestTree(); t.RemoveAt(5); }
public void TestInvalidCompareTo() { GeneralTree <string> g = new GeneralTree <string>("aa"); g.CompareTo(null); }
public void TestInvalidIndexRemoveAt1() { GeneralTree <int> t = new GeneralTree <int>(3); t.RemoveAt(1); }
public void Format(XLWorkbook workbook, GeneralTree<IDirectoryTreeNode> features) { IXLWorksheet tocWorksheet = workbook.AddWorksheet("TOC", 0); int startRow = 1; BuildTableOfContents(workbook, tocWorksheet, ref startRow, 1, features); }