Exemple #1
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);
        }
Exemple #2
0
        public void Should_get_collection_figures()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);

            var db = new ADatabase(Database.Alias);

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

            var getResult = db.Collection
                            .GetFigures(createResult.Value.String("name"));

            Assert.AreEqual(200, getResult.StatusCode);
            Assert.IsTrue(getResult.Success);
            Assert.IsTrue(getResult.HasValue);
            Assert.AreEqual(createResult.Value.String("id"), getResult.Value.String("id"));
            Assert.AreEqual(createResult.Value.String("name"), getResult.Value.String("name"));
            Assert.AreEqual(createResult.Value.Bool("isSystem"), getResult.Value.Bool("isSystem"));
            Assert.AreEqual(createResult.Value.Bool("isVolatile"), getResult.Value.Bool("isVolatile"));
            Assert.AreEqual(createResult.Value.Int("status"), getResult.Value.Int("status"));
            Assert.AreEqual(createResult.Value.Int("type"), getResult.Value.Int("type"));
            Assert.AreEqual(createResult.Value.Bool("waitForSync"), getResult.Value.Bool("waitForSync"));
            Assert.IsTrue(getResult.Value.Bool("doCompact"));
            Assert.IsTrue(getResult.Value.Long("journalSize") > 0);
            Assert.AreEqual(AKeyGeneratorType.Traditional, getResult.Value.Enum <AKeyGeneratorType>("keyOptions.type"));
            Assert.AreEqual(true, getResult.Value.Bool("keyOptions.allowUserKeys"));
            Assert.AreEqual(0, getResult.Value.Long("count"));
            Assert.IsTrue(getResult.Value.Document("figures").Count > 0);
        }
Exemple #3
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);
        }
Exemple #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();

            Assert.AreEqual(fahrenheit, Convert.ToSingle(queryResult.Value.First()));
        }
Exemple #5
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);
            Assert.AreEqual(name1, listResult.Value[0].String("name"));
            Assert.AreEqual(code1, listResult.Value[0].String("code"));
            Assert.AreEqual(name2, listResult.Value[1].String("name"));
            Assert.AreEqual(code2, listResult.Value[1].String("code"));
        }
Exemple #6
0
        public void Should_get_collection_cehcksum()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);

            var db = new ADatabase(Database.Alias);

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

            var getResult = db.Collection
                            .WithData(true)
                            .WithRevisions(true)
                            .GetChecksum(createResult.Value.String("name"));

            Assert.AreEqual(200, getResult.StatusCode);
            Assert.IsTrue(getResult.Success);
            Assert.IsTrue(getResult.HasValue);
            Assert.AreEqual(createResult.Value.String("id"), getResult.Value.String("id"));
            Assert.AreEqual(createResult.Value.String("name"), getResult.Value.String("name"));
            Assert.AreEqual(createResult.Value.Bool("isSystem"), getResult.Value.Bool("isSystem"));
            Assert.AreEqual(createResult.Value.Int("status"), getResult.Value.Int("status"));
            Assert.AreEqual(createResult.Value.Int("type"), getResult.Value.Int("type"));
            Assert.IsTrue(getResult.Value.IsString("revision"));
            Assert.IsTrue(getResult.Value.IsString("checksum"));
        }
Exemple #7
0
        public void Should_get_all_indexes_in_collection()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);
            Database.CreateTestCollection(Database.TestDocumentCollectionName, ACollectionType.Document);
            var db = new ADatabase(Database.Alias);

            var operationResult = db.Collection
                                  .GetAllIndexes(Database.TestDocumentCollectionName);

            Assert.AreEqual(200, operationResult.StatusCode);
            Assert.IsTrue(operationResult.Success);
            Assert.IsTrue(operationResult.HasValue);
            Assert.IsTrue(operationResult.Value.Size("indexes") > 0);
            Assert.IsTrue(operationResult.Value.IsDocument("identifiers"));
        }
Exemple #8
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.ID());
            Assert.AreEqual("1", doc1Result.Value.Key());
            Assert.IsFalse(string.IsNullOrEmpty(doc1Result.Value.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.ID());
            Assert.AreEqual("2", doc2Result.Value.Key());
            Assert.IsFalse(string.IsNullOrEmpty(doc2Result.Value.Rev()));
        }
Exemple #9
0
        public void Should_fail_to_rotate_collection_journal()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);

            var db = new ADatabase(Database.Alias);

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

            var operationResult = db.Collection
                                  .RotateJournal(createResult.Value.String("name"));

            Assert.AreEqual(400, operationResult.StatusCode);
            Assert.IsFalse(operationResult.Success);
            Assert.IsTrue(operationResult.HasValue);
            Assert.IsFalse(operationResult.Value);
        }
Exemple #10
0
        public void Should_delete_collection()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);

            var db = new ADatabase(Database.Alias);

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

            var deleteResult = db.Collection
                               .Delete(createResult.Value.String("name"));

            Assert.AreEqual(200, deleteResult.StatusCode);
            Assert.IsTrue(deleteResult.Success);
            Assert.IsTrue(deleteResult.HasValue);
            Assert.AreEqual(createResult.Value.String("id"), deleteResult.Value.String("id"));
        }
        public void Should_get_all_documents_in_collection()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);
            Database.CreateTestCollection(Database.TestDocumentCollectionName, ACollectionType.Document);
            Database.ClearCollectionAndFetchTestDocumentData(Database.TestDocumentCollectionName);

            var db = new ADatabase(Database.Alias);

            var operationResult = db.Collection
                                  .GetAllDocuments(Database.TestDocumentCollectionName);

            Assert.AreEqual(200, operationResult.StatusCode);
            Assert.IsTrue(operationResult.Success);
            Assert.IsTrue(operationResult.HasValue);
            Assert.AreEqual(operationResult.Value.Count, 2);
            Assert.IsFalse(string.IsNullOrEmpty(operationResult.Value[0]));
            Assert.IsFalse(string.IsNullOrEmpty(operationResult.Value[1]));
        }
Exemple #12
0
        public void Should_create_document_collection()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);

            var db = new ADatabase(Database.Alias);

            var createResult = db.Collection
                               .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"));
        }
Exemple #13
0
        public void Should_rename_collection()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);

            var db = new ADatabase(Database.Alias);

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

            var operationResult = db.Collection
                                  .Rename(createResult.Value.String("name"), Database.TestEdgeCollectionName);

            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(Database.TestEdgeCollectionName, 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"));
        }
Exemple #14
0
        public void Should_unload_collection()
        {
            Database.CreateTestDatabase(Database.TestDatabaseGeneral);

            var db = new ADatabase(Database.Alias);

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

            var operationResult = db.Collection
                                  .Unload(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.IsTrue(operationResult.Value.Enum <ACollectionStatus>("status") == ACollectionStatus.Unloaded || operationResult.Value.Enum <ACollectionStatus>("status") == ACollectionStatus.Unloading);
            Assert.AreEqual(createResult.Value.Int("type"), operationResult.Value.Int("type"));
        }
Exemple #15
0
        public void Should_unregister_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 unregisterResult = db.Function.Unregister("myfunctions::temperature::celsiustofahrenheit");

            Assert.AreEqual(200, unregisterResult.StatusCode);
            Assert.IsTrue(unregisterResult.Success);
            Assert.IsTrue(unregisterResult.HasValue);
            Assert.IsTrue(unregisterResult.Value);
        }
 public IndexOperationsTests()
 {
     Database.CreateTestDatabase(Database.TestDatabaseGeneral);
 }
Exemple #17
0
 public IssueTests()
 {
     Database.CreateTestDatabase(Database.TestDatabaseGeneral);
 }
Exemple #18
0
 public DocumentOperationsTests()
 {
     Database.CreateTestDatabase(Database.TestDatabaseGeneral);
     Database.CreateTestCollection(Database.TestDocumentCollectionName, ACollectionType.Document);
 }
 public PerformanceTests()
 {
     Database.CreateTestDatabase(Database.TestDatabaseGeneral);
 }