public async Task QuickStart_ShouldSucceed() { try { await QuickStartDoc(); } finally { using (var systemDbTransport = HttpApiTransport.UsingBasicAuth( new Uri($"http://{_arangoDbHost}:8529/"), "_system", "root", "root")) { var systemDb = new DatabaseApiClient(systemDbTransport); try { await systemDb.DeleteDatabaseAsync("arangodb-net-standard"); } catch (ApiErrorException ex) { // assume database didn't exist Console.WriteLine(ex.Message); } } } }
/// <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)); } } } }
public async Task SetJwt_ShouldSucceed() { string jwtToken = null; string arangodbBaseUrl = $"http://{_fixture.ArangoDbHost}:8529/"; using (var transport = HttpApiTransport.UsingNoAuth( new Uri(arangodbBaseUrl), nameof(HttpApiTransportTest))) { var authClient = new AuthApiClient(transport); var jwtTokenResponse = await authClient.GetJwtTokenAsync( new JwtTokenRequestBody { Username = _fixture.Username, Password = _fixture.Password }); jwtToken = jwtTokenResponse.Jwt; // Use token in current transport transport.SetJwtToken(jwtToken); var databaseApi = new DatabaseApiClient(transport); var userDatabasesResponse = await databaseApi.GetUserDatabasesAsync(); Assert.NotEmpty(userDatabasesResponse.Result); } }
public DatabaseApiClientTest(DatabaseApiClientTestFixture fixture) { _fixture = fixture; _systemClient = fixture.DatabaseClientSystem; _systemClient.ThrowErrorsAsExceptions = false; _fixture.DatabaseClientNonExistent.ThrowErrorsAsExceptions = false; _fixture.DatabaseClientOther.ThrowErrorsAsExceptions = false; }
protected async Task DropDatabase(string dbName) { using (var systemDbClient = GetHttpTransport("_system")) { var dbApiClient = new DatabaseApiClient(systemDbClient); var response = await dbApiClient.DeleteDatabaseAsync(dbName); } }
public override async Task InitializeAsync() { await base.InitializeAsync(); string dbName = nameof(DatabaseApiClientTestFixture); await CreateDatabase(dbName); DatabaseClientOther = GetArangoDBClient(dbName).Database; }
/// <summary> /// Create an instance of <see cref="ArangoDBClient"/> from an existing /// <see cref="IApiClientTransport"/> instance. /// </summary> /// <param name="transport">The ArangoDB transport layer implementation.</param> public ArangoDBClient(IApiClientTransport transport) { _transport = transport; Cursor = new CursorApiClient(_transport); Database = new DatabaseApiClient(_transport); Document = new DocumentApiClient(_transport); Collection = new CollectionApiClient(_transport); Transaction = new TransactionApiClient(_transport); Graph = new GraphApiClient(_transport); }
/// <summary> /// Create an instance of <see cref="ArangoDBClient"/> from an existing /// <see cref="HttpClient"/> instance. /// </summary> /// <param name="client"></param> public ArangoDBClient(HttpClient client) { _transport = new HttpApiTransport(client); Cursor = new CursorApiClient(_transport); Database = new DatabaseApiClient(_transport); Document = new DocumentApiClient(_transport); Collection = new CollectionApiClient(_transport); Transaction = new TransactionApiClient(_transport); Graph = new GraphApiClient(_transport); }
/// <summary> /// Create an instance of <see cref="ArangoDBClient"/> /// using the provided transport and serialization layers. /// </summary> /// <param name="transport">The ArangoDB transport layer implementation.</param> /// <param name="serialization">The serialization layer implementation.</param> public ArangoDBClient(IApiClientTransport transport, IApiClientSerialization serialization) { _transport = transport; Auth = new AuthApiClient(_transport, serialization); Cursor = new CursorApiClient(_transport, serialization); Database = new DatabaseApiClient(_transport, serialization); Document = new DocumentApiClient(_transport, serialization); Collection = new CollectionApiClient(_transport, serialization); Transaction = new TransactionApiClient(_transport, serialization); Graph = new GraphApiClient(_transport, serialization); }
/// <summary> /// Create an instance of <see cref="ArangoDBClient"/> from an existing /// <see cref="HttpClient"/> instance, using the default JSON serialization. /// </summary> /// <param name="client"></param> public ArangoDBClient(HttpClient client) { _transport = new HttpApiTransport(client, HttpContentType.Json); AqlFunction = new AqlFunctionApiClient(_transport); Auth = new AuthApiClient(_transport); Cursor = new CursorApiClient(_transport); Database = new DatabaseApiClient(_transport); Document = new DocumentApiClient(_transport); Collection = new CollectionApiClient(_transport); Transaction = new TransactionApiClient(_transport); Graph = new GraphApiClient(_transport); }
private void InitializeApis( IApiClientTransport transport, IApiClientSerialization serialization) { AqlFunction = new AqlFunctionApiClient(transport, serialization); Auth = new AuthApiClient(transport, serialization); Cursor = new CursorApiClient(transport, serialization); Database = new DatabaseApiClient(transport, serialization); Document = new DocumentApiClient(transport, serialization); Collection = new CollectionApiClient(transport, serialization); Transaction = new TransactionApiClient(transport, serialization); Graph = new GraphApiClient(transport, serialization); User = new UserApiClient(transport, serialization); }
public async Task UsingJwtAuth_ShouldSucceed() { string jwtToken = null; string arangodbBaseUrl = $"http://{_fixture.ArangoDbHost}:8529/"; using (var transport = HttpApiTransport.UsingNoAuth( new Uri(arangodbBaseUrl), nameof(HttpApiTransportTest))) { var authClient = new AuthApiClient(transport); authClient.ThrowErrorsAsExceptions = true; var jwtTokenResponse = await authClient.GetJwtTokenAsync( new JwtTokenRequestBody { Username = _fixture.Username, Password = _fixture.Password }); jwtToken = jwtTokenResponse.Jwt; DatabaseApiClient databaseApi = new DatabaseApiClient(transport) { ThrowErrorsAsExceptions = true }; // Not authorized, should throw. var ex = await Assert.ThrowsAsync <ApiErrorException>(async() => await databaseApi.GetCurrentDatabaseInfoAsync()); } // Use token in a new transport created via `UsingJwtAuth`. using (var transport = HttpApiTransport.UsingJwtAuth( new Uri(arangodbBaseUrl), nameof(HttpApiTransportTest), jwtToken)) { var databaseApi = new DatabaseApiClient(transport); var userDatabasesResponse = await databaseApi.GetUserDatabasesAsync(); Assert.NotEmpty(userDatabasesResponse.Results); } }
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); } } }
public void ResetDatabase() { var databaseApiClient = new DatabaseApiClient(); databaseApiClient.ResetDatabase(); }
public DatabaseApiClientTest(DatabaseApiClientTestFixture fixture) { _fixture = fixture; _systemClient = fixture.DatabaseClientSystem; }
/// <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); }