public void ExtractSnippet(string fileName, string pattern, string expectedFile) { // Run the extraction ISnippetExtractor snippetExtractor; if (!this.extractorCache.TryGetValue(fileName, out snippetExtractor)) { snippetExtractor = new CSharpSnippetExtractor(this.SourceDirectories); this.extractorCache[fileName] = snippetExtractor; } Projbook.Core.Model.Snippet snippet = snippetExtractor.Extract(fileName, pattern); // Load the expected file content MemoryStream memoryStream = new MemoryStream(); using (var fileReader = new StreamReader(new FileStream(Path.GetFullPath(Path.Combine("Resources", "Expected", expectedFile)), FileMode.Open))) using (var fileWriter = new StreamWriter(memoryStream)) { fileWriter.Write(fileReader.ReadToEnd()); } // Assert Assert.AreEqual( System.Text.Encoding.UTF8.GetString(memoryStream.ToArray()).Replace("\r\n", Environment.NewLine), snippet.Content.Replace("\r\n", Environment.NewLine)); }
public void ExtractSnippetNotFound(string fileName, string pattern) { // Run the extraction CSharpSnippetExtractor extractor = new CSharpSnippetExtractor(this.SourceDirectories); Projbook.Core.Model.Snippet snippet = extractor.Extract(fileName, pattern); }
public void ExtractSnippetInvalidRule(string pattern) { // Run the extraction CSharpSnippetExtractor extractor = new CSharpSnippetExtractor(pattern, this.SourceDirectories); Projbook.Core.Model.Snippet snippet = extractor.Extract(); }