I currently try to setup some integration testing in order to verify that my RavenDB queries return what i expect.
I followed the documentation and have a single test up and running.
The problem starts when i add an additional test method to the same class. I get the following exception:
System.InvalidOperationException : Cannot configure server after it was started. Please call 'ConfigureServer' method before any 'GetDocumentStore' is called.
So basically it tells me, the server is already running. But this confuses me. Since XUnit creates an new instance of the test class for every discovered test method in that class. Additionally it calls Dispose() on any instance, that implements IDisposable. Which is indirectly implemented by the base class RavenTestDriver.
So what i think is happening:
- XUnit creates a new instance of my test class
- XUnit calls my test method
- My test method calls
ConfigureServer, the RavenDB Embedded Server is started - My test method finishes
- XUnit calls
Disposeon my instance of the test class, the RavenDB Embedded Server is stopped - Rince and repeat for the next test method
But i looks like, my assumption on #5 is wrong. The RavenDB Embedded Server seems to be never stopped. Additionally i cannot find a way to manually stop it. I was trying to manually dispoose it with EmbeddedServer.Instance.Dispose(). But that doesn't change anything. (The .Instance gives a clue, that the EmbeddedServer is probably a singleton, which may be part of the problem here).
I also tried to move the ConfigureServer call into the constructor of the test class. Since XUnit class the constructore for every test method (just like the setup-method from JUnit). But then i get the same result.
But the interesting part is: Calling ConfigureServer in two different classes just works fine.
I have created a small reproducer repository.
So has anybody an idea on how to setup RavenDB in a Unit/Integration-Test environment where you want to run multiple tests against it?