public void read_normal_exception()
        {
            var record = new JobExecutionRecord();
            var ex = new DivideByZeroException("Only Chuck Norris can do that");

            record.ReadException(ex);

            record.ExceptionText.ShouldBe(ex.ToString());
        }
        public void creates_the_grammar_error()
        {
            var ex = new DivideByZeroException("No!");
            var fixture = new InvalidFixture(typeof (FixtureThatBlowsUp), ex);

            var model = fixture.Compile(null);
            var error = model.errors.Single();

            error.error.ShouldBe(ex.ToString());
            error.message.ShouldBe("Fixture StoryTeller.Testing.FixtureThatBlowsUp could not be loaded");
        }
        public void read_aggregate_exception()
        {
            var ex1 = new DivideByZeroException("Only Chuck Norris can do that");
            var ex2 = new RankException("You're last!");
            var ex3 = new InvalidTimeZoneException("You are in the wrong place!");

            var ex = new AggregateException(ex1, ex2, ex3);

            var record = new JobExecutionRecord();
            record.ReadException(ex);

            record.ExceptionText.ShouldNotBe(ex.ToString());
            record.ExceptionText.ShouldContain(ex1.ToString());
            record.ExceptionText.ShouldContain(ex2.ToString());
            record.ExceptionText.ShouldContain(ex3.ToString());

            record.ExceptionText.ShouldContain(JobExecutionRecord.ExceptionSeparator);
        }
        public void CanAppendMessageWithException()
        {
            //-- Arrange

            var logger = CreateTestLogger();
            var exception = new DivideByZeroException();

            //-- Act

            logger.ThisIsMyErrorMessageWithExceptionParameter(num: 123, str: "ABC", e: exception);

            //-- Assert

            var log = _logAppender.TakeLog();

            Assert.That(log.Length, Is.EqualTo(1));
            Assert.That(log[0].Level, Is.EqualTo(LogLevel.Error));
            Assert.That(log[0].SingleLineText, Is.EqualTo("This is my error message with exception parameter: num=123, str=ABC"));
            Assert.That(log[0].FullDetailsText.Contains(exception.ToString()));
            Assert.That(log[0].Exception, Is.SameAs(exception));
        }
        public void log_exception_once()
        {
            var subject1 = MockRepository.GenerateMock<ISubject>();
            var subject2 = MockRepository.GenerateMock<ISubject>();

            var log = new StubbedChainExecutionLog();
            log.StartSubject(subject1);
            log.StartSubject(subject2);

            var ex = new DivideByZeroException();

            log.LogException(ex);

            log.FinishSubject();
            log.LogException(ex);

            log.FinishSubject();
            log.LogException(ex);



            log.Steps.Select(x => x.Log).OfType<ExceptionReport>()
                .Single().ExceptionText.ShouldBe(ex.ToString());
        }
        public void TwoValuesWithFormatDetailsAndException()
        {
            //-- Arrange

            var exception = new DivideByZeroException();
            var node = new NameValuePairLogNode<string, decimal>(
                "Test.MessageOne", LogLevel.Info, exception,
                value1: new LogNameValuePair<string> {
                    Name = "accountId",
                    Value = "ABCD1234"
                },
                value2: new LogNameValuePair<decimal> {
                    Name = "balance",
                    Value = 1234567890m,
                    Format = "#,###.00",
                    IsDetail = true
                });

            _threadLog.AppendNode(node);

            //-- Act

            var singleLineText = node.SingleLineText;
            var fullDetailsText = node.FullDetailsText;
            var nameValuePairs = node.NameValuePairsText;

            //-- Assert

            Assert.That(singleLineText, Is.EqualTo("Message one: accountId=ABCD1234"));

            Assert.That(fullDetailsText, Is.EqualTo(
                "balance=1,234,567,890.00" + System.Environment.NewLine +
                exception.ToString()));

            Assert.That(nameValuePairs, Is.EqualTo(
                ExpectedBaseNameValuePairs +
                " exception=System.DivideByZeroException accountId=ABCD1234 balance=1,234,567,890.00"));
        }
        public void ZeroValuesWithException()
        {
            //-- Arrange

            var exception = new DivideByZeroException();
            var node = new NameValuePairLogNode("Test.MessageOne", LogLevel.Info, exception);
            _threadLog.AppendNode(node);

            //-- Act

            var singleLineText = node.SingleLineText;
            var fullDetailsText = node.FullDetailsText;
            var nameValuePairs = node.NameValuePairsText;

            //-- Assert

            Assert.That(singleLineText, Is.EqualTo("Message one"));
            Assert.That(fullDetailsText.Contains(exception.ToString()));
            Assert.That(nameValuePairs, Is.EqualTo(
                ExpectedBaseNameValuePairs + " exceptionType=System.DivideByZeroException exception=\"Attempted to divide by zero.\""
            ));
        }