Permalink
Browse files

Added failing test for get/load scenarios

  • Loading branch information...
1 parent 238a226 commit bd60b25f4c135d0e017a76dc17178acba2a6177e @phillip-haydon committed Oct 9, 2012
Showing with 146 additions and 19 deletions.
  1. +146 −19 src/Raven.DynamicSession.Tests/QueryGetFixture.cs
@@ -1,38 +1,165 @@
-using NUnit.Framework;
+using System;
+using System.Linq;
+using System.Threading;
+using NUnit.Framework;
+using Raven.Client.Linq;
namespace Raven.DynamicSession.Tests
{
[TestFixture]
- public class QueryGetFixture : EmbeddedRavenDBFixture
+ public class QueryGetFixture
{
- [Test]
- public void Can_query_post_after_dynamic_insert()
+ public class DynamicQueries : EmbeddedRavenDBFixture
{
- //Arrange
- var store = GetStore();
- Configure(store, typeof(Post), "Posts");
+ public class TestObject
+ {
+ public Guid Id { get; set; }
+ public string Name { get; set; }
+ }
- using (dynamic session = store.OpenDynamicSession())
+ [Test]
+ public void Can_call_load_to_query_doc_stored_by_typed_insert()
{
- session.posts.insert(new
+ //Arrange
+ var store = GetStore();
+
+ using (var session = store.OpenSession())
+ {
+ session.Store(new Post
+ {
+ Name = "Test Document 1"
+ });
+ session.SaveChanges();
+ }
+
+ dynamic result;
+
+ Thread.Sleep(1000);
+
+ using (dynamic session = store.OpenDynamicSession())
{
- Name = "Hello World"
- }, 123);
+ //Act
+ result = session.posts.load("posts/1");
+ }
- session.SaveChanges();
+ //Assert
+ Assert.That(result, Is.Not.Null);
+ Assert.That(result.Name, Is.EqualTo("Test Document 1"));
}
- //Act
- Post result;
+ [Test]
+ public void Can_call_get_to_query_doc_stored_by_typed_insert()
+ {
+ //Arrange
+ var store = GetStore();
- using (var session = store.OpenSession())
+ using (var session = store.OpenSession())
+ {
+ session.Store(new Post
+ {
+ Name = "Test Document 2"
+ });
+ session.SaveChanges();
+ }
+
+ using (dynamic session = store.OpenDynamicSession())
+ {
+ //Act
+ dynamic result = session.posts.get("posts/1");
+
+ //Assert
+ Assert.That(result, Is.Not.Null);
+ Assert.That(result.Name, Is.EqualTo("Test Document 2"));
+ }
+ }
+
+ [Test]
+ public void Can_call_load_to_query_doc_stored_by_dynamic_insert()
{
- result = session.Load<Post>("posts/123");
+ //Arrange
+ var store = GetStore();
+ var id = Guid.NewGuid();
+
+ using (dynamic session = store.OpenDynamicSession())
+ {
+ session.posts.insert(new
+ {
+ Name = "Test Document 3"
+ }, id);
+ session.SaveChanges();
+ }
+
+ using (dynamic session = store.OpenDynamicSession())
+ {
+ //Act
+ dynamic result = session.posts.load(id);
+
+ //Assert
+ Assert.That(result, Is.Not.Null);
+ Assert.That(result.Name, Is.EqualTo("Test Document 3"));
+ }
}
- //Assert
- Assert.That(result, Is.Not.Null);
- Assert.That(result.Name, Is.EqualTo("Hello World"));
+ [Test]
+ public void Can_call_get_to_query_doc_stored_by_dynamic_insert()
+ {
+ //Arrange
+ var store = GetStore();
+ var id = Guid.NewGuid();
+
+ using (dynamic session = store.OpenDynamicSession())
+ {
+ session.posts.insert(new
+ {
+ Name = "Test Document 3"
+ }, id);
+ session.SaveChanges();
+ }
+
+ using (dynamic session = store.OpenDynamicSession())
+ {
+ //Act
+ dynamic result = session.posts.get(id);
+
+ //Assert
+ Assert.That(result, Is.Not.Null);
+ Assert.That(result.Name, Is.EqualTo("Test Document 3"));
+ }
+ }
+ }
+
+ public class TypedQueries : EmbeddedRavenDBFixture
+ {
+ [Test]
+ public void Can_query_post_after_dynamic_insert()
+ {
+ //Arrange
+ var store = GetStore();
+ Configure(store, typeof(Post), "Posts");
+
+ using (dynamic session = store.OpenDynamicSession())
+ {
+ session.posts.insert(new
+ {
+ Name = "Hello World"
+ }, 123);
+
+ session.SaveChanges();
+ }
+
+ //Act
+ Post result;
+
+ using (var session = store.OpenSession())
+ {
+ result = session.Load<Post>("posts/123");
+ }
+
+ //Assert
+ Assert.That(result, Is.Not.Null);
+ Assert.That(result.Name, Is.EqualTo("Hello World"));
+ }
+
}
public class Post

0 comments on commit bd60b25

Please sign in to comment.