Skip to content

Commit dcc4e51

Browse files
author
Pete
committed
Merge branch 'hotfix-1.3.7'
2 parents 88a6768 + b75f7c7 commit dcc4e51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+855
-976
lines changed

packaging/chocolatey/Setup.Install.nuspec

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/ServicePulse.Chocolatey.sln

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
namespace ServicePulse.Host.Tests
2+
{
3+
using NUnit.Framework;
4+
using ServicePulse.Host.Hosting;
5+
6+
[TestFixture]
7+
public class CaseLessOptionSetTests
8+
{
9+
bool flag;
10+
private OptionSet testOptions;
11+
12+
[SetUp]
13+
public void Setup()
14+
{
15+
testOptions = new CaseLessOptionSet
16+
{
17+
{
18+
"t|test",
19+
"Test option",
20+
key => { flag = true; }
21+
}
22+
};
23+
}
24+
25+
[Test]
26+
public void LowercaseTestShouldSucceed()
27+
{
28+
flag = false;
29+
testOptions.Parse(new[]{"-test"});
30+
Assert.IsTrue(flag, "-test did not parse as a valid option");
31+
}
32+
33+
[Test]
34+
public void MixedCaseTestShouldSucceed()
35+
{
36+
flag = false;
37+
testOptions.Parse(new[] { "-Test" });
38+
Assert.IsTrue(flag, "-Test did not parse as a valid option");
39+
}
40+
41+
[Test]
42+
public void UppercaseTestShouldSucceed()
43+
{
44+
flag = false;
45+
testOptions.Parse(new[] { "-TEST" });
46+
Assert.IsTrue(flag, "-TEST did not parse as a valid option");
47+
}
48+
49+
[Test]
50+
public void ShortTestShouldSucceed()
51+
{
52+
flag = false;
53+
testOptions.Parse(new[] { "-t" });
54+
Assert.IsTrue(flag, "-TEST did not parse as a valid option");
55+
}
56+
57+
[Test]
58+
public void ShortTestShouldFail()
59+
{
60+
flag = false;
61+
testOptions.Parse(new[] { "-x" });
62+
Assert.IsFalse(flag, "-x should not parse as a valid option");
63+
}
64+
65+
[Test]
66+
public void Ensure_MultiSet_Option_Work()
67+
{
68+
69+
const string validUrl = @"http://localhost:1010/sp/";
70+
var executionMode = ExecutionMode.Run;
71+
72+
var installOptions = new CaseLessOptionSet
73+
{
74+
{
75+
"?|h|help",
76+
"Help about the command line options.",
77+
key => { }
78+
},
79+
{
80+
"i|install",
81+
@"Install the endpoint as a Windows service.",
82+
s =>{executionMode = ExecutionMode.Install;}
83+
},
84+
{
85+
"servicename=",
86+
@"Specify the service name for the installed service.",
87+
s => { }
88+
},
89+
{
90+
"servicecontrolurl=",
91+
@"Configures the service control url.",
92+
s => { }
93+
},
94+
{
95+
"url=",
96+
@"Configures ServicePulse to listen on the specified url.",
97+
s => { }
98+
}
99+
};
100+
101+
102+
var extractOptions = new CaseLessOptionSet
103+
{
104+
{
105+
"?|h|help",
106+
"Help about the command line options.",
107+
key => { }
108+
},
109+
{
110+
"e|extract",
111+
@"Extract files to be installed in a Web Server.",
112+
s => {executionMode = ExecutionMode.Extract;}
113+
},
114+
{
115+
"servicecontrolurl=",
116+
@"Configures the service control url.",
117+
s => { }
118+
},
119+
{
120+
"outpath=",
121+
@"The output path to extract files to. By default it extracts to the current directory.",
122+
s => { }
123+
}
124+
};
125+
126+
var path = @"c:\foo\bar";
127+
var args = new[]
128+
{
129+
"-e",
130+
$"--servicecontrolurl={validUrl}",
131+
$"--outpath={path}"
132+
};
133+
134+
135+
installOptions.Parse(args);
136+
Assert.IsTrue(executionMode == ExecutionMode.Run);
137+
extractOptions.Parse(args);
138+
Assert.IsTrue(executionMode == ExecutionMode.Extract);
139+
}
140+
141+
142+
[Test]
143+
public void ReturnsUnknownArguments()
144+
{
145+
var unknownArgs = testOptions.Parse(new[] { "-test", "-unknown" });
146+
Assert.IsTrue(unknownArgs.Count == 1, "Unknown argument was not detected");
147+
Assert.IsTrue(unknownArgs[0].Equals("-unknown"), "Unknown argument was not returned");
148+
}
149+
}
150+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
namespace ServicePulse.Host.Tests
2+
{
3+
using System;
4+
using NUnit.Framework;
5+
using ServicePulse.Host.Hosting;
6+
7+
[TestFixture]
8+
public class HostArgumentsTests
9+
{
10+
string[] args;
11+
const string validUrl = @"http://localhost:1010/sp/";
12+
const string invalidUrl = @"http//localhost:1010/sp/";
13+
14+
[Test]
15+
public void Run_Args_Unknown_Argument_Shows_Help()
16+
{
17+
args = new[]
18+
{
19+
"--foobar"
20+
};
21+
var hostArgs = new HostArguments(args);
22+
Assert.IsTrue(hostArgs.Help, "Unknown argument did not set help flag");
23+
}
24+
25+
[Test]
26+
public void Run_Args_No_Arguments_Is_Valid()
27+
{
28+
// No Arguments
29+
args = new string[] {};
30+
var hostArgs = new HostArguments(args);
31+
Assert.IsTrue(hostArgs.executionMode == ExecutionMode.Run, "With no args execution mode should be run");
32+
Assert.IsFalse(hostArgs.Help, "With no args help should not be triggered");
33+
}
34+
35+
[Test]
36+
public void Run_Args_With_Valid_URL()
37+
{
38+
args = new[]
39+
{
40+
$"--url={validUrl}"
41+
};
42+
43+
var hostArgs = new HostArguments(args);
44+
Assert.IsTrue(hostArgs.executionMode == ExecutionMode.Run, "With only valid url args execution mode should be run");
45+
Assert.IsFalse(hostArgs.Help, "With only valid url arguments help should not be triggered");
46+
Assert.IsTrue(hostArgs.Url.Equals(validUrl, StringComparison.Ordinal), "Valid url argument was not parsed correctly");
47+
}
48+
49+
[Test]
50+
public void Run_Args_With_Invalid_URL()
51+
{
52+
53+
args = new[]
54+
{
55+
$"--url={invalidUrl}"
56+
};
57+
var hostArgs = new HostArguments(args);
58+
Assert.IsTrue(hostArgs.Help, "With invalid url argument help should be triggered");
59+
}
60+
61+
[Test]
62+
public void Run_Args_Extra_Args_Trigger_help()
63+
{
64+
65+
args = new[]
66+
{
67+
$"--url={validUrl}",
68+
$"--serviceControlUrl={validUrl}" //ServiceControl URL isn't valid in run mode. Needs to be manually set
69+
};
70+
var hostArgs = new HostArguments(args);
71+
Assert.IsTrue(hostArgs.Help, "With extra arguments help should be triggered");
72+
}
73+
74+
[Test]
75+
public void Extract_Args_With_Defaults()
76+
{
77+
args = new[]
78+
{
79+
"-extract"
80+
};
81+
var hostArgs = new HostArguments(args);
82+
Assert.IsFalse(hostArgs.Help, "extract argument should not show help");
83+
Assert.IsTrue(hostArgs.executionMode == ExecutionMode.Extract, "extract argument did not parse to correct execution mode");
84+
}
85+
86+
[Test]
87+
public void Extract_Args_With_SC_Specified()
88+
{
89+
args = new[]
90+
{
91+
"-extract",
92+
$"--serviceControlUrl={validUrl}"
93+
};
94+
var hostArgs = new HostArguments(args);
95+
Assert.IsFalse(hostArgs.Help, "extract argument should not show help");
96+
Assert.IsTrue(hostArgs.executionMode == ExecutionMode.Extract, "extract argument did not parse to correct execution mode");
97+
Assert.IsTrue(hostArgs.ServiceControlUrl.Equals(validUrl, StringComparison.Ordinal), "ServiceControlUrl argument was not parsed correctly");
98+
}
99+
100+
[Test]
101+
public void Extract_Args_With_Output_Specified()
102+
{
103+
var path = @"c:\foo\bar";
104+
args = new[]
105+
{
106+
"-extract",
107+
$"--outPath={path}"
108+
};
109+
var hostArgs = new HostArguments(args);
110+
Assert.IsTrue(hostArgs.executionMode == ExecutionMode.Extract, "extract argument did not parse to correct execution mode");
111+
Assert.IsFalse(hostArgs.Help, "extract argument should not show help");
112+
Assert.IsTrue(hostArgs.OutputPath.Equals(path, StringComparison.Ordinal), "outpath argument was not parsed correctly");
113+
}
114+
115+
[Test]
116+
public void Extract_Args_With_All_Params_Specified()
117+
{
118+
var path = @"c:\foo\bar";
119+
args = new[]
120+
{
121+
"-e",
122+
$"--servicecontrolurl={validUrl}",
123+
$"--outpath={path}"
124+
125+
};
126+
var hostArgs = new HostArguments(args);
127+
Assert.IsTrue(hostArgs.executionMode == ExecutionMode.Extract, "extract argument did not parse to correct execution mode");
128+
Assert.IsFalse(hostArgs.Help, "extract argument should not show help");
129+
Assert.IsTrue(hostArgs.OutputPath.Equals(path, StringComparison.Ordinal), "outpath argument was not parsed correctly");
130+
Assert.IsTrue(hostArgs.ServiceControlUrl.Equals(validUrl, StringComparison.Ordinal), "ServiceControlUrl argument was not parsed correctly");
131+
}
132+
}
133+
}
134+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Setting up javascript unit tests
2+
3+
We use Resharper to manage our development javascript tests
4+
5+
First, install [PhantomJs](http://phantomjs.org/), a headless browser. It comes as a zip, don't forget to unlock the zip before extracting it. I put mine here `C:\Apps\phantomjs-2.0.0-windows\bin\phantomjs.exe`.
6+
7+
From the Resharper menu in Visual Studio select Options...
8+
9+
In the Tasks tab expand Unit Testing and highlight Javascript Tests
10+
11+
You will need to
12+
13+
- Enable [QUnit](http://qunitjs.com/) support
14+
- Enable [Jasmine](http://jasmine.github.io/) support
15+
- Set the Jasmine version to 2.0
16+
- You will need to specify path to the PhantomJS.exe.
17+
- Add the command line arguments `--proxy-type=none`
18+
- Optionally add a path to a custom html harness `SpecsRunner.html`
19+
20+
21+
Like this
22+
23+
<img src="readme_fig_1.png" />
24+
25+
26+
When you open up a javascript test file you will be able to run the test like you would a regular C# unit test.
168 KB
Loading

src/ServicePulse.Host.Tests/ServicePulse.Host.Tests.csproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@
4545
<Reference Include="System.Xml" />
4646
</ItemGroup>
4747
<ItemGroup>
48+
<Compile Include="CommandLineTests\CaseLessOptionSetTests.cs" />
49+
<Compile Include="CommandLineTests\HostArgsTests.cs" />
4850
<Compile Include="VerifyAppConstantsJSTextReplacement.cs" />
4951
<Compile Include="Properties\AssemblyInfo.cs" />
5052
</ItemGroup>
5153
<ItemGroup>
5254
<None Include="packages.config" />
55+
<None Include="README.md" />
5356
</ItemGroup>
5457
<ItemGroup>
5558
<Content Include="..\packages\PhantomJS.2.0.0\tools\phantomjs\phantomjs.exe">
@@ -65,6 +68,7 @@
6568
<Content Include="phantomjs-license.txt">
6669
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6770
</Content>
71+
<Content Include="README_fig_1.PNG" />
6872
<Content Include="Scripts\jasmine-samples\Player.js" />
6973
<Content Include="Scripts\jasmine-samples\PlayerSpec.js" />
7074
<Content Include="Scripts\jasmine-samples\Song.js" />
@@ -84,7 +88,12 @@
8488
<Content Include="tests\js\_references.js" />
8589
<Content Include="tests\js\services\services.spec.js" />
8690
</ItemGroup>
87-
<ItemGroup />
91+
<ItemGroup>
92+
<ProjectReference Include="..\ServicePulse.Host\ServicePulse.Host.csproj">
93+
<Project>{d120b791-bd1b-4e06-b4e1-69801a73209b}</Project>
94+
<Name>ServicePulse.Host</Name>
95+
</ProjectReference>
96+
</ItemGroup>
8897
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8998
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
9099
Other similar extension points exist, see Microsoft.Common.targets.

0 commit comments

Comments
 (0)