public void NoMatch_PassesThrough(string baseUrl, string baseDir, string requestUrl)
        {
            IAppBuilder builder = new AppBuilder();
            builder.UseDirectoryBrowser(baseUrl, baseDir);
            var app = (AppFunc)builder.Build(typeof(AppFunc));

            IDictionary<string, object> env = CreateEmptyRequest(requestUrl);
            app(env).Wait();

            Assert.Equal(404, env["owin.ResponseStatusCode"]);
        }
        public void NearMatch_RedirectAddSlash(string baseUrl, string baseDir, string requestUrl)
        {
            IAppBuilder builder = new AppBuilder();
            builder.UseDirectoryBrowser(baseUrl, baseDir);
            var app = (AppFunc)builder.Build(typeof(AppFunc));

            IDictionary<string, object> env = CreateEmptyRequest(requestUrl);
            app(env).Wait();

            Assert.Equal(301, env["owin.ResponseStatusCode"]);
            var responseHeaders = (IDictionary<string, string[]>)env["owin.ResponseHeaders"];
            Assert.Equal(requestUrl + "/", responseHeaders["Location"][0]);
            Assert.Equal(0, ((Stream)env["owin.ResponseBody"]).Length);
        }
        public void FoundDirectory_Served(string baseUrl, string baseDir, string requestUrl)
        {
            IAppBuilder builder = new AppBuilder();
            builder.UseDirectoryBrowser(baseUrl, baseDir);
            var app = (AppFunc)builder.Build(typeof(AppFunc));

            IDictionary<string, object> env = CreateEmptyRequest(requestUrl);
            app(env).Wait();

            Assert.False(env.ContainsKey("owin.ResponseStatusCode"));
            var responseHeaders = (IDictionary<string, string[]>)env["owin.ResponseHeaders"];
            Assert.Equal("text/html", responseHeaders["Content-Type"][0]);
            Assert.True(responseHeaders["Content-Length"][0].Length > 0);
            Assert.Equal(responseHeaders["Content-Length"][0], ((Stream)env["owin.ResponseBody"]).Length.ToString());
        }
        public void NoKnownAcceptContentType_406NotAcceptable(string[] acceptHeader)
        {
            IAppBuilder builder = new AppBuilder();
            builder.UseDirectoryBrowser(string.Empty, string.Empty);
            var app = (AppFunc)builder.Build(typeof(AppFunc));

            IDictionary<string, object> env = CreateEmptyRequest("/");
            SetAcceptHeader(env, acceptHeader);
            app(env).Wait();

            Assert.Equal(406, env["owin.ResponseStatusCode"]);
        }
        // TODO: text/*, q rankings, etc.
        public void KnownAcceptContentType_Served(string[] acceptHeader, string expectedContentType)
        {
            IAppBuilder builder = new AppBuilder();
            builder.UseDirectoryBrowser(string.Empty, string.Empty);
            var app = (AppFunc)builder.Build(typeof(AppFunc));

            IDictionary<string, object> env = CreateEmptyRequest("/");
            SetAcceptHeader(env, acceptHeader);
            app(env).Wait();

            Assert.False(env.ContainsKey("owin.ResponseStatusCode"));
            var responseHeaders = (IDictionary<string, string[]>)env["owin.ResponseHeaders"];
            Assert.Equal(expectedContentType, responseHeaders["Content-Type"][0]);
            Assert.True(responseHeaders["Content-Length"][0].Length > 0);
            Assert.Equal(responseHeaders["Content-Length"][0], ((Stream)env["owin.ResponseBody"]).Length.ToString());
        }