Created
April 3, 2013 10:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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