How are people testing? In memory testing with MiniNode?

Hi,

I started to look into doing some testing this morning using the MiniNode class in EventStore.Core.Tests.Helpers

Is this what people are using for testing the EventStore? I just want to write some simple tests to verify that what I can save and reload some aggregates and everything works as expected.

This is the code I have (in a base class for ES testing):

        protected IEventStoreConnection InMemoryEventStore;
        const string InMemoryDbPath = @"C:\EventStore\InMemoryDb";
        private MiniNode _inMemoryNode;

        [TestFixtureSetUp]
        public void FixtureSetup()
        {
            _inMemoryNode = new MiniNode(InMemoryDbPath);
            _inMemoryNode.Start();
            InMemoryEventStore = EventStoreConnection.Create(_inMemoryNode.TcpEndPoint);
            InMemoryEventStore.Connect();
        }

        [TestFixtureTearDown]
        public void FixtureTearDown()
        {
            InMemoryEventStore.Close();
            _inMemoryNode.Shutdown();
        }



If I reference the  EventStore.Core and EventStore.Core.Tests in isolation, I start getting errors such as:

SetUp : System.TypeInitializationException : The type initializer for ‘EventStore.Core.Tests.Helpers.MiniNode’ threw an exception.

----> System.TypeInitializationException : The type initializer for ‘EventStore.Common.Log.LogManager’ threw an exception.

----> System.IO.FileNotFoundException : Could not load file or assembly ‘NLog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c’ or one of its dependencies. The system cannot find the file specified.

If I reference EventStore.Core and EventStore.Core.Tests in the directory in which I am running EventStore, everything works as expected. So it looks like i need the full directory for testing.

Is this how other people are testing?

cheers

Tom

(in reality I am really integration testing repository code, where I serialize aggregates, reload them and read/write streams etc…)

I would avoid doing this - as of the v3 RCs we support entirely in-memory operation using the “–mem-db” flag - for meaningful integration tests your best bet is to use Process.Start to bring up an in-memory server and then use it with the actual client API
in your tests.

Cheers,

James

Cheers James,

I’ve changed the code to:

protected IEventStoreConnection InMemoryEventStore;

#if Build
        private const string EventStorePath = @"TODO";
#else
        private const string EventStorePath = @"C:\EventStore-V3-Debug\EventStore.SingleNode.exe";
#endif
        [TestFixtureSetUp]
        public void FixtureSetup()
        {
            Process.Start(EventStorePath, "--mem-db");
            var ipAddress = IPAddress.Parse("127.0.0.1");
            var ipEndPoint = new IPEndPoint(ipAddress, 1113);

            InMemoryEventStore = EventStoreConnection.Create(ipEndPoint);
            InMemoryEventStore.Connect();
        }

        [TestFixtureTearDown]
        public void FixtureTearDown()
        {
            InMemoryEventStore.Close();
        }
    }

which looks to work as expected so cheers!!
tom

That seems reasonable - at that point you can easily test projections as well, which might be useful. You can just post and control them using ProjectionsManager.

Cheers,

James

Yep. That's the next thing on my list! I only have a single projection at the moment but want to get the testing infrastructure in place before adding any more.

tom

Hi,

Just for completeness I thought I’d post my updated code. This is the code I now have:

using NUnit.Framework;

[SetUpFixture]

public class AssemblySetup

{

#if Build

private const string EventStorePath = @“C:\EventStore-NET\EventStore.SingleNode.exe”;

#else

private const string EventStorePath = @“C:\EventStore-V3-Debug\EventStore.SingleNode.exe”;

#endif

private Process _process;

[SetUp]

public void RunBeforeAnyTests()

{

_process = Process.Start(EventStorePath, “–mem-db --tcp-port=1120 --http-port=2120”);

}

[TearDown]

public void RunAfterAnyTests()

{

_process.Kill();

}

}

I am launching the EventStore once for all tests in my assembly, then killing the process when they complete. I am then connecting to the EventStore as before in the [TestFixtureSetUp] and closing the connection in the [TestFixtureTearDown]

This is working locally and on my build server.

cheers

Tom