public async Task When_InvokingMiddlewareWithPathAndIgnorePattern_Expect_Logged(string path, string ignorePattern, bool logged) { // Arrange Mock <ILogger <RequestLoggingMiddleware> > mock = new Mock <ILogger <RequestLoggingMiddleware> >(); mock.Setup(m => m.IsEnabled(It.IsAny <LogLevel>())).Returns(true); RequestLoggingMiddleware.Options options = new RequestLoggingMiddleware.Options { IgnorePatterns = new string[] { ignorePattern }, }; RequestLoggingMiddleware middleware = new RequestLoggingMiddleware( (httpContext) => Task.CompletedTask, mock.Object, Options.Create(options)); HttpContext context = new DefaultHttpContext(); context.Request.Path = path; // Act await middleware.Invoke(context); // Assert mock.Verify( m => m.Log( It.IsAny <LogLevel>(), It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), null, (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Exactly(logged ? 2 : 0)); }
public void When_InstantiatingOptions_Expect_IgnorePatternsEmpty() { // Arrange RequestLoggingMiddleware.Options options; // Act options = new RequestLoggingMiddleware.Options(); // Assert Assert.Empty(options.IgnorePatterns); }