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); }
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)); }
public void OnExceptionThrowsExceptionForNullHttpContext() { InternalExceptionLogger.LogException(new Exception(), null); }
public void OnExceptionThrowsExceptionForNullException() { var httpContext = new Mock <HttpContextBase>(); InternalExceptionLogger.LogException(null, httpContext.Object); }