Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #189 #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Rotativa.Demo/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ public ActionResult ErrorTest()
return new ActionAsPdf("SomethingBad") { FileName = "Test.pdf" };
}

public ActionResult HttpStatus500Test()
{
return new UrlAsPdf("https://httpstat.us/500") { FileName = "Test.pdf" };

}
public ActionResult HttpStatus404Test()
{
return new UrlAsPdf("https://httpstat.us/404") { FileName = "Test.pdf" };
}
public ActionResult HttpStatus200Test()
{
return new UrlAsPdf("https://httpstat.us/200") { FileName = "Test.pdf" };

}

public ActionResult SomethingBad()
{
return Redirect("http://thisdoesntexists");
Expand Down
51 changes: 27 additions & 24 deletions Rotativa.Demo/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@

<h2>@ViewBag.Message</h2>
<p>
<ul>
<li>@Html.ActionLink("Home", "Index", new {name = "Giorgio"})</li>
<li>@Html.ActionLink("Test", "Test", "Home")</li>
<li>@Html.ActionLink("Test Image", "TestImage", "Home")</li>
<li>@Html.ActionLink("Test Image Png", "TestImagePng", "Home")</li>
<li>@Html.ActionLink("Test URL", "TestUrl", "Home")</li>
<li>@Html.ActionLink("Test External URL", "TestExternalUrl", "Home")</li>
<li>@Html.ActionLink("Test View", "TestView", "Home")</li>
<li>@Html.ActionLink("Test View Image", "TestViewImage", "Home")</li>
<li>@Html.ActionLink("Test Save on Server", "TestSaveOnServer", new { fileName = "test.pdf"})</li>
<li>@Html.ActionLink("Logged In Test", "AuthorizedTest", "Home")</li>
<li>@Html.ActionLink("Logged In Test Image", "AuthorizedTestImage", "Home")</li>
<li>@Html.ActionLink("Route Test", "RouteTest", "Home")</li>
<li>@Html.ActionLink("Test ViewAsPdf with a model", "TestViewWithModel")</li>
<li>@Html.ActionLink("Test ViewAsImage with a model", "TestImageViewWithModel")</li>
<li>@Html.ActionLink("Test PartialViewAsPdf with a model", "TestPartialViewWithModel")</li>
<li>@Html.ActionLink("Test PartialViewAsImage with a model", "TestImagePartialViewWithModel")</li>
<li>@Html.ActionLink("Error Test", "ErrorTest", "Home")</li>
<li>@Html.ActionLink("Binary Test", "BinaryTest", "Home")</li>
<li>@Html.ActionLink("Ajax Test", "Index", "AjaxTests")</li>
<li>@Html.ActionLink("Ajax Image Test", "IndexImage", "AjaxTests")</li>
<li>@Html.ActionLink("External CSS Test", "Index", "CssTests")</li>
<li>@Html.ActionLink("External CSS Test Image", "IndexImage", "CssTests")</li>
</ul>
<ul>
<li>@Html.ActionLink("Home", "Index", new { name = "Giorgio" })</li>
<li>@Html.ActionLink("Test", "Test", "Home")</li>
<li>@Html.ActionLink("Test Image", "TestImage", "Home")</li>
<li>@Html.ActionLink("Test Image Png", "TestImagePng", "Home")</li>
<li>@Html.ActionLink("Test URL", "TestUrl", "Home")</li>
<li>@Html.ActionLink("Test External URL", "TestExternalUrl", "Home")</li>
<li>@Html.ActionLink("Test View", "TestView", "Home")</li>
<li>@Html.ActionLink("Test View Image", "TestViewImage", "Home")</li>
<li>@Html.ActionLink("Test Save on Server", "TestSaveOnServer", new { fileName = "test.pdf" })</li>
<li>@Html.ActionLink("Logged In Test", "AuthorizedTest", "Home")</li>
<li>@Html.ActionLink("Logged In Test Image", "AuthorizedTestImage", "Home")</li>
<li>@Html.ActionLink("Route Test", "RouteTest", "Home")</li>
<li>@Html.ActionLink("Test ViewAsPdf with a model", "TestViewWithModel")</li>
<li>@Html.ActionLink("Test ViewAsImage with a model", "TestImageViewWithModel")</li>
<li>@Html.ActionLink("Test PartialViewAsPdf with a model", "TestPartialViewWithModel")</li>
<li>@Html.ActionLink("Test PartialViewAsImage with a model", "TestImagePartialViewWithModel")</li>
<li>@Html.ActionLink("Error Test", "ErrorTest", "Home")</li>
<li>@Html.ActionLink("Binary Test", "BinaryTest", "Home")</li>
<li>@Html.ActionLink("Ajax Test", "Index", "AjaxTests")</li>
<li>@Html.ActionLink("Ajax Image Test", "IndexImage", "AjaxTests")</li>
<li>@Html.ActionLink("External CSS Test", "Index", "CssTests")</li>
<li>@Html.ActionLink("External CSS Test Image", "IndexImage", "CssTests")</li>
<li>@Html.ActionLink("HttpStatus 500 Test", "HttpStatus500Test", "Home")</li>
<li>@Html.ActionLink("HttpStatus 404 Test", "HttpStatus404Test", "Home")</li>
<li>@Html.ActionLink("HttpStatus 200 Test", "HttpStatus200Test", "Home")</li>
</ul>

</p>

Expand Down
35 changes: 35 additions & 0 deletions Rotativa.Tests/RotativaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,5 +360,40 @@ public void Can_print_image_from_page_with_external_css_file()
image.RawFormat.Should().Be.EqualTo(ImageFormat.Jpeg);
}
}

[Test]
public void HttpError_statuses_does_not_generate_pdf_file()
{
var testLink = selenium.FindElement(By.LinkText("HttpStatus 200 Test"));
var pdfHref = testLink.GetAttribute("href");

var content = "200 OK";
using (var wc = new WebClient())
{
var pdfResult = wc.DownloadData(new Uri(pdfHref));
var pdfTester = new PdfTester();
pdfTester.LoadPdf(pdfResult);
pdfTester.PdfIsValid.Should().Be.True();
pdfTester.PdfContains(content).Should().Be.True();
}

testLink = selenium.FindElement(By.LinkText("HttpStatus 404 Test"));
pdfHref = testLink.GetAttribute("href");


using (var wc = new WebClient())
{
Assert.Throws(typeof(WebException), () => wc.DownloadData(new Uri(pdfHref)));
}

testLink = selenium.FindElement(By.LinkText("HttpStatus 500 Test"));
pdfHref = testLink.GetAttribute("href");


using (var wc = new WebClient())
{
Assert.Throws(typeof(WebException), () => wc.DownloadData(new Uri(pdfHref)));
}
}
}
}
2 changes: 1 addition & 1 deletion Rotativa/WkhtmlDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected static byte[] Convert(string wkhtmlPath, string switches, string html,

string error = proc.StandardError.ReadToEnd();

if (ms.Length == 0)
if (ms.Length == 0 || !string.IsNullOrEmpty(error) || proc.ExitCode > 0)
{
throw new Exception(error);
}
Expand Down