I've read a lot of question about how to mock RavenDb. There is a common answer : "Don't"
This puts me into a strange situation. One of my strongest reasons for mocking interfaces is to test how my code reacts to errors.
It can be very complicated to inject errors if you are unable to mock the object that can cause errors.
Am I thinking in the wrong direction here????
//lg
Why should you mock in order to simulate an error? Create a in memory database (using the EmbaddedDocumentStore), and just do the error, no need to simulate it.
I don't know if you are aware but RavenDB has excellent helpers for unit tests.
The only thing you have to do is to implement the RavenTestBase as shown below:
[TestFixture]
public class RavenDummyTests : RavenTestBase
{
private IDocumentStore _documentStore;
[SetUp]
public void Setup()
{
_documentStore = NewDocumentStore();
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
_documentStore.Dispose();
}
[Test]
public void Search_And_Where_Result_In_An_And()
{
using (var db = _documentStore.OpenSession())
{
db.Store(_oscar);
db.Store(_max);
db.Store(_tiger);
db.SaveChanges();
}
WaitForIndexing(_documentStore); // <== very helpful
using (var db = _documentStore.OpenSession())
{
var query = db.Query<Cat>().Search(cat => cat.Color, "gray").Where(cat => cat.Name == "max");
var list = query.ToList();
Assert.IsEmpty(list);
Assert.AreEqual("Color:(gray) AND (Name:max)", query.ToString());
}
}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With