public void Should_store_and_retrieve_basic_arango_specific_fields_from_document()
        {
            var doc = new Dictionary<string, object>()
                .ID("col/123_a:b-c")
                .Key("123_a:b-c")
                .Rev("123456789");

            Assert.IsTrue(doc.HasID());
            Assert.AreEqual("col/123_a:b-c", doc.ID());
            Assert.IsTrue(doc.HasKey());
            Assert.AreEqual("123_a:b-c", doc.Key());
            Assert.IsTrue(doc.HasRev());
            Assert.AreEqual("123456789", doc.Rev());

            Assert.Throws<ArgumentException>(() => {
                 var doc1 = new Dictionary<string, object>()
                     .ID("col/123 a");
            });

            Assert.Throws<ArgumentException>(() => {
                 var doc1 = new Dictionary<string, object>()
                     .Key("123 a");
            });

            Assert.Throws<ArgumentException>(() => {
                 var doc1 = new Dictionary<string, object>()
                     .Rev("123a");
            });
        }
        public void Should_replace_edge_with_ifMatch_and_return_412()
        {
            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("123456789")
                .Replace(createResult.Value.ID(), newDocument);

            Assert.AreEqual(412, replaceResult.StatusCode);
            Assert.IsFalse(replaceResult.Success);
            Assert.IsTrue(replaceResult.HasValue);
            Assert.AreEqual(replaceResult.Value.ID(), document.ID());
            Assert.AreEqual(replaceResult.Value.Key(), document.Key());
            Assert.AreEqual(replaceResult.Value.Rev(), document.Rev());
        }
        public void Should_update_edge_with_mergeArrays_set_to_true()
        {
            Database.ClearTestCollection(Database.TestEdgeCollectionName);
            var db = new ADatabase(Database.Alias);

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

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

            document.Merge(createResult.Value);

            var newDocument = new Dictionary<string, object>()
                .String("foo", "some other new string")
                .Document("bar", new Dictionary<string, object>().String("bar", "other string value"));

            var updateResult = db
                .Document
                .MergeObjects(true) // this is also default behavior
                .Update(createResult.Value.ID(), newDocument);

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

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

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

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

            Assert.IsTrue(getResult.Value.Has("bar.foo"));

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

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

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

            document.Merge(createResult.Value);

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

            var updateResult = db
                .Document
                .KeepNull(false)
                .Update(createResult.Value.ID(), newDocument);

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

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

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

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

            Assert.IsTrue(getResult.Value.Has("bar"));

            Assert.IsFalse(getResult.Value.Has("baz"));
        }
        public void Should_update_document_with_mergeArrays_set_to_false()
        {
            var db = new ADatabase(Database.Alias);

            var newDocument = new Dictionary<string, object>()
                .String("foo", "some string")
                .Document("bar", new Dictionary<string, object>().String("foo", "string value"));

            var createResult = db.Document
                .Create(Database.TestDocumentCollectionName, newDocument);

            newDocument.Merge(createResult.Value);

            var document = new Dictionary<string, object>()
                .String("foo", "some other new string")
                .Document("bar", new Dictionary<string, object>().String("bar", "other string value"));

            var updateResult = db.Document
                .MergeObjects(false)
                .Update(newDocument.ID(), document);

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

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

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

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

            Assert.IsFalse(getResult.Value.Has("bar.foo"));

            Assert.IsTrue(getResult.Value.Has("bar.bar"));
        }
        public void Should_create_document_with_custom_ID()
        {
            Database.ClearTestCollection(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

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

            var createResult = db.Document
                .Create(Database.TestDocumentCollectionName, document);

            Assert.AreEqual(202, createResult.StatusCode);
            Assert.IsTrue(createResult.Success);
            Assert.IsTrue(createResult.HasValue);
            Assert.AreEqual(Database.TestDocumentCollectionName + "/" + document.Key(), createResult.Value.ID());
            Assert.AreEqual(document.Key(), createResult.Value.Key());
            Assert.IsTrue(createResult.Value.IsString("_rev"));
        }