I just wanted to take a minute to say THANK YOU for the EventStore.ClientAPI.Embedded. It has made my integration tests so much easier and configuration-free.
Here’s how I’m using it with integration tests. Sorry / You’re welcome F#
namespace TestingNamespace
open System.Net
open EventStore.Core
open EventStore.ClientAPI.Embedded
open EventStore.ClientAPI
type EmbeddedEventStore = {
VNode: ClusterVNode;
Connection: IEventStoreConnection;
}
module TestEventStore =
let get () =
let noIp = new IPEndPoint(IPAddress.None, 0)
let vnode =
EmbeddedVNodeBuilder
.AsSingleNode()
.RunInMemory()
.WithExternalTcpOn(noIp)
.WithInternalTcpOn(noIp)
.WithExternalHttpOn(noIp)
.WithInternalHttpOn(noIp)
.Build()
vnode.Start()
let connection = EmbeddedEventStoreConnection.Create(vnode)
{VNode = vnode; Connection = connection;}
let stop testEs =
testEs.Connection.Close()
testEs.VNode.Stop()
``
A global event store for testing, MSTest version
namespace TestingNamespace
open Microsoft.VisualStudio.TestTools.UnitTesting
[]
type GlobalTestEventStore () =
[<DefaultValue>]
static val mutable private _testEs : EmbeddedEventStore
[<DefaultValue>]
static val mutable private _closedEs : EmbeddedEventStore
static member Connection with get () = GlobalTestEventStore._testEs.Connection
static member ClosedConnection with get () = GlobalTestEventStore._closedEs.Connection
[<AssemblyInitialize>]
static member StartTestEventStore(context:TestContext) =
GlobalTestEventStore._testEs <- TestEventStore.get ()
GlobalTestEventStore._closedEs <- TestEventStore.get ()
TestEventStore.stop GlobalTestEventStore._closedEs
[<AssemblyCleanup>]
static member StopTestEventStore() =
TestEventStore.stop GlobalTestEventStore._testEs
``
ClosedConnection is for testing error cases where the EventStore is not available.
One minor thing that would clear up a bunch of warnings on my builds is a way to synchronously wait for the VNode to shut down. ClusterVNode.Stop() only queues a shutdown, doesn’t wait for it. Therefore various event callbacks after cleanup is done cause AppDomainUnloaded exceptions when my builds run tests. Not a big deal, though.