mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-16 22:20:44 +08:00
Updating tracing and adding specflow support for command handlers
--HG-- branch : dev
This commit is contained in:
parent
0c6ae8b8d7
commit
152d8dea15
34
src/Orchard.Specs/Bindings/CommandLine.cs
Normal file
34
src/Orchard.Specs/Bindings/CommandLine.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -62,7 +62,30 @@ namespace Orchard.Specs.Bindings {
|
|||||||
Trace.WriteLine("This call to Host.Reinitialize should not be needed, eventually");
|
Trace.WriteLine("This call to Host.Reinitialize should not be needed, eventually");
|
||||||
MvcApplication.Host.Reinitialize_Obsolete();
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,11 @@ namespace Orchard.Specs.Bindings {
|
|||||||
get { return _webHost; }
|
get { return _webHost; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RequestDetails Details {
|
||||||
|
get { return _details; }
|
||||||
|
set { _details = value; }
|
||||||
|
}
|
||||||
|
|
||||||
[Given(@"I have a clean site")]
|
[Given(@"I have a clean site")]
|
||||||
public void GivenIHaveACleanSite() {
|
public void GivenIHaveACleanSite() {
|
||||||
GivenIHaveACleanSiteBasedOn("Orchard.Web");
|
GivenIHaveACleanSiteBasedOn("Orchard.Web");
|
||||||
@ -122,16 +127,16 @@ namespace Orchard.Specs.Bindings {
|
|||||||
[When(@"I go to ""(.*)"" on host (.*)")]
|
[When(@"I go to ""(.*)"" on host (.*)")]
|
||||||
public void WhenIGoToPathOnHost(string urlPath, string host) {
|
public void WhenIGoToPathOnHost(string urlPath, string host) {
|
||||||
Host.HostName = host;
|
Host.HostName = host;
|
||||||
_details = Host.SendRequest(urlPath);
|
Details = Host.SendRequest(urlPath);
|
||||||
_doc = new HtmlDocument();
|
_doc = new HtmlDocument();
|
||||||
_doc.Load(new StringReader(_details.ResponseText));
|
_doc.Load(new StringReader(Details.ResponseText));
|
||||||
}
|
}
|
||||||
|
|
||||||
[When(@"I go to ""(.*)""")]
|
[When(@"I go to ""(.*)""")]
|
||||||
public void WhenIGoTo(string urlPath) {
|
public void WhenIGoTo(string urlPath) {
|
||||||
_details = Host.SendRequest(urlPath);
|
Details = Host.SendRequest(urlPath);
|
||||||
_doc = new HtmlDocument();
|
_doc = new HtmlDocument();
|
||||||
_doc.Load(new StringReader(_details.ResponseText));
|
_doc.Load(new StringReader(Details.ResponseText));
|
||||||
}
|
}
|
||||||
|
|
||||||
[When(@"I follow ""(.*)""")]
|
[When(@"I follow ""(.*)""")]
|
||||||
@ -153,7 +158,7 @@ namespace Orchard.Specs.Bindings {
|
|||||||
foreach (var row in table.Rows) {
|
foreach (var row in table.Rows) {
|
||||||
var r = row;
|
var r = row;
|
||||||
var input = inputs.SingleOrDefault(x => x.GetAttributeValue("name", x.GetAttributeValue("id", "")) == r["name"]);
|
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"]);
|
input.Attributes.Add("value", row["value"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,21 +170,21 @@ namespace Orchard.Specs.Bindings {
|
|||||||
.Single(elt => elt.GetAttributeValue("value", null) == submitText);
|
.Single(elt => elt.GetAttributeValue("value", null) == submitText);
|
||||||
|
|
||||||
var form = Form.LocateAround(submit);
|
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
|
var inputs = form.Children
|
||||||
.SelectMany(elt => elt.DescendantsAndSelf("input"))
|
.SelectMany(elt => elt.DescendantsAndSelf("input"))
|
||||||
.GroupBy(elt => elt.GetAttributeValue("name", elt.GetAttributeValue("id", "")), elt => elt.GetAttributeValue("value", ""))
|
.GroupBy(elt => elt.GetAttributeValue("name", elt.GetAttributeValue("id", "")), elt => elt.GetAttributeValue("value", ""))
|
||||||
.ToDictionary(elt => elt.Key, elt => (IEnumerable<string>)elt);
|
.ToDictionary(elt => elt.Key, elt => (IEnumerable<string>)elt);
|
||||||
|
|
||||||
_details = Host.SendRequest(urlPath, inputs);
|
Details = Host.SendRequest(urlPath, inputs);
|
||||||
_doc = new HtmlDocument();
|
_doc = new HtmlDocument();
|
||||||
_doc.Load(new StringReader(_details.ResponseText));
|
_doc.Load(new StringReader(Details.ResponseText));
|
||||||
}
|
}
|
||||||
|
|
||||||
[When(@"I am redirected")]
|
[When(@"I am redirected")]
|
||||||
public void WhenIAmRedirected() {
|
public void WhenIAmRedirected() {
|
||||||
var urlPath = "";
|
var urlPath = "";
|
||||||
if (_details.ResponseHeaders.TryGetValue("Location", out urlPath)) {
|
if (Details.ResponseHeaders.TryGetValue("Location", out urlPath)) {
|
||||||
WhenIGoTo(urlPath);
|
WhenIGoTo(urlPath);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -189,13 +194,13 @@ namespace Orchard.Specs.Bindings {
|
|||||||
|
|
||||||
[Then(@"the status should be (.*) (.*)")]
|
[Then(@"the status should be (.*) (.*)")]
|
||||||
public void ThenTheStatusShouldBe(int statusCode, string statusDescription) {
|
public void ThenTheStatusShouldBe(int statusCode, string statusDescription) {
|
||||||
Assert.That(_details.StatusCode, Is.EqualTo(statusCode));
|
Assert.That(Details.StatusCode, Is.EqualTo(statusCode));
|
||||||
Assert.That(_details.StatusDescription, Is.EqualTo(statusDescription));
|
Assert.That(Details.StatusDescription, Is.EqualTo(statusDescription));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Then(@"I should see ""(.*)""")]
|
[Then(@"I should see ""(.*)""")]
|
||||||
public void ThenIShouldSee(string text) {
|
public void ThenIShouldSee(string text) {
|
||||||
Assert.That(_details.ResponseText, Is.StringContaining(text));
|
Assert.That(Details.ResponseText, Is.StringContaining(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Then(@"the title contains ""(.*)""")]
|
[Then(@"the title contains ""(.*)""")]
|
||||||
|
@ -26,9 +26,6 @@
|
|||||||
<add name="CaptureTraceMessages" />
|
<add name="CaptureTraceMessages" />
|
||||||
</listeners>
|
</listeners>
|
||||||
</source>
|
</source>
|
||||||
<!--<source name="Orchard.Localization.Text" switchValue="Warning"/>
|
|
||||||
<source name="Orchard.Mvc.ViewEngines.WebFormsViewEngineProvider" switchValue="Warning"/>-->
|
|
||||||
|
|
||||||
</sources>
|
</sources>
|
||||||
<sharedListeners>
|
<sharedListeners>
|
||||||
<add name="CaptureTraceMessages" type="Orchard.Specs.Hosting.HostingTraceListener, Orchard.Specs" initializeData="" />
|
<add name="CaptureTraceMessages" type="Orchard.Specs.Hosting.HostingTraceListener, Orchard.Specs" initializeData="" />
|
||||||
|
@ -17,7 +17,8 @@ namespace Orchard.Specs.Hosting {
|
|||||||
}
|
}
|
||||||
protected override IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase) {
|
protected override IPersistenceConfigurer GetPersistenceConfigurer(bool createDatabase) {
|
||||||
var config = (SQLiteConfiguration)base.GetPersistenceConfigurer(createDatabase);
|
var config = (SQLiteConfiguration)base.GetPersistenceConfigurer(createDatabase);
|
||||||
return config.ShowSql();
|
//config.ShowSql();
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ namespace Orchard.Specs.Hosting {
|
|||||||
|
|
||||||
baseDir
|
baseDir
|
||||||
.ShallowCopy("*.dll", _tempSite.Combine("bin"))
|
.ShallowCopy("*.dll", _tempSite.Combine("bin"))
|
||||||
|
.ShallowCopy("*.exe", _tempSite.Combine("bin"))
|
||||||
.ShallowCopy("*.pdb", _tempSite.Combine("bin"));
|
.ShallowCopy("*.pdb", _tempSite.Combine("bin"));
|
||||||
|
|
||||||
HostName = "localhost";
|
HostName = "localhost";
|
||||||
|
@ -74,3 +74,11 @@ Scenario: A new tenant runs the setup
|
|||||||
And I go to "/Default.aspx"
|
And I go to "/Default.aspx"
|
||||||
Then I should see "<h1>Scott Site</h1>"
|
Then I should see "<h1>Scott Site</h1>"
|
||||||
And I should see "Welcome, <strong>admin</strong>!"
|
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"
|
||||||
|
23
src/Orchard.Specs/MultiTenancy.feature.cs
generated
23
src/Orchard.Specs/MultiTenancy.feature.cs
generated
@ -250,6 +250,29 @@ this.ScenarioSetup(scenarioInfo);
|
|||||||
testRunner.Then("I should see \"<h1>Scott Site</h1>\"");
|
testRunner.Then("I should see \"<h1>Scott Site</h1>\"");
|
||||||
#line 76
|
#line 76
|
||||||
testRunner.And("I should see \"Welcome, <strong>admin</strong>!\"");
|
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
|
#line hidden
|
||||||
testRunner.CollectScenarioErrors();
|
testRunner.CollectScenarioErrors();
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Bindings\BindingBase.cs" />
|
<Compile Include="Bindings\BindingBase.cs" />
|
||||||
|
<Compile Include="Bindings\CommandLine.cs" />
|
||||||
<Compile Include="Bindings\OrchardSiteFactory.cs" />
|
<Compile Include="Bindings\OrchardSiteFactory.cs" />
|
||||||
<Compile Include="Hosting\MessageSink.cs" />
|
<Compile Include="Hosting\MessageSink.cs" />
|
||||||
<Compile Include="Hosting\HostingTraceListener.cs" />
|
<Compile Include="Hosting\HostingTraceListener.cs" />
|
||||||
@ -158,7 +159,7 @@
|
|||||||
<Content Include="Hosting\Orchard.Web\Themes\Web.config">
|
<Content Include="Hosting\Orchard.Web\Themes\Web.config">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Include="Hosting\Orchard.Web\Config\Sites.Default.config">
|
<Content Include="Hosting\Orchard.Web\Config\Sites.config">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<None Include="Hosting\Orchard.Web\Config\Diagnostics.config">
|
<None Include="Hosting\Orchard.Web\Config\Diagnostics.config">
|
||||||
@ -248,6 +249,10 @@
|
|||||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||||
<Name>Orchard.Framework</Name>
|
<Name>Orchard.Framework</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Tools\Orchard\Orchard.csproj">
|
||||||
|
<Project>{33B1BC8D-E292-4972-A363-22056B207156}</Project>
|
||||||
|
<Name>Orchard</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<WCFMetadata Include="Service References\" />
|
<WCFMetadata Include="Service References\" />
|
||||||
|
@ -28,4 +28,5 @@ namespace Orchard.Environment {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IStandaloneEnvironment CreateStandaloneEnvironment(ShellSettings shellSettings);
|
IStandaloneEnvironment CreateStandaloneEnvironment(ShellSettings shellSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,13 @@ namespace Orchard.Environment.ShellBuilders {
|
|||||||
.InjectActionInvoker();
|
.InjectActionInvoker();
|
||||||
}
|
}
|
||||||
|
|
||||||
var optionalHostConfig = HostingEnvironment.MapPath("~/Config/Sites." + settings.Name + ".config");
|
var optionalShellConfig = HostingEnvironment.MapPath("~/Config/Sites.config");
|
||||||
if (File.Exists(optionalHostConfig))
|
if (File.Exists(optionalShellConfig))
|
||||||
builder.RegisterModule(new ConfigurationSettingsReader(ConfigurationSettingsReader.DefaultSectionName, optionalHostConfig));
|
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));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user