public void Log_ExceptionWithMultipleLevelsOfInnerExceptions_LogsWholeHierachyAsExpected()
        {
            // Arrange
            int expectedNumberOfLoggedExceptions = 6;

            var exceptionWithMultipleInnerExceptions = new CompositeException("failure 1 / parent",
                                                                              new Exception[]
            {
                new ArgumentException("failure 2 / inner level 1"),
                new InvalidOperationException("failure 3 / inner level 1"),
                new MultipleFailuresException("failure 4 / parent level 1")
                {
                    InnerExceptions = new Exception[]
                    {
                        new ArgumentException("failure 5 / inner level 2"),
                        new InvalidOperationException("failure 6 / inner level 2")
                    },
                }
            });

            var logger = new CachingSqlLoggingProvider();

            // Act
            logger.Log(exceptionWithMultipleInnerExceptions);

            // Arrange
            Assert.AreEqual(expectedNumberOfLoggedExceptions, logger.LoggedExceptions.Count,
                            "Inner exceptions that contain multiple exceptions by them selves should be logged.");
        }
        public void Log_CompositeExceptionWithMultipleInnerExceptions_LogsMultipleInnerExceptions()
        {
            // Arrange
            int       expectedNumberOfLoggedExceptions = 3;
            Exception exceptionWithMultipleInnerExceptions;

            try
            {
                throw new CompositeException("failure 1 / parent exception",
                                             new Exception[]
                {
                    CreateThrownException <ArgumentException>(),
                    CreateThrownException <InvalidOperationException>()
                });
            }
            catch (Exception ex)
            {
                exceptionWithMultipleInnerExceptions = ex;
            }

            var logger = new CachingSqlLoggingProvider();

            // Act
            logger.Log(exceptionWithMultipleInnerExceptions);

            // Arrange
            Assert.AreEqual(expectedNumberOfLoggedExceptions, logger.LoggedExceptions.Count,
                            "The logged exception contains two inner exceptions and they are expected to be logged.");
        }
        public void Log_ExceptionWithInnerException_LogsExceptionAndItsInnerException()
        {
            // Arrange
            int expectedNumberOfLoggedExceptions = 2;

            Exception exceptionToLog = new InvalidCastException("message", new FormatException());

            var logger = new CachingSqlLoggingProvider();

            // Act
            logger.Log(exceptionToLog);

            // Arrange
            Assert.AreEqual(expectedNumberOfLoggedExceptions, logger.LoggedExceptions.Count,
                            "We'd expect a single exception to be logged and nothing else..");
            Assert.AreEqual(exceptionToLog.InnerException, logger.LoggedExceptions[1].Exception);
        }
        public void Log_ExceptionWithoutInnerException_LogsThatSingleException()
        {
            // Arrange
            int expectedNumberOfLoggedExceptions = 1;

            Exception exceptionToLog = CreateThrownException <ArgumentNullException>();

            var logger = new CachingSqlLoggingProvider();

            // Act
            logger.Log(exceptionToLog);

            // Arrange
            Assert.AreEqual(expectedNumberOfLoggedExceptions, logger.LoggedExceptions.Count,
                            "We'd expect a single exception to be logged and nothing else..");
            Assert.AreEqual(exceptionToLog, logger.LoggedExceptions[0].Exception);
        }
        public void Logging_CustomExceptionWithMultipleInnerExceptions_LogsMultipleInnerExceptions()
        {
            // Arrange
            int expectedNumberOfLoggedExceptions = 3;

            var exceptionWithMultipleInnerExceptions = new MultipleFailuresException("failure 1 / parent")
            {
                InnerExceptions = new Exception[]
                {
                    new ArgumentException("failure 2 / inner exception 1"),
                    new InvalidOperationException("failure 3 / inner exception 2")
                }
            };

            var logger = new CachingSqlLoggingProvider();

            // Act
            logger.Log(exceptionWithMultipleInnerExceptions);

            // Arrange
            Assert.AreEqual(expectedNumberOfLoggedExceptions, logger.LoggedExceptions.Count,
                            "The logged exception exposed two inner exceptions through it's public 'InnerExceptions' " +
                            "property and they are expected to be logged.");
        }