diff --git a/arangodb-net-standard.Test/DatabaseApi/DatabaseApiClientTest.cs b/arangodb-net-standard.Test/DatabaseApi/DatabaseApiClientTest.cs
new file mode 100644
index 00000000..6a1eca65
--- /dev/null
+++ b/arangodb-net-standard.Test/DatabaseApi/DatabaseApiClientTest.cs
@@ -0,0 +1,84 @@
+using ArangoDBNetStandard;
+using ArangoDBNetStandard.DatabaseApi;
+using System.Linq;
+using System.Net;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace ArangoDBNetStandardTest.DatabaseApi
+{
+ ///
+ /// Test class for .
+ ///
+ public class DatabaseApiClientTest : IClassFixture
+ {
+ private DatabaseApiClientTestFixture _fixture;
+
+ public DatabaseApiClientTest(DatabaseApiClientTestFixture fixture)
+ {
+ _fixture = fixture;
+ }
+
+ [Fact]
+ public async Task ListDatabasesAsync_ShouldSucceed()
+ {
+ ListDatabaseResult result = await _fixture.DatabaseClientSystem.ListDatabasesAsync();
+
+ Assert.False(result.Error);
+ Assert.Equal(HttpStatusCode.OK, result.Code);
+ Assert.True(result.Result.Count() > 0);
+ }
+
+ [Fact]
+ public async Task ListDatabasesAsync_ShouldThrow_WhenDatabaseIsNotSystem()
+ {
+ var ex = await Assert.ThrowsAsync(async () =>
+ {
+ await _fixture.DatabaseClientOther.ListDatabasesAsync();
+ });
+
+ ApiErrorResponse apiError = ex.ApiError;
+
+ Assert.Equal(HttpStatusCode.Forbidden, apiError.Code);
+ Assert.Equal(1230, apiError.ErrorNum);
+ }
+
+ [Fact]
+ public async Task ListDatabasesAsync_ShouldThrow_WhenDatabaseDoesNotExist()
+ {
+ var ex = await Assert.ThrowsAsync(async () =>
+ {
+ await _fixture.DatabaseClientNonExistent.ListDatabasesAsync();
+ });
+
+ ApiErrorResponse apiError = ex.ApiError;
+
+ Assert.Equal(HttpStatusCode.NotFound, apiError.Code);
+ Assert.Equal(1228, apiError.ErrorNum);
+ }
+
+ [Fact]
+ public async Task ListUserDatabasesAsync_ShouldSucceed()
+ {
+ ListDatabaseResult result = await _fixture.DatabaseClientOther.ListUserDatabasesAsync();
+
+ Assert.False(result.Error);
+ Assert.Equal(HttpStatusCode.OK, result.Code);
+ Assert.True(result.Result.Count() > 0);
+ }
+
+ [Fact]
+ public async Task ListUserDatabasesAsync_ShouldThrow_WhenDatabaseDoesNotExist()
+ {
+ var ex = await Assert.ThrowsAsync(async () =>
+ {
+ await _fixture.DatabaseClientNonExistent.ListDatabasesAsync();
+ });
+
+ ApiErrorResponse apiError = ex.ApiError;
+
+ Assert.Equal(HttpStatusCode.NotFound, apiError.Code);
+ Assert.Equal(1228, apiError.ErrorNum);
+ }
+ }
+}
diff --git a/arangodb-net-standard.Test/DatabaseApi/DatabaseApiClientTestFixture.cs b/arangodb-net-standard.Test/DatabaseApi/DatabaseApiClientTestFixture.cs
new file mode 100644
index 00000000..12d9c4ea
--- /dev/null
+++ b/arangodb-net-standard.Test/DatabaseApi/DatabaseApiClientTestFixture.cs
@@ -0,0 +1,44 @@
+using System.Threading.Tasks;
+using ArangoDBNetStandard;
+using ArangoDBNetStandard.DatabaseApi;
+
+namespace ArangoDBNetStandardTest.DatabaseApi
+{
+ ///
+ /// Provides per-test-class fixture data for .
+ ///
+ public class DatabaseApiClientTestFixture : ApiClientTestFixtureBase
+ {
+ ///
+ /// A targeting the _system database.
+ ///
+ public DatabaseApiClient DatabaseClientSystem { get; internal set; }
+
+ ///
+ /// A targeting a database that does not exist.
+ ///
+ public DatabaseApiClient DatabaseClientNonExistent { get; internal set; }
+
+ ///
+ /// A targeting an existing database other than _system.
+ ///
+ public DatabaseApiClient DatabaseClientOther { get; internal set; }
+
+ public DatabaseApiClientTestFixture()
+ {
+ DatabaseClientSystem = GetArangoDBClient("_system").Database;
+ DatabaseClientNonExistent = GetArangoDBClient("DatabaseThatDoesNotExist").Database;
+ }
+
+ public override async Task InitializeAsync()
+ {
+ await base.InitializeAsync();
+
+ string dbName = nameof(DatabaseApiClientTestFixture);
+
+ await CreateDatabase(dbName);
+
+ DatabaseClientOther = GetArangoDBClient(dbName).Database;
+ }
+ }
+}
diff --git a/arangodb-net-standard/DatabaseApi/DatabaseApiClient.cs b/arangodb-net-standard/DatabaseApi/DatabaseApiClient.cs
index 3ba532d6..58f882af 100644
--- a/arangodb-net-standard/DatabaseApi/DatabaseApiClient.cs
+++ b/arangodb-net-standard/DatabaseApi/DatabaseApiClient.cs
@@ -9,7 +9,7 @@
namespace ArangoDBNetStandard.DatabaseApi
{
- public class DatabaseApiClient: ApiClientBase
+ public class DatabaseApiClient : ApiClientBase
{
private IApiClientTransport _client;
private readonly string _databaseApiPath = "_api/database";
@@ -48,5 +48,44 @@ public async Task DeleteDatabaseAsync(string dbName)
throw new ApiErrorException(apiError);
}
}
+
+ ///
+ /// Retrieves the list of all existing databases.
+ /// (Only possible from within the _system database)
+ ///
+ ///
+ /// You should use to fetch the list of the databases
+ /// available for the current user.
+ ///
+ ///
+ public async Task ListDatabasesAsync()
+ {
+ using (var response = await _client.GetAsync(_databaseApiPath))
+ {
+ if (response.IsSuccessStatusCode)
+ {
+ var stream = await response.Content.ReadAsStreamAsync();
+ return DeserializeJsonFromStream(stream, true, false);
+ }
+ throw await GetApiErrorException(response);
+ }
+ }
+
+ ///
+ /// Retrieves the list of all databases the current user can access.
+ ///
+ ///
+ public async Task ListUserDatabasesAsync()
+ {
+ using (var response = await _client.GetAsync(_databaseApiPath + "/user"))
+ {
+ if (response.IsSuccessStatusCode)
+ {
+ var stream = await response.Content.ReadAsStreamAsync();
+ return DeserializeJsonFromStream(stream, true, false);
+ }
+ throw await GetApiErrorException(response);
+ }
+ }
}
}
diff --git a/arangodb-net-standard/DatabaseApi/ListDatabaseResult.cs b/arangodb-net-standard/DatabaseApi/ListDatabaseResult.cs
new file mode 100644
index 00000000..ee59cd9c
--- /dev/null
+++ b/arangodb-net-standard/DatabaseApi/ListDatabaseResult.cs
@@ -0,0 +1,27 @@
+using System.Collections.Generic;
+using System.Net;
+
+namespace ArangoDBNetStandard.DatabaseApi
+{
+ ///
+ /// Represents the content of the response returned
+ /// by an endpoint that gets the list of databases.
+ ///
+ public class ListDatabaseResult
+ {
+ ///
+ /// Indicates whether an error occurred (false in this case).
+ ///
+ public bool Error { get; set; }
+
+ ///
+ /// The HTTP status code.
+ ///
+ public HttpStatusCode Code { get; set; }
+
+ ///
+ /// The list of databases.
+ ///
+ public IEnumerable Result { get; set; }
+ }
+}
diff --git a/arangodb-net-standard/Transport/Http/HttpApiTransport.cs b/arangodb-net-standard/Transport/Http/HttpApiTransport.cs
index f05bd714..6c936e3d 100644
--- a/arangodb-net-standard/Transport/Http/HttpApiTransport.cs
+++ b/arangodb-net-standard/Transport/Http/HttpApiTransport.cs
@@ -111,7 +111,6 @@ public async Task PutAsync(string requestUri, StringContent
///
public async Task GetAsync(string requestUri)
{
-
var response = await _client.GetAsync(requestUri);
return new HttpApiClientResponse(response);
}
diff --git a/project/roadmap.md b/project/roadmap.md
index 2c08cddd..8d944eeb 100644
--- a/project/roadmap.md
+++ b/project/roadmap.md
@@ -39,10 +39,10 @@ A tick indicates an item is implemented and has automated tests in place.
#### Database API
-- [ ] GET/_api/database List of databases
+- [X] GET/_api/database List of databases
- [ ] POST/_api/database Create database
- [ ] GET/_api/database/current Information of the database
-- [ ] GET/_api/database/user List of accessible databases
+- [X] GET/_api/database/user List of accessible databases
- [ ] DELETE/_api/database/{database-name} Drop database
#### Document API