public void Should_update_edge_with_ifMatch()
        {
            Database.ClearTestCollection(Database.TestEdgeCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary<string, object>()
                .String("foo", "some string")
                .Int("bar", 12345);

            var createResult = db.Edge
                .Create(Database.TestEdgeCollectionName, _documents[0].String("_id"), _documents[1].String("_id"), document);

            var newDocument = new Dictionary<string, object>()
                .String("foo", "some other new string")
                .Int("bar", 54321)
                .Int("baz", 12345);

            var updateResult = db.Edge
                .IfMatch(createResult.Value.String("_rev"))
                .Update(createResult.Value.String("_id"), newDocument);

            Assert.AreEqual(202, updateResult.StatusCode);
            Assert.IsTrue(updateResult.Success);
            Assert.IsTrue(updateResult.HasValue);
            Assert.AreEqual(updateResult.Value.String("_id"), createResult.Value.String("_id"));
            Assert.AreEqual(updateResult.Value.String("_key"), createResult.Value.String("_key"));
            Assert.AreNotEqual(updateResult.Value.String("_rev"), createResult.Value.String("_rev"));

            var getResult = db.Edge
                .Get(updateResult.Value.String("_id"));

            Assert.AreEqual(getResult.Value.String("_id"), updateResult.Value.String("_id"));
            Assert.AreEqual(getResult.Value.String("_key"), updateResult.Value.String("_key"));
            Assert.AreEqual(getResult.Value.String("_rev"), updateResult.Value.String("_rev"));

            Assert.AreNotEqual(getResult.Value.String("foo"), document.String("foo"));
            Assert.AreEqual(getResult.Value.String("foo"), newDocument.String("foo"));

            Assert.AreNotEqual(getResult.Value.Int("bar"), document.Int("bar"));
            Assert.AreEqual(getResult.Value.Int("bar"), newDocument.Int("bar"));

            // by default JSON integers are deserialized to long type
            Assert.IsTrue(getResult.Value.IsLong("baz"));
        }
        public void Should_replace_edge_with_waitForSync()
        {
            Database.ClearTestCollection(Database.TestEdgeCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary<string, object>()
                .String("foo", "some string")
                .Int("bar", 12345);

            var createResult = db.Edge
                .Create(Database.TestEdgeCollectionName, _documents[0].String("_id"), _documents[1].String("_id"), document);

            var newDocument = new Dictionary<string, object>()
                .String("foo", "some other new string")
                .Int("baz", 54321);

            var replaceResult = db.Edge
                .WaitForSync(true)
                .Replace(createResult.Value.String("_id"), newDocument);

            Assert.AreEqual(201, replaceResult.StatusCode);
            Assert.IsTrue(replaceResult.Success);
            Assert.IsTrue(replaceResult.HasValue);
            Assert.AreEqual(replaceResult.Value.String("_id"), createResult.Value.String("_id"));
            Assert.AreEqual(replaceResult.Value.String("_key"), createResult.Value.String("_key"));
            Assert.AreNotEqual(replaceResult.Value.String("_rev"), createResult.Value.String("_rev"));

            var getResult = db.Edge
                .Get(replaceResult.Value.String("_id"));

            Assert.AreEqual(getResult.Value.String("_id"), replaceResult.Value.String("_id"));
            Assert.AreEqual(getResult.Value.String("_key"), replaceResult.Value.String("_key"));
            Assert.AreEqual(getResult.Value.String("_rev"), replaceResult.Value.String("_rev"));

            Assert.AreNotEqual(getResult.Value.String("foo"), document.String("foo"));
            Assert.AreEqual(getResult.Value.String("foo"), newDocument.String("foo"));

            Assert.AreEqual(getResult.Value.Int("baz"), newDocument.Int("baz"));

            Assert.IsFalse(getResult.Value.Has("bar"));
        }
        public void Should_update_edge_with_generic_object()
        {
            Database.ClearTestCollection(Database.TestEdgeCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary<string, object>()
                .String("foo", "some string")
                .Int("bar", 12345);

            var createResult = db.Edge
                .Create(Database.TestEdgeCollectionName, _documents[0].String("_id"), _documents[1].String("_id"), document);

            var dummy = new Dummy();
            dummy.Foo = "some other new string";
            dummy.Bar = 54321;
            dummy.Baz = 12345;

            var updateResult = db.Edge
                .Update(createResult.Value.String("_id"), dummy);

            Assert.AreEqual(202, updateResult.StatusCode);
            Assert.IsTrue(updateResult.Success);
            Assert.IsTrue(updateResult.HasValue);
            Assert.AreEqual(updateResult.Value.String("_id"), createResult.Value.String("_id"));
            Assert.AreEqual(updateResult.Value.String("_key"), createResult.Value.String("_key"));
            Assert.AreNotEqual(updateResult.Value.String("_rev"), createResult.Value.String("_rev"));

            var getResult = db.Edge
                .Get(updateResult.Value.String("_id"));

            Assert.AreEqual(getResult.Value.String("_id"), updateResult.Value.String("_id"));
            Assert.AreEqual(getResult.Value.String("_key"), updateResult.Value.String("_key"));
            Assert.AreEqual(getResult.Value.String("_rev"), updateResult.Value.String("_rev"));

            Assert.AreNotEqual(getResult.Value.String("foo"), document.String("foo"));
            Assert.AreEqual(getResult.Value.String("foo"), dummy.Foo);

            Assert.AreNotEqual(getResult.Value.Int("bar"), document.Int("bar"));
            Assert.AreEqual(getResult.Value.Int("bar"), dummy.Bar);
            Assert.AreEqual(getResult.Value.Int("baz"), dummy.Baz);
        }
        public void Should_get_edge_as_generic_object()
        {
            Database.ClearTestCollection(Database.TestEdgeCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary<string, object>()
                .String("foo", "foo string value")
                .Int("bar", 12345);

            var createResult = db.Edge
                .Create(Database.TestEdgeCollectionName, _documents[0].String("_id"), _documents[1].String("_id"), document);

            var getResult = db.Edge
                .Get<Dummy>(createResult.Value.String("_id"));

            Assert.AreEqual(200, getResult.StatusCode);
            Assert.IsTrue(getResult.Success);
            Assert.IsTrue(getResult.HasValue);
            Assert.AreEqual(document.String("foo"), getResult.Value.Foo);
            Assert.AreEqual(document.Int("bar"), getResult.Value.Bar);
            Assert.AreEqual(0, getResult.Value.Baz);
        }
        public void Should_replace_edge_with_ifMatch_and_lastUpdatePolicy()
        {
            Database.ClearTestCollection(Database.TestEdgeCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary<string, object>()
                .String("foo", "some string")
                .Int("bar", 12345);

            var createResult = db.Edge
                .Create(Database.TestEdgeCollectionName, _documents[0].String("_id"), _documents[1].String("_id"), document);

            document.Merge(createResult.Value);

            var newDocument = new Dictionary<string, object>()
                .String("foo", "some other new string")
                .Int("baz", 54321);

            var replaceResult = db.Edge
                .IfMatch("123456789", AUpdatePolicy.Last)
                .Replace(createResult.Value.String("_id"), newDocument);

            Assert.AreEqual(202, replaceResult.StatusCode);
            Assert.IsTrue(replaceResult.Success);
            Assert.IsTrue(replaceResult.HasValue);
            Assert.AreEqual(replaceResult.Value.String("_id"), document.String("_id"));
            Assert.AreEqual(replaceResult.Value.String("_key"), document.String("_key"));
            Assert.AreNotEqual(replaceResult.Value.String("_rev"), document.String("_rev"));

            var getResult = db.Document
                .Get(replaceResult.Value.String("_id"));

            Assert.AreEqual(getResult.Value.String("_id"), replaceResult.Value.String("_id"));
            Assert.AreEqual(getResult.Value.String("_key"), replaceResult.Value.String("_key"));
            Assert.AreEqual(getResult.Value.String("_rev"), replaceResult.Value.String("_rev"));

            Assert.AreNotEqual(getResult.Value.String("foo"), document.String("foo"));
            Assert.AreEqual(getResult.Value.String("foo"), newDocument.String("foo"));

            Assert.AreEqual(getResult.Value.Int("baz"), newDocument.Int("baz"));

            Assert.IsFalse(getResult.Value.Has("bar"));
        }
        public void Should_create_edge()
        {
            Database.ClearTestCollection(Database.TestEdgeCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary<string, object>()
                .String("foo", "foo string value")
                .Int("bar", 12345);

            var createResult = db.Edge
                .Create(Database.TestEdgeCollectionName, _documents[0].String("_id"), _documents[1].String("_id"), document);

            Assert.AreEqual(202, createResult.StatusCode);
            Assert.IsTrue(createResult.Success);
            Assert.IsTrue(createResult.HasValue);
            Assert.IsTrue(createResult.Value.IsString("_id"));
            Assert.IsTrue(createResult.Value.IsString("_key"));
            Assert.IsTrue(createResult.Value.IsString("_rev"));

            var getResult = db.Edge
                .Get(createResult.Value.String("_id"));

            Assert.AreEqual(200, getResult.StatusCode);
            Assert.IsTrue(getResult.Success);
            Assert.IsTrue(getResult.HasValue);
            Assert.AreEqual(getResult.Value.String("_id"), createResult.Value.String("_id"));
            Assert.AreEqual(getResult.Value.String("_key"), createResult.Value.String("_key"));
            Assert.AreEqual(getResult.Value.String("_rev"), createResult.Value.String("_rev"));
            Assert.IsTrue(getResult.Value.IsString("_from"));
            Assert.IsTrue(getResult.Value.IsString("_to"));
            Assert.AreEqual(getResult.Value.String("foo"), document.String("foo"));
            Assert.AreEqual(getResult.Value.Int("bar"), document.Int("bar"));
        }
        public void Should_update_document_with_waitForSync()
        {
            var documents = Database.ClearCollectionAndFetchTestDocumentData(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary<string, object>()
                .String("foo", "some other new string")
                .Int("bar", 54321)
                .Int("baz", 12345);

            var updateResult = db.Document
                .WaitForSync(true)
                .Update(documents[0].String("_id"), document);

            Assert.AreEqual(201, updateResult.StatusCode);
            Assert.IsTrue(updateResult.Success);
            Assert.IsTrue(updateResult.HasValue);
            Assert.AreEqual(updateResult.Value.String("_id"), documents[0].String("_id"));
            Assert.AreEqual(updateResult.Value.String("_key"), documents[0].String("_key"));
            Assert.AreNotEqual(updateResult.Value.String("_rev"), documents[0].String("_rev"));

            var getResult = db.Document
                .Get(updateResult.Value.String("_id"));

            Assert.AreEqual(getResult.Value.String("_id"), updateResult.Value.String("_id"));
            Assert.AreEqual(getResult.Value.String("_key"), updateResult.Value.String("_key"));
            Assert.AreEqual(getResult.Value.String("_rev"), updateResult.Value.String("_rev"));

            Assert.AreNotEqual(getResult.Value.String("foo"), documents[0].String("foo"));
            Assert.AreEqual(getResult.Value.String("foo"), document.String("foo"));

            Assert.AreNotEqual(getResult.Value.Int("bar"), documents[0].Int("bar"));
            Assert.AreEqual(getResult.Value.Int("bar"), document.Int("bar"));
            Assert.AreEqual(getResult.Value.Int("baz"), document.Int("baz"));
        }
        public void Should_replace_document_with_ifMatch()
        {
            var documents = Database.ClearCollectionAndFetchTestDocumentData(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary<string, object>()
                .String("foo", "some other new string")
                .Int("baz", 54321);

            var replaceResult = db.Document
                .IfMatch(documents[0].String("_rev"))
                .Replace(documents[0].String("_id"), document);

            Assert.AreEqual(202, replaceResult.StatusCode);
            Assert.IsTrue(replaceResult.Success);
            Assert.IsTrue(replaceResult.HasValue);
            Assert.AreEqual(replaceResult.Value.String("_id"), documents[0].String("_id"));
            Assert.AreEqual(replaceResult.Value.String("_key"), documents[0].String("_key"));
            Assert.AreNotEqual(replaceResult.Value.String("_rev"), documents[0].String("_rev"));

            var getResult = db.Document
                .Get(replaceResult.Value.String("_id"));

            Assert.AreEqual(getResult.Value.String("_id"), replaceResult.Value.String("_id"));
            Assert.AreEqual(getResult.Value.String("_key"), replaceResult.Value.String("_key"));
            Assert.AreEqual(getResult.Value.String("_rev"), replaceResult.Value.String("_rev"));

            Assert.AreNotEqual(getResult.Value.String("foo"), documents[0].String("foo"));
            Assert.AreEqual(getResult.Value.String("foo"), document.String("foo"));

            Assert.AreEqual(getResult.Value.Int("baz"), document.Int("baz"));

            Assert.IsFalse(getResult.Value.Has("bar"));
        }
        public void Should_replace_edge_with_ifMatch()
        {
            Database.ClearTestCollection(Database.TestEdgeCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary<string, object>()
                .String("foo", "some string")
                .Int("bar", 12345);

            var createResult = db
                .Document
                .CreateEdge(Database.TestEdgeCollectionName, _documents[0].ID(), _documents[1].ID(), document);

            document.Merge(createResult.Value);

            var newDocument = new Dictionary<string, object>()
                .From(_documents[0].ID())
                .To(_documents[1].ID())
                .String("foo", "some other new string")
                .Int("baz", 54321);

            var replaceResult = db
                .Document
                .IfMatch(document.Rev())
                .Replace(createResult.Value.ID(), newDocument);

            Assert.AreEqual(202, replaceResult.StatusCode);
            Assert.IsTrue(replaceResult.Success);
            Assert.IsTrue(replaceResult.HasValue);
            Assert.AreEqual(replaceResult.Value.ID(), document.ID());
            Assert.AreEqual(replaceResult.Value.Key(), document.Key());
            Assert.AreNotEqual(replaceResult.Value.Rev(), document.Rev());

            var getResult = db
                .Document
                .Get(replaceResult.Value.ID());

            Assert.AreEqual(getResult.Value.ID(), replaceResult.Value.ID());
            Assert.AreEqual(getResult.Value.Key(), replaceResult.Value.Key());
            Assert.AreEqual(getResult.Value.Rev(), replaceResult.Value.Rev());

            Assert.AreNotEqual(getResult.Value.String("foo"), document.String("foo"));
            Assert.AreEqual(getResult.Value.String("foo"), newDocument.String("foo"));

            Assert.AreEqual(getResult.Value.Int("baz"), newDocument.Int("baz"));

            Assert.IsFalse(getResult.Value.Has("bar"));
        }
        public void Should_create_edge_with_returnNew_parameter()
        {
            Database.ClearTestCollection(Database.TestEdgeCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary<string, object>()
                .From(_documents[0].ID())
                .To(_documents[1].ID())
                .String("foo", "foo string value")
                .Int("bar", 12345);

            var createResult = db
                .Document
                .ReturnNew()
                .CreateEdge(Database.TestEdgeCollectionName, document);

            Assert.AreEqual(202, createResult.StatusCode);
            Assert.IsTrue(createResult.Success);
            Assert.IsTrue(createResult.HasValue);
            Assert.IsTrue(createResult.Value.IsString("_id"));
            Assert.IsTrue(createResult.Value.IsString("_key"));
            Assert.IsTrue(createResult.Value.IsString("_rev"));
            Assert.IsTrue(createResult.Value.Has("new"));
            Assert.AreEqual(createResult.Value.ID(), createResult.Value.String("new._id"));
            Assert.AreEqual(createResult.Value.Key(), createResult.Value.String("new._key"));
            Assert.AreEqual(createResult.Value.Rev(), createResult.Value.String("new._rev"));
            Assert.AreEqual(document.String("_from"), createResult.Value.String("new._from"));
            Assert.AreEqual(document.String("_to"), createResult.Value.String("new._to"));
            Assert.AreEqual(document.String("foo"), createResult.Value.String("new.foo"));
            Assert.AreEqual(document.Int("bar"), createResult.Value.Int("new.bar"));
        }