Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnii committed Feb 25, 2019
1 parent b63c91f commit 77a2439
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
12 changes: 1 addition & 11 deletions src/SpeakEasy.Specifications/Bodies/FileUploadBodySpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IFile>() });
Expand All @@ -39,16 +39,6 @@ class when_serializing
It should_have_content_type_for_multipart_form_data = () =>
serializable.ShouldBeOfExactType<MultipartMimeContent>();
}
class when_serializing_
{
static IContent serializable;

Because of = () =>
serializable = body.Serialize(transmissionSettings, An<IArrayFormatter>());

It should_have_content_type_for_multipart_form_data = () =>
serializable.ShouldBeOfExactType<MultipartMimeContent>();
}

class when_serializing_a_multipart_form
{
Expand Down
1 change: 1 addition & 0 deletions src/SpeakEasy.Specifications/Requests/PostRequestSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/SpeakEasy/Contents/MultipartFormDataContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -56,7 +56,7 @@ public MultipartFileFormDataContent(Resource resource)
}
}
}

httpRequest.Content = content;
}
}
Expand Down

0 comments on commit 77a2439

Please sign in to comment.