コード例 #1
0
        public void OnExceptionGetsOrAddsTheLoggerToHttpContext()
        {
            var httpContext = new Mock <HttpContextBase>();

            httpContext.Setup(p => p.Items).Returns(new Dictionary <string, object>());

            InternalExceptionLogger.LogException(new Exception(), httpContext.Object);

            var dictionary = httpContext.Object.Items[KissLog.AspNet.Web.LoggerFactory.DictionaryKey] as IDictionary <string, Logger>;

            Assert.IsNotNull(dictionary);
            Assert.AreEqual(1, dictionary.Count);
        }
コード例 #2
0
        public void OnExceptionLogsTheError()
        {
            var ex = new Exception($"Exception {Guid.NewGuid()}");

            var httpContext = new Mock <HttpContextBase>();

            httpContext.Setup(p => p.Items).Returns(new Dictionary <string, object>());

            InternalExceptionLogger.LogException(ex, httpContext.Object);

            var    dictionary = httpContext.Object.Items[KissLog.AspNet.Web.LoggerFactory.DictionaryKey] as IDictionary <string, Logger>;
            Logger logger     = dictionary[Constants.DefaultLoggerCategoryName];

            Exception  capturedException = logger.DataContainer.Exceptions.First();
            LogMessage message           = logger.DataContainer.LogMessages.First();

            Assert.AreEqual(ex.Message, capturedException.Message);
            Assert.IsTrue(message.Message.Contains(ex.Message));
        }
コード例 #3
0
 public void OnExceptionThrowsExceptionForNullHttpContext()
 {
     InternalExceptionLogger.LogException(new Exception(), null);
 }
コード例 #4
0
        public void OnExceptionThrowsExceptionForNullException()
        {
            var httpContext = new Mock <HttpContextBase>();

            InternalExceptionLogger.LogException(null, httpContext.Object);
        }