Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created March 23, 2011 13:00
Show Gist options
  • Save thecodejunkie/883061 to your computer and use it in GitHub Desktop.
Save thecodejunkie/883061 to your computer and use it in GitHub Desktop.
Using a custom extension to the Nancy test harness to be able to add multipart/form-data encoded data into the request
[Fact]
public void Should_add_multipart_formdata_encoded_files_to_request_filestream()
{
// Given
var stream =
CreateFakeFileStream("This is the contents of a file");
var multipart = new BrowserContextMultipartFormData(x => {
x.AddFile("foo", "foo.txt", "text/plain", stream);
});
// When
var context = browser.Get("/", (with) => {
with.HttpRequest();
with.MultiPartFormData(multipart);
});
// Then
context.Request.Files.ShouldHaveCount(1);
context.Request.Files.First().ContentType.ShouldEqual("text/plain");
context.Request.Files.First().Name.ShouldEqual("foo.txt");
context.Request.Files.First().Value.AsString().ShouldEqual("This is the contents of a file");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment