public void Embed(bool verbose, string expectedOutput)
        {
            StringMarkupDocumentWriter logWriter = new StringMarkupDocumentWriter(verbose);
            logWriter["AnyStream"].Embed(new TextAttachment("foo", "text/plain", "don't care"));

            Assert.AreEqual(expectedOutput, logWriter.ToString());
        }
        public void AttachBytes(bool verbose, string expectedOutput)
        {
            StringMarkupDocumentWriter logWriter = new StringMarkupDocumentWriter(verbose);
            logWriter.Attach(new BinaryAttachment("foo", "application/octet-stream", new byte[0])); 

            Assert.AreEqual(expectedOutput, logWriter.ToString());
        }
        public void Write(bool verbose, string expectedOutput)
        {
            StringMarkupDocumentWriter logWriter = new StringMarkupDocumentWriter(verbose);
            logWriter["AnyStream"].Write("abcdef");

            Assert.AreEqual(expectedOutput, logWriter.ToString());
        }
        public void Sections(bool verbose, string expectedOutput)
        {
            StringMarkupDocumentWriter logWriter = new StringMarkupDocumentWriter(verbose);
            using (logWriter["AnyStream"].BeginSection("foo"))
                logWriter["AnyStream"].Write("Bar bar bar");

            Assert.AreEqual(expectedOutput, logWriter.ToString());
        }
        public void WriteTo()
        {
            StackTraceData data = new StackTraceData("   at SomeMethod\r\n   at Gallio.Tests.Model.Diagnostics.StackTraceDataTest.WriteTo() in C:\\Source\\MbUnit\\v3\\src\\Gallio\\Gallio.Tests\\Model\\Diagnostics\\StackTraceDataTest.cs:line 70\r\n   at Gallio.Tests.Model.Diagnostics.StackTraceDataTest.Blah() in C:\\Source\\MbUnit\\v3\\src\\Gallio\\Gallio.Tests\\Model\\Diagnostics\\StackTraceDataTest.cs:line 72\r\n");

            StringMarkupDocumentWriter writer = new StringMarkupDocumentWriter(true);
            data.WriteTo(writer.Failures);

            Assert.AreEqual("[Marker \'StackTrace\']   at SomeMethod\n   at Gallio.Tests.Model.Diagnostics.StackTraceDataTest.WriteTo() in [Marker \'CodeLocation\']C:\\Source\\MbUnit\\v3\\src\\Gallio\\Gallio.Tests\\Model\\Diagnostics\\StackTraceDataTest.cs:line 70[End]\n   at Gallio.Tests.Model.Diagnostics.StackTraceDataTest.Blah() in [Marker \'CodeLocation\']C:\\Source\\MbUnit\\v3\\src\\Gallio\\Gallio.Tests\\Model\\Diagnostics\\StackTraceDataTest.cs:line 72[End][End]", writer.ToString());
        }
 public void ConstructsWithCodeElement()
 {
     var mockCodeElement = MockRepository.GenerateStub<ICodeElementInfo>();
     mockCodeElement.Stub(x => x.GetCodeLocation()).Return(new CodeLocation("C:\\Path\\File.cs", 123, 456));
     mockCodeElement.Stub(x => x.CodeReference).Return(new CodeReference("AssemblyName", "The.Ultimate.NameSpace", "TypeName", "MemberName", "ParameterName"));
     var data = new StackTraceData(mockCodeElement);
     var writer = new StringMarkupDocumentWriter(true);
     data.WriteTo(writer.Failures);
     Assert.AreEqual("[Marker \'StackTrace\']   at MemberName\n   at The.Ultimate.NameSpace.TypeName() in [Marker \'CodeLocation\']C:\\Path\\File.cs:line 123[End][End]", writer.ToString());
 }
        public void WriteToBareBones()
        {
            AssertionFailure failure = new AssertionFailureBuilder("Description")
                .SetStackTrace(null)
                .ToAssertionFailure();
            TestLog.Write(failure);

            StringMarkupDocumentWriter writer = new StringMarkupDocumentWriter(true);
            failure.WriteTo(writer.Failures);

            Assert.AreEqual("[Marker \'AssertionFailure\'][Section \'Description\']\n[End]\n[End]", writer.ToString());
        }
        public void WriteToEverything()
        {
            AssertionFailure failure = new AssertionFailureBuilder("Description")
                .SetMessage("Message goes here")
                .SetStackTrace(new StackTraceData("Stack goes here"))
                .AddRawExpectedValue("Expected value")
                .AddRawActualValue("Actual value")
                .AddRawLabeledValue("Very Long Label That Will Not Be Padded", "")
                .AddRawLabeledValue("x", 42)
                .AddException(new Exception("Boom"))
                .AddException(new Exception("Kaput"))
                .AddInnerFailure(new AssertionFailureBuilder("Inner").SetStackTrace(null).ToAssertionFailure())
                .ToAssertionFailure();
            TestLog.Write(failure);

            StringMarkupDocumentWriter writer = new StringMarkupDocumentWriter(true);
            failure.WriteTo(writer.Failures);

            Assert.AreEqual("[Marker \'AssertionFailure\'][Section \'Description\']\nMessage goes here\n\n[Marker \'Monospace\'][Marker \'Label\']Expected Value : [End]\"Expected value\"\n[Marker \'Label\']Actual Value   : [End]\"Actual value\"\n[Marker \'Label\']Very Long Label That Will Not Be Padded : [End]\"\"\n[Marker \'Label\']x              : [End]42\n[End]\n[Marker \'Exception\'][Marker \'ExceptionType\']System.Exception[End]: [Marker \'ExceptionMessage\']Boom[End][End]\n\n[Marker \'Exception\'][Marker \'ExceptionType\']System.Exception[End]: [Marker \'ExceptionMessage\']Kaput[End][End]\n\n[Marker \'StackTrace\']Stack goes here[End]\n[Marker \'AssertionFailure\'][Section \'Inner\']\n[End]\n[End][End]\n[End]", writer.ToString());
        }
 /// <summary>
 /// Formats the failure as a string.
 /// </summary>
 /// <returns>The formatted string.</returns>
 public override string ToString()
 {
     var writer = new StringMarkupDocumentWriter(false);
     WriteTo(writer.Default);
     return writer.ToString();
 }
        public void WriteToEverything(bool useStandardFormatting)
        {
            ExceptionData innerData = new ExceptionData("type", "message", "stacktrace", ExceptionData.NoProperties, null);
            ExceptionData outerData = new ExceptionData("type", "message", "stacktrace",
                new PropertySet() {
                    { "Prop1", "Value1" },
                    { "Prop2", "Value2" }
                }, innerData);

            StringMarkupDocumentWriter writer = new StringMarkupDocumentWriter(true);
            outerData.WriteTo(writer.Failures, useStandardFormatting);

            Assert.AreEqual("[Marker \'Exception\'][Marker \'ExceptionType\']type[End]: [Marker \'ExceptionMessage\']message[End] ---> [Marker \'Exception\'][Marker \'ExceptionType\']type[End]: [Marker \'ExceptionMessage\']message[End]\n"
                + "[Marker \'StackTrace\']stacktrace[End][End]\n   --- End of inner exception stack trace ---\n"
                + (useStandardFormatting ? "" : "[Marker \'ExceptionPropertyName\']Prop1[End]: [Marker \'ExceptionPropertyValue\']Value1[End]\n[Marker \'ExceptionPropertyName\']Prop2[End]: [Marker \'ExceptionPropertyValue\']Value2[End]\n")
                + "[Marker \'StackTrace\']stacktrace[End][End]",
                writer.ToString());
        }
        public void WriteToBareBones()
        {
            ExceptionData data = new ExceptionData("type", "message", "stacktrace", ExceptionData.NoProperties, null);
            StringMarkupDocumentWriter writer = new StringMarkupDocumentWriter(true);
            data.WriteTo(writer.Failures);

            Assert.AreEqual("[Marker \'Exception\'][Marker \'ExceptionType\']type[End]: [Marker \'ExceptionMessage\']message[End]\n[Marker \'StackTrace\']stacktrace[End][End]",
                writer.ToString());
        }