Esempio n. 1
0
        public void Should_create_document_from_generic_object()
        {
            Database.ClearTestCollection(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var dummy = new Dummy();

            dummy.Foo = "foo string value";
            dummy.Bar = 12345;

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

            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.Document
                            .Get(createResult.Value.ID());

            Assert.AreEqual(getResult.Value.ID(), createResult.Value.ID());
            Assert.AreEqual(getResult.Value.Key(), createResult.Value.Key());
            Assert.AreEqual(getResult.Value.Rev(), createResult.Value.Rev());
            Assert.AreEqual(getResult.Value.String("foo"), dummy.Foo);
            Assert.AreEqual(getResult.Value.Int("bar"), dummy.Bar);
            Assert.AreEqual(0, dummy.Baz);
        }
Esempio n. 2
0
        public void Should_create_document_with_returnNew_parameter()
        {
            Database.ClearTestCollection(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

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

            var createResult = db.Document
                               .ReturnNew()
                               .Create(Database.TestDocumentCollectionName, 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("foo"), createResult.Value.String("new.foo"));
            Assert.AreEqual(document.Int("bar"), createResult.Value.Int("new.bar"));
        }
Esempio n. 3
0
        public void Should_execute_transaction_with_single_value_parameter_and_return_document_ID()
        {
            Database.ClearTestCollection(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var transactionResult = db.Transaction
                                    .WriteCollection(Database.TestDocumentCollectionName)
                                    .Param("data", "some string value")
                                    .Execute <string>(@"
                function (params) { 
                    var db = require('internal').db; 

                    return db." + Database.TestDocumentCollectionName + @".save({ foo: params.data })._id;
                }
                ");

            Assert.AreEqual(200, transactionResult.StatusCode);
            Assert.IsTrue(transactionResult.Success);
            Assert.IsTrue(transactionResult.HasValue);
            Assert.IsFalse(string.IsNullOrEmpty(transactionResult.Value));

            var docId = transactionResult.Value;

            var getResult = db.Document
                            .Get(docId);

            Assert.AreEqual(200, getResult.StatusCode);
            Assert.IsTrue(getResult.Success);
            Assert.IsTrue(getResult.HasValue);
            Assert.AreEqual(getResult.Value.ID(), docId);
        }
Esempio n. 4
0
        public void Should_execute_transaction_with_list_parameter_and_return_document_IDs()
        {
            Database.ClearTestCollection(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var transactionData = new List <TransactionEntity>
            {
                new TransactionEntity
                {
                    Foo = "string1"
                },
                new TransactionEntity
                {
                    Foo = "string2"
                },
                new TransactionEntity
                {
                    Foo = "string3"
                }
            };

            var transactionResult = db.Transaction
                                    .WriteCollection(Database.TestDocumentCollectionName)
                                    .Param("data", transactionData)
                                    .Execute <List <TransactionEntity> >(@"
                function (params) { 
                    var db = require('internal').db;

                    for (var i = 0; i < params.data.length; i++) {
                        db." + Database.TestDocumentCollectionName + @".save(params.data[i]);
                    }

                    return db._query('FOR doc IN " + Database.TestDocumentCollectionName + @" SORT TO_NUMBER(doc._key) RETURN doc').toArray();
                }
                ");

            Assert.AreEqual(200, transactionResult.StatusCode);
            Assert.IsTrue(transactionResult.Success);
            Assert.IsTrue(transactionResult.HasValue);
            Assert.AreEqual(3, transactionResult.Value.Count);

            for (int i = 0; i < transactionResult.Value.Count; i++)
            {
                Assert.AreEqual(transactionData[i].Foo, transactionResult.Value[i].Foo);
            }
        }
Esempio n. 5
0
        public void Should_create_document()
        {
            Database.ClearTestCollection(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var document = new Dictionary <string, object>()
                           .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.IsTrue(createResult.Value.IsString("_id"));
            Assert.IsTrue(createResult.Value.IsString("_key"));
            Assert.IsTrue(createResult.Value.IsString("_rev"));
        }
Esempio n. 6
0
        public void Should_execute_transaction_and_return_generic_object()
        {
            Database.ClearTestCollection(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var transactionResult = db.Transaction
                                    .WriteCollection(Database.TestDocumentCollectionName)
                                    .Execute <TransactionEntity>(@"
                function () { 
                    var db = require('internal').db; 

                    db." + Database.TestDocumentCollectionName + @".save({ });

                    return { 'Executed': true };
                }
                ");

            Assert.AreEqual(200, transactionResult.StatusCode);
            Assert.IsTrue(transactionResult.Success);
            Assert.IsTrue(transactionResult.HasValue);
            Assert.IsTrue(transactionResult.Value.Executed);
        }