private void Validate()
        {
            lock (RevalidationTimer)
            {
                var report = _validator.Validate();

                if (report.IsComplete)
                {
                    RevalidationTimer.Change(Timeout.Infinite, Timeout.Infinite);
                }
                else
                {
                    RevalidationTimer.Change(200, Timeout.Infinite);
                }

                if (report == PreviousReport)
                {
                    return;
                }

                var diff = report.Diff(PreviousReport);
                PreviousReport = report;

                foreach (var affectedFile in diff.AffectedFiles)
                {
                    string       path;
                    Diagnostic[] fileDiagnostics;

                    if (report.WarningsByFile.TryGetValue(affectedFile.Key, out List <Warning> warnings))
                    {
                        path            = warnings.First().Location.FullFilePath;
                        path            = Path.Combine(report.Configuration.RootWorkingDirectory, affectedFile.Key);
                        fileDiagnostics = new Diagnostic[warnings.Count];
                        for (int i = 0; i < fileDiagnostics.Length; i++)
                        {
                            var warning = warnings[i];
                            int line    = Math.Max(warning.Location.StartLine, 0);
                            fileDiagnostics[i] = new Diagnostic()
                            {
                                Code     = new DiagnosticCode(warning.ID.Identifier),
                                Range    = ToRange(warning.Location),
                                Message  = warning.Message,
                                Severity = ToDiagnosticSeverity(warning),
                                //Source = "MarkdownValidator"
                            };
                        }
                    }
                    else
                    {
                        path            = Path.Combine(report.Configuration.RootWorkingDirectory, affectedFile.Key);
                        fileDiagnostics = Array.Empty <Diagnostic>();
                    }

                    PublishDiagnostics(fileDiagnostics, path);
                }
            }
        }
Ejemplo n.º 2
0
        private ValidationReport Validate()
        {
            var report = Validator.Validate(ValidateFully);

            if (ValidateFully)
            {
                Xunit.Assert.True(report.IsComplete);
            }
            return(report);
        }
Ejemplo n.º 3
0
        public static void Fuzz(int iterations, int stringSizeMin, int stringSizeMax, string alphabet, string fileAlphabet, int maxFileNameLength)
        {
            MarkdownContextValidator validator = new MarkdownContextValidator();
            Random seedRandom = new Random();

#if RELEASE
            try
            {
#endif
            int concurrent      = 4;
            int localIterations = iterations / concurrent;
            Task[] tasks        = new Task[concurrent];
            for (int t = 0; t < concurrent; t++)
            {
                Random random = new Random(seedRandom.Next());
                tasks[t] = Task.Run(() =>
                {
                    char[] stringChars = new string(' ', stringSizeMax).ToCharArray();
                    for (int i = 0; i < localIterations; i++)
                    {
                        if (i % 100 == 99)
                        {
                            validator.Validate();
                        }
                        try
                        {
                            int fileNameLength = 1 + random.Next(maxFileNameLength);
                            stringChars[random.Next(fileNameLength)] = fileAlphabet[random.Next(fileAlphabet.Length)];
                            string fileName = new string(stringChars, 0, fileNameLength);

                            int stringLength = random.Next(stringSizeMin, stringSizeMax);
                            stringChars[random.Next(stringLength)] = alphabet[random.Next(alphabet.Length)];
                            string randomString = new string(stringChars, 0, stringLength);

                            if (i % 100 == 0)
                            {
                                if (!validator.UpdateMarkdownFile(fileName, randomString))
                                {
                                    validator.AddMarkdownFile(fileName, randomString);
                                }
                            }
                            else
                            {
                                fileName = Guid.NewGuid() + fileName;
                                validator.AddMarkdownFile(fileName, randomString);
                            }
                        }
                        catch (ArgumentException ae) when(ae.Message.EndsWith("is not a child path of the root working directory of the context", StringComparison.Ordinal))
                        {
                        }
                        catch (PathTooLongException) { }
                    }
                });
            }
            Task.WaitAll(tasks);
#if RELEASE
        }

        catch
        {
            Console.WriteLine("Failed");
            Console.ReadLine();
        }
#endif
        }
Ejemplo n.º 4
0
        public void ValidationReport_Equals_Empty()
        {
            var validator = new MarkdownContextValidator();

            Assert.Equal(validator.Validate(), validator.ValidateFully());
        }