public async Task Invoke_NoLogs() { var mockLogger = new Mock <IExceptionLogger>(); RequestDelegate requestDelegate = context => Task.CompletedTask; var middleware = new ErrorReportingExceptionLoggerMiddleware(requestDelegate, mockLogger.Object); await middleware.Invoke(new DefaultHttpContext()); mockLogger.Verify(l => l.LogAsync(It.IsAny <Exception>(), It.IsAny <DefaultHttpContext>(), CancellationToken.None), Times.Never()); }
public async Task Invoke_LogsAndThrows() { var mockLogger = new Mock <IExceptionLogger>(); RequestDelegate requestDelegate = context => { throw new DivideByZeroException(); }; var middleware = new ErrorReportingExceptionLoggerMiddleware(requestDelegate, mockLogger.Object); await Assert.ThrowsAsync <DivideByZeroException>(() => middleware.Invoke(new DefaultHttpContext())); mockLogger.Verify(l => l.LogAsync(It.IsAny <Exception>(), It.IsAny <DefaultHttpContext>(), CancellationToken.None), Times.Once()); }
public async Task Invoke_LogsAndThrows() { var mockLogger = new Mock <IExceptionLogger <ReportErrorEventResponse> >(); RequestDelegate requestDelegate = context => { throw new Exception(); }; var middleware = new ErrorReportingExceptionLoggerMiddleware(requestDelegate, mockLogger.Object); await Assert.ThrowsAsync <Exception>(() => middleware.Invoke(new DefaultHttpContext())); mockLogger.Verify(l => l.LogAsync(It.IsAny <DefaultHttpContext>(), It.IsAny <Exception>()), Times.Once()); mockLogger.Verify(l => l.Log(It.IsAny <DefaultHttpContext>(), It.IsAny <Exception>()), Times.Never()); }