/// <summary> /// Tests a successful code example, defined /// in the default namespace, whose source code /// can be found. /// </summary> public static void TestCodeExample1(List <CodeExampleInfo> examples) { var exampleFullName = "Tests.CodeExamples.CodeExample1"; var example = Select(examples, exampleFullName); Assert.IsNotNull(example); CodeExampleInfoAssert.IsSuccessful(example); Assert.IsTrue(example.HasSourceCode); StringWriter writer = new StringWriter(); writer.WriteLine("CodeExample1:output"); CodeExampleInfoAssert.HasOutput(example, writer.ToString()); var commentSymbol = example.Language.CommentSymbol; writer = new StringWriter(); writer.WriteLine("using System;"); writer.WriteLine(); writer.WriteLine("namespace Tests.CodeExamples"); writer.WriteLine("{"); writer.WriteLine(" public class CodeExample1 "); writer.WriteLine(" {"); writer.WriteLine(" public void Main()"); writer.WriteLine(" {"); writer.WriteLine(" Console.WriteLine(\"CodeExample1:output\");"); writer.WriteLine(" }"); writer.WriteLine(" }"); writer.WriteLine("}"); writer.WriteLine(); writer.WriteLine(commentSymbol + "Executing method Main() produces the following output:"); writer.WriteLine(commentSymbol); writer.WriteLine(commentSymbol + "CodeExample1:output"); CodeExampleInfoAssert.HasOutputFile(example, writer.ToString()); }
/// <summary> /// Tests a successful code example, defined /// in the default namespace, whose source code /// cannot be found. /// </summary> /// <remarks> /// <para> /// Source code files must be stored in a directory tree under a /// user defined folder, the <see cref="CodeExamplesAnalyzer.CodeBase"/>, /// reflecting the project namespace hierarchy. /// </para> /// <para> /// As a consequence, the source code for <see cref="CodeExample6"/> cannot /// be found since the file is in not in the expected directory. /// </para> /// </remarks> public static void TestCodeExample6(List <CodeExampleInfo> examples) { var exampleFullName = "Tests.CodeExamples.CodeExample6"; var example = Select(examples, exampleFullName); Assert.IsNotNull(example); CodeExampleInfoAssert.IsSuccessful(example); Assert.IsFalse(example.HasSourceCode); StringWriter writer = new StringWriter(); writer.WriteLine("CodeExample6:output"); CodeExampleInfoAssert.HasOutput(example, writer.ToString()); CodeExampleInfoAssert.HasNotOutputFile(example); }