Skip to content

Commit

Permalink
add tests for reporting; fix include from custom xslt
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparnagy committed Jun 17, 2010
1 parent 64e433d commit d40dcfa
Show file tree
Hide file tree
Showing 28 changed files with 11,026 additions and 42 deletions.
16 changes: 0 additions & 16 deletions Reporting/LocalUrlResolver.cs

This file was deleted.

1 change: 0 additions & 1 deletion Reporting/TechTalk.SpecFlow.Reporting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
</Compile>
<Compile Include="AssemblyServices.cs" />
<Compile Include="BindingCollector.cs" />
<Compile Include="LocalUrlResolver.cs" />
<Compile Include="MsBuildProjectReader.cs" />
<Compile Include="NUnitExecutionReport\NUnitExecutionReportGenerator.cs" />
<Compile Include="NUnitExecutionReport\ReportElements\NUnitExecutionReport.cs" />
Expand Down
12 changes: 4 additions & 8 deletions Reporting/XmlResourceResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@

namespace TechTalk.SpecFlow.Reporting
{
public class XmlResourceResolver : XmlResolver
public class XmlResourceResolver : XmlUrlResolver
{
private ICredentials credentials;

public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
{
if (absoluteUri == null || !"resource".Equals(absoluteUri.Scheme, StringComparison.InvariantCultureIgnoreCase))
return base.GetEntity(absoluteUri, role, ofObjectToReturn);

string resourceName = absoluteUri.AbsolutePath.TrimStart(Path.AltDirectorySeparatorChar).Replace(Path.AltDirectorySeparatorChar, Type.Delimiter);
string assemblyName = absoluteUri.Host;

Assembly assembly = Assembly.Load(assemblyName);
return new ResourceXmlReader(assembly, resourceName);
}

public override ICredentials Credentials
{
set { credentials = value; }
}
}
}
25 changes: 9 additions & 16 deletions Reporting/XsltHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,12 @@ public static void TransformHtml(XmlSerializer serializer, object report, Type r
XmlResolver resourceResolver;

var reportName = reportType.Name.Replace("Generator", "");

if (UseCustomStylesheet(xsltFile))
{
XmlDocument document = new XmlDocument();
document.Load(xsltFile);
resourceResolver = new LocalUrlResolver();
xslt.Load(document, xsltSettings, resourceResolver);
}
else
using (var xsltReader = GetTemplateReader(reportType, reportName, xsltFile))
{
using (var xsltReader = new ResourceXmlReader(reportType, reportName + ".xslt"))
{
resourceResolver = new XmlResourceResolver();
xslt.Load(xsltReader, xsltSettings, resourceResolver);
}
resourceResolver = new XmlResourceResolver();
xslt.Load(xsltReader, xsltSettings, resourceResolver);
}

var xmlOutputReader = new XmlTextReader(new StringReader(xmlOutputWriter.ToString()));

XsltArgumentList argumentList = new XsltArgumentList();
Expand All @@ -63,9 +53,12 @@ public static void TransformHtml(XmlSerializer serializer, object report, Type r
}
}

private static bool UseCustomStylesheet(string xsltFile)
private static XmlReader GetTemplateReader(Type reportType, string reportName, string xsltFile)
{
return !string.IsNullOrEmpty(xsltFile);
if (string.IsNullOrEmpty(xsltFile))
return new ResourceXmlReader(reportType, reportName + ".xslt");

return new XmlTextReader(xsltFile);
}

private static void Transform(this XslCompiledTransform xslt, XmlReader input, XsltArgumentList arguments, Stream results, XmlResolver documentResolver)
Expand Down
26 changes: 26 additions & 0 deletions TechTalk.SpecFlow.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Resources", "Resources", "{
Installer\Resources\welcome_dialog.bmp = Installer\Resources\welcome_dialog.bmp
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReportingTests", "Tests\ReportingTests\ReportingTests.csproj", "{1965463E-6972-4618-8E59-D3259AE7A125}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReportingTest.SampleProject", "Tests\ReportingTest.SampleProject\ReportingTest.SampleProject.csproj", "{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -185,6 +189,26 @@ Global
{89167EB9-F458-48DA-9D8F-F639A74F5871}.Release|Mixed Platforms.Build.0 = Release|x86
{89167EB9-F458-48DA-9D8F-F639A74F5871}.Release|x86.ActiveCfg = Release|x86
{89167EB9-F458-48DA-9D8F-F639A74F5871}.Release|x86.Build.0 = Release|x86
{1965463E-6972-4618-8E59-D3259AE7A125}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1965463E-6972-4618-8E59-D3259AE7A125}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1965463E-6972-4618-8E59-D3259AE7A125}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{1965463E-6972-4618-8E59-D3259AE7A125}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{1965463E-6972-4618-8E59-D3259AE7A125}.Debug|x86.ActiveCfg = Debug|Any CPU
{1965463E-6972-4618-8E59-D3259AE7A125}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1965463E-6972-4618-8E59-D3259AE7A125}.Release|Any CPU.Build.0 = Release|Any CPU
{1965463E-6972-4618-8E59-D3259AE7A125}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{1965463E-6972-4618-8E59-D3259AE7A125}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{1965463E-6972-4618-8E59-D3259AE7A125}.Release|x86.ActiveCfg = Release|Any CPU
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}.Debug|x86.ActiveCfg = Debug|Any CPU
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}.Release|Any CPU.Build.0 = Release|Any CPU
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -198,5 +222,7 @@ Global
{3FE793A8-E662-4026-B4EC-891324073235} = {A10B5CD6-38EC-4D7E-9D1C-2EBA8017E437}
{D3F6B835-B228-4DCF-B533-B6ED469A33B3} = {A10B5CD6-38EC-4D7E-9D1C-2EBA8017E437}
{3836A6FC-4ECC-413A-AC8F-83A0A773EC9E} = {A10B5CD6-38EC-4D7E-9D1C-2EBA8017E437}
{1965463E-6972-4618-8E59-D3259AE7A125} = {A10B5CD6-38EC-4D7E-9D1C-2EBA8017E437}
{E5C299D5-E7CC-4477-9A0B-4797B74BC88B} = {A10B5CD6-38EC-4D7E-9D1C-2EBA8017E437}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions Tests/ReportingTest.SampleProject/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
</configSections>

<specFlow>
<unitTestProvider name="NUnit"/>
</specFlow>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Feature: Feature with failing scenarios
In order to test reporting
As a SpecFlow developer
I want to have a feature that has failing scenarios

@ignore
Scenario: Ignored scenario
Given I have a precondition that is successful

Scenario: Scenario with pending steps
Given I have a pending precondition

Scenario: Scenario with failing steps
Given I have a precondition that is failing
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Feature with successful scenarios
In order to test reporting
As a SpecFlow developer
I want to have a feature that has successful scenarios

Scenario: First successful scenario
Given I have a precondition that is successful
When I do something that works
Then I have a postcondition that is successful

Scenario: Second successful scenario
Given I have a precondition that is successful
And I have a precondition that is successful
When I do something that works
Then I have a postcondition that is successful
6 changes: 6 additions & 0 deletions Tests/ReportingTest.SampleProject/NUnitResult/generate.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

pushd %~dp0\..

..\..\lib\nunit\nunit-console.exe bin\Debug\ReportingTest.SampleProject.dll /labels /xml=NUnitResult\TestResult.xml /out:NUnitResult\TestResult.txt /err:NUnitResult\TestResult.err

popd
36 changes: 36 additions & 0 deletions Tests/ReportingTest.SampleProject/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("ReportingTest.SampleProject")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("ReportingTest.SampleProject")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[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("72c7aff1-9d5f-4975-9396-294c8d4ced33")]

// 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")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{E5C299D5-E7CC-4477-9A0B-4797B74BC88B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ReportingTest.SampleProject</RootNamespace>
<AssemblyName>ReportingTest.SampleProject</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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.5.1.9189, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nunit\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StepDefinitions.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Runtime\TechTalk.SpecFlow.csproj">
<Project>{413EE28C-4F89-4C6F-BA1E-2CDEE4CD43B4}</Project>
<Name>TechTalk.SpecFlow</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="FeatureWithFailingScenarios.feature">
</None>
<None Include="FeatureWithSuccessfulScenarios.feature">
</None>
<None Include="NUnitResult\generate.cmd" />
</ItemGroup>
<ItemGroup>
<Content Include="NUnitResult\TestResult.txt" />
<Content Include="NUnitResult\TestResult.xml" />
<Content Include="readme.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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>
35 changes: 35 additions & 0 deletions Tests/ReportingTest.SampleProject/StepDefinitions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
using NUnit.Framework;

namespace ReportingTest.SampleProject
{
[Binding]
public class StepDefinitions
{
[Given(@"I have a precondition that is (.*)")]
[When(@"I do something that (.*)")]
[Then(@"I have a postcondition that is (.*)")]
public void GivenIHaveAPreconditionThatIs(string result)
{
switch(result.ToLower())
{
case "successful":
case "works":
return;
case "failing":
Assert.Fail("simulated failure");
break;
case "pending":
ScenarioContext.Current.Pending();
break;
default:
Assert.Fail("unknown result");
break;
}
}
}
}
11 changes: 11 additions & 0 deletions Tests/ReportingTest.SampleProject/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This project is not a test project for SpecFlow, but a sample specflow test
project that is used for testing the reporting.

The unit tests generated by SpecFlow are disabled, to avoid execution and
fake error reports for SpecFlow.

Enable the sample tests:
- set the "Custom Tool" property of the feature file nodes to "SpecFlowSingleFileGenerator"

Disable the sample tests:
- set the "Custom Tool" property of the feature file nodes to empty
Loading

0 comments on commit d40dcfa

Please sign in to comment.