Example #1
0
 /// <summary>
 /// Databases and users created through this method will be dropped
 /// during the test fixture's dispose routine. For that reason, do not pass details
 /// of an existing user or database that you expect to stay around after a test run.
 /// </summary>
 /// <param name="dbName"></param>
 /// <param name="users">Optional set of users to create along with the database.</param>
 /// <returns></returns>
 protected async Task CreateDatabase(string dbName, IEnumerable <DatabaseUser> users = null)
 {
     // Create the test database
     using (var systemDbClient = GetHttpTransport("_system"))
     {
         var dbApiClient = new DatabaseApiClient(systemDbClient);
         try
         {
             var postDatabaseResponse = await dbApiClient.PostDatabaseAsync(new PostDatabaseBody
             {
                 Name  = dbName,
                 Users = users
             });
         }
         catch (ApiErrorException ex) when(ex.ApiError.ErrorNum == 1207)
         {
             // database must exist already
             Console.WriteLine(ex.Message);
         }
         finally
         {
             _databases.Add(dbName);
             if (users != null)
             {
                 _users?.AddRange(users.Select(u => u.Username));
             }
         }
     }
 }
Example #2
0
 protected async Task CreateDatabase(string dbName)
 {
     // Create the test database
     using (var systemDbClient = GetHttpTransport("_system"))
     {
         var dbApiClient = new DatabaseApiClient(systemDbClient);
         try
         {
             var postDatabaseResponse = await dbApiClient.PostDatabaseAsync(new PostDatabaseBody
             {
                 Name = dbName
             });
         }
         catch (ApiErrorException ex) when(ex.ApiError.ErrorNum == 1207)
         {
             // database must exist already
             Console.WriteLine(ex.Message);
         }
         finally
         {
             _databases.Add(dbName);
         }
     }
 }
Example #3
0
        /// <summary>
        /// The function body here is intended for use in "Quick Start" usage documentation.
        /// </summary>
        /// <returns></returns>
        private async Task QuickStartDoc()
        {
            // You must use the system database to create databases!
            using (var systemDbTransport = HttpApiTransport.UsingBasicAuth(
                       new Uri($"http://{_arangoDbHost}:8529/"),
                       "_system",
                       "root",
                       "root"))
            {
                var systemDb = new DatabaseApiClient(systemDbTransport);

                // Create a new database with one user.
                await systemDb.PostDatabaseAsync(
                    new PostDatabaseBody
                {
                    Name  = "arangodb-net-standard",
                    Users = new List <DatabaseUser>
                    {
                        new DatabaseUser
                        {
                            Username = "******",
                            Passwd   = "yoko123"
                        }
                    }
                });
            }

            // Use our new database, with basic auth credentials for the user jlennon.
            var transport = HttpApiTransport.UsingBasicAuth(
                new Uri($"http://{_arangoDbHost}:8529"),
                "arangodb-net-standard",
                "jlennon",
                "yoko123");

            var adb = new ArangoDBClient(transport);

            // Create a collection in the database
            await adb.Collection.PostCollectionAsync(
                new PostCollectionBody
            {
                Name = "MyCollection"
                       // A whole heap of other options exist to define key options,
                       // sharding options, etc
            });

            // Create document in the collection using anonymous type
            await adb.Document.PostDocumentAsync(
                "MyCollection",
                new
            {
                MyProperty = "Value"
            });

            // Create document in the collection using strong type
            await adb.Document.PostDocumentAsync(
                "MyCollection",
                new MyClass
            {
                ItemNumber  = 123456,
                Description = "Some item"
            });

            // Run AQL query (create a query cursor)
            var response = await adb.Cursor.PostCursorAsync <MyClassDocument>(
                @"FOR doc IN MyCollection 
                  FILTER doc.ItemNumber == 123456 
                  RETURN doc");

            MyClassDocument item = response.Result.First();

            // Partially update document
            await adb.Document.PatchDocumentAsync <object, object>(
                "MyCollection",
                item._key,
                new { Description = "More description" });

            // Fully update document
            item.Description = "Some item with some more description";
            await adb.Document.PutDocumentAsync(
                $"MyCollection/{item._key}",
                item);
        }