Skip to content

Instantly share code, notes, and snippets.

@jokokko
Created August 7, 2014 13:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokokko/ac846a7ee2c83d3754da to your computer and use it in GitHub Desktop.
Save jokokko/ac846a7ee2c83d3754da to your computer and use it in GitHub Desktop.
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