-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add database API endpoints to retrieve the list of databases. #30
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using ArangoDBNetStandard; | ||
using ArangoDBNetStandard.DatabaseApi; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace ArangoDBNetStandardTest.DatabaseApi | ||
{ | ||
/// <summary> | ||
/// Test class for <see cref="DatabaseApiClient"/>. | ||
/// </summary> | ||
public class DatabaseApiClientTest : IClassFixture<DatabaseApiClientTestFixture> | ||
{ | ||
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<ApiErrorException>(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<ApiErrorException>(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<ApiErrorException>(async () => | ||
{ | ||
await _fixture.DatabaseClientNonExistent.ListDatabasesAsync(); | ||
}); | ||
|
||
ApiErrorResponse apiError = ex.ApiError; | ||
|
||
Assert.Equal(HttpStatusCode.NotFound, apiError.Code); | ||
Assert.Equal(1228, apiError.ErrorNum); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Threading.Tasks; | ||
using ArangoDBNetStandard; | ||
using ArangoDBNetStandard.DatabaseApi; | ||
|
||
namespace ArangoDBNetStandardTest.DatabaseApi | ||
{ | ||
/// <summary> | ||
/// Provides per-test-class fixture data for <see cref="DatabaseApiClientTest"/>. | ||
/// </summary> | ||
public class DatabaseApiClientTestFixture : ApiClientTestFixtureBase | ||
{ | ||
/// <summary> | ||
/// A <see cref="DatabaseApiClient"/> targeting the _system database. | ||
/// </summary> | ||
public DatabaseApiClient DatabaseClientSystem { get; internal set; } | ||
|
||
/// <summary> | ||
/// A <see cref="DatabaseApiClient"/> targeting a database that does not exist. | ||
/// </summary> | ||
public DatabaseApiClient DatabaseClientNonExistent { get; internal set; } | ||
|
||
/// <summary> | ||
/// A <see cref="DatabaseApiClient"/> targeting an existing database other than _system. | ||
/// </summary> | ||
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; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Collections.Generic; | ||
using System.Net; | ||
|
||
namespace ArangoDBNetStandard.DatabaseApi | ||
{ | ||
/// <summary> | ||
/// Represents the content of the response returned | ||
/// by an endpoint that gets the list of databases. | ||
/// </summary> | ||
public class ListDatabaseResult | ||
{ | ||
/// <summary> | ||
/// Indicates whether an error occurred (false in this case). | ||
/// </summary> | ||
public bool Error { get; set; } | ||
|
||
/// <summary> | ||
/// The HTTP status code. | ||
/// </summary> | ||
public HttpStatusCode Code { get; set; } | ||
|
||
/// <summary> | ||
/// The list of databases. | ||
/// </summary> | ||
public IEnumerable<string> Result { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
- [ ] POST/_api/database Create database | ||
- [X] GET/_api/database List of databases | ||
- [X] POST/_api/database Create database | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have tests yet for Create database? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll answer my own question - as far as I can tell, we haven't done the proper implementation for Create database yet so we shouldn't check it off in the task list yet. Can you uncheck it for now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep I will do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we do not have an explicit test for create database, most (if not all) the per-test-class fixtures use the method the create a test database. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the criteria for marking a task complete is that we have implemented both the endpoint and tests of the endpoint. Those methods existed for use in other tests but there are no tests explicitly for them yet. |
||
- [ ] 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rossmills99 Maybe this should be named
GetDatabasesAsync
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think I agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will create a new issue for that.