public void ShouldBeInvokedForMatchingPaths() { var handlerInvocationTest = new MiddlewareInvocationTest<PageContentMiddleware>(); Action<Mock<IOwinResponse>, Mock<IOwinContext>, string> verification = (response, context, path) => response.Verify(r => r.Write(It.IsAny<string>()), Times.Exactly(1), string.Format("The handler {0} SHOULD have been invoked for path: {1}", typeof(PageContentMiddleware).Name, path)); //Handler should be invoked for the following request paths handlerInvocationTest.TestInvokeWhenRequestPathIs("/somedirectory/page.html", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/somedirectory/oldschool.htm", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/someotherdirectory/another.html", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/some/long/path/with/a/page/at/the/end.html", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/directory/page.php", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("", verification); verification = (response, context, path) => response.Verify(r => r.Write(It.IsAny<string>()), Times.Exactly(0), string.Format("The handler {0} should NOT have been invoked for path: {1}", typeof(PageContentMiddleware).Name, path)); //Handler should NOT be invoked for the following request paths handlerInvocationTest.TestInvokeWhenRequestPathIs("/path-without-extension", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/somepath/file.xml", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/style/site.css", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/js/thenextbigthang.js", verification); }
public void ShouldBeInvokedForMatchingPaths() { var handlerInvocationTest = new MiddlewareInvocationTest<JavascriptContentMiddleware>(); Action<Mock<IOwinResponse>, Mock<IOwinContext>, string> verification = (response, context, path) => response.Verify(r => r.Write(It.IsAny<string>()), Times.Exactly(1), string.Format("The handler {0} SHOULD have been invoked for path: {1}", typeof(JavascriptContentMiddleware).Name, path)); //Handler should be invoked for the following request paths handlerInvocationTest.TestInvokeWhenRequestPathIs("/js/thenextbigthang.js", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/path/of/any/length/site.js", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/base-path-file.js", verification); verification = (response, context, path) => response.Verify(r => r.Write(It.IsAny<string>()), Times.Exactly(0), string.Format("The handler {0} should NOT have been invoked for path: {1}", typeof(JavascriptContentMiddleware).Name, path)); //Handler should NOT be invoked for the following request paths handlerInvocationTest.TestInvokeWhenRequestPathIs("/somedirectory/page.html", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/scripts/not-a-javascript-file.jsx", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/a-tricky-path.js.txt", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/versioned-js-not-supported-at-this-time.js?any-kind-of-query-string-that-is-used-to-implement-a-versioning-strategy=vNext!!", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("", verification); }
public void ShouldBeInvokedForMatchingPaths() { var handlerInvocationTest = new MiddlewareInvocationTest<HeadersMiddleware>(); Action<Mock<IOwinResponse>, Mock<IOwinContext>, string> verification = (response, context, path) => response.VerifyGet(r => r.Headers, Times.AtLeastOnce(), string.Format("The middleware {0} SHOULD have been invoked for path: {1}", typeof(HeadersMiddleware).Name, path)); //Handler should be invoked for the following request paths handlerInvocationTest.TestInvokeWhenRequestPathIs("/header_X-Frame-Options_SAMEORIGIN/page.html", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/Header_X-Frame-Options_SAMEORIGIN/page.html", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/somedirectory/header_X-Frame-Options_SAMEORIGIN/oldschool.htm", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/header_X-Frame-Options_SAMEORIGIN/header_Server_theserver/another.html", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/header_X-Request-Guid_d5845750-c5d9-46fc-84c8-2320f6149f3d/page.php", verification); verification = (response, context, path) => response.VerifyGet(r => r.Headers, Times.Exactly(0), string.Format("The middleware {0} should NOT have been invoked for path: {1}", typeof(HeadersMiddleware).Name, path)); //Handler should NOT be invoked for the following request paths handlerInvocationTest.TestInvokeWhenRequestPathIs("/", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/X-Request-Guid_d5845750-c5d9-46fc-84c8-2320f6149f3d/page.html", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/somepath/file.xml", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/style/site.css", verification); handlerInvocationTest.TestInvokeWhenRequestPathIs("/js/thenextbigthang.js", verification); }