-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xXxHostRunner refactor, ConsoleHostRunnerTests
- Loading branch information
Showing
11 changed files
with
108 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/******************************************************************************** | ||
* ConsoleHostRunner.cs * | ||
* * | ||
* Author: Denes Solti * | ||
********************************************************************************/ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Solti.Utils.Rpc.Hosting.Tests | ||
{ | ||
using Internals; | ||
|
||
[TestFixture] | ||
public class ConsoleHostRunnerTests | ||
{ | ||
private class BadDependencyAppHost : AppHostBase | ||
{ | ||
public override string Name => throw new System.NotImplementedException(); | ||
|
||
public override string Url => throw new System.NotImplementedException(); | ||
|
||
public BadDependencyAppHost() : base() | ||
{ | ||
Dependencies.Add("invalid"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Start_ShouldValidateTheDependencies() => Assert.Throws<Exception>(() => | ||
{ | ||
using IHost appHost = new BadDependencyAppHost(); | ||
using IHostRunner hostRunner = new ConsoleHostRunner(appHost); | ||
hostRunner.Start(); | ||
}); | ||
|
||
private class ConsoleAppHost : AppHostBase | ||
{ | ||
public override string Name => nameof(ConsoleAppHost); | ||
|
||
public override string Url => "http://127.0.0.1:1986/api/"; | ||
|
||
public ManualResetEventSlim Started { get; } = new ManualResetEventSlim(); | ||
|
||
public override void OnStart() | ||
{ | ||
base.OnStart(); | ||
Started.Set(); | ||
} | ||
|
||
protected override void Dispose(bool disposeManaged) | ||
{ | ||
if (disposeManaged) | ||
Started.Dispose(); | ||
|
||
base.Dispose(disposeManaged); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Runner_ShouldTerminateOnCtrlC() | ||
{ | ||
using ConsoleAppHost appHost = new ConsoleAppHost(); | ||
using ConsoleHostRunner hostRunner = new ConsoleHostRunner(appHost); | ||
|
||
Task t = Task.Factory.StartNew(((IHostRunner) hostRunner).Start); | ||
Assert.That(appHost.Started.Wait(TimeSpan.FromSeconds(1))); | ||
|
||
hostRunner.OnConsoleCancel(null, null); | ||
|
||
Assert.That(t.Wait(TimeSpan.FromSeconds(1))); | ||
} | ||
} | ||
} |