Created
August 7, 2014 13:15
-
-
Save jokokko/ac846a7ee2c83d3754da to your computer and use it in GitHub Desktop.
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
public interface IEventStoreTest | |
{ | |
} | |
internal static class EventStoreTestMixins | |
{ | |
... | |
public static EventStoreHelper StartInMemStore(this IEventStoreTest test) | |
{ | |
KillExistingEventStore(); | |
var process = new Process(); | |
process.StartInfo = new ProcessStartInfo(EventStorePath, "--mem-db --run-projections=all") | |
{ | |
RedirectStandardOutput = true, | |
CreateNoWindow = true, | |
UseShellExecute = false | |
}; | |
var mre = new ManualResetEvent(false); | |
ThreadPool.QueueUserWorkItem(state => | |
{ | |
process.Start(); | |
while (!process.StandardOutput.EndOfStream) | |
{ | |
string line = process.StandardOutput.ReadLine(); | |
if (!string.IsNullOrEmpty(line) && line.Contains("SPARTA")) | |
{ | |
mre.Set(); | |
} | |
} | |
}); | |
if (!mre.WaitOne(TimeSpan.FromSeconds(10))) | |
{ | |
throw new InvalidOperationException("Event Store not started in 10 secs"); | |
} | |
return new EventStoreHelper(BuildConnection(), new ActionDisposable(process.Kill)); | |
} | |
} | |
public sealed class SomeEventStoreTest : IEventStoreTest | |
{ | |
private readonly EventStoreHelper store; | |
public SomeEventStoreTest() | |
{ | |
store = this.StartInMemStore(); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment