Permalink
Browse files

fixed options bug (and added a unit tests project)

  • Loading branch information...
1 parent f7ec3ea commit 3aa32c9220b3621c19573032ff56347b9239d301 @webgio committed Aug 2, 2012
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Rotativa.UnitTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Rotativa.UnitTests")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("16b3b1ae-f9b3-4ad0-a9a2-f949cfad9eca")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{26A2783C-662D-4885-BD2B-A9AFB55C6BF9}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Rotativa.UnitTests</RootNamespace>
+ <AssemblyName>Rotativa.UnitTests</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <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>
+ <Reference Include="SharpTestsEx">
+ <HintPath>..\packages\SharpTestsEx.1.1.1\lib\SharpTestsEx.dll</HintPath>
+ </Reference>
+ <Reference Include="SharpTestsEx.Mvc">
+ <HintPath>..\packages\SharpTestsEx.1.1.1\lib\SharpTestsEx.Mvc.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="WkhtmltopdfCommandLineStringTests.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Rotativa\Rotativa.csproj">
+ <Project>{D93FAA11-31F0-4629-B53C-AA8680283529}</Project>
+ <Name>Rotativa</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(SolutionDir)\.nuget\nuget.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">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using Rotativa.Options;
+using SharpTestsEx;
+
+namespace Rotativa.UnitTests
+{
+ public class TestAsPdfResult: AsPdfResultBase
+ {
+ public string GetConvertOptionsValue()
+ {
+ return base.GetConvertOptions();
+ }
+ protected override string GetUrl(System.Web.Mvc.ControllerContext context)
+ {
+ return string.Empty;
+ }
+ }
+ [TestFixture]
+ public class WkhtmltopdfCommandLineStringTests
+ {
+ [Test]
+ public void WhenAPdfActioResultHasSetOptionsAsProperties_TheResultingCommandLineHasTheCorrectOptions()
+ {
+ var pdfResult = new TestAsPdfResult();
+ var post = new Dictionary<string, string>();
+ post.Add("param1", "value1");
+ post.Add("param2", "value2");
+ pdfResult.Post = post;
+ pdfResult.PageOrientation = Orientation.Landscape;
+ var commandlineOptions = pdfResult.GetConvertOptionsValue();
+ commandlineOptions.Should().Contain("--post param1 value1 --post param2 value2");
+ commandlineOptions.Should().Contain("-O Landscape");
+ }
+ }
+}
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="NUnit" version="2.6.0.12054" targetFramework="net40" />
+ <package id="SharpTestsEx" version="1.1.1" targetFramework="net40" />
+</packages>
View
@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{C58DBD
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rotativa.Tests", "Rotativa.Tests\Rotativa.Tests.csproj", "{DE9EB72A-2AE7-42E8-9A44-AA525B463688}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rotativa.UnitTests", "Rotativa.UnitTests\Rotativa.UnitTests.csproj", "{26A2783C-662D-4885-BD2B-A9AFB55C6BF9}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -32,6 +34,10 @@ Global
{DE9EB72A-2AE7-42E8-9A44-AA525B463688}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE9EB72A-2AE7-42E8-9A44-AA525B463688}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE9EB72A-2AE7-42E8-9A44-AA525B463688}.Release|Any CPU.Build.0 = Release|Any CPU
+ {26A2783C-662D-4885-BD2B-A9AFB55C6BF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {26A2783C-662D-4885-BD2B-A9AFB55C6BF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {26A2783C-662D-4885-BD2B-A9AFB55C6BF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {26A2783C-662D-4885-BD2B-A9AFB55C6BF9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -165,26 +165,26 @@ protected string GetConvertOptions()
if (PageMargins != null)
result.Append(PageMargins.ToString());
- FieldInfo[] fields = GetType().GetFields();
+ var fields = GetType().GetProperties();
foreach (var fi in fields)
{
var of = fi.GetCustomAttributes(typeof(OptionFlag), true).FirstOrDefault() as OptionFlag;
if (of == null)
continue;
- object value = fi.GetValue(this);
+ object value = fi.GetValue(this, null);
if (value == null)
continue;
- if (fi.FieldType == typeof(Dictionary<string, string>))
+ if (fi.PropertyType == typeof(Dictionary<string, string>))
{
var dictionary = (Dictionary<string, string>)value;
foreach (var d in dictionary)
{
result.AppendFormat(" {0} {1} {2}", of.Name, d.Key, d.Value);
}
}
- else if (fi.FieldType == typeof(bool))
+ else if (fi.PropertyType == typeof(bool))
{
if ((bool)value)
result.AppendFormat(CultureInfo.InvariantCulture, " {0}", of.Name);
@@ -4,4 +4,5 @@
<repository path="..\Rotativa.Demo\packages.config" />
<repository path="..\Rotativa.SpecFlow\packages.config" />
<repository path="..\Rotativa.Tests\packages.config" />
+ <repository path="..\Rotativa.UnitTests\packages.config" />
</repositories>

0 comments on commit 3aa32c9

Please sign in to comment.