Exemplo n.º 1
0
        /// <summary>
        /// Creates <see cref="ParsingReport"/> from a given <see cref="FileParsingReport"/> and other parameters
        /// </summary>
        internal static ParsingReport CreateParsingReport(FileParsingReport report, TimeSpan duration, string fileRootPath)
        {
            if (report == null)
            {
                return(null);
            }

            var parsingReport = new ParsingReport
            {
                Duration             = duration,
                TotalLinesCount      = report.TotalLinesCount,
                SuccessfulLinesCount = report.SuccessfulLinesCount
            };

            if (report.HasErrors)
            {
                parsingReport.Errors = parsingReport.Errors ?? new List <LineParsingError>();

                parsingReport.Errors.AddRange(
                    GetParsingErrors(report.Errors, fileRootPath));
            }

            if (report.HasWarnings)
            {
                parsingReport.Errors = parsingReport.Errors ?? new List <LineParsingError>();
                parsingReport.Errors.AddRange(
                    GetParsingErrors(report.Warnings, fileRootPath));
            }

            return(parsingReport);
        }
Exemplo n.º 2
0
        public INode Create(FileSystemInfoBase root, FileSystemInfoBase location, ParsingReport report)
        {
            string relativePathFromRoot = root == null ? @".\" : PathExtensions.MakeRelativePath(root, location, this.fileSystem);

            var directory = location as DirectoryInfoBase;

            if (directory != null)
            {
                return(new FolderNode(directory, relativePathFromRoot));
            }

            var file = location as FileInfoBase;

            if (file != null)
            {
                if (this.relevantFileDetector.IsFeatureFile(file))
                {
                    try
                    {
                        Feature feature = this.featureParser.Parse(file.FullName);
                        return(feature != null ? new FeatureNode(file, relativePathFromRoot, feature) : null);
                    }
                    catch (FeatureParseException exception)
                    {
                        report.Add(exception.Message);
                        Log.Error(exception.Message);
                        return(null);
                    }
                }
                else if (this.relevantFileDetector.IsMarkdownFile(file))
                {
                    try
                    {
                        XElement markdownContent =
                            this.htmlMarkdownFormatter.Format(this.fileSystem.File.ReadAllText(file.FullName));
                        return(new MarkdownNode(file, relativePathFromRoot, markdownContent));
                    }
                    catch (Exception exception)
                    {
                        string description = "Error parsing the Markdown file located at " + file.FullName + ". Error: " + exception.Message;
                        report.Add(description);
                        Log.Error(description);
                        return(null);
                    }
                }
                else if (this.relevantFileDetector.IsImageFile(file))
                {
                    return(new ImageNode(file, relativePathFromRoot));
                }
            }

            var message = "Cannot create an IItemNode-derived object for " + location.FullName;

            report.Add(message);
            Log.Error(message);
            return(null);
        }
        public void CreateParsingReportTest()
        {
            FileParsingReport fileParsingReport = new FileParsingReport {
                SuccessfulLinesCount = 10
            };

            // Add errors
            fileParsingReport.Errors.Add(new ParsingError(null, 10, ParsingErrorReason.BadTimestampFormat));
            fileParsingReport.Errors.Add(new ParsingError(null, 11, ParsingErrorReason.BadTimestampFormat));

            fileParsingReport.Errors.Add(new ParsingError(null, 12, ParsingErrorReason.BadWeightFormat));

            // Add warnings
            fileParsingReport.Warnings.Add(new ParsingError(null, 14, ParsingErrorReason.DuplicateItemId));
            fileParsingReport.Warnings.Add(new ParsingError(null, 15, ParsingErrorReason.DuplicateItemId));

            ParsingReport parsingReport = WebJobLogic.CreateParsingReport(fileParsingReport, new TimeSpan(), null);

            Assert.IsNotNull(parsingReport);
            Assert.AreEqual(3, parsingReport.Errors.Count);

            // Ensure errors are added in parsing report
            Assert.IsTrue(
                parsingReport.Errors.Select(x => x.Error)
                .Contains(ParsingErrorReason.BadTimestampFormat));
            Assert.AreEqual(1,
                            parsingReport.Errors
                            .Count(x => x.Error == ParsingErrorReason.BadTimestampFormat));
            Assert.AreEqual(2,
                            parsingReport.Errors
                            .First(x => x.Error == ParsingErrorReason.BadTimestampFormat)
                            .Count);

            Assert.IsTrue(
                parsingReport.Errors.Select(x => x.Error)
                .Contains(ParsingErrorReason.BadWeightFormat));
            Assert.AreEqual(1,
                            parsingReport.Errors
                            .Count(x => x.Error == ParsingErrorReason.BadWeightFormat));
            Assert.AreEqual(1,
                            parsingReport.Errors
                            .First(x => x.Error == ParsingErrorReason.BadWeightFormat)
                            .Count);

            // Ensure warnings are added in parsing report
            Assert.IsTrue(
                parsingReport.Errors.Select(x => x.Error)
                .Contains(ParsingErrorReason.DuplicateItemId));
            Assert.AreEqual(1,
                            parsingReport.Errors
                            .Count(x => x.Error == ParsingErrorReason.DuplicateItemId));
            Assert.AreEqual(2,
                            parsingReport.Errors
                            .First(x => x.Error == ParsingErrorReason.DuplicateItemId)
                            .Count);
        }
Exemplo n.º 4
0
        public void Create_BogusLocationType_AddsEntryToReport()
        {
            var featureNodeFactory = this.CreateFeatureNodeFactory();

            var report = new ParsingReport();

            featureNodeFactory.Create(null, new BogusFileSystemInfoBase {
                fullName = "Totally Bad Name"
            }, report);

            Check.That(report.First()).Contains(@"Totally Bad Name");
        }
Exemplo n.º 5
0
        public void Create_InvalidFileType_AddsEntryToReport()
        {
            FileSystem.AddFile(@"c:\test.dll", new MockFileData("Invalid feature file"));

            var featureNodeFactory = this.CreateFeatureNodeFactory();

            var report = new ParsingReport();

            featureNodeFactory.Create(null, FileSystem.FileInfo.FromFileName(@"c:\test.dll"), report);

            Check.That(report.First()).Contains(@"c:\test.dll");
        }
Exemplo n.º 6
0
        public void Create_MarkdownParsingError_AddsEntryToReport()
        {
            FileSystem.AddFile(@"c:\test.md", new MockFileData("* Some Markdown text"));

            var featureNodeFactory = this.CreateFeatureNodeFactory(new MockMarkdownProvider());

            var report = new ParsingReport();

            featureNodeFactory.Create(null, FileSystem.FileInfo.FromFileName(@"c:\test.md"), report);

            Check.That(report.Count).Equals(1);
            Check.That(report.First()).Equals(@"Error parsing the Markdown file located at c:\test.md. Error: Error parsing text.");
        }
Exemplo n.º 7
0
        public void Run(IContainer container)
        {
            var configuration = container.Resolve <IConfiguration>();

            if (!configuration.OutputFolder.Exists)
            {
                configuration.OutputFolder.Create();
            }

            var featureCrawler = container.Resolve <DirectoryTreeCrawler>();
            var parsingReport  = new ParsingReport();

            Tree features = featureCrawler.Crawl(configuration.FeatureFolder, parsingReport);

            if (parsingReport.Any())
            {
                var error = $"Some files ({parsingReport.Count}) were not parsed correctly.";
                Log.Error(error);
            }

            if (features == null)
            {
                Log.Warn("No features found at {0}", configuration.FeatureFolder);
                return;
            }

            ApplyTestResultsToFeatures(container, configuration, features);

            var documentationBuilder = container.Resolve <IDocumentationBuilder>();

            try
            {
                documentationBuilder.Build(features);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Something went wrong during generation: {0}", ex);
                throw;
            }

            if (parsingReport.Any())
            {
                throw new ApplicationException("Some files were not parsed correctly.");
            }
        }
Exemplo n.º 8
0
        public INode Create(FileSystemInfo root, FileSystemInfo location, ParsingReport report)
        {
            string relativePathFromRoot = root == null ? @".\" : PathExtensions.MakeRelativePath(root, location);

            var directory = location as DirectoryInfo;

            if (directory != null)
            {
                return(new FolderNode(directory, relativePathFromRoot));
            }

            var file = location as FileInfo;

            if (file != null)
            {
                if (this.relevantFileDetector.IsFeatureFile(file))
                {
                    try
                    {
                        Feature feature = this.featureParser.Parse(file.FullName);
                        return(feature != null ? new FeatureNode(file, relativePathFromRoot, feature) : null);
                    }
                    catch (FeatureParseException exception)
                    {
                        report.Add(exception.Message);
                        Log.Error(exception.Message);
                        return(null);
                    }
                }
                else if (this.relevantFileDetector.IsImageFile(file))
                {
                    return(new ImageNode(file, relativePathFromRoot));
                }
            }

            var message = "Cannot create an IItemNode-derived object for " + location.FullName;

            report.Add(message);
            Log.Error(message);
            return(null);
        }
Exemplo n.º 9
0
        private Tree Crawl(DirectoryInfo directory, INode rootNode, ParsingReport parsingReport)
        {
            INode currentNode =
                this.featureNodeFactory.Create(rootNode != null ? rootNode.OriginalLocation : null, directory, parsingReport);

            if (rootNode == null)
            {
                rootNode = currentNode;
            }

            var tree = new Tree(currentNode);

            var filesAreFound = this.CollectFiles(directory, rootNode, tree, parsingReport);

            var directoriesAreFound = this.CollectDirectories(directory, rootNode, tree, parsingReport);

            if (!filesAreFound && !directoriesAreFound)
            {
                return(null);
            }

            return(tree);
        }
Exemplo n.º 10
0
        private bool CollectFiles(DirectoryInfo directory, INode rootNode, Tree tree, ParsingReport parsingReport)
        {
            List <INode> collectedNodes = new List <INode>();

            foreach (FileInfo file in directory.GetFiles().Where(file => this.relevantFileDetector.IsRelevant(file)))
            {
                INode node = this.featureNodeFactory.Create(rootNode.OriginalLocation, file, parsingReport);
                if (node != null)
                {
                    collectedNodes.Add(node);
                }
            }

            foreach (var node in OrderFileNodes(collectedNodes))
            {
                tree.Add(node);
            }

            return(collectedNodes.Count > 0);
        }
Exemplo n.º 11
0
        private bool CollectDirectories(DirectoryInfo directory, INode rootNode, Tree tree, ParsingReport parsingReport)
        {
            List <Tree> collectedNodes = new List <Tree>();

            foreach (DirectoryInfo subDirectory in directory.GetDirectories().OrderBy(di => di.Name))
            {
                Tree subTree = this.Crawl(subDirectory, rootNode, parsingReport);
                if (subTree != null)
                {
                    collectedNodes.Add(subTree);
                }
            }

            foreach (var node in collectedNodes)
            {
                tree.Add(node);
            }

            return(collectedNodes.Count > 0);
        }
Exemplo n.º 12
0
 public Tree Crawl(DirectoryInfo directory, ParsingReport parsingReport)
 {
     return(this.Crawl(directory, null, parsingReport));
 }