public async Task SendFileWorks()
        {
            IOwinResponse     response = new OwinResponse();
            string            name     = null;
            long              offset   = 0;
            long?             length   = null;
            CancellationToken token;
            Func <string, long, long?, CancellationToken, Task> func = (n, o, l, c) =>
            {
                name   = n;
                offset = o;
                length = l;
                token  = c;
                return(Task.FromResult(0));
            };

            response.Set("sendfile.SendAsync", func);

            await response.SendFileAsync("bob", 1, 3, CancellationToken.None);

            Assert.Equal("bob", name);
            Assert.Equal(1, offset);
            Assert.Equal(3, length);
            Assert.Equal(CancellationToken.None, token);
        }
 public void SendFileSupport()
 {
     IOwinResponse response = new OwinResponse();
     Assert.False(response.SupportsSendFile());
     // response.Set("sendfile.SendAsync", new Object());
     // Assert.False(response.SupportsSendFile()); // Get<type> throw for type mismatch.
     response.Set("sendfile.SendAsync", new Func<string, long, long?, CancellationToken, Task>((_, __, ___, ____) => Task.FromResult(0)));
     Assert.True(response.SupportsSendFile());
 }
        public void SendFileSupport()
        {
            IOwinResponse response = new OwinResponse();

            Assert.False(response.SupportsSendFile());
            // response.Set("sendfile.SendAsync", new Object());
            // Assert.False(response.SupportsSendFile()); // Get<type> throw for type mismatch.
            response.Set("sendfile.SendAsync", new Func <string, long, long?, CancellationToken, Task>((_, __, ___, ____) => Task.FromResult(0)));
            Assert.True(response.SupportsSendFile());
        }
Esempio n. 4
0
        /// <summary>
        /// Creates request OWIN respresentation.
        /// </summary>
        /// <param name="method">The request method.</param>
        /// <param name="scheme">The request scheme.</param>
        /// <param name="pathBase">The request base path.</param>
        /// <param name="path">The request path.</param>
        /// <param name="headers">The request headers.</param>
        /// <param name="queryString">The request query string</param>
        /// <param name="requestBody">The body of request.</param>
        /// <returns>OWIN representation for provided request parameters.</returns>
        private static Dictionary <string, object> CreateOwinEnvironment(string method, string scheme, string pathBase,
                                                                         string path, IDictionary <string, string[]> headers, string queryString = "", byte[] requestBody = null)
        {
            var environment = new Dictionary <string, object>(StringComparer.Ordinal);

            environment[CommonOwinKeys.OwinCallCancelled] = new CancellationToken();

            #region OWIN request params

            var request = new OwinRequest(environment)
            {
                Method      = method,
                Scheme      = scheme,
                Path        = new PathString(path),
                PathBase    = new PathString(pathBase),
                QueryString = new QueryString(queryString),
                Body        = new MemoryStream(requestBody ?? new byte[0]),
                Protocol    = Protocols.Http1
            };

            // request.Headers is readonly
            request.Set(CommonOwinKeys.RequestHeaders, headers);

            #endregion


            #region set default OWIN response params

            var response = new OwinResponse(environment)
            {
                Body = new MemoryStream(), StatusCode = StatusCode.Code200Ok
            };
            //response.Headers is readonly
            response.Set(CommonOwinKeys.ResponseHeaders, new Dictionary <string, string[]>(StringComparer.OrdinalIgnoreCase));

            #endregion


            return(environment);
        }
        public async Task SendFileWorks()
        {
            IOwinResponse response = new OwinResponse();
            string name = null;
            long offset = 0;
            long? length = null;
            CancellationToken token;
            Func<string, long, long?, CancellationToken, Task> func = (n, o, l, c) =>
                {
                    name = n;
                    offset = o;
                    length = l;
                    token = c;
                    return Task.FromResult(0);
                };

            response.Set("sendfile.SendAsync", func);

            await response.SendFileAsync("bob", 1, 3, CancellationToken.None);
            Assert.Equal("bob", name);
            Assert.Equal(1, offset);
            Assert.Equal(3, length);
            Assert.Equal(CancellationToken.None, token);
        }