예제 #1
0
        public void Write_should_append_to_log_with_formatting()
        {
            // given
            TestFileRunnerLogger logger = CreateLogger();
            string expectedText         = ExpectedMessage("a message item1 item2");

            // when
            logger.Write("a message {0} {1}", "item1", "item2");

            // then
            string actualText = logger.LogStringBuilder.ToString();

            Assert.That(actualText, Is.EqualTo(expectedText));
        }
예제 #2
0
        public void GetLog_should_return_current_log_text()
        {
            // given
            TestFileRunnerLogger logger = CreateLogger();
            string expectedText         = ExpectedMessage("a message");

            logger.Write("a message");

            // when
            string actualText = logger.GetLog();

            // then
            Assert.That(actualText, Is.EqualTo(expectedText));
        }
예제 #3
0
        public void Write_should_swallow_bad_string_formatting()
        {
            // given
            TestFileRunnerLogger logger = CreateLogger();
            string expectedText         = ExpectedMessage("Logger caught a formatting exception. Message: 'bad formatting {0} {1} {4}' args.length: 1");

            // when
            logger.Write("bad formatting {0} {1} {4}", 1);

            // then
            string actualText = logger.LogStringBuilder.ToString();

            // stringbuilder still writes until it gets an exception
            Assert.That(actualText, Is.EqualTo(expectedText));
        }