Last active
January 1, 2016 09:49
-
-
Save dschenkelman/8127048 to your computer and use it in GitHub Desktop.
Async XBehave Steps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Trait("AcceptanceTest", "RunningScriptsTests")] | |
[Trait("Requires", "Internet Connection")] | |
[Trait("Requires", "Administrator Privileges")] | |
public void RunningWebApiHostSampleEnablesWebAccessInLocalhostXBehave(string originalWorkingDirectory, Task<int> scriptTask) | |
{ | |
const string MethodName = "RunningWebApiHostSampleEnablesWebAccessInLocalhostXBehave"; | |
"Given an existing Web API host sample (similar to https://github.com/scriptcs/scriptcs-samples/tree/master/webapihost)" | |
._(() => | |
{ | |
originalWorkingDirectory = Environment.CurrentDirectory; | |
if (Directory.Exists(_localDirectory)) Directory.Delete(_localDirectory, true); | |
_localDirectory = Path.Combine(AcceptanceTestHelpers.GetExecutingAssemblyDirectory(), MethodName); | |
var webApiHostDirectory = Path.Combine(AcceptanceTestHelpers.GetExecutingAssemblyDirectory(), | |
@"Files\webapihost"); | |
Directory.CreateDirectory(_localDirectory); | |
AcceptanceTestHelpers.CopyDirectory(webApiHostDirectory, _localDirectory, true); | |
Environment.CurrentDirectory = _localDirectory; | |
Program.Main("-install".Split(' ')); | |
}).Teardown(() => Environment.CurrentDirectory = originalWorkingDirectory); | |
"When the sample is executed"._(() => | |
{ | |
scriptTask = Task.Run(() => Program.Main("start.csx".Split(' '))); | |
}); | |
"Then the endpoint can be hit"._(async () => | |
{ | |
await Task.Delay(10000); | |
// never reached | |
var client = new HttpClient(); | |
var getResult = await client.GetStringAsync("http://localhost:8080/api/test"); | |
getResult.ShouldContain("Hello world!"); | |
}); | |
"And the program terminates correctly"._(async () => | |
{ | |
var result = await scriptTask; | |
// never reached | |
result.ShouldEqual(0); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Trait("AcceptanceTest", "RunningScriptsTests")] | |
[Trait("Requires", "Internet Connection")] | |
[Trait("Requires", "Administrator Privileges")] | |
public void RunningWebApiHostSampleEnablesWebAccessInLocalhostXBehave(string originalWorkingDirectory, Task<int> scriptTask) | |
{ | |
const string MethodName = "RunningWebApiHostSampleEnablesWebAccessInLocalhostXBehave"; | |
"Given an existing Web API host sample (similar to https://github.com/scriptcs/scriptcs-samples/tree/master/webapihost)" | |
._(() => | |
{ | |
originalWorkingDirectory = Environment.CurrentDirectory; | |
if (Directory.Exists(_localDirectory)) Directory.Delete(_localDirectory, true); | |
_localDirectory = Path.Combine(AcceptanceTestHelpers.GetExecutingAssemblyDirectory(), MethodName); | |
var webApiHostDirectory = Path.Combine(AcceptanceTestHelpers.GetExecutingAssemblyDirectory(), | |
@"Files\webapihost"); | |
Directory.CreateDirectory(_localDirectory); | |
AcceptanceTestHelpers.CopyDirectory(webApiHostDirectory, _localDirectory, true); | |
Environment.CurrentDirectory = _localDirectory; | |
Program.Main("-install".Split(' ')); | |
}).Teardown(() => Environment.CurrentDirectory = originalWorkingDirectory); | |
"When the sample is executed"._(() => | |
{ | |
scriptTask = Task.Run(() => Program.Main("start.csx".Split(' '))); | |
}); | |
"Then the endpoint can be hit"._(() => | |
{ | |
Task.Delay(10000).Wait(); | |
var client = new HttpClient(); | |
var getResult = client.GetStringAsync("http://localhost:8080/api/test").Result; | |
getResult.ShouldContain("Hello world!"); | |
}); | |
"And the program terminates correctly"._(() => | |
{ | |
var result = scriptTask.Result; | |
result.ShouldEqual(0); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment