public RollingContextTest Update(string source, string fileName = DefaultFileName) { source = SourceHelper.CleanSource(source); if (!Validator.UpdateMarkdownFile(fileName, source)) { Validator.AddMarkdownFile(fileName, source); } return(this); }
private void TryUpdate(string path, string source) { try { if (!_validator.UpdateMarkdownFile(path, source)) { _validator.AddEntity(path); } } catch (ArgumentException ae) { OnOutOfContext(path, ae); } }
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 }