Skip to content

Instantly share code, notes, and snippets.

@codescribler
Created April 3, 2013 10:14
Show Gist options
  • Save codescribler/5299993 to your computer and use it in GitHub Desktop.
Save codescribler/5299993 to your computer and use it in GitHub Desktop.
In memory raven db helper code with addition of index to cover all docs to allow for a purge of the db between tests.
public class InMemoryDocumentStore : IDocumentStoreConnection
{
public InMemoryDocumentStore()
{
Store = new EmbeddableDocumentStore()
{
RunInMemory = true
};
Store.RegisterListener(new NoStaleQueries());
Store.Initialize();
new RavenIndex().AddIndexes(this);
// Required for in memory tests only!
Store.DatabaseCommands.PutIndex("AllDocumentsById", new IndexDefinition
{
Name = "AllDocumentsById",
Map =
"from doc in docs let DocId = doc[\"@metadata\"][\"@id\"] select new {DocId};"
});
}
public DocumentStore Store { get; set; }
}
public interface IDocumentStoreConnection
{
DocumentStore Store { get; set; }
}
public class NoStaleQueries : IDocumentQueryListener
{
public void BeforeQueryExecuted(IDocumentQueryCustomization queryCustomization)
{
queryCustomization.WaitForNonStaleResults();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment