SpecFlow test for dynamic compilation

The SpecFlow test for dynamic compilation wasn't actually trigering
dynamic compilation for all modules, because some of the were copied
to the "~/bin" assembly of the hosted ASP.NET application used for
SpecFlow testing.

This now works as expected, and we have 3 tests for this: one with
dynamic compilation enabled, one with dynamic comilation disabled,
and one with forced dynamic compilation (other loaders disabled).

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-12-13 16:32:00 -08:00
parent 18c097b66a
commit 01d740efd3
8 changed files with 167 additions and 32 deletions

View File

@@ -21,6 +21,7 @@ namespace Orchard.Specs.Bindings {
private MessageSink _messages;
private static readonly Path _orchardTemp = Path.Get(System.IO.Path.GetTempPath()).Combine("Orchard.Specs");
private ExtensionDeploymentOptions _moduleDeploymentOptions = ExtensionDeploymentOptions.CompiledAssembly;
private DynamicComilationOption _dynamicCompilationOption = DynamicComilationOption.Enabled;
public WebHost Host {
get { return _webHost; }
@@ -70,6 +71,17 @@ namespace Orchard.Specs.Bindings {
_moduleDeploymentOptions = ExtensionDeploymentOptions.SourceCode;
}
[Given(@"I have chosen to load modules using dymamic compilation only")]
public void GivenIHaveChosenToLoadModulesUsingDynamicComilationOnly() {
_moduleDeploymentOptions = ExtensionDeploymentOptions.SourceCode;
_dynamicCompilationOption = DynamicComilationOption.Force;
}
[Given(@"I have chosen to load modules with dynamic compilation disabled")]
public void GivenIHaveChosenToLoadModulesAsSourceFilesOnly() {
_dynamicCompilationOption = DynamicComilationOption.Disabled;
}
[Given(@"I have a clean site based on (.*)")]
public void GivenIHaveACleanSiteBasedOn(string siteFolder) {
GivenIHaveACleanSiteBasedOn(siteFolder, "/");
@@ -78,7 +90,7 @@ namespace Orchard.Specs.Bindings {
[Given(@"I have a clean site based on (.*) at ""(.*)""")]
public void GivenIHaveACleanSiteBasedOn(string siteFolder, string virtualDirectory) {
_webHost = new WebHost(_orchardTemp);
Host.Initialize(siteFolder, virtualDirectory ?? "/");
Host.Initialize(siteFolder, virtualDirectory ?? "/", _dynamicCompilationOption);
var shuttle = new Shuttle();
Host.Execute(() => {
log4net.Config.BasicConfigurator.Configure(new CastleAppender());

View File

@@ -6,4 +6,10 @@ namespace Orchard.Specs.Hosting {
CompiledAssembly = 0x01,
SourceCode = 0x02,
}
public enum DynamicComilationOption {
Enabled, // Allow compiling of csproj files as needed
Disabled, // Never compile csproj files
Force // Force loading modules by compiling csproj files
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<HostComponents>
<Components>
<Component Type="Orchard.Environment.Extensions.Loaders.DynamicExtensionLoader">
<Properties>
<Property Name="Disabled" Value="true"/>
</Properties>
</Component>
</Components>
</HostComponents>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<HostComponents>
<Components>
<Component Type="Orchard.Environment.Extensions.Loaders.DynamicExtensionLoader">
<Properties>
<Property Name="Disabled" Value="false"/>
</Properties>
</Component>
<Component Type="Orchard.Environment.Extensions.Loaders.PrecompiledExtensionLoader">
<Properties>
<Property Name="Disabled" Value="true"/>
</Properties>
</Component>
<Component Type="Orchard.Environment.Extensions.Loaders.ReferencedExtensionLoader">
<Properties>
<Property Name="Disabled" Value="true"/>
</Properties>
</Component>
</Components>
</HostComponents>

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
@@ -24,8 +25,8 @@ namespace Orchard.Specs.Hosting {
_orchardTemp = orchardTemp;
}
public void Initialize(string templateName, string virtualDirectory) {
Stopwatch stopwatch = new Stopwatch();
public void Initialize(string templateName, string virtualDirectory, DynamicComilationOption dynamicCompilationOption) {
var stopwatch = new Stopwatch();
stopwatch.Start();
var baseDir = Path.Get(AppDomain.CurrentDomain.BaseDirectory);
@@ -59,6 +60,19 @@ namespace Orchard.Specs.Hosting {
baseDir.Combine("Hosting").Combine(templateName)
.DeepCopy(_tempSite);
if (dynamicCompilationOption != DynamicComilationOption.Enabled) {
var sourceConfig = baseDir.Combine("Hosting").Combine("TemplateConfigs");
var siteConfig = _tempSite.Combine("Config");
switch (dynamicCompilationOption) {
case DynamicComilationOption.Disabled:
File.Copy(sourceConfig.Combine("DisableDynamicCompilation.HostComponents.config"), siteConfig.Combine("HostComponents.config"));
break;
case DynamicComilationOption.Force:
File.Copy(sourceConfig.Combine("ForceDynamicCompilation.HostComponents.config"), siteConfig.Combine("HostComponents.config"));
break;
}
}
Log("Copy binaries of the \"Orchard.Web\" project");
_orchardWebPath.Combine("bin")
.ShallowCopy("*.dll", _tempSite.Combine("bin"))
@@ -81,11 +95,16 @@ namespace Orchard.Specs.Hosting {
// can be achieved through serialization to the ASP.NET appdomain
// (see Execute(Action) method)
Log("Copy Orchard.Specflow test project binaries");
baseDir
.ShallowCopy("*.dll", _tempSite.Combine("bin"))
.ShallowCopy("*.exe", _tempSite.Combine("bin"))
.ShallowCopy("*.pdb", _tempSite.Combine("bin"));
baseDir.ShallowCopy(
path => IsSpecFlowTestAssembly(path) && !_tempSite.Combine("bin").Combine(path.FileName).Exists,
_tempSite.Combine("bin"));
StartAspNetHost(virtualDirectory);
Log("ASP.NET host initialization completed in {0} sec", stopwatch.Elapsed.TotalSeconds);
}
private void StartAspNetHost(string virtualDirectory) {
Log("Starting up ASP.NET host");
HostName = "localhost";
PhysicalDirectory = _tempSite;
@@ -93,6 +112,7 @@ namespace Orchard.Specs.Hosting {
_webHostAgent = (WebHostAgent)ApplicationHost.CreateApplicationHost(typeof(WebHostAgent), VirtualDirectory, PhysicalDirectory);
var shuttle = new Shuttle();
Execute(() => { shuttle.CodeGenDir = HttpRuntime.CodegenDir; });
@@ -100,11 +120,10 @@ namespace Orchard.Specs.Hosting {
_codeGenDir = shuttle.CodeGenDir;
_codeGenDir = _codeGenDir.Parent;
Log("ASP.NET CodeGenDir: \"{0}\"", _codeGenDir);
Log("ASP.NET host initialization completed in {0} sec", stopwatch.Elapsed.TotalSeconds);
}
[Serializable]
class Shuttle {
public class Shuttle {
public string CodeGenDir;
}
@@ -199,6 +218,16 @@ namespace Orchard.Specs.Hosting {
return true;
}
private bool IsSpecFlowTestAssembly(Path path) {
if (!IsAssemblyFile(path))
return false;
if (IsOrchardExtensionFile(path))
return false;
return true;
}
private bool IsAssemblyFile(Path path) {
return StringComparer.OrdinalIgnoreCase.Equals(path.Extension, ".exe") ||
StringComparer.OrdinalIgnoreCase.Equals(path.Extension, ".dll") ||

View File

@@ -107,7 +107,7 @@
</Reference>
<Reference Include="System.Web.Routing">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
<Private>True</Private>
<Private>False</Private>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -249,6 +249,14 @@
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>ContentTypes.feature.cs</LastGenOutput>
</None>
<Content Include="Hosting\TemplateConfigs\DisableDynamicCompilation.HostComponents.config">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Hosting\TemplateConfigs\ForceDynamicCompilation.HostComponents.config">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="SiteCompilation.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>SiteCompilation.feature.cs</LastGenOutput>

View File

@@ -3,8 +3,20 @@
As a privileged user
I want to have the modules compiled/installed properly
Scenario: Dynamic compilation support: modules can be deployed as source files only
Scenario: Dynamic compilation can be disabled
Given I have chosen to load modules with dynamic compilation disabled
And I have installed Orchard
When I go to "admin"
Then I should see "<div id="orchard-version">Orchard v(?:\.\d+){2,4}</div>"
Scenario: Dynamic compilation will kick in if modules are deployed as source files only
Given I have chosen to deploy modules as source files only
And I have installed Orchard
When I go to "admin"
Then I should see "<div id="orchard-version">Orchard v(?:\.\d+){2,4}</div>"
Scenario: Dynamic compilation can be forced by disabling the precompiled module loader
Given I have chosen to load modules using dymamic compilation only
And I have installed Orchard
When I go to "admin"
Then I should see "<div id="orchard-version">Orchard v(?:\.\d+){2,4}</div>"

View File

@@ -1,7 +1,7 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:1.3.2.0
// SpecFlow Version:1.4.0.0
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
@@ -14,7 +14,7 @@ namespace Orchard.Specs
using TechTalk.SpecFlow;
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.3.2.0")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.4.0.0")]
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("The compilation of modules installed in a site")]
@@ -31,7 +31,7 @@ namespace Orchard.Specs
{
testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "The compilation of modules installed in a site", "In order to install on Orchard site\r\nAs a privileged user\r\nI want to have the mod" +
"ules compiled/installed properly", ((string[])(null)));
"ules compiled/installed properly", GenerationTargetLanguage.CSharp, ((string[])(null)));
testRunner.OnFeatureStart(featureInfo);
}
@@ -54,20 +54,58 @@ namespace Orchard.Specs
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Dynamic compilation support: modules can be deployed as source files only")]
public virtual void DynamicCompilationSupportModulesCanBeDeployedAsSourceFilesOnly()
[NUnit.Framework.DescriptionAttribute("Dynamic compilation can be disabled")]
public virtual void DynamicCompilationCanBeDisabled()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Dynamic compilation support: modules can be deployed as source files only", ((string[])(null)));
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Dynamic compilation can be disabled", ((string[])(null)));
#line 6
this.ScenarioSetup(scenarioInfo);
#line 7
testRunner.Given("I have chosen to deploy modules as source files only");
testRunner.Given("I have chosen to load modules with dynamic compilation disabled");
#line 8
testRunner.And("I have installed Orchard");
#line 9
testRunner.When("I go to \"admin\"");
#line 10
testRunner.Then("I should see \"<div id=\"orchard-version\">Orchard v(?:\\.\\d+){2,4}</div>\"");
#line hidden
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Dynamic compilation will kick in if modules are deployed as source files only")]
public virtual void DynamicCompilationWillKickInIfModulesAreDeployedAsSourceFilesOnly()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Dynamic compilation will kick in if modules are deployed as source files only", ((string[])(null)));
#line 12
this.ScenarioSetup(scenarioInfo);
#line 13
testRunner.Given("I have chosen to deploy modules as source files only");
#line 14
testRunner.And("I have installed Orchard");
#line 15
testRunner.When("I go to \"admin\"");
#line 16
testRunner.Then("I should see \"<div id=\"orchard-version\">Orchard v(?:\\.\\d+){2,4}</div>\"");
#line hidden
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Dynamic compilation can be forced by disabling the precompiled module loader")]
public virtual void DynamicCompilationCanBeForcedByDisablingThePrecompiledModuleLoader()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Dynamic compilation can be forced by disabling the precompiled module loader", ((string[])(null)));
#line 18
this.ScenarioSetup(scenarioInfo);
#line 19
testRunner.Given("I have chosen to load modules using dymamic compilation only");
#line 20
testRunner.And("I have installed Orchard");
#line 21
testRunner.When("I go to \"admin\"");
#line 22
testRunner.Then("I should see \"<div id=\"orchard-version\">Orchard v(?:\\.\\d+){2,4}</div>\"");
#line hidden
testRunner.CollectScenarioErrors();
}