Working towards routing support for miti-tenancy

Adding large-grained initialization steps for integration tests
Fixing a collection issue with shell descriptor records and manager
Adding index action to tenants controller

--HG--
branch : dev
This commit is contained in:
Louis DeJardin
2010-04-21 19:41:37 -07:00
parent 5936a86d60
commit eaf553b048
12 changed files with 257 additions and 153 deletions

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TechTalk.SpecFlow;
namespace Orchard.Specs.Bindings {
public class BindingBase {
protected static T Binding<T>() {
return (T)ScenarioContext.Current.GetBindingInstance(typeof(T));
}
protected Table TableData<T>(params T[] rows) {
return BuildTable(rows);
}
protected Table TableData<T>(IEnumerable<T> rows) {
return BuildTable(rows);
}
private Table BuildTable<T>(IEnumerable<T> rows) {
var properties = typeof(T).GetProperties();
var table = new Table(properties.Select(x => x.Name).ToArray());
foreach (var row in rows) {
var row1 = row;
table.AddRow(properties.Select(p => Convert.ToString(p.GetValue(row1, null))).ToArray());
}
return table;
}
}
}

View File

@@ -0,0 +1,54 @@
using System.Linq;
using System.Text;
using Orchard.Environment.Configuration;
using Orchard.Environment.Topology;
using Orchard.Environment.Topology.Models;
using Orchard.Specs.Hosting.Orchard.Web;
using TechTalk.SpecFlow;
namespace Orchard.Specs.Bindings {
[Binding]
public class OrchardSiteFactory : BindingBase {
[Given(@"I have installed Orchard")]
public void GivenIHaveInstalledOrchard() {
var webApp = Binding<WebAppHosting>();
webApp.GivenIHaveACleanSiteWith(TableData(
new { extension = "module", names = "Orchard.Setup, Orchard.Users, Orchard.Roles, Orchard.Pages, Orchard.Comments, TinyMce" },
new { extension = "core", names = "Common, Dashboard, Feeds, HomePage, Navigation, Scheduling, Settings, Themes, XmlRpc" },
new { extension = "theme", names = "SafeMode, Classic" }));
webApp.WhenIGoTo("Setup");
webApp.WhenIFillIn(TableData(
new { name = "SiteName", value = "My Site" },
new { name = "AdminPassword", value = "6655321" }));
webApp.WhenIHit("Finish Setup");
}
[Given(@"I have installed ""(.*)\""")]
public void GivenIHaveInstalled(string name) {
Binding<WebAppHosting>().GivenIHaveModule(name);
GivenIHaveEnabled(name);
}
[Given(@"I have enabled ""(.*)\""")]
public void GivenIHaveEnabled(string name) {
var webApp = Binding<WebAppHosting>();
webApp.Host.Execute(() => {
using (var environment = MvcApplication.CreateStandaloneEnvironment("Default")) {
var descriptorManager = environment.Resolve<IShellDescriptorManager>();
var descriptor = descriptorManager.GetShellDescriptor();
descriptorManager.UpdateShellDescriptor(
descriptor.SerialNumber,
descriptor.EnabledFeatures.Concat(new[] { new ShellFeature { Name = name } }),
descriptor.Parameters);
}
MvcApplication.Host.Reinitialize_Obsolete();
});
}
}
}

View File

@@ -20,6 +20,10 @@ namespace Orchard.Specs.Bindings {
private HtmlDocument _doc;
private MessageSink _messages;
public WebHost Host {
get { return _webHost; }
}
[Given(@"I have a clean site")]
public void GivenIHaveACleanSite() {
GivenIHaveACleanSiteBasedOn("Orchard.Web");
@@ -29,10 +33,10 @@ namespace Orchard.Specs.Bindings {
[Given(@"I have a clean site based on (.*)")]
public void GivenIHaveACleanSiteBasedOn(string siteFolder) {
_webHost = new WebHost();
_webHost.Initialize(siteFolder, "/");
Host.Initialize(siteFolder, "/");
var sink = new MessageSink();
_webHost.Execute(() => {
Host.Execute(() => {
HostingTraceListener.SetHook(msg => sink.Receive(msg));
});
_messages = sink;
@@ -40,17 +44,17 @@ namespace Orchard.Specs.Bindings {
[Given(@"I have module ""(.*)""")]
public void GivenIHaveModule(string moduleName) {
_webHost.CopyExtension("Modules", moduleName);
Host.CopyExtension("Modules", moduleName);
}
[Given(@"I have theme ""(.*)""")]
public void GivenIHaveTheme(string themeName) {
_webHost.CopyExtension("Themes", themeName);
Host.CopyExtension("Themes", themeName);
}
[Given(@"I have core ""(.*)""")]
public void GivenIHaveCore(string moduleName) {
_webHost.CopyExtension("Core", moduleName);
Host.CopyExtension("Core", moduleName);
}
[Given(@"I have a clean site with")]
@@ -84,7 +88,7 @@ namespace Orchard.Specs.Bindings {
[When(@"I go to ""(.*)""")]
public void WhenIGoTo(string urlPath) {
_details = _webHost.SendRequest(urlPath);
_details = Host.SendRequest(urlPath);
_doc = new HtmlDocument();
_doc.Load(new StringReader(_details.ResponseText));
}
@@ -126,7 +130,7 @@ namespace Orchard.Specs.Bindings {
.GroupBy(elt => elt.GetAttributeValue("name", elt.GetAttributeValue("id", "")), elt => elt.GetAttributeValue("value", ""))
.ToDictionary(elt => elt.Key, elt => (IEnumerable<string>)elt);
_details = _webHost.SendRequest(urlPath, inputs);
_details = Host.SendRequest(urlPath, inputs);
_doc = new HtmlDocument();
_doc.Load(new StringReader(_details.ResponseText));
}

View File

@@ -1,21 +1,26 @@
using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Autofac;
using Autofac.Integration.Web;
using Orchard.Environment;
using Orchard.Environment.Configuration;
namespace Orchard.Specs.Hosting.Orchard.Web
{
public class MvcApplication : HttpApplication
{
private static IContainer _hostContainer;
private static IOrchardHost _host;
protected void Application_Start()
{
_host = OrchardStarter.CreateHost(MvcSingletons);
_host.Initialize();
_hostContainer = OrchardStarter.CreateHostContainer(MvcSingletons);
_host = _hostContainer.Resolve<IOrchardHost>();
Host.Initialize();
var route = RouteTable.Routes.MapRoute("foo", "hello-world", new { controller = "Home", action = "Index" });
route.RouteHandler = new HelloYetAgainHandler();
@@ -24,12 +29,12 @@ namespace Orchard.Specs.Hosting.Orchard.Web
protected void Application_BeginRequest()
{
_host.BeginRequest();
Host.BeginRequest();
}
protected void Application_EndRequest()
{
_host.EndRequest();
Host.EndRequest();
}
protected void MvcSingletons(ContainerBuilder builder)
@@ -41,5 +46,13 @@ namespace Orchard.Specs.Hosting.Orchard.Web
builder.RegisterInstance(ViewEngines.Engines);
}
public static IOrchardHost Host {
get { return _host; }
}
public static IStandaloneEnvironment CreateStandaloneEnvironment(string name) {
var settings = _hostContainer.Resolve<IShellSettingsManager>().LoadSettings().SingleOrDefault(x => x.Name == name);
return Host.CreateStandaloneEnvironment(settings);
}
}
}

View File

@@ -0,0 +1,13 @@
Feature: Multiple tenant management
In order to host several isolated web applications
As a root Orchard system operator
I want to create and manage tenant configurations
Scenario: Default site is listed
Given I have installed Orchard
And I have installed "Orchard.MultiTenancy"
When I go to "Admin/MultiTenancy"
Then I should see "List of Site's Tenants"
And I should see "Default"
And the status should be 200 OK

View File

@@ -0,0 +1,76 @@
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:1.2.0.0
// Runtime Version:2.0.50727.4927
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
namespace Orchard.Specs
{
using TechTalk.SpecFlow;
[NUnit.Framework.TestFixtureAttribute()]
[NUnit.Framework.DescriptionAttribute("Multiple tenant management")]
public partial class MultipleTenantManagementFeature
{
private static TechTalk.SpecFlow.ITestRunner testRunner;
#line 1 "MultiTenancy.feature"
#line hidden
[NUnit.Framework.TestFixtureSetUpAttribute()]
public virtual void FeatureSetup()
{
testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Multiple tenant management", "In order to host several isolated web applications\r\nAs a root Orchard system oper" +
"ator\r\nI want to create and manage tenant configurations", ((string[])(null)));
testRunner.OnFeatureStart(featureInfo);
}
[NUnit.Framework.TestFixtureTearDownAttribute()]
public virtual void FeatureTearDown()
{
testRunner.OnFeatureEnd();
testRunner = null;
}
public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
{
testRunner.OnScenarioStart(scenarioInfo);
}
[NUnit.Framework.TearDownAttribute()]
public virtual void ScenarioTearDown()
{
testRunner.OnScenarioEnd();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Default site is listed")]
public virtual void DefaultSiteIsListed()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Default site is listed", ((string[])(null)));
#line 6
this.ScenarioSetup(scenarioInfo);
#line 7
testRunner.Given("I have installed Orchard");
#line 8
testRunner.And("I have installed \"Orchard.MultiTenancy\"");
#line 9
testRunner.When("I go to \"Admin/MultiTenancy\"");
#line 10
testRunner.Then("I should see \"List of Site\'s Tenants\"");
#line 11
testRunner.And("I should see \"Default\"");
#line 12
testRunner.And("the status should be 200 OK");
#line hidden
testRunner.CollectScenarioErrors();
}
}
}

View File

@@ -86,12 +86,19 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Bindings\BindingBase.cs" />
<Compile Include="Bindings\OrchardSiteFactory.cs" />
<Compile Include="Hosting\MessageSink.cs" />
<Compile Include="Hosting\HostingTraceListener.cs" />
<Compile Include="Hosting\Simple.Web\HelloYetAgainHandler.cs" />
<Compile Include="Hosting\RequestExtensions.cs" />
<Compile Include="Hosting\RequestDetails.cs" />
<Compile Include="Hosting\Simple.Web\Global.asax.cs" />
<Compile Include="MultiTenancy.feature.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>MultiTenancy.feature</DependentUpon>
</Compile>
<Compile Include="Util\PathExtensions.cs" />
<Compile Include="WebHosting.feature.cs">
<DependentUpon>WebHosting.feature</DependentUpon>
@@ -135,6 +142,10 @@
<Content Include="Hosting\Simple.Web\Web.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="MultiTenancy.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>MultiTenancy.feature.cs</LastGenOutput>
</None>
<None Include="WebHosting.feature">
<Generator>SpecFlowSingleFileGenerator</Generator>
<LastGenOutput>WebHosting.feature.cs</LastGenOutput>

View File

@@ -9,36 +9,12 @@ Scenario: Returning static files
Then I should see "Hello world!"
And the status should be 200 OK
Scenario: Returning static files 2
Given I have a clean site based on Simple.Web
When I go to "Content\Static.txt"
Then the status should be 200 OK
And I should see "Hello world!"
Scenario: Returning static files 3
Given I have a clean site based on Simple.Web
When I go to "/Static.txt"
Then the status should be 200 OK
And I should see "Hello world!"
Scenario: Returning static files 4
Given I have a clean site based on Simple.Web
When I go to "Static.txt"
Then the status should be 200 OK
And I should see "Hello world!"
Scenario: Returning web forms page
Given I have a clean site based on Simple.Web
When I go to "Simple/Page.aspx"
Then I should see "Hello again"
And the status should be 200 OK
Scenario: Returning web forms page 2
Given I have a clean site based on Simple.Web
When I go to "Simple\Page.aspx"
Then the status should be 200 OK
And I should see "Hello again"
Scenario: Returning a routed request
Given I have a clean site based on Simple.Web
When I go to "hello-world"
@@ -63,7 +39,6 @@ Scenario: Submitting a form with input, default, and hidden fields
And I should see "passthrough2:beta"
And I should see "input1:gamma"
Scenario: Cookies follow along your request
Given I have a clean site based on Simple.Web
When I go to "/simple/cookie-set.aspx"

View File

@@ -70,114 +70,38 @@ this.ScenarioSetup(scenarioInfo);
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Returning static files 2")]
public virtual void ReturningStaticFiles2()
[NUnit.Framework.DescriptionAttribute("Returning web forms page")]
public virtual void ReturningWebFormsPage()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Returning static files 2", ((string[])(null)));
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Returning web forms page", ((string[])(null)));
#line 12
this.ScenarioSetup(scenarioInfo);
#line 13
testRunner.Given("I have a clean site based on Simple.Web");
#line 14
testRunner.When("I go to \"Content\\Static.txt\"");
#line 15
testRunner.Then("the status should be 200 OK");
#line 16
testRunner.And("I should see \"Hello world!\"");
#line hidden
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Returning static files 3")]
public virtual void ReturningStaticFiles3()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Returning static files 3", ((string[])(null)));
#line 18
this.ScenarioSetup(scenarioInfo);
#line 19
testRunner.Given("I have a clean site based on Simple.Web");
#line 20
testRunner.When("I go to \"/Static.txt\"");
#line 21
testRunner.Then("the status should be 200 OK");
#line 22
testRunner.And("I should see \"Hello world!\"");
#line hidden
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Returning static files 4")]
public virtual void ReturningStaticFiles4()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Returning static files 4", ((string[])(null)));
#line 24
this.ScenarioSetup(scenarioInfo);
#line 25
testRunner.Given("I have a clean site based on Simple.Web");
#line 26
testRunner.When("I go to \"Static.txt\"");
#line 27
testRunner.Then("the status should be 200 OK");
#line 28
testRunner.And("I should see \"Hello world!\"");
#line hidden
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Returning web forms page")]
public virtual void ReturningWebFormsPage()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Returning web forms page", ((string[])(null)));
#line 30
this.ScenarioSetup(scenarioInfo);
#line 31
testRunner.Given("I have a clean site based on Simple.Web");
#line 32
testRunner.When("I go to \"Simple/Page.aspx\"");
#line 33
#line 15
testRunner.Then("I should see \"Hello again\"");
#line 34
#line 16
testRunner.And("the status should be 200 OK");
#line hidden
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Returning web forms page 2")]
public virtual void ReturningWebFormsPage2()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Returning web forms page 2", ((string[])(null)));
#line 36
this.ScenarioSetup(scenarioInfo);
#line 37
testRunner.Given("I have a clean site based on Simple.Web");
#line 38
testRunner.When("I go to \"Simple\\Page.aspx\"");
#line 39
testRunner.Then("the status should be 200 OK");
#line 40
testRunner.And("I should see \"Hello again\"");
#line hidden
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Returning a routed request")]
public virtual void ReturningARoutedRequest()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Returning a routed request", ((string[])(null)));
#line 42
#line 18
this.ScenarioSetup(scenarioInfo);
#line 43
#line 19
testRunner.Given("I have a clean site based on Simple.Web");
#line 44
#line 20
testRunner.When("I go to \"hello-world\"");
#line 45
#line 21
testRunner.Then("the status should be 200 OK");
#line 46
#line 22
testRunner.And("I should see \"Hello yet again\"");
#line hidden
testRunner.CollectScenarioErrors();
@@ -188,17 +112,17 @@ this.ScenarioSetup(scenarioInfo);
public virtual void FollowingALink()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Following a link", ((string[])(null)));
#line 48
#line 24
this.ScenarioSetup(scenarioInfo);
#line 49
#line 25
testRunner.Given("I have a clean site based on Simple.Web");
#line 50
#line 26
testRunner.When("I go to \"/simple/page.aspx\"");
#line 51
#line 27
testRunner.And("I follow \"next page\"");
#line 52
#line 28
testRunner.Then("the status should be 200 OK");
#line 53
#line 29
testRunner.And("I should see \"Hello yet again\"");
#line hidden
testRunner.CollectScenarioErrors();
@@ -209,11 +133,11 @@ this.ScenarioSetup(scenarioInfo);
public virtual void SubmittingAFormWithInputDefaultAndHiddenFields()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Submitting a form with input, default, and hidden fields", ((string[])(null)));
#line 55
#line 31
this.ScenarioSetup(scenarioInfo);
#line 56
#line 32
testRunner.Given("I have a clean site based on Simple.Web");
#line 57
#line 33
testRunner.And("I am on \"/simple/page.aspx\"");
#line hidden
TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] {
@@ -222,15 +146,15 @@ this.ScenarioSetup(scenarioInfo);
table1.AddRow(new string[] {
"input1",
"gamma"});
#line 58
#line 34
testRunner.When("I fill in", ((string)(null)), table1);
#line 61
#line 37
testRunner.And("I hit \"Go!\"");
#line 62
#line 38
testRunner.Then("I should see \"passthrough1:alpha\"");
#line 63
#line 39
testRunner.And("I should see \"passthrough2:beta\"");
#line 64
#line 40
testRunner.And("I should see \"input1:gamma\"");
#line hidden
testRunner.CollectScenarioErrors();
@@ -241,15 +165,15 @@ this.ScenarioSetup(scenarioInfo);
public virtual void CookiesFollowAlongYourRequest()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Cookies follow along your request", ((string[])(null)));
#line 67
#line 42
this.ScenarioSetup(scenarioInfo);
#line 68
#line 43
testRunner.Given("I have a clean site based on Simple.Web");
#line 69
#line 44
testRunner.When("I go to \"/simple/cookie-set.aspx\"");
#line 70
#line 45
testRunner.And("I go to \"/simple/cookie-show.aspx\"");
#line 71
#line 46
testRunner.Then("I should see \"foo:bar\"");
#line hidden
testRunner.CollectScenarioErrors();