public void RunWithoutReportInfoTest() { string codeBase = Environment.CurrentDirectory; string defaultNamespace = "Tests.CodeExamples"; var analyzer = new CodeExamplesAnalyzer( codeBase, defaultNamespace); // Without report info. StringWriter consoleWriter = new StringWriter(); var defaultOut = Console.Out; Console.SetOut(consoleWriter); var examples = analyzer.Run(false); Assert.AreEqual(String.Empty, consoleWriter.ToString()); Console.SetOut(defaultOut); CodeExampleTester.TestCodeExample0(examples); CodeExampleTester.TestCodeExample1(examples); CodeExampleTester.TestCodeExample2(examples); CodeExampleTester.TestCodeExample3(examples); CodeExampleTester.TestCodeExample4(examples); CodeExampleTester.TestCodeExample5(examples); CodeExampleTester.TestCodeExample6(examples); CodeExampleTester.TestCodeExample7(examples); }
public void RunWithReportInfoTest() { string codeBase = Environment.CurrentDirectory; string defaultNamespace = "Tests.CodeExamples"; var analyzer = new CodeExamplesAnalyzer( codeBase, defaultNamespace); // With report info. var consoleWriter = new StringWriter(); var defaultOut = Console.Out; Console.SetOut(consoleWriter); var examples = analyzer.Run(true); StringWriter expectedWriter = new StringWriter(); expectedWriter.WriteLine("Tests.CodeExamples.CodeExample6:"); expectedWriter.WriteLine(" Source code: cannot be found."); expectedWriter.WriteLine(" Execution: successful."); expectedWriter.WriteLine("Tests.CodeExamples.CodeExample7:"); expectedWriter.WriteLine(" Source code: cannot be found."); expectedWriter.WriteLine(" Execution: failed. Exception: CodeExample7:error"); expectedWriter.WriteLine("Tests.CodeExamples.CodeExample0:"); expectedWriter.WriteLine(" Source code: found."); expectedWriter.WriteLine(" Execution: failed. Exception: CodeExample0:error"); expectedWriter.WriteLine("Tests.CodeExamples.CodeExample1:"); expectedWriter.WriteLine(" Source code: found."); expectedWriter.WriteLine(" Execution: successful."); expectedWriter.WriteLine("Tests.CodeExamples.Advanced.CodeExample4:"); expectedWriter.WriteLine(" Source code: found."); expectedWriter.WriteLine(" Execution: failed. Exception: CodeExample4:error"); expectedWriter.WriteLine("Tests.CodeExamples.Advanced.CodeExample5:"); expectedWriter.WriteLine(" Source code: found."); expectedWriter.WriteLine(" Execution: successful."); expectedWriter.WriteLine("Tests.CodeExamples.Advanced.CodeExample2:"); expectedWriter.WriteLine(" Source code: cannot be found."); expectedWriter.WriteLine(" Execution: successful."); expectedWriter.WriteLine("Tests.CodeExamples.Advanced.CodeExample3:"); expectedWriter.WriteLine(" Source code: cannot be found."); expectedWriter.WriteLine(" Execution: failed. Exception: CodeExample3:error"); expectedWriter.WriteLine(); expectedWriter.WriteLine("Number of examples: 8."); expectedWriter.WriteLine(" Number of examples with no source code: 4."); expectedWriter.WriteLine(" Number of failed examples: 4."); var expected = expectedWriter.ToString(); var actual = consoleWriter.ToString(); Assert.AreEqual(expected, actual); Console.SetOut(defaultOut); CodeExampleTester.TestCodeExample0(examples); CodeExampleTester.TestCodeExample1(examples); CodeExampleTester.TestCodeExample2(examples); CodeExampleTester.TestCodeExample3(examples); CodeExampleTester.TestCodeExample4(examples); CodeExampleTester.TestCodeExample5(examples); CodeExampleTester.TestCodeExample6(examples); CodeExampleTester.TestCodeExample7(examples); }