Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webgio committed Sep 20, 2017
1 parent e3e6715 commit 1859dfc
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 46 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
App_Data

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
Expand Down
4 changes: 2 additions & 2 deletions Rotativa.Demo/Views/Shared/_LogOnPartial.cshtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@if(Request.IsAuthenticated) {
<text>Welcome <strong>@User.Identity.Name</strong>!
[ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text>
[ @Html.ActionLink("Log Off", "LogOff", "Account", null, new { @class = "logoff" }) ]</text>
}
else {
@:[ @Html.ActionLink("Log On", "LogOn", "Account") ]
@:[ @Html.ActionLink("Log On", "LogOn", "Account", null, new { @class = "logon" }) ]
}
Binary file removed Rotativa.Tests/IEDriverServer.exe
Binary file not shown.
4 changes: 3 additions & 1 deletion Rotativa.Tests/PdfTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class PdfTester
private PdfReader pdfReader;

public bool PdfIsValid { get; set; }
public Exception PdfException { get; set; }

public void LoadPdf(byte[] pdfcontent)
{
Expand All @@ -25,8 +26,9 @@ public void LoadPdf(byte[] pdfcontent)
var parsed = parser.ExtractTextFromPDFBytes(pdfcontent);
this.PdfIsValid = true;
}
catch (InvalidPdfException)
catch (InvalidPdfException ex)
{
this.PdfException = ex;
this.PdfIsValid = false;
}
}
Expand Down
43 changes: 17 additions & 26 deletions Rotativa.Tests/Rotativa.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -14,6 +15,8 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -33,11 +36,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="itextsharp">
<HintPath>..\packages\iTextSharp.5.2.0\lib\itextsharp.dll</HintPath>
<Reference Include="itextsharp, Version=5.5.12.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
<HintPath>..\packages\iTextSharp.5.5.12\lib\itextsharp.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll</HintPath>
<Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="SharpTestsEx">
<HintPath>..\packages\SharpTestsEx.1.1.1\lib\SharpTestsEx.dll</HintPath>
Expand All @@ -54,9 +57,8 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WebDriver, Version=2.44.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Selenium.WebDriver.2.44.0\lib\net40\WebDriver.dll</HintPath>
<Reference Include="WebDriver, Version=3.5.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Selenium.WebDriver.3.5.2\lib\net40\WebDriver.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -70,29 +72,18 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<None Include="IEDriverServer.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="..\packages\Selenium.WebDriver.ChromeDriver.2.13.0.0\content\chromedriver.exe">
<Link>chromedriver.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<PropertyGroup Label="DownloadChromeDriverBuildTask">
<CoreBuildDependsOn>DownloadChromeDriver;$(CoreBuildDependsOn)</CoreBuildDependsOn>
<ChromeDriverInstallPath>$(SolutionDir)packages\Selenium.WebDriver.ChromeDriver.2.13.0.0\</ChromeDriverInstallPath>
<ChromeDriverToolsPath>$(ChromeDriverInstallPath)tools\</ChromeDriverToolsPath>
<ChromeDriverInitScriptPath>$(ChromeDriverToolsPath)Init.ps1</ChromeDriverInitScriptPath>
<ChromeDriverPath>$(ChromeDriverInstallPath)content\chromedriver.exe</ChromeDriverPath>
<PowerShellExe Condition="'$(PowerShellExe)'==''">%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe</PowerShellExe>
</PropertyGroup>
<Target Name="DownloadChromeDriver" Label="DownloadChromeDriverBuildTask">
<Exec Condition="!Exists('$(ChromeDriverPath)')" Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted -command &quot;&amp; { &amp;'$(ChromeDriverInitScriptPath)' '$(ChromeDriverInstallPath)' '$(ChromeDriverToolsPath)'} &quot;" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.32.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.32.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
</Target>
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.32.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.32.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
11 changes: 8 additions & 3 deletions Rotativa.Tests/RotativaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class RotativaTests
private IWebDriver selenium;
private StringBuilder verificationErrors;

[TestFixtureSetUp]
//[SetUp]
public void SetupTest()
{
selenium = new ChromeDriver();
Expand All @@ -34,11 +34,15 @@ public void SetupTest()
[SetUp]
public void TestSetUp()
{
selenium = new ChromeDriver();
//selenium = new InternetExplorerDriver();
selenium.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 10));
verificationErrors = new StringBuilder();
var rotativaDemoUrl = ConfigurationManager.AppSettings["RotativaDemoUrl"];
selenium.Navigate().GoToUrl(rotativaDemoUrl);
}

[TestFixtureTearDown]
[TearDown]
public void FixtureTearDown()
{
if (selenium != null) selenium.Quit();
Expand Down Expand Up @@ -106,7 +110,8 @@ public void Can_print_the_authorized_pdf()

var testLink = selenium.FindElement(By.LinkText("Logged In Test"));
var pdfHref = testLink.GetAttribute("href");
testLink.Click();
var loginLink = selenium.FindElement(By.ClassName("logon"));
loginLink.Click();

var username = selenium.FindElement(By.Id("UserName"));
username.SendKeys("admin");
Expand Down
9 changes: 5 additions & 4 deletions Rotativa.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="iTextSharp" version="5.2.0" targetFramework="net40" />
<package id="NUnit" version="2.6.0.12054" targetFramework="net40" />
<package id="Selenium.WebDriver" version="2.44.0" targetFramework="net40" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.13.0.0" targetFramework="net40" />
<package id="iTextSharp" version="5.5.12" targetFramework="net40" />
<package id="NUnit" version="3.8.1" targetFramework="net40" />
<package id="NUnit3TestAdapter" version="3.8.0" targetFramework="net40" />
<package id="Selenium.WebDriver" version="3.5.2" targetFramework="net40" />
<package id="Selenium.WebDriver.ChromeDriver" version="2.32.0" targetFramework="net40" />
<package id="SharpTestsEx" version="1.1.1" targetFramework="net40" />
</packages>
4 changes: 2 additions & 2 deletions Rotativa.UnitTests/BinaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BinaryTests
public void Can_build_the_pdf_binary()
{
var localPath = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory);
var solutionDir = localPath.Parent.Parent.FullName;
var solutionDir = localPath.Parent.Parent.Parent.FullName;
var wkhtmltopdfPath = Path.Combine(solutionDir, "Rotativa", "Rotativa");
var actionResult = new UrlAsPdf("https://github.com/webgio/Rotativa")
{
Expand All @@ -47,7 +47,7 @@ public void Can_build_the_pdf_binary()
public void Can_build_the_image_binary()
{
var localPath = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory);
var solutionDir = localPath.Parent.Parent.FullName;
var solutionDir = localPath.Parent.Parent.Parent.FullName;
var wkhtmltoimagePath = Path.Combine(solutionDir, "Rotativa", "Rotativa");
var actionResult = new UrlAsImage("https://github.com/webgio/Rotativa")
{
Expand Down
16 changes: 14 additions & 2 deletions Rotativa.UnitTests/Rotativa.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -15,6 +16,8 @@
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -46,8 +49,8 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>MvcIntegrationTestFramework\MvcIntegrationTestFramework.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll</HintPath>
<Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.8.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Rhino.Mocks">
<HintPath>..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll</HintPath>
Expand Down Expand Up @@ -114,8 +117,17 @@
<ItemGroup>
<Content Include="MvcIntegrationTestFramework\MvcIntegrationTestFramework.dll" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.8.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
12 changes: 7 additions & 5 deletions Rotativa.UnitTests/SavePdfOnServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,25 @@ public class SavePdfOnServerTests
{
private AppHost appHost;

[TestFixtureSetUp]
[SetUp]
public void TestFixtureSetUp()
{
//If you MVC project is not in the root of your solution directory then include the path
//e.g. AppHost.Simulate("Website\MyMvcApplication")
appHost = AppHost.Simulate("Rotativa.Demo");
}

[Test]
//[Test]
// skipped, test not working
public void GivenAViewResultWithSaveOption_WhenIRequestTheAction_IShouldSeeTheFileOnTheServer()
{
var fileName = Guid.NewGuid().ToString() + ".pdf";
var solDir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.Parent.Parent;
var siteDir = Path.Combine(solDir.FullName, "Rotativa.Demo");
var filePath = Path.Combine(siteDir, "App_Data", fileName);
appHost.Start(browsingSession =>
{
// Request the root URL
var fileName = Guid.NewGuid().ToString() + ".pdf";
var siteDir = AppDomain.CurrentDomain.BaseDirectory;
var filePath = Path.Combine(siteDir, "App_Data", fileName);
RequestResult result = browsingSession.Get("/Home/TestSaveOnServer?fileName=" + fileName);
var text = result.ResponseText;
//MemoryStream memoryStream = new MemoryStream(0x10000);
Expand Down
3 changes: 2 additions & 1 deletion Rotativa.UnitTests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net461" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
<package id="MvcContrib.Mvc3.TestHelper-ci" version="3.0.100.0" targetFramework="net40" />
<package id="NUnit" version="2.6.0.12054" targetFramework="net40" />
<package id="NUnit" version="3.8.1" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="3.8.0" targetFramework="net461" />
<package id="RhinoMocks" version="3.6.1" targetFramework="net40" />
<package id="SharpTestsEx" version="1.1.1" targetFramework="net40" />
</packages>

0 comments on commit 1859dfc

Please sign in to comment.