diff --git a/src/Orchard.Specs/Bindings/WebAppHosting.cs b/src/Orchard.Specs/Bindings/WebAppHosting.cs index 6c34e63b2..d1a05ecf8 100644 --- a/src/Orchard.Specs/Bindings/WebAppHosting.cs +++ b/src/Orchard.Specs/Bindings/WebAppHosting.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; @@ -23,8 +22,14 @@ namespace Orchard.Specs.Bindings { [Given(@"I have a clean site")] public void GivenIHaveACleanSite() { + GivenIHaveACleanSiteBasedOn("Orchard.Web"); + } + + + [Given(@"I have a clean site based on (.*)")] + public void GivenIHaveACleanSiteBasedOn(string siteFolder) { _webHost = new WebHost(); - _webHost.Initialize("Orchard.Web", "/"); + _webHost.Initialize(siteFolder, "/"); var sink = new MessageSink(); _webHost.Execute(() => { @@ -33,15 +38,6 @@ namespace Orchard.Specs.Bindings { _messages = sink; } - public class MessageSink : MarshalByRefObject { - readonly IList _messages = new List(); - - public void Receive(string message) { - _messages.Add(message); - } - } - - [Given(@"I have module ""(.*)""")] public void GivenIHaveModule(string moduleName) { _webHost.CopyExtension("Modules", moduleName); diff --git a/src/Orchard.Specs/Hosting/MessageSink.cs b/src/Orchard.Specs/Hosting/MessageSink.cs new file mode 100644 index 000000000..588c3d21b --- /dev/null +++ b/src/Orchard.Specs/Hosting/MessageSink.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; + +namespace Orchard.Specs.Hosting { + public class MessageSink : MarshalByRefObject { + readonly IList _messages = new List(); + + public void Receive(string message) { + _messages.Add(message); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Specs/Hosting/Orchard.Web/Content/Static.txt b/src/Orchard.Specs/Hosting/Simple.Web/Content/Static.txt similarity index 100% rename from src/Orchard.Specs/Hosting/Orchard.Web/Content/Static.txt rename to src/Orchard.Specs/Hosting/Simple.Web/Content/Static.txt diff --git a/src/Orchard.Specs/Hosting/Simple.Web/Global.asax b/src/Orchard.Specs/Hosting/Simple.Web/Global.asax new file mode 100644 index 000000000..bb7870ac3 --- /dev/null +++ b/src/Orchard.Specs/Hosting/Simple.Web/Global.asax @@ -0,0 +1 @@ +<%@ Application Inherits="Orchard.Specs.Hosting.Simple.Web.MvcApplication, Orchard.Specs" %> \ No newline at end of file diff --git a/src/Orchard.Specs/Hosting/Simple.Web/Global.asax.cs b/src/Orchard.Specs/Hosting/Simple.Web/Global.asax.cs new file mode 100644 index 000000000..3ec512b2a --- /dev/null +++ b/src/Orchard.Specs/Hosting/Simple.Web/Global.asax.cs @@ -0,0 +1,22 @@ +using System; +using System.Web; +using System.Web.Mvc; +using System.Web.Routing; +using Autofac; +using Autofac.Integration.Web; +using Orchard.Environment; +using Orchard.Specs.Hosting.Orchard.Web; + +namespace Orchard.Specs.Hosting.Simple.Web { + public class MvcApplication : HttpApplication + { + protected void Application_Start() + { + + var route = RouteTable.Routes.MapRoute("foo", "hello-world", new { controller = "Home", action = "Index" }); + route.RouteHandler = new HelloYetAgainHandler(); + + } + + } +} \ No newline at end of file diff --git a/src/Orchard.Specs/Hosting/Orchard.Web/HelloYetAgainHandler.cs b/src/Orchard.Specs/Hosting/Simple.Web/HelloYetAgainHandler.cs similarity index 100% rename from src/Orchard.Specs/Hosting/Orchard.Web/HelloYetAgainHandler.cs rename to src/Orchard.Specs/Hosting/Simple.Web/HelloYetAgainHandler.cs diff --git a/src/Orchard.Specs/Hosting/Orchard.Web/Simple/Page.aspx b/src/Orchard.Specs/Hosting/Simple.Web/Simple/Page.aspx similarity index 100% rename from src/Orchard.Specs/Hosting/Orchard.Web/Simple/Page.aspx rename to src/Orchard.Specs/Hosting/Simple.Web/Simple/Page.aspx diff --git a/src/Orchard.Specs/Hosting/Orchard.Web/Static.txt b/src/Orchard.Specs/Hosting/Simple.Web/Static.txt similarity index 100% rename from src/Orchard.Specs/Hosting/Orchard.Web/Static.txt rename to src/Orchard.Specs/Hosting/Simple.Web/Static.txt diff --git a/src/Orchard.Specs/Hosting/Simple.Web/Web.config b/src/Orchard.Specs/Hosting/Simple.Web/Web.config new file mode 100644 index 000000000..11178f5a8 --- /dev/null +++ b/src/Orchard.Specs/Hosting/Simple.Web/Web.config @@ -0,0 +1,169 @@ + + + + + + + +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Orchard.Specs/Orchard.Specs.csproj b/src/Orchard.Specs/Orchard.Specs.csproj index 60a787467..11b38351b 100644 --- a/src/Orchard.Specs/Orchard.Specs.csproj +++ b/src/Orchard.Specs/Orchard.Specs.csproj @@ -86,10 +86,12 @@ + - + + WebHosting.feature @@ -130,6 +132,9 @@ Always + + Always + SpecFlowSingleFileGenerator WebHosting.feature.cs @@ -205,7 +210,7 @@ - + Always @@ -214,10 +219,13 @@ Always - + Always - + + Always + + Always diff --git a/src/Orchard.Specs/WebHosting.feature b/src/Orchard.Specs/WebHosting.feature index 2d6fb4b5a..d91c53252 100644 --- a/src/Orchard.Specs/WebHosting.feature +++ b/src/Orchard.Specs/WebHosting.feature @@ -4,49 +4,49 @@ I want to verify basic hosting is working Scenario: Returning static files - Given I have a clean site + 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!" + Then I should see "Hello world!" + And the status should be 200 OK Scenario: Returning static files 2 - Given I have a clean site + 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 + 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 + 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 + 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" + 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 + 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 + Given I have a clean site based on Simple.Web When I go to "hello-world" Then the status should be 200 OK And I should see "Hello yet again" Scenario: Following a link - Given I have a clean site + Given I have a clean site based on Simple.Web When I go to "/simple/page.aspx" And I follow "next page" Then the status should be 200 OK diff --git a/src/Orchard.Specs/WebHosting.feature.cs b/src/Orchard.Specs/WebHosting.feature.cs index 3423c94a0..e099421b6 100644 --- a/src/Orchard.Specs/WebHosting.feature.cs +++ b/src/Orchard.Specs/WebHosting.feature.cs @@ -2,7 +2,7 @@ // // This code was generated by SpecFlow (http://www.specflow.org/). // SpecFlow Version:1.2.0.0 -// Runtime Version:2.0.50727.4200 +// Runtime Version:2.0.50727.4927 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -58,13 +58,13 @@ namespace Orchard.Specs #line 6 this.ScenarioSetup(scenarioInfo); #line 7 - testRunner.Given("I have a clean site"); + testRunner.Given("I have a clean site based on Simple.Web"); #line 8 testRunner.When("I go to \"Content/Static.txt\""); #line 9 - testRunner.Then("the status should be 200 OK"); + testRunner.Then("I should see \"Hello world!\""); #line 10 - testRunner.And("I should see \"Hello world!\""); + testRunner.And("the status should be 200 OK"); #line hidden testRunner.CollectScenarioErrors(); } @@ -77,7 +77,7 @@ this.ScenarioSetup(scenarioInfo); #line 12 this.ScenarioSetup(scenarioInfo); #line 13 - testRunner.Given("I have a clean site"); + testRunner.Given("I have a clean site based on Simple.Web"); #line 14 testRunner.When("I go to \"Content\\Static.txt\""); #line 15 @@ -96,7 +96,7 @@ this.ScenarioSetup(scenarioInfo); #line 18 this.ScenarioSetup(scenarioInfo); #line 19 - testRunner.Given("I have a clean site"); + testRunner.Given("I have a clean site based on Simple.Web"); #line 20 testRunner.When("I go to \"/Static.txt\""); #line 21 @@ -115,7 +115,7 @@ this.ScenarioSetup(scenarioInfo); #line 24 this.ScenarioSetup(scenarioInfo); #line 25 - testRunner.Given("I have a clean site"); + testRunner.Given("I have a clean site based on Simple.Web"); #line 26 testRunner.When("I go to \"Static.txt\""); #line 27 @@ -134,13 +134,13 @@ this.ScenarioSetup(scenarioInfo); #line 30 this.ScenarioSetup(scenarioInfo); #line 31 - testRunner.Given("I have a clean site"); + testRunner.Given("I have a clean site based on Simple.Web"); #line 32 testRunner.When("I go to \"Simple/Page.aspx\""); #line 33 - testRunner.Then("the status should be 200 OK"); + testRunner.Then("I should see \"Hello again\""); #line 34 - testRunner.And("I should see \"Hello again\""); + testRunner.And("the status should be 200 OK"); #line hidden testRunner.CollectScenarioErrors(); } @@ -153,7 +153,7 @@ this.ScenarioSetup(scenarioInfo); #line 36 this.ScenarioSetup(scenarioInfo); #line 37 - testRunner.Given("I have a clean site"); + testRunner.Given("I have a clean site based on Simple.Web"); #line 38 testRunner.When("I go to \"Simple\\Page.aspx\""); #line 39 @@ -172,7 +172,7 @@ this.ScenarioSetup(scenarioInfo); #line 42 this.ScenarioSetup(scenarioInfo); #line 43 - testRunner.Given("I have a clean site"); + testRunner.Given("I have a clean site based on Simple.Web"); #line 44 testRunner.When("I go to \"hello-world\""); #line 45 @@ -191,7 +191,7 @@ this.ScenarioSetup(scenarioInfo); #line 48 this.ScenarioSetup(scenarioInfo); #line 49 - testRunner.Given("I have a clean site"); + testRunner.Given("I have a clean site based on Simple.Web"); #line 50 testRunner.When("I go to \"/simple/page.aspx\""); #line 51 diff --git a/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs b/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs index a725c0d44..44d183c15 100644 --- a/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs +++ b/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs @@ -46,10 +46,10 @@ namespace Orchard.Tests.Environment { builder => { builder.RegisterInstance(new StubShellSettingsLoader()).As(); builder.RegisterType().As().InstancePerLifetimeScope(); - builder.RegisterType().As().SingleInstance(); builder.RegisterType().As(); builder.RegisterType().As(); builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterInstance(_controllerBuilder); builder.RegisterInstance(_routeCollection); builder.RegisterInstance(_modelBinderDictionary); @@ -62,14 +62,14 @@ namespace Orchard.Tests.Environment { _lifetime = _container.BeginLifetimeScope(); _container.Mock() - .SetupGet(cp=>cp.ApplicationContainer).Returns(_container); + .SetupGet(cp => cp.ApplicationContainer).Returns(_container); _container.Mock() .SetupGet(cp => cp.RequestLifetime).Returns(_lifetime); _container.Mock() .Setup(cp => cp.EndRequestLifetime()).Callback(() => _lifetime.Dispose()); _container.Mock() - .Setup(cp => cp.GetShellDescriptor()).Returns(new ShellDescriptor()); + .Setup(cp => cp.GetShellDescriptor()).Returns(default(ShellDescriptor)); var temp = Path.GetTempFileName(); File.Delete(temp); @@ -83,9 +83,47 @@ namespace Orchard.Tests.Environment { updater.Update(_lifetime); } + public class StubExtensionManager : IExtensionManager { + public IEnumerable AvailableExtensions() { + var ext = new ExtensionDescriptor { Name = "Orchard.Framework" }; + ext.Features = new[] { new FeatureDescriptor { Extension = ext, Name = ext.Name } }; + yield return ext; + } + + public IEnumerable LoadFeatures(IEnumerable featureDescriptors) { + foreach (var descriptor in featureDescriptors) { + if (descriptor.Name == "Orchard.Framework") { + yield return new Feature { + Descriptor = descriptor, + ExportedTypes = new[] { + typeof (TestDependency), + typeof (TestSingletonDependency), + typeof (TestTransientDependency), + } + }; + } + } + } + + public Feature LoadFeature(FeatureDescriptor featureDescriptor) { + throw new NotImplementedException(); + } + + public IEnumerable ActiveExtensions_Obsolete() { + throw new NotImplementedException(); + } + + public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) { + throw new NotImplementedException(); + } + + public void UninstallExtension(string extensionType, string extensionName) { + throw new NotImplementedException(); + } + } + public class StubShellSettingsLoader : IShellSettingsManager { - private readonly List _shellSettings = new List - {new ShellSettings {Name = "testing"}}; + private readonly List _shellSettings = new List { new ShellSettings { Name = "Default" } }; public IEnumerable LoadSettings() { return _shellSettings.AsEnumerable(); @@ -110,6 +148,7 @@ namespace Orchard.Tests.Environment { public void DifferentShellInstanceShouldBeReturnedAfterEachCreate() { var host = _lifetime.Resolve(); var runtime1 = host.CreateShell_Obsolete(); + host.Reinitialize_Obsolete(); var runtime2 = host.CreateShell_Obsolete(); Assert.That(runtime1, Is.Not.SameAs(runtime2)); } @@ -119,6 +158,7 @@ namespace Orchard.Tests.Environment { public void NormalDependenciesShouldBeUniquePerRequestContainer() { var host = _lifetime.Resolve(); var container1 = host.CreateShellContainer_Obsolete(); + host.Reinitialize_Obsolete(); var container2 = host.CreateShellContainer_Obsolete(); var requestContainer1a = container1.BeginLifetimeScope(); var requestContainer1b = container1.BeginLifetimeScope(); @@ -217,7 +257,7 @@ namespace Orchard.Tests.Environment { public static class TextExtensions { public static ILifetimeScope CreateShellContainer_Obsolete(this IOrchardHost host) { - return ((DefaultOrchardHost) host) + return ((DefaultOrchardHost)host) .Current .Single(x => x.Settings.Name == "Default") .LifetimeScope; diff --git a/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContextFactoryTests.cs b/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContextFactoryTests.cs index 4ee775e37..9c7645970 100644 --- a/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContextFactoryTests.cs +++ b/src/Orchard.Tests/Environment/ShellBuilders/DefaultShellContextFactoryTests.cs @@ -39,7 +39,7 @@ namespace Orchard.Tests.Environment.ShellBuilders { _container.Mock() .Setup(x => x.CreateContainer(settings, topology)) - .Returns(shellLifetimeScope ); + .Returns(shellLifetimeScope); _container.Mock() .Setup(x => x.GetShellDescriptor()) @@ -57,12 +57,17 @@ namespace Orchard.Tests.Environment.ShellBuilders { } [Test] - public void NullSettingsReturnsSetupContext() { - var settings = new ShellSettings { Name = "Default" }; + public void CreatingSetupContextUsesOrchardSetupFeature() { + var settings = default(ShellSettings); + var descriptor = default(ShellDescriptor); var topology = new ShellTopology(); _container.Mock() - .Setup(x => x.Compose(settings, It.IsAny())) + .Setup(x => x.Compose(It.IsAny(), It.IsAny())) + .Callback((ShellSettings s, ShellDescriptor d) => { + settings = s; + descriptor = d; + }) .Returns(topology); _container.Mock() @@ -70,7 +75,7 @@ namespace Orchard.Tests.Environment.ShellBuilders { .Returns(_container.BeginLifetimeScope("shell")); var factory = _container.Resolve(); - var context = factory.CreateShellContext(null); + var context = factory.CreateSetupContext(); Assert.That(context.Descriptor.EnabledFeatures, Has.Some.With.Property("Name").EqualTo("Orchard.Setup")); }