Created
February 28, 2012 15:48
-
-
Save Buildstarted/1933264 to your computer and use it in GitHub Desktop.
Seems to be a bug in RavenDB
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
using System.Linq; | |
using NUnit.Framework; | |
using Raven.Client.Embedded; | |
namespace DocumentStoreTest | |
{ | |
[TestFixture] | |
public class DocumentStoreTests | |
{ | |
//This test attempts to lookup an existing item when none exist in the | |
//database. It returns null which that variable is assigned a new value | |
//storing that new value, however, fails. | |
[Test] | |
public void DocumentStoreFailsWhenGrabbingNonExistingItemAndStoringNewOne() | |
{ | |
using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true, Identifier = "docstore1" }.Initialize()) | |
{ | |
using (var session = documentStore.OpenSession()) | |
{ | |
TestModel testModelItem = session.Query<TestModel>().SingleOrDefault(t => t.Id == 1) ?? | |
new TestModel { Id = 1 }; | |
Assert.IsNotNull(testModelItem); | |
session.Store(testModelItem); | |
session.SaveChanges(); | |
} | |
using (var session = documentStore.OpenSession()) | |
{ | |
var list = session.Query<TestModel>().ToList(); | |
Assert.AreEqual(1, list.Count()); | |
} | |
} | |
} | |
//This test adds a new item to the database and then performs a lookup on a | |
//non existing item. Sets the variable to a new value and stores it. | |
//works like expected | |
[Test] | |
public void DocumentStoreWorksWhenAddingItemAndThenGrabbingNonExistingItemAndStoringNewOne() | |
{ | |
using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true, Identifier = "docstore2" }.Initialize()) | |
{ | |
using (var session = documentStore.OpenSession()) | |
{ | |
session.Store(new TestModel { Id = 1 }); | |
session.SaveChanges(); | |
TestModel testModelItem = session.Query<TestModel>().SingleOrDefault(t => t.Id == 2) ?? | |
new TestModel { Id = 2 }; | |
Assert.IsNotNull(testModelItem); | |
session.Store(testModelItem); | |
session.SaveChanges(); | |
var list = session.Query<TestModel>().ToList(); | |
Assert.AreEqual(2, list.Count()); | |
} | |
} | |
} | |
//This test adds a new item to the database and then deletes it and then | |
//performs a lookup on a non existing item. Sets the variable to a new | |
//value and stores it, however, fails. | |
[Test] | |
public void DocumentStoreWorksWhenAddingItemThenDeletingItAndThenGrabbingNonExistingItemAndStoringNewOne() | |
{ | |
using (var documentStore = new EmbeddableDocumentStore { RunInMemory = true, Identifier = "docstore3" }.Initialize()) | |
{ | |
using (var session = documentStore.OpenSession()) | |
{ | |
var deletedModel = new TestModel {Id = 1}; | |
session.Store(deletedModel); | |
session.SaveChanges(); | |
session.Delete(deletedModel); | |
session.SaveChanges(); | |
TestModel testModelItem = session.Query<TestModel>().SingleOrDefault(t => t.Id == 2) ?? | |
new TestModel { Id = 2 }; | |
Assert.IsNotNull(testModelItem); | |
session.Store(testModelItem); | |
session.SaveChanges(); | |
var list = session.Query<TestModel>().ToList(); | |
Assert.AreEqual(1, list.Count()); | |
} | |
} | |
} | |
} | |
public class TestModel | |
{ | |
public int Id { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment