Updating tracing and adding specflow support for command handlers

--HG--
branch : dev
This commit is contained in:
Louis DeJardin 2010-04-26 11:36:55 -07:00
parent 0c6ae8b8d7
commit 152d8dea15
12 changed files with 123 additions and 21 deletions

View File

@ -0,0 +1,34 @@
using System;
using System.IO;
using System.Linq;
using Orchard.Commands;
using Orchard.Parameters;
using Orchard.Specs.Hosting;
using TechTalk.SpecFlow;
namespace Orchard.Specs.Bindings {
[Binding]
public class CommandLine : BindingBase {
[When(@"I execute >(.*)")]
public void WhenIExecute(string commandLine) {
var details = new RequestDetails();
Binding<WebAppHosting>().Host.Execute(() => {
var args = commandLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var parameters = new CommandParametersParser().Parse(args);
var agent = new CommandHostAgent();
var input = new StringReader("");
var output = new StringWriter();
details.StatusCode = agent.RunSingleCommand(
input,
output,
"Default",
parameters.Arguments.ToArray(),
parameters.Switches.ToDictionary(kv => kv.Key, kv => kv.Value));
details.StatusDescription = details.StatusCode.ToString();
details.ResponseText = output.ToString();
});
Binding<WebAppHosting>().Details = details;
}
}
}

View File

@ -62,7 +62,30 @@ namespace Orchard.Specs.Bindings {
Trace.WriteLine("This call to Host.Reinitialize should not be needed, eventually");
MvcApplication.Host.Reinitialize_Obsolete();
});
}
[Given(@"I have tenant ""(.*)\"" on ""(.*)\"" as ""(.*)\""")]
public void GivenIHaveTenantOnSiteAsName(string shellName, string hostName, string siteName) {
var webApp = Binding<WebAppHosting>();
webApp.Host.Execute(() => {
var shellSettings = new ShellSettings {
Name = shellName,
RequestUrlHost = hostName,
State = new TenantState("Uninitialized"),
};
using (var environment = MvcApplication.CreateStandaloneEnvironment("Default")) {
environment.Resolve<IShellSettingsManager>().SaveSettings(shellSettings);
}
MvcApplication.Host.Reinitialize_Obsolete();
});
webApp.WhenIGoToPathOnHost("Setup", hostName);
webApp.WhenIFillIn(TableData(
new { name = "SiteName", value = siteName },
new { name = "AdminPassword", value = "6655321" }));
webApp.WhenIHit("Finish Setup");
}
}
}

View File

@ -30,6 +30,11 @@ namespace Orchard.Specs.Bindings {
get { return _webHost; }
}
public RequestDetails Details {
get { return _details; }
set { _details = value; }
}
[Given(@"I have a clean site")]
public void GivenIHaveACleanSite() {
GivenIHaveACleanSiteBasedOn("Orchard.Web");
@ -122,16 +127,16 @@ namespace Orchard.Specs.Bindings {
[When(@"I go to ""(.*)"" on host (.*)")]
public void WhenIGoToPathOnHost(string urlPath, string host) {
Host.HostName = host;
_details = Host.SendRequest(urlPath);
Details = Host.SendRequest(urlPath);
_doc = new HtmlDocument();
_doc.Load(new StringReader(_details.ResponseText));
_doc.Load(new StringReader(Details.ResponseText));
}
[When(@"I go to ""(.*)""")]
public void WhenIGoTo(string urlPath) {
_details = Host.SendRequest(urlPath);
Details = Host.SendRequest(urlPath);
_doc = new HtmlDocument();
_doc.Load(new StringReader(_details.ResponseText));
_doc.Load(new StringReader(Details.ResponseText));
}
[When(@"I follow ""(.*)""")]
@ -153,7 +158,7 @@ namespace Orchard.Specs.Bindings {
foreach (var row in table.Rows) {
var r = row;
var input = inputs.SingleOrDefault(x => x.GetAttributeValue("name", x.GetAttributeValue("id", "")) == r["name"]);
Assert.That(input, Is.Not.Null, "Unable to locate <input> name {0} in page html:\r\n\r\n{1}", r["name"], _details.ResponseText);
Assert.That(input, Is.Not.Null, "Unable to locate <input> name {0} in page html:\r\n\r\n{1}", r["name"], Details.ResponseText);
input.Attributes.Add("value", row["value"]);
}
}
@ -165,21 +170,21 @@ namespace Orchard.Specs.Bindings {
.Single(elt => elt.GetAttributeValue("value", null) == submitText);
var form = Form.LocateAround(submit);
var urlPath = form.Start.GetAttributeValue("action", _details.UrlPath);
var urlPath = form.Start.GetAttributeValue("action", Details.UrlPath);
var inputs = form.Children
.SelectMany(elt => elt.DescendantsAndSelf("input"))
.GroupBy(elt => elt.GetAttributeValue("name", elt.GetAttributeValue("id", "")), elt => elt.GetAttributeValue("value", ""))
.ToDictionary(elt => elt.Key, elt => (IEnumerable<string>)elt);
_details = Host.SendRequest(urlPath, inputs);
Details = Host.SendRequest(urlPath, inputs);
_doc = new HtmlDocument();
_doc.Load(new StringReader(_details.ResponseText));
_doc.Load(new StringReader(Details.ResponseText));
}
[When(@"I am redirected")]
public void WhenIAmRedirected() {
var urlPath = "";
if (_details.ResponseHeaders.TryGetValue("Location", out urlPath)) {
if (Details.ResponseHeaders.TryGetValue("Location", out urlPath)) {
WhenIGoTo(urlPath);
}
else {
@ -189,13 +194,13 @@ namespace Orchard.Specs.Bindings {
[Then(@"the status should be (.*) (.*)")]
public void ThenTheStatusShouldBe(int statusCode, string statusDescription) {
Assert.That(_details.StatusCode, Is.EqualTo(statusCode));
Assert.That(_details.StatusDescription, Is.EqualTo(statusDescription));
Assert.That(Details.StatusCode, Is.EqualTo(statusCode));
Assert.That(Details.StatusDescription, Is.EqualTo(statusDescription));
}
[Then(@"I should see ""(.*)""")]
public void ThenIShouldSee(string text) {
Assert.That(_details.ResponseText, Is.StringContaining(text));
Assert.That(Details.ResponseText, Is.StringContaining(text));
}
[Then(@"the title contains ""(.*)""")]

View File

@ -26,9 +26,6 @@
<add name="CaptureTraceMessages" />
</listeners>
</source>
<!--<source name="Orchard.Localization.Text" switchValue="Warning"/>
<source name="Orchard.Mvc.ViewEngines.WebFormsViewEngineProvider" switchValue="Warning"/>-->
</sources>
<sharedListeners>
<add name="CaptureTraceMessages" type="Orchard.Specs.Hosting.HostingTraceListener, Orchard.Specs" initializeData="" />

View File

@ -17,7 +17,8 @@ namespace Orchard.Specs.Hosting {
}
protected override IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase) {
var config = (SQLiteConfiguration)base.GetPersistenceConfigurer(createDatabase);
return config.ShowSql();
//config.ShowSql();
return config;
}
}
}

View File

@ -28,6 +28,7 @@ namespace Orchard.Specs.Hosting {
baseDir
.ShallowCopy("*.dll", _tempSite.Combine("bin"))
.ShallowCopy("*.exe", _tempSite.Combine("bin"))
.ShallowCopy("*.pdb", _tempSite.Combine("bin"));
HostName = "localhost";

View File

@ -74,3 +74,11 @@ Scenario: A new tenant runs the setup
And I go to "/Default.aspx"
Then I should see "<h1>Scott Site</h1>"
And I should see "Welcome, <strong>admin</strong>!"
Scenario: Listing tenants from command line
Given I have installed Orchard
And I have installed "Orchard.MultiTenancy"
And I have tenant "Alpha" on "example.org" as "New-site-name"
When I execute >orchard tenant list
Then I should see "Name: Alpha"
And I should see "Request Url Host: example.org"

View File

@ -250,6 +250,29 @@ this.ScenarioSetup(scenarioInfo);
testRunner.Then("I should see \"<h1>Scott Site</h1>\"");
#line 76
testRunner.And("I should see \"Welcome, <strong>admin</strong>!\"");
#line hidden
testRunner.CollectScenarioErrors();
}
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Listing tenants from command line")]
public virtual void ListingTenantsFromCommandLine()
{
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Listing tenants from command line", ((string[])(null)));
#line 78
this.ScenarioSetup(scenarioInfo);
#line 79
testRunner.Given("I have installed Orchard");
#line 80
testRunner.And("I have installed \"Orchard.MultiTenancy\"");
#line 81
testRunner.And("I have tenant \"Alpha\" on \"example.org\" as \"New-site-name\"");
#line 82
testRunner.When("I execute >tenant list");
#line 83
testRunner.Then("I should see \"Name: Alpha\"");
#line 84
testRunner.And("I should see \"Request Url Host: example.org\"");
#line hidden
testRunner.CollectScenarioErrors();
}

View File

@ -103,6 +103,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Bindings\BindingBase.cs" />
<Compile Include="Bindings\CommandLine.cs" />
<Compile Include="Bindings\OrchardSiteFactory.cs" />
<Compile Include="Hosting\MessageSink.cs" />
<Compile Include="Hosting\HostingTraceListener.cs" />
@ -158,7 +159,7 @@
<Content Include="Hosting\Orchard.Web\Themes\Web.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Hosting\Orchard.Web\Config\Sites.Default.config">
<Content Include="Hosting\Orchard.Web\Config\Sites.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Hosting\Orchard.Web\Config\Diagnostics.config">
@ -248,6 +249,10 @@
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
<Name>Orchard.Framework</Name>
</ProjectReference>
<ProjectReference Include="..\Tools\Orchard\Orchard.csproj">
<Project>{33B1BC8D-E292-4972-A363-22056B207156}</Project>
<Name>Orchard</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />

View File

@ -28,4 +28,5 @@ namespace Orchard.Environment {
/// </summary>
IStandaloneEnvironment CreateStandaloneEnvironment(ShellSettings shellSettings);
}
}

View File

@ -87,9 +87,13 @@ namespace Orchard.Environment.ShellBuilders {
.InjectActionInvoker();
}
var optionalHostConfig = HostingEnvironment.MapPath("~/Config/Sites." + settings.Name + ".config");
if (File.Exists(optionalHostConfig))
builder.RegisterModule(new ConfigurationSettingsReader(ConfigurationSettingsReader.DefaultSectionName, optionalHostConfig));
var optionalShellConfig = HostingEnvironment.MapPath("~/Config/Sites.config");
if (File.Exists(optionalShellConfig))
builder.RegisterModule(new ConfigurationSettingsReader(ConfigurationSettingsReader.DefaultSectionName, optionalShellConfig));
var optionalShellByNameConfig = HostingEnvironment.MapPath("~/Config/Sites." + settings.Name + ".config");
if (File.Exists(optionalShellByNameConfig))
builder.RegisterModule(new ConfigurationSettingsReader(ConfigurationSettingsReader.DefaultSectionName, optionalShellByNameConfig));
});
}