From 77a2439c0a751c24191705aea3687fc3026a293b Mon Sep 17 00:00:00 2001 From: jonnii Date: Mon, 25 Feb 2019 16:22:28 -0500 Subject: [PATCH] more --- .../Bodies/FileUploadBodySpecs.cs | 12 +----------- .../Requests/PostRequestSpecs.cs | 1 + src/SpeakEasy/Contents/MultipartFormDataContent.cs | 8 ++++---- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/SpeakEasy.Specifications/Bodies/FileUploadBodySpecs.cs b/src/SpeakEasy.Specifications/Bodies/FileUploadBodySpecs.cs index f06e188..dd6cdfd 100644 --- a/src/SpeakEasy.Specifications/Bodies/FileUploadBodySpecs.cs +++ b/src/SpeakEasy.Specifications/Bodies/FileUploadBodySpecs.cs @@ -16,7 +16,7 @@ class FileUploadBodySpecs : WithFakes static Resource resource; - private Establish context = () => + Establish context = () => { resource = Resource.Create("http://example.com/fribble/frabble"); body = new FileUploadBody(resource, new[] { An() }); @@ -39,16 +39,6 @@ class when_serializing It should_have_content_type_for_multipart_form_data = () => serializable.ShouldBeOfExactType(); } - class when_serializing_ - { - static IContent serializable; - - Because of = () => - serializable = body.Serialize(transmissionSettings, An()); - - It should_have_content_type_for_multipart_form_data = () => - serializable.ShouldBeOfExactType(); - } class when_serializing_a_multipart_form { diff --git a/src/SpeakEasy.Specifications/Requests/PostRequestSpecs.cs b/src/SpeakEasy.Specifications/Requests/PostRequestSpecs.cs index 5c43c37..49520f0 100644 --- a/src/SpeakEasy.Specifications/Requests/PostRequestSpecs.cs +++ b/src/SpeakEasy.Specifications/Requests/PostRequestSpecs.cs @@ -52,6 +52,7 @@ class when_building_request_url_with_post_request_body It should_not_generate_query_params = () => request.BuildRequestUrl(new CommaSeparatedArrayFormatter()).ShouldEqual("http://example.com/companies"); } + class when_building_request_url_with_post_request_body_of_a_file { static IRequestBody body; diff --git a/src/SpeakEasy/Contents/MultipartFormDataContent.cs b/src/SpeakEasy/Contents/MultipartFormDataContent.cs index c7929b9..0fc9994 100644 --- a/src/SpeakEasy/Contents/MultipartFormDataContent.cs +++ b/src/SpeakEasy/Contents/MultipartFormDataContent.cs @@ -24,13 +24,13 @@ public MultipartFileFormDataContent(Resource resource) { foreach (var parameter in resource.Parameters) { - if (parameter.Value is IFile) + if (parameter.Value is IFile file) { - var file = (IFile) parameter.Value; var ms = new MemoryStream(); await file.WriteToAsync(ms); - + var fileContent = new StringContent(Encoding.ASCII.GetString(ms.ToArray())); + fileContent.Headers.ContentType = string.IsNullOrWhiteSpace(file.ContentType) ? MediaTypeHeaderValue.Parse("application/octet-stream") : MediaTypeHeaderValue.Parse(file.ContentType); @@ -56,7 +56,7 @@ public MultipartFileFormDataContent(Resource resource) } } } - + httpRequest.Content = content; } }