public async void Invoke_WithNonMatchingPath_IgnoresRequest() { // Arrange var elmStore = new ElmStore(); var factory = new LoggerFactory(); var optionsMock = new Mock<IOptions<ElmOptions>>(); optionsMock .SetupGet(o => o.Options) .Returns(new ElmOptions()); factory.AddProvider(new ElmLoggerProvider(elmStore, optionsMock.Object.Options)); RequestDelegate next = _ => { return Task.FromResult<object>(null); }; var captureMiddleware = new ElmCaptureMiddleware( next, factory, optionsMock.Object); var pageMiddleware = new ElmPageMiddleware( next, optionsMock.Object, elmStore); var contextMock = GetMockContext("/nonmatchingpath"); // Act await captureMiddleware.Invoke(contextMock.Object); await pageMiddleware.Invoke(contextMock.Object); // Assert // Request.Query is used by the ElmPageMiddleware to parse the query parameters contextMock.VerifyGet(c => c.Request.Query, Times.Never()); }
public async void Invoke_WithMatchingPath_FulfillsRequest() { // Arrange var elmStore = new ElmStore(); var factory = new LoggerFactory(); var optionsMock = new Mock<IOptions<ElmOptions>>(); optionsMock .SetupGet(o => o.Options) .Returns(new ElmOptions()); factory.AddProvider(new ElmLoggerProvider(elmStore, optionsMock.Object.Options)); RequestDelegate next = _ => { return Task.FromResult<object>(null); }; var captureMiddleware = new ElmCaptureMiddleware( next, factory, optionsMock.Object); var pageMiddleware = new ElmPageMiddleware( next, optionsMock.Object, elmStore); var contextMock = GetMockContext("/Elm"); using (var responseStream = new MemoryStream()) { contextMock .SetupGet(c => c.Response.Body) .Returns(responseStream); contextMock .SetupGet(c => c.ApplicationServices) .Returns(() => null); // Act await captureMiddleware.Invoke(contextMock.Object); await pageMiddleware.Invoke(contextMock.Object); string response = Encoding.UTF8.GetString(responseStream.ToArray()); // Assert contextMock.VerifyGet(c => c.Request.Query, Times.AtLeastOnce()); Assert.True(response.Contains("<title>ASP.NET Logs</title>")); } }