Exemplo n.º 1
0
        public async Task ReadParametersFromPostRequest()
        {
            /* given */
            var httpRequest = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri("http://files/upload")
            };

            var streamContent = new StreamContent(new MemoryStream());

            streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = "my-file.txt"
            };

            var formDataContent = new MultipartFormDataContent
            {
                { new StringContent("1"), "flowChunkNumber" },
                { new StringContent("2048"), "flowChunkSize" },
                { new StringContent("1024"), "flowTotalSize" },
                { new StringContent("0001-my-file.file"), "flowIdentifier" },
                { new StringContent("my-file.file"), "flowFilename" },
                { streamContent, "content", "my-file.txt" }
            };
            var context = new FlowRequestContext(httpRequest);

            /* when */
            using (formDataContent)
            {
                httpRequest.Content = formDataContent;

                var         reader = new FlowRequestReader();
                FlowRequest request;
                using (var memoryStream = new MemoryStream())
                {
                    request =
                        await reader.ReadPostAsync(context, new FileSystem()).ConfigureAwait(false);
                }

                /* then */
                request.FlowChunkNumber.ShouldBeEquivalentTo(1);
                request.FlowChunkSize.ShouldBeEquivalentTo(2048);
                request.FlowTotalSize.ShouldBeEquivalentTo(1024);
                request.FlowIdentifier.ShouldBeEquivalentTo("0001-my-file.file");
                request.FlowFilename.ShouldBeEquivalentTo("my-file.file");
            }
        }
        public async Task ReadParametersFromPostRequest()
        {
            /* given */
            var httpRequest = new HttpRequestMessage
            {
                Method = HttpMethod.Get,
                RequestUri = new Uri("http://files/upload")
            };

            var streamContent = new StreamContent(new MemoryStream());
            streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = "my-file.txt"
            };

            var formDataContent = new MultipartFormDataContent
            {
                {new StringContent("1"), "flowChunkNumber"},
                {new StringContent("2048"), "flowChunkSize"},
                {new StringContent("1024"), "flowTotalSize"},
                {new StringContent("0001-my-file.file"), "flowIdentifier"},
                {new StringContent("my-file.file"), "flowFilename"},
                {streamContent, "content", "my-file.txt"}
            };
            var context = new FlowRequestContext(httpRequest);

            /* when */
            using (formDataContent)
            {
                httpRequest.Content = formDataContent;

                var reader = new FlowRequestReader();
                FlowRequest request;
                using (var memoryStream = new MemoryStream())
                {
                    request =
                        await reader.ReadPostAsync(context, new FileSystem());
                }

                /* then */
                request.FlowChunkNumber.ShouldBeEquivalentTo(1);
                request.FlowChunkSize.ShouldBeEquivalentTo(2048);
                request.FlowTotalSize.ShouldBeEquivalentTo(1024);
                request.FlowIdentifier.ShouldBeEquivalentTo("0001-my-file.file");
                request.FlowFilename.ShouldBeEquivalentTo("my-file.file");
            }
        }