public void should_be_able_insert_typed_documents() { using (var session = new TemporarySession()) { var testObject1 = new TestDoc { Text = "hello world 1" }; var testObject2 = new TestDoc { Text = "hello world 2" }; var testObject3 = new TestDoc { Text = "hello world 3" }; session.Bulk.Update(new[] { testObject1, testObject2, testObject3 }); var result = session.Bulk.All(new ViewQuery() { IncludeDocs = true }); result.Rows.Length.ShouldBe(3); result.Documents.First().ToObject <TestDoc>().Text.ShouldBe("hello world 1"); } }
public void should_be_able_to_get_delete_all_docs_using_helper() { using (var session = new TemporarySession()) { var testObject1 = new TestDoc { Text = "hello world" }; var testObject2 = new TestDoc { Text = "hello world" }; var testObject3 = new TestDoc { Text = "hello world" }; var info1 = session.Save(testObject1); var info2 = session.Save(testObject2); var info3 = session.Save(testObject3); var result = session.Bulk.All(new ViewQuery() { IncludeDocs = true }); result.Rows.Length.ShouldBe(3); session.Bulk.Delete(result.Documents.ToArray()); result = session.Bulk.All(new ViewQuery() { IncludeDocs = true }); result.Rows.Length.ShouldBe(0); } }
public void should_use_configuration_database_when_specified() { using (var session = new TemporarySession()) { using (var anotherSession = new TemporarySession()) { Documents.Configure <TestDoc>(database: anotherSession.DatabaseName); var testObject = new TestDoc { Text = "hello world" }; var info = session.Save(testObject, "test"); var fromDb = session.Get <JObject>(info.Id); fromDb.ShouldBe(null); session.DatabaseName.ShouldBe(session.DefaultDatabase); var fromDb2 = session.Get <TestDoc>(info.Id); fromDb2.ShouldNotBe(null); var info2 = session.Documents.Save(testObject); info2.Id.ShouldBe(info.Id); session.DatabaseName.ShouldBe(session.DefaultDatabase); } } }
public void db_put_get_delete() { using (var session = new TemporarySession()) { var testObject = new TestDoc { Text = "hello world" }; var result = session.Get <TestDoc>("test"); Assert.That(result, Is.Null); var info = session.Save(testObject, "test"); testObject.Text = "hello world chagned"; session.Save(testObject); testObject.Text = "hello world changed"; info = session.Save(testObject); testObject.Text = "hello world changed 2"; session.Save(testObject, info); session.Delete(testObject); result = session.Get <TestDoc>("test"); Assert.That(result, Is.Null); } }
public void create_design_doc_with_a_update_handler_create_new_doc() { using (var session = new TemporarySession()) { var designDoc = new SimpleDesignDocument(); designDoc.Updates["test"] = @" function(doc,req) { if (!doc) { if (req.id) return [{ _id : req.id}, Text= toJSON('New World')] return [null, toJSON('Empty World')]; } doc.world = 'hello'; doc.edited_by = req.userCtx; return [doc, toJSON('Existing World')]; }".Trim(); session.Design("test").Put(designDoc); var testObject = new TestDoc { Text = "hello world" }; var results = session.Design("test").Update <TestDoc, string>("test", testObject); Assert.That(results, Is.EqualTo("New World")); results = session.Design("test").Update <TestDoc, string>("test", testObject); Assert.That(results, Is.EqualTo("Existing World")); var orginalInfo = session.Documents.GetInfo(testObject); results = session.Design("test").Update <TestDoc, string>("test", new TestDoc() { Text = "brand new" }, orginalInfo.Id); Assert.That(results, Is.EqualTo("Existing World")); } }
public void create_design_doc_with_a_view_and_query() { using (var session = new TemporarySession()) { var testObject = new TestDoc { Text = "hello world" }; var info1 = session.Documents.Save(testObject, "test1"); var info2 = session.Documents.Save(testObject, "test2"); var designDoc = new SimpleDesignDocument(); designDoc.Views["test"] = new SimpleDesignDocument.View() { Map = "function(doc){ emit(doc._id); }" }; session.Design("test").Put(designDoc); var results = session.Design("test").View <object, TestDoc>("test"); Assert.That(results.Rows.Length, Is.EqualTo(2)); results = session.Design("test").ViewDocs <TestDoc>("test"); Assert.That(results.Documents.Length, Is.GreaterThan(0)); Assert.That(results.Documents[0], Is.Not.Null); results = session.Design("test").ViewDocs <TestDoc>("test", track: true); var doc1 = results.Documents[0]; doc1.Text = "arg I got changed from a view result"; Assert.That(session.Documents.GetInfo(doc1), Is.Not.Null); session.Documents.Save(doc1); } }
public void should_be_able_to_get_all_docs() { using (var session = new TemporarySession()) { var testObject1 = new TestDoc { Text = "hello world" }; var testObject2 = new TestDoc { Text = "hello world" }; var testObject3 = new TestDoc { Text = "hello world" }; var info1 = session.Save(testObject1); var info2 = session.Save(testObject2); var info3 = session.Save(testObject3); var result = session.Bulk.All(); result.Rows.Length.ShouldBe(3); } }
public void should_be_able_update_typed_documents() { using (var session = new TemporarySession()) { var testObject1 = new TestDoc { Text = "hello world 1" }; var testObject2 = new TestDoc { Text = "hello world 2" }; var testObject3 = new TestDoc { Text = "hello world 3" }; session.Documents.Save(testObject1); session.Documents.Save(testObject2); session.Documents.Save(testObject3); testObject1.Text = "updated 1"; testObject2.Text = "updated 2"; testObject3.Text = "updated 3"; session.Bulk.Update(new[] { testObject1, testObject2, testObject3 }); var result = session.Bulk.All(new ViewQuery() { IncludeDocs = true }); result.Rows.Length.ShouldBe(3); result.Documents.Skip(0).First()["type"].ShouldBe("TestDoc"); result.Documents.Skip(0).First().ToObject <TestDoc>().Text.ShouldBe("updated 1"); result.Documents.Skip(1).First().ToObject <TestDoc>().Text.ShouldBe("updated 2"); result.Documents.Skip(2).First().ToObject <TestDoc>().Text.ShouldBe("updated 3"); } }
public void should_allow_keys_to_contain_slashes() { using (var session = new TemporarySession()) { var testObject1 = new TestDoc { _id = "test/1", Text = "hello world" }; var result1 = session.Get <TestDoc>("test/1"); Assert.That(result1, Is.Null); session.Save(testObject1, testObject1._id); var result2 = session.Get <TestDoc>("test/1"); Assert.That(result2, Is.Not.Null); Assert.That(result2._id == "Test/1"); var testObject2 = new TestDoc { _id = "test/2", Text = "hello world" }; var result3 = session.Get <TestDoc>("test/2"); Assert.That(result3, Is.Null); session.Save(testObject2, testObject2._id); var result4 = session.Get <TestDoc>("test/2"); Assert.That(result4, Is.Not.Null); Assert.That(result4._id == "Test/2"); } }