public void Handle(HttpStatusCode statusCode, NancyContext context) { var response = new GenericFileResponse("views/404.html", "text/html"); response.StatusCode = statusCode; context.Response = response; }
public void Should_set_status_code_to_ok() { // Given, When var response = new GenericFileResponse(this.imagePath, imageContentType, this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.OK); }
public void Should_set_status_code_to_not_found_when_file_name_is_empty() { // Given, When var response = new GenericFileResponse(string.Empty, imageContentType); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_set_status_code_to_not_found_when_file_name_is_null() { // Given, When var response = new GenericFileResponse(null, imageContentType, this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_set_filename_property_to_filename() { // Given, When var response = new GenericFileResponse(this.imagePath, imageContentType, this.context); // Then response.Filename.ShouldEqual(Path.GetFileName(this.imagePath)); }
public void Should_set_status_code_to_ok() { // Given // When var response = new GenericFileResponse(this.filePath, "text/plain", this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.OK); }
public void Should_set_status_code_to_not_found_when_file_does_not_exist() { // Given // When var response = new GenericFileResponse("nancy", this.fileContentType, this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_contain_etag_in_response_header() { // Given, when var response = new GenericFileResponse(this.imagePath, imageContentType, this.context); // Then response.Headers["ETag"].ShouldStartWith("\""); response.Headers["ETag"].ShouldEndWith("\""); }
public void Should_set_content_length_in_response_header() { // Given, when var path = Path.Combine(this.GetLocation(), this.filePath); var expected = new FileInfo(path).Length.ToString(); var response = new GenericFileResponse(this.filePath, this.fileContentType, this.context); // Then response.Headers["Content-Length"].ShouldEqual(expected); }
public void Should_set_content_length_in_response_header() { // Given, when var expected = new FileInfo(imagePath).Length.ToString(); var response = new GenericFileResponse(this.imagePath, imageContentType, this.context); // Then response.Headers["Content-Length"].ShouldEqual(expected); }
public void Should_set_status_code_to_not_found_when_file_name_does_not_contain_extension() { // Given var fileNameWithoutExtensions = Path.GetFileNameWithoutExtension(this.filePath); // When var response = new GenericFileResponse(fileNameWithoutExtensions, this.fileContentType, this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_set_status_code_to_not_found_when_file_does_not_exist() { // Given var path = Path.Combine("Resources", "thatsnotit.jpg"); // When var response = new GenericFileResponse(path, imageContentType, this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_set_status_code_to_not_found_when_file_name_does_not_contain_extension() { // Given var path = Path.Combine("Resources", "zip"); // When var response = new GenericFileResponse(path, imageContentType); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_set_status_code_to_not_found_when_file_is_above_root_path() { // Given var path = Path.Combine(this.imagePath, "..", ".."); // When var response = new GenericFileResponse(path, imageContentType, this.context); // Then response.StatusCode.ShouldEqual(HttpStatusCode.NotFound); }
public void Should_return_file_unchanged() { // Given var expected = File.ReadAllBytes(this.imagePath); var response = new GenericFileResponse(this.imagePath, imageContentType, this.context); // When var result = GetResponseContents(response); // Then result.ShouldEqualSequence(expected); }
public void Should_return_file_unchanged() { // Given var path = Path.Combine(this.GetLocation(), this.filePath); var expected = File.ReadAllBytes(path); var response = new GenericFileResponse(this.filePath, this.fileContentType, this.context); // When var result = GetResponseContents(response); // Then result.ShouldEqualSequence(expected); }
public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden() { // Given var assemblyPath = Path.GetDirectoryName(this.GetType().Assembly.Location); GenericFileResponse.RootPath = assemblyPath; var filename = Path.GetFileName(this.GetType().Assembly.Location); var response = new GenericFileResponse(filename, "image/png"); // When var result = response.AsAttachment(); // Then result.Headers["Content-Disposition"].ShouldContain(filename); result.ContentType.ShouldEqual("image/png"); }
public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden() { // Given var environment = new DefaultNancyEnvironment(); environment.StaticContent(safepaths: this.GetLocation()); var filename = this.GetFilePath(); var response = new GenericFileResponse(filename, "foo/bar", new NancyContext() { Environment = environment }); // When var result = response.AsAttachment(); // Then result.Headers["Content-Disposition"].ShouldContain(Path.GetFileName(filename)); result.ContentType.ShouldEqual("foo/bar"); }
public void Should_use_filename_and_content_type_for_attachments_from_file_response_if_not_overridden() { // Given var assemblyPath = Path.GetDirectoryName(this.GetType().Assembly.Location); var environment = new DefaultNancyEnvironment(); environment.StaticContent(safepaths: assemblyPath); var filename = Path.GetFileName(this.GetType().Assembly.Location); var response = new GenericFileResponse(filename, "image/png", new NancyContext() { Environment = environment }); // When var result = response.AsAttachment(); // Then result.Headers["Content-Disposition"].ShouldContain(filename); result.ContentType.ShouldEqual("image/png"); }
public TrackingModule() { Get["/gif/{id}"] = _ => { var query = this.Bind <TicketQueryById>(); Tickets.LogAccess(query.Id, Request.UserHostAddress); var filename = @"Content\transparent_1x1.gif"; var response = new GenericFileResponse(filename) { ContentType = MimeTypes.GetMimeType(filename) }; return(response); }; Get["/gif/search/{name}"] = _ => { var query = this.Bind <TicketQueryByName>(); var result = new TicketQueryMultiResults { Query = query, Results = Tickets.Find(query.Name).ToList() }; return(result); }; Get["/gif/{id}/details"] = _ => { var query = this.Bind <TicketQueryById>(); object result; var ticket = Tickets.Find(query.Id); if (ticket == null) { result = HttpStatusCode.NotFound; } else { result = new TicketQuerySingleResult { Query = query, Result = ticket }; } return(result); }; Post["/gif/generate"] = _ => { var input = this.Bind <GenerateTicketInputModel>(); var ticket = Tickets.CreateTicket(input.Name); return(Response.AsRedirect($"/gif/{ticket.Id}/details")); }; }