public void Setup() { loggerFactory = Substitute.For <ILoggerFactory>(); logger = Substitute.For <ICorrelationLogger>(); loggerFactory.CreateCorrelationLogger(Arg.Any <RequestErrorLogger>()).Returns(logger); correlation = Substitute.For <ICorrelation>(); sut = new RequestErrorLogger(loggerFactory, request => correlation); }
public void Setup() { loggerFactory = Substitute.For<ILoggerFactory>(); logger = Substitute.For<ICorrelationLogger>(); loggerFactory.CreateCorrelationLogger(Arg.Any<RequestErrorLogger>()).Returns(logger); correlation = Substitute.For<ICorrelation>(); sut = new RequestErrorLogger(loggerFactory, request => correlation); }
public void CorrelationCanBeNull() { var exception = new ArgumentException("Test"); var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://www.server.domain"); var httpRouteData = new HttpRouteData(new HttpRoute()); var httpControllerContext = new HttpControllerContext(new HttpConfiguration(), httpRouteData, httpRequestMessage); var actionContext = new HttpActionContext(httpControllerContext, new ReflectedHttpActionDescriptor()); actionContext.ActionArguments.Add("Key1", "Value1"); actionContext.ActionArguments.Add("Key2", "Value2"); var exceptionContext = new ExceptionContext(exception, new ExceptionContextCatchBlock("TestBlock", false, false), actionContext); var loggerContext = new ExceptionLoggerContext(exceptionContext); sut = new RequestErrorLogger(loggerFactory, request => null); sut.Log(loggerContext); logger.Received().LogError(null, exception, "Unhandled exception from request: {0}({1})", httpRequestMessage, "Key1: Value1, Key2: Value2"); }
public void ErrorIsLoggedEvenIfCorrelationCannotBeRetrieved() { var exception = new ArgumentException("Test"); var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://www.server.domain"); var httpRouteData = new HttpRouteData(new HttpRoute()); var httpControllerContext = new HttpControllerContext(new HttpConfiguration(), httpRouteData, httpRequestMessage); var actionContext = new HttpActionContext(httpControllerContext, new ReflectedHttpActionDescriptor()); actionContext.ActionArguments.Add("Key1", "Value1"); actionContext.ActionArguments.Add("Key2", "Value2"); var exceptionContext = new ExceptionContext(exception, new ExceptionContextCatchBlock("TestBlock", false, false), actionContext); var loggerContext = new ExceptionLoggerContext(exceptionContext); sut = new RequestErrorLogger(loggerFactory, request => { throw new Exception(); }); sut.Log(loggerContext); logger.Received().LogError(null, exception, "Unhandled exception from request: {0}({1})", httpRequestMessage, "Key1: Value1, Key2: Value2"); }
public void NullLoggerThrowsError() { sut = new RequestErrorLogger(null, request => correlation); }