Exemple #1
0
        public void DescribeError_returns_same_exception(EventId eventId, object state, Func <object, Exception, string> formatter)
        {
            var exception = new Exception();

            var result = ExceptionExtensions.DescribeError(exception, eventId, state, formatter);

            Assert.That(result, Is.SameAs(exception));
        }
Exemple #2
0
        public void DescribeError_adds_eventId_to_exceptionInfo(EventId eventId, object state, Func <object, Exception, string> formatter)
        {
            var exception = new Exception();

            ExceptionExtensions.DescribeError(exception, eventId, state, formatter);

            Assume.That(exception.Data.Contains(ExceptionExtensions.ExceptionInfoKey));

            var exceptionInfo = exception.Data[ExceptionExtensions.ExceptionInfoKey] as ExceptionInfo;

            Assert.That(exceptionInfo, Is.Not.Null);
            Assert.That(exceptionInfo.EventId, Is.EqualTo(eventId));
        }
Exemple #3
0
        public void DescribeError_adds_valid_formatter_to_exceptionInfo(EventId eventId, object state, Func <object, Exception, string> formatter)
        {
            var exception = new Exception();

            ExceptionExtensions.DescribeError(exception, eventId, state, formatter);

            Assume.That(exception.Data.Contains(ExceptionExtensions.ExceptionInfoKey));

            var exceptionInfo = exception.Data[ExceptionExtensions.ExceptionInfoKey] as ExceptionInfo;

            Assert.That(exceptionInfo, Is.Not.Null);
            Assert.That(exceptionInfo.Formatter, Is.Not.Null);

            var formattedMessage = exceptionInfo.Formatter(state, exception);

            Mock.Get(formatter).Verify(p => p(state, exception));
        }
Exemple #4
0
        public void DescribeError_adds_valid_logger_delegate_to_exceptionInfo(EventId eventId, object state, Func <object, Exception, string> formatter, ILogger logger)
        {
            var exception = new Exception();

            ExceptionExtensions.DescribeError(exception, eventId, state, formatter);

            Assume.That(exception.Data.Contains(ExceptionExtensions.ExceptionInfoKey));

            var exceptionInfo = exception.Data[ExceptionExtensions.ExceptionInfoKey] as ExceptionInfo;

            Assert.That(exceptionInfo, Is.Not.Null);
            Assert.That(exceptionInfo.Logger, Is.Not.Null);

            exceptionInfo.Logger(logger, eventId, state, exception, exceptionInfo.Formatter);

            Mock.Get(logger).Verify(o => o.Log(LogLevel.Error, eventId, state, exception, It.IsAny <Func <object, Exception, string> >()));
        }