Reputation: 311
Turns out I am storing the document correctly so the beginning part of this question is not correct, probably due to my inexperience with RavenDB. However I still have the question of being able to open the RavenDB Management Studio while using an EmbeddableDocumentStore in a unit test.
I seem to be running into a problem storing documents in the EmbeddableDocumentStore during a unit test using NUnit. In order to see if I am actually storing the document I am trying to connect to the embedded database.
When trying to open the url http://computername:8080/ (for some reason raven db always uses the computer name on my pc) the browser loading bar just spins and if I stop the unit test and try the url again Chrome just gives me the message that it could not connect. Here's some code for context.
[TestFixture]
public class Test2 : IDisposable
{
private EmbeddableDocumentStore _documentStore;
[SetUp]
public void SetUp()
{
if (_documentStore != null) return;
_documentStore = new EmbeddableDocumentStore
{
DataDirectory = "Data",
RunInMemory = true,
UseEmbeddedHttpServer = true
};
_documentStore.Configuration.AnonymousUserAccessMode = AnonymousUserAccessMode.All;
_documentStore.Initialize();
}
[Test]
public void Test()
{
var document = StaticData.getdocument();
using (var session = _documentStore.OpenSession())
{
session.Store(document);
session.SaveChanges();
}
using (var session = _documentStore.OpenSession())
{
var test = session.Load<ObjectType>().Length;
//This is always 0
}
}
public void Dispose()
{
_documentStore.Dispose();
}
}
Also I have the Raven.Studio.xap file in the root of my Test project.
I am using VS2012, and .Net 4.5 if that makes a difference.
Upvotes: 6
Views: 1767
Reputation: 1462
The exact details of how to apply @Ayende Rahien's solution is missing from his answer, so I'll tell the exact steps here:
In case you are creating your EmbeddableDocumentStore with the UseEmbeddedHttpServer set to true, remove it, as the WaitForUserToContinueTheTest creates a server for you.
In the test code that you want to debug, call the WaitForUserToContinueTheTest method.
Set a breakpoint in Visual Studio after the WaitForUserToContinueTheTest method.
When running in debug mode, a browser window with the URL localhost:8080/raven/studio.html or :8080/raven/studio.html should open automatically.
To exit the while loop in the WaitForUserToContinueTheTest, use the Raven HTTP GUI and go to "Documents" -> "All documents". On the right side, right click the "Pls delete me" row, and click "Delete". Now Visual Studio should continue your test.
(By the way, I hope the RavenDB team will improve the unit testing documentation better.)
Upvotes: 0
Reputation: 22956
Here you go:
static public void WaitForUserToContinueTheTest(EmbeddableDocumentStore documentStore, bool debug = true)
{
if (debug && Debugger.IsAttached == false)
return;
documentStore.SetStudioConfigToAllowSingleDb();
documentStore.DatabaseCommands.Put("Pls Delete Me", null,
RavenJObject.FromObject(new { StackTrace = new StackTrace(true) }),
new RavenJObject());
documentStore.Configuration.AnonymousUserAccessMode = AnonymousUserAccessMode.All;
using (var server = new HttpServer(documentStore.Configuration, documentStore.DocumentDatabase))
{
server.StartListening();
Process.Start(documentStore.Configuration.ServerUrl); // start the server
do
{
Thread.Sleep(100);
} while (documentStore.DatabaseCommands.Get("Pls Delete Me") != null && (debug == false || Debugger.IsAttached));
}
}
Upvotes: 4