コード例 #1
0
ファイル: IssueTests.cs プロジェクト: yojimbo87/ArangoDB-NET
        public void Issue_No16_SortedList()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName, ACollectionType.Document);
            var db = new ADatabase(Database.Alias);

            var entity = new IssueNo16Entity();
            entity.SortedList = new SortedList<int, bool>();
            entity.SortedList.Add(1, true);
            entity.SortedList.Add(2, false);
            entity.SortedList.Add(3, false);
            entity.SortedList.Add(4, false);

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

            Assert.IsTrue(createResult.Success);

            var getResult = db.Document.Get<IssueNo16Entity>(createResult.Value.ID());

            Assert.IsTrue(getResult.Success);
            Assert.IsTrue(getResult.HasValue);

            for (int i = 0; i < getResult.Value.SortedList.Count; i++)
            {
                Assert.AreEqual(entity.SortedList.ElementAt(i).Key, getResult.Value.SortedList.ElementAt(i).Key);
                Assert.AreEqual(entity.SortedList.ElementAt(i).Value, getResult.Value.SortedList.ElementAt(i).Value);
            }
        }
コード例 #2
0
        public void Should_execute_AQL_query_with_batchSize()
        {
            var documents = Database.ClearCollectionAndFetchTestDocumentData(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var doc3 = new Dictionary<string, object>()
                .String("foo", "foo string 3");

            db.Document
                .Create(Database.TestDocumentCollectionName, doc3);

            var doc4 = new Dictionary<string, object>()
                .String("foo", "foo string 4");

            db.Document
                .Create(Database.TestDocumentCollectionName, doc4);

            var queryResult = db.Query
                .BatchSize(1)
                .Aql(string.Format(@"
                FOR item IN {0}
                    RETURN item
                ", Database.TestDocumentCollectionName))
                .ToList();

            Assert.AreEqual(200, queryResult.StatusCode);
            Assert.IsTrue(queryResult.Success);
            Assert.IsTrue(queryResult.HasValue);
            Assert.AreEqual(queryResult.Value.Count, 4);
        }
コード例 #3
0
ファイル: IssueTests.cs プロジェクト: yojimbo87/ArangoDB-NET
        public void Issue_No15_List_save_and_retrieve()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName, ACollectionType.Document);
            var db = new ADatabase(Database.Alias);

            var entity = new IssueNo15Entity();
            entity.ListNumbers = new List<int> { 1, 2, 3 };
            entity.ArrayNumbers = new int[] { 4, 5, 6};

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

            Assert.IsTrue(createResult.Success);

            var getresult = db.Document.Get<IssueNo15Entity>(createResult.Value.ID());

            Assert.IsTrue(getresult.Success);
            Assert.IsTrue(getresult.HasValue);

            for (int i = 0; i < getresult.Value.ListNumbers.Count; i++)
            {
                Assert.AreEqual(entity.ListNumbers[i], getresult.Value.ListNumbers[i]);
            }

            for (int i = 0; i < getresult.Value.ArrayNumbers.Length; i++)
            {
                Assert.AreEqual(entity.ArrayNumbers[i], getresult.Value.ArrayNumbers[i]);
            }
        }
コード例 #4
0
        public void Should_replace_function()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);
            var db = new ADatabase(Database.Alias);

            var registerResult = db.Function.Register(
                "myfunctions::temperature::celsiustofahrenheit",
                "function (celsius) { return celsius * 1.8 + 40; }"
            );

            Assert.AreEqual(201, registerResult.StatusCode);
            Assert.IsTrue(registerResult.Success);
            Assert.IsTrue(registerResult.HasValue);
            Assert.IsTrue(registerResult.Value);

            var replaceResult = db.Function.Register(
                "myfunctions::temperature::celsiustofahrenheit",
                "function (celsius) { return celsius * 1.8 + 32; }"
            );

            Assert.AreEqual(200, replaceResult.StatusCode);
            Assert.IsTrue(replaceResult.Success);
            Assert.IsTrue(replaceResult.HasValue);
            Assert.IsTrue(replaceResult.Value);

            const int celsius = 30;
            const float fahrenheit = celsius * 1.8f + 32;

            var queryResult = db.Query
                .BindVar("celsius", celsius)
                .Aql("return myfunctions::temperature::celsiustofahrenheit(@celsius)")
                .ToList<float>();

            Assert.AreEqual(fahrenheit, queryResult.Value.First());
        }
コード例 #5
0
        public void Should_change_collection_properties()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);

            var db = new ADatabase(Database.Alias);

            var createResult = db.Collection
                .Create(Database.TestDocumentCollectionName);

            const long journalSize = 199999999;

            var operationResult = db.Collection
                .WaitForSync(true)
                .JournalSize(journalSize)
                .ChangeProperties(createResult.Value.String("name"));

            Assert.AreEqual(200, operationResult.StatusCode);
            Assert.IsTrue(operationResult.Success);
            Assert.IsTrue(operationResult.HasValue);
            Assert.AreEqual(createResult.Value.String("id"), operationResult.Value.String("id"));
            Assert.AreEqual(createResult.Value.String("name"), operationResult.Value.String("name"));
            Assert.AreEqual(createResult.Value.Bool("isSystem"), operationResult.Value.Bool("isSystem"));
            Assert.AreEqual(createResult.Value.Int("status"), operationResult.Value.Int("status"));
            Assert.AreEqual(createResult.Value.Int("type"), operationResult.Value.Int("type"));
            Assert.IsFalse(operationResult.Value.Bool("isVolatile"));
            Assert.IsTrue(operationResult.Value.Bool("doCompact"));
            Assert.AreEqual(AKeyGeneratorType.Traditional, operationResult.Value.Enum<AKeyGeneratorType>("keyOptions.type"));
            Assert.IsTrue(operationResult.Value.Bool("keyOptions.allowUserKeys"));
            Assert.IsTrue(operationResult.Value.Bool("waitForSync"));
            Assert.IsTrue(operationResult.Value.Long("journalSize") == journalSize);
        }
コード例 #6
0
        public void Should_list_functions()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);
            var db = new ADatabase(Database.Alias);

            const string name1 = "myfunctions::temperature::celsiustofahrenheit1";
            const string code1 = "function (celsius) { return celsius * 1.8 + 40; }";
            var registerResult1 = db.Function.Register(name1, code1);

            Assert.AreEqual(true, registerResult1.Success);

            const string name2 = "myfunctions::temperature::celsiustofahrenheit2";
            const string code2 = "function (celsius) { return celsius * 1.8 + 32; }";
            var registerResult2 = db.Function.Register(name2, code2);

            Assert.AreEqual(true, registerResult2.Success);

            var listResult = db.Function.List();

            Assert.AreEqual(200, listResult.StatusCode);
            Assert.IsTrue(listResult.Success);
            Assert.IsTrue(listResult.HasValue);
            Assert.AreEqual(2, listResult.Value.Count);
            // retrieved order of the functions seems to be reversed
            Assert.AreEqual(name2, listResult.Value[0].String("name"));
            Assert.AreEqual(code2, listResult.Value[0].String("code"));
            Assert.AreEqual(name1, listResult.Value[1].String("name"));
            Assert.AreEqual(code1, listResult.Value[1].String("code"));
        }
コード例 #7
0
        public void Should_execute_AQL_query_fluent()
        {
            var documents = Database.ClearCollectionAndFetchTestDocumentData(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);
            var useCount = true;
            var useBatchSize = true;

            var queryOperation = db.Query
                .Aql(string.Format(@"
                FOR item IN {0}
                    RETURN item
                ", Database.TestDocumentCollectionName));

            if (useCount)
            {
                queryOperation.Count(true);
            }

            if (useBatchSize)
            {
                queryOperation.BatchSize(1);
            }

            var queryResult = queryOperation.ToList();

            Assert.AreEqual(200, queryResult.StatusCode);
            Assert.IsTrue(queryResult.Success);
            Assert.IsTrue(queryResult.HasValue);
            Assert.AreEqual(queryResult.Value.Count, 2);
            Assert.AreEqual(queryResult.Extra.Long("count"), 2);
        }
コード例 #8
0
        public void Should_execute_get_foxx_request()
        {
            var db = new ADatabase(Database.SystemAlias);
            var getResult = db.Foxx.Get<Dictionary<string, object>>("/getting-started/hello-world");

            Assert.AreEqual(200, getResult.StatusCode);
            Assert.AreEqual("bar", getResult.Value.String("foo"));
        }
コード例 #9
0
        public void Should_check_document()
        {
            var documents = Database.ClearCollectionAndFetchTestDocumentData(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var checkResult = db.Document
                .Check(documents[0].String("_id"));

            Assert.AreEqual(200, checkResult.StatusCode);
            Assert.IsTrue(checkResult.Success);
            Assert.IsTrue(checkResult.HasValue);
            Assert.AreEqual(checkResult.Value, documents[0].String("_rev"));
        }
コード例 #10
0
        public void Should_create_database()
        {
            Database.CleanupTestDatabases();

            var db = new ADatabase(Database.SystemAlias);

            var createResult = db.Create(Database.TestDatabaseOneTime);

            Assert.AreEqual(201, createResult.StatusCode);
            Assert.IsTrue(createResult.Success);
            Assert.IsTrue(createResult.HasValue);
            Assert.IsTrue(createResult.Value);
        }
コード例 #11
0
        public void Should_check_document_with_ifMatch_and_return_412()
        {
            var documents = Database.ClearCollectionAndFetchTestDocumentData(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var checkResult = db.Document
                .IfMatch("123456789")
                .Check(documents[0].String("_id"));

            Assert.AreEqual(412, checkResult.StatusCode);
            Assert.IsFalse(checkResult.Success);
            Assert.IsTrue(checkResult.HasValue);
            Assert.AreEqual(checkResult.Value, documents[0].String("_rev"));
        }
コード例 #12
0
        public void Should_execute_post_foxx_request_with_body()
        {
            var db = new ADatabase(Database.SystemAlias);

            var body = Dictator.New()
                .String("foo", "some string");

            var postResult = db.Foxx
                .Body(body)
                .Post<Dictionary<string, object>>("/getting-started/hello-world");

            Assert.AreEqual(200, postResult.StatusCode);
            Assert.AreEqual(body.String("foo"), postResult.Value.String("foo"));
        }
コード例 #13
0
        public void Should_check_document_with_ifNoneMatch()
        {
            var documents = Database.ClearCollectionAndFetchTestDocumentData(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var checkResult = db.Document
                .IfNoneMatch("123456789")
                .Check(documents[0].ID());

            Assert.AreEqual(200, checkResult.StatusCode);
            Assert.IsTrue(checkResult.Success);
            Assert.IsTrue(checkResult.HasValue);
            Assert.AreEqual(checkResult.Value, documents[0].Rev());
        }
コード例 #14
0
        public void Should_delete_database()
        {
            Database.CleanupTestDatabases();

            var db = new ADatabase(Database.SystemAlias);

            var createResult = db.Create(Database.TestDatabaseGeneral);

            var deleteResult = db.Drop(Database.TestDatabaseGeneral);

            Assert.AreEqual(200, deleteResult.StatusCode);
            Assert.IsTrue(deleteResult.Success);
            Assert.IsTrue(deleteResult.HasValue);
            Assert.IsTrue(deleteResult.Value);
        }
コード例 #15
0
        public void Should_fail_create_already_existing_database()
        {
            Database.CleanupTestDatabases();

            var db = new ADatabase(Database.SystemAlias);

            var createResult = db.Create(Database.TestDatabaseGeneral);

            var createResult2 = db.Create(Database.TestDatabaseGeneral);

            Assert.AreEqual(409, createResult2.StatusCode);
            Assert.IsFalse(createResult2.Success);
            Assert.IsTrue(createResult2.HasValue);
            Assert.IsFalse(createResult2.Value);
            Assert.IsNotNull(createResult2.Error);
        }
コード例 #16
0
        public void Should_create_autoincrement_collection()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);

            var db = new ADatabase(Database.Alias);

            var createResult = db.Collection
                .KeyGeneratorType(AKeyGeneratorType.Autoincrement)
                .Create(Database.TestDocumentCollectionName);

            Assert.AreEqual(200, createResult.StatusCode);
            Assert.IsTrue(createResult.Success);
            Assert.IsTrue(createResult.HasValue);
            Assert.AreEqual(true, createResult.Value.IsString("id"));
            Assert.AreEqual(Database.TestDocumentCollectionName, createResult.Value.String("name"));
            Assert.AreEqual(false, createResult.Value.Bool("waitForSync"));
            Assert.AreEqual(false, createResult.Value.Bool("isVolatile"));
            Assert.AreEqual(false, createResult.Value.Bool("isSystem"));
            Assert.AreEqual(ACollectionStatus.Loaded, createResult.Value.Enum<ACollectionStatus>("status"));
            Assert.AreEqual(ACollectionType.Document, createResult.Value.Enum<ACollectionType>("type"));

            // create documents and test if their key are incremented accordingly

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

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

            Assert.AreEqual(202, doc1Result.StatusCode);
            Assert.IsTrue(doc1Result.Success);
            Assert.IsTrue(doc1Result.HasValue);
            Assert.AreEqual(Database.TestDocumentCollectionName + "/" + 1, doc1Result.Value.String("_id"));
            Assert.AreEqual("1", doc1Result.Value.String("_key"));
            Assert.IsFalse(string.IsNullOrEmpty(doc1Result.Value.String("_rev")));

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

            Assert.AreEqual(202, doc2Result.StatusCode);
            Assert.IsTrue(doc2Result.Success);
            Assert.IsTrue(doc2Result.HasValue);
            Assert.AreEqual(Database.TestDocumentCollectionName + "/" + 2, doc2Result.Value.String("_id"));
            Assert.AreEqual("2", doc2Result.Value.String("_key"));
            Assert.IsFalse(string.IsNullOrEmpty(doc2Result.Value.String("_rev")));
        }
コード例 #17
0
        public void Should_create_database_with_users()
        {
            Database.CleanupTestDatabases();

            var db = new ADatabase(Database.SystemAlias);

            var users = new List<AUser>()
            {
                new AUser { Username = "******", Password = "******", Active = true },
                new AUser { Username = "******", Password = "******", Active = false }
            };

            var createResult = db.Create(Database.TestDatabaseOneTime, users);

            Assert.AreEqual(201, createResult.StatusCode);
            Assert.IsTrue(createResult.Success);
            Assert.IsTrue(createResult.HasValue);
            Assert.IsTrue(createResult.Value);
        }
コード例 #18
0
        public void Should_create_cap_contraint()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName, ACollectionType.Document);
            var db = new ADatabase(Database.Alias);

            var createResult = db.Index
                .Type(AIndexType.Cap)
                .Size(10)
                .Create(Database.TestDocumentCollectionName);

            Assert.AreEqual(201, createResult.StatusCode);
            Assert.IsTrue(createResult.Success);
            Assert.IsTrue(createResult.HasValue);
            Assert.IsTrue(createResult.Value.IsID("id"));
            Assert.AreEqual(AIndexType.Cap, createResult.Value.Enum<AIndexType>("type"));
            Assert.IsFalse(createResult.Value.Bool("unique"));
            Assert.AreEqual(10, createResult.Value.Long("size"));
            Assert.AreEqual(0, createResult.Value.Long("byteSize"));
            Assert.IsTrue(createResult.Value.Bool("isNewlyCreated"));
        }
コード例 #19
0
        public void Should_check_edge()
        {
            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 checkResult = db.Edge
                .Check(createResult.Value.String("_id"));

            Assert.AreEqual(200, checkResult.StatusCode);
            Assert.IsTrue(checkResult.Success);
            Assert.IsTrue(checkResult.HasValue);
            Assert.AreEqual(checkResult.Value, createResult.Value.String("_rev"));
        }
コード例 #20
0
        public void Should_execute_transaction_and_return_document()
        {
            Database.ClearTestCollection(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

            var transactionResult = db.Transaction
                .WriteCollection(Database.TestDocumentCollectionName)
                .Execute<Dictionary<string, object>>(@"
                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.Bool("Executed"));
        }
コード例 #21
0
        public void Should_execute_transaction_and_return_int_value()
        {
            Database.ClearTestCollection(Database.TestDocumentCollectionName);
            var db = new ADatabase(Database.Alias);

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

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

                    return db." + Database.TestDocumentCollectionName + @".count();
                }
                ");

            Assert.AreEqual(200, transactionResult.StatusCode);
            Assert.IsTrue(transactionResult.Success);
            Assert.IsTrue(transactionResult.HasValue);
            Assert.AreEqual(1, transactionResult.Value);
        }
コード例 #22
0
        public void Should_create_geo_index()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName, ACollectionType.Document);
            var db = new ADatabase(Database.Alias);

            var createResult = db.Index
                .Type(AIndexType.Geo)
                .Fields("foo")
                .Create(Database.TestDocumentCollectionName);

            Assert.AreEqual(201, createResult.StatusCode);
            Assert.IsTrue(createResult.Success);
            Assert.IsTrue(createResult.HasValue);
            Assert.IsTrue(createResult.Value.IsID("id"));
            Assert.AreEqual("geo1", createResult.Value.String("type"));
            Assert.IsFalse(createResult.Value.Bool("unique"));
            Assert.IsTrue(createResult.Value.Bool("sparse"));

            Assert.AreEqual(1, createResult.Value.Size("fields"));
            new List<string> { "foo" }.ForEach(field => Assert.IsTrue(createResult.Value.List<string>("fields").Contains(field)));

            Assert.IsTrue(createResult.Value.Bool("isNewlyCreated"));
        }
コード例 #23
0
        //[Test()]
        public void Insertion_10k()
        {
            Database.CreateTestCollection(Database.TestDocumentCollectionName, ACollectionType.Document);
            var db = new ADatabase(Database.Alias);

            var startTime = DateTime.Now;
            Debug.WriteLine("Start Time: " + startTime.ToLongTimeString());

            var entity = new PerformanceEntity();
            entity.Id = "1234567890123456789012345678901234";
            entity.Key = "1234567";
            entity.Revision = "1234567";
            entity.Name = "Mohamad Abu Bakar";
            entity.IcNumber = "1234567-12-3444";
            entity.Department = "IT Department";
            entity.Height = 1234;
            entity.DateOfBirth = new DateTime(2015, 1, 27, 3, 33, 3);
            entity.Salary = 3333;

            var jsonEntity = JSON.ToJSON(entity);

            for (int i = 0; i < 10000; i++)
            {
            //                var entity = new PerformanceEntity();
            //                entity.Id = "1234567890123456789012345678901234";
            //                entity.Key = "1234567";
            //                entity.Revision = "1234567";
            //                entity.Name = "Mohamad Abu Bakar";
            //                entity.IcNumber = "1234567-12-3444";
            //                entity.Department = "IT Department";
            //                entity.Height = 1234;
            //                entity.DateOfBirth = new DateTime(2015, 1, 27, 3, 33, 3);
            //                entity.Salary = 3333;

            //                var entity = new Dictionary<string, object>()
            //                    .String("Id", "1234567890123456789012345678901234")
            //                    .String("Key", "1234567")
            //                    .String("Revision", "1234567")
            //                    .String("Name", "Mohamad Abu Bakar")
            //                    .String("IcNumber", "1234567-12-3444")
            //                    .String("Department", "IT Department")
            //                    .Int("Height", 1234)
            //                    .DateTime("DateOfBirth", new DateTime(2015, 1, 27, 3, 33, 3))
            //                    .Int("Salary", 3333);

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

                SimpleHttpPostCreateDocument(
                    "http://localhost:8529/_db/" + Database.TestDatabaseGeneral + "/_api/document?collection=" + Database.TestDocumentCollectionName,
                    jsonEntity
                );

                //var updateDocument = new Dictionary<string, object>()
                //    .String("DocumentId", "SomeId");
                //db2.Document.Update(result.Value.ID(), updateDocument);
            }

            /*var tasks = new Task[10];

            for (int i = 0; i < 10; i++)
            {
                tasks[i] = Task.Factory.StartNew(() =>
                {
                    int messages_sent_by_one_task = 0;

                    while(messages_sent_by_one_task < 1000)
                    {
                        SimpleHttpPostCreateDocument(
                            "http://localhost:8529/_db/" + Database.TestDatabaseGeneral + "/_api/document?collection=" + Database.TestDocumentCollectionName,
                            jsonEntity
                        );

                        messages_sent_by_one_task++;
                    }
                });
            }

            while (tasks.Any(t => !t.IsCompleted)) { }*/

            var endTime = DateTime.Now;
            TimeSpan duration = endTime - startTime;

            Debug.WriteLine("End Time: " + endTime.ToLongTimeString());
            Debug.WriteLine("Total time taken: " + duration.TotalSeconds);
        }
コード例 #24
0
ファイル: Performance.cs プロジェクト: yojimbo87/ArangoDB-NET
        public void TestArangoClientSequentialInsertion(int iterationCount)
        {
            Console.WriteLine("Operation start: TestArangoClientSequentialInsertion\n");

            var db = new ADatabase(Database.Alias);

            ExecuteTimedTest(iterationCount, () => {
                var entity = new PerformanceEntity();
                entity.Id = "1234567890123456789012345678901234";
                entity.Key = "1234567";
                entity.Revision = "1234567";
                entity.Name = "Mohamad Abu Bakar";
                entity.IcNumber = "1234567-12-3444";
                entity.Department = "IT Department";
                entity.Height = 1234;
                entity.DateOfBirth = new DateTime(2015, 1, 27, 3, 33, 3);
                entity.Salary = 3333;

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

            Console.WriteLine("\nOperation end: TestArangoClientSequentialInsertion");
        }
コード例 #25
0
ファイル: Performance.cs プロジェクト: kangkot/ArangoDB-NET
        public void TestSimpleSequentialHttpPostRequests()
        {
            Console.WriteLine("Operation start: TestSimpleSequentialHttpPostRequests");

            var db = new ADatabase(Database.Alias);

            var entity = new PerformanceEntity();
            entity.Id = "1234567890123456789012345678901234";
            entity.Key = "1234567";
            entity.Revision = "1234567";
            entity.Name = "Mohamad Abu Bakar";
            entity.IcNumber = "1234567-12-3444";
            entity.Department = "IT Department";
            entity.Height = 1234;
            entity.DateOfBirth = new DateTime(2015, 1, 27, 3, 33, 3);
            entity.Salary = 3333;

            var jsonEntity = JSON.ToJSON(entity);

            ServicePointManager.DefaultConnectionLimit = 40;
            ServicePointManager.Expect100Continue = false;
            ServicePointManager.UseNagleAlgorithm = false;

            ExecuteTimedTest(10, () => {
                for (int i = 0; i < 10000; i++)
                {
                    SimpleHttpPostCreateDocument(
                        "http://localhost:8529/_db/" + Database.TestDatabaseGeneral + "/_api/document?collection=" + Database.TestDocumentCollectionName,
                        jsonEntity
                    );
                }
            });

            //            Stopwatch stopwatch = Stopwatch.StartNew();
            //
            //            for (int i = 0; i < 10000; i++)
            //            {
            //                SimpleHttpPostCreateDocument(
            //                    "http://localhost:8529/_db/" + Database.TestDatabaseGeneral + "/_api/document?collection=" + Database.TestDocumentCollectionName,
            //                    jsonEntity
            //                );
            //            }
            //
            //            Console.WriteLine("Elapsed time [s]: {0}", stopwatch.Elapsed.TotalMilliseconds / 1000);

            Console.WriteLine("Operation end: TestSimpleSequentialHttpPostRequests");
        }
コード例 #26
0
ファイル: Performance.cs プロジェクト: yojimbo87/ArangoDB-NET
        public void TestSimpleSequentialHttpPostRequests(int iterationCount)
        {
            Console.WriteLine("Operation start: TestSimpleSequentialHttpPostRequests\n");

            var db = new ADatabase(Database.Alias);

            //ServicePointManager.DefaultConnectionLimit = 40;
            //ServicePointManager.Expect100Continue = false;
            //ServicePointManager.UseNagleAlgorithm = false;

            ExecuteTimedTest(iterationCount, () => {
                var entity = new PerformanceEntity();
                entity.Id = "1234567890123456789012345678901234";
                entity.Key = "1234567";
                entity.Revision = "1234567";
                entity.Name = "Mohamad Abu Bakar";
                entity.IcNumber = "1234567-12-3444";
                entity.Department = "IT Department";
                entity.Height = 1234;
                entity.DateOfBirth = new DateTime(2015, 1, 27, 3, 33, 3);
                entity.Salary = 3333;

                var jsonEntity = JSON.ToJSON(entity);

                var response = SimpleHttpPostCreateDocument(
                    "http://localhost:8529/_db/" + Database.TestDatabaseGeneral + "/_api/document?collection=" + Database.TestDocumentCollectionName,
                    jsonEntity
                );

                var deserializedResponse = JSON.ToObject<Dictionary<string, object>>(response);
            });

            Console.WriteLine("\nOperation end: TestSimpleSequentialHttpPostRequests");
        }
コード例 #27
0
        public void Should_fail_create_database_from_non_system_database()
        {
            Database.CleanupTestDatabases();

            var db = new ADatabase(Database.SystemAlias);

            var createResult = db.Create(Database.TestDatabaseGeneral);

            var nonSystemDatabase = new ADatabase(Database.Alias);

            var createResult2 = nonSystemDatabase.Create(Database.TestDatabaseOneTime);

            Assert.AreEqual(403, createResult2.StatusCode);
            Assert.IsFalse(createResult2.Success);
            Assert.IsTrue(createResult2.HasValue);
            Assert.IsFalse(createResult2.Value);
            Assert.IsNotNull(createResult2.Error);
        }
コード例 #28
0
        public void Should_get_current_database()
        {
            Database.CleanupTestDatabases();

            var db = new ADatabase(Database.SystemAlias);

            var resultCurrent = db.GetCurrent();

            Assert.AreEqual(200, resultCurrent.StatusCode);
            Assert.IsTrue(resultCurrent.Success);
            Assert.IsTrue(resultCurrent.HasValue);
            Assert.AreEqual("_system", resultCurrent.Value.String("name"));
            Assert.AreEqual(false, string.IsNullOrEmpty(resultCurrent.Value.String("id")));
            Assert.AreEqual(false, string.IsNullOrEmpty(resultCurrent.Value.String("path")));
            Assert.AreEqual(true, resultCurrent.Value.Bool("isSystem"));
        }
コード例 #29
0
        public void Should_get_database_collections()
        {
            Database.CleanupTestDatabases();
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);

            var db = new ADatabase(Database.Alias);

            var createResult = db.Collection
                .Create(Database.TestDocumentCollectionName);

            var getResult = db
                .ExcludeSystem(true)
                .GetAllCollections();

            Assert.AreEqual(200, getResult.StatusCode);
            Assert.IsTrue(getResult.Success);
            Assert.IsTrue(getResult.HasValue);

            var foundCreatedCollection = getResult.Value.FirstOrDefault(col => col.String("name") == createResult.Value.String("name"));

            Assert.IsNotNull(foundCreatedCollection);

            var foundSystemCollection = getResult.Value.FirstOrDefault(col => col.String("name") == "_system");

            Assert.IsNull(foundSystemCollection);
        }
コード例 #30
0
        public void Should_get_list_of_all_databases()
        {
            Database.CleanupTestDatabases();

            var db = new ADatabase(Database.SystemAlias);

            var resultCreate = db.Create(Database.TestDatabaseOneTime);

            var resultList = db.GetAllDatabases();

            Assert.AreEqual(200, resultList.StatusCode);
            Assert.IsTrue(resultList.Success);
            Assert.IsTrue(resultList.HasValue);
            Assert.IsTrue(resultList.Value.Contains(Database.TestDatabaseOneTime));
            Assert.IsTrue(resultList.Value.Contains("_system"));
        }