-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
251 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using ArangoDBNetStandard; | ||
using ArangoDBNetStandard.UserApi; | ||
using ArangoDBNetStandard.UserApi.Models; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace ArangoDBNetStandardTest.UserApi | ||
{ | ||
public class UserApiClientTest : IClassFixture<UserApiClientTestFixture> | ||
{ | ||
private readonly IUserApiClient _userClient; | ||
|
||
private readonly UserApiClientTestFixture _fixture; | ||
|
||
public UserApiClientTest(UserApiClientTestFixture fixture) | ||
{ | ||
_userClient = fixture.ArangoClient.User; | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteUserAsync_ShouldSucceed() | ||
{ | ||
var deleteResponse = await _userClient.DeleteUserAsync( | ||
_fixture.UsernameToDelete); | ||
|
||
Assert.False(deleteResponse.Error); | ||
Assert.Equal(HttpStatusCode.Accepted, deleteResponse.Code); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteUserAsync_ShouldThrow_WhenUserDoesNotExist() | ||
{ | ||
var ex = await Assert.ThrowsAsync<ApiErrorException>(async () => | ||
await _userClient.DeleteUserAsync( | ||
nameof(DeleteUserAsync_ShouldThrow_WhenUserDoesNotExist))); | ||
|
||
Assert.True(ex.ApiError.Error); | ||
Assert.Equal(HttpStatusCode.NotFound, ex.ApiError.Code); | ||
Assert.NotNull(ex.ApiError.ErrorMessage); | ||
Assert.Equal(1703, ex.ApiError.ErrorNum); // ERROR_USER_NOT_FOUND | ||
} | ||
|
||
[Fact] | ||
public async Task PostUserAsync_ShouldSucceed() | ||
{ | ||
PostUserResponse postResponse = await _userClient.PostUserAsync( | ||
new PostUserBody() | ||
{ | ||
User = _fixture.UsernameToCreate, | ||
Passwd = "password", | ||
Extra = new Dictionary<string, object>() | ||
{ | ||
["somedata"] = "here" | ||
} | ||
}); | ||
|
||
Assert.False(postResponse.Error); | ||
Assert.Equal(HttpStatusCode.Created, postResponse.Code); | ||
Assert.Equal(_fixture.UsernameToCreate, postResponse.User); | ||
Assert.True(postResponse.Active); | ||
Assert.True(postResponse.Extra.ContainsKey("somedata")); | ||
Assert.Equal("here", postResponse.Extra["somedata"].ToString()); | ||
} | ||
|
||
[Fact] | ||
public async Task PostUserAsync_ShouldThrow_WhenUserAlreadyExist() | ||
{ | ||
var ex = await Assert.ThrowsAsync<ApiErrorException>(async () => | ||
await _userClient.PostUserAsync(new PostUserBody() | ||
{ | ||
User = _fixture.UsernameExisting, | ||
Passwd = "password", | ||
Extra = new Dictionary<string, object>() | ||
{ | ||
["somedata"] = "here" | ||
} | ||
})); | ||
|
||
Assert.True(ex.ApiError.Error); | ||
Assert.Equal(HttpStatusCode.Conflict, ex.ApiError.Code); | ||
Assert.NotNull(ex.ApiError.ErrorMessage); | ||
Assert.Equal(1702, ex.ApiError.ErrorNum); // ERROR_USER_DUPLICATE | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
arangodb-net-standard.Test/UserApi/UserApiClientTestFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using ArangoDBNetStandard; | ||
using ArangoDBNetStandard.DatabaseApi.Models; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace ArangoDBNetStandardTest.UserApi | ||
{ | ||
/// <summary> | ||
/// Provides per-test-class fixture data for <see cref="UserApiClientTest"/>. | ||
/// </summary> | ||
public class UserApiClientTestFixture : ApiClientTestFixtureBase | ||
{ | ||
public ArangoDBClient ArangoClient { get; private set; } | ||
|
||
public string UsernameToDelete { get; private set; } | ||
|
||
public string UsernameToCreate { get; private set; } | ||
|
||
public string UsernameExisting { get; private set; } | ||
|
||
public UserApiClientTestFixture() | ||
{ | ||
ArangoClient = GetArangoDBClient("_system"); | ||
UsernameToDelete = nameof(UserApiClientTestFixture) + "Delete"; | ||
UsernameToCreate = nameof(UserApiClientTestFixture) + "Post"; | ||
UsernameExisting = nameof(UserApiClientTestFixture) + "Existing"; | ||
} | ||
|
||
public override async Task InitializeAsync() | ||
{ | ||
await base.InitializeAsync(); | ||
|
||
string dbName = nameof(UserApiClientTestFixture); | ||
|
||
await CreateDatabase(dbName, new DatabaseUser[] | ||
{ | ||
new DatabaseUser() | ||
{ | ||
Username = UsernameToDelete | ||
}, | ||
new DatabaseUser() | ||
{ | ||
Username = UsernameExisting | ||
} | ||
}); | ||
|
||
_users.Add(UsernameToCreate); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ArangoDBNetStandard.UserApi.Models | ||
{ | ||
/// <summary> | ||
/// Represents a request body to create a user. | ||
/// </summary> | ||
public class PostUserBody | ||
{ | ||
/// <summary> | ||
/// The name of the user. | ||
/// </summary> | ||
public string User { get; set; } | ||
|
||
/// <summary> | ||
/// The user password. | ||
/// If no password is specified, the empty string will be used. | ||
/// If you pass the special value ARANGODB_DEFAULT_ROOT_PASSWORD, | ||
/// then the password will be set the value stored in the environment variable | ||
/// ARANGODB_DEFAULT_ROOT_PASSWORD. | ||
/// This can be used to pass an instance variable into ArangoDB. | ||
/// </summary> | ||
public string Passwd { get; set; } | ||
|
||
/// <summary> | ||
/// An optional flag that specifies whether the user is active. | ||
/// If not specified, this will default to true. | ||
/// </summary> | ||
public bool? Active { get; set; } | ||
|
||
/// <summary> | ||
/// Optional object with arbitrary extra data about the user. | ||
/// </summary> | ||
public Dictionary<string, object> Extra { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Collections.Generic; | ||
using System.Net; | ||
|
||
namespace ArangoDBNetStandard.UserApi.Models | ||
{ | ||
public class PostUserResponse | ||
{ | ||
/// <summary> | ||
/// The name of the user. | ||
/// </summary> | ||
public string User { get; set; } | ||
|
||
/// <summary> | ||
/// Whether the user is active. | ||
/// </summary> | ||
public bool Active { get; set; } | ||
|
||
/// <summary> | ||
/// Object with arbitrary extra data about the user. | ||
/// </summary> | ||
public Dictionary<string, object> Extra { get; set; } | ||
|
||
/// <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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f1fbee5
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.
Thank you so much for implementing this feature! Is there a plan to push the latest commit to Nuget? Thanks.
f1fbee5
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.
Hey @andrewmruddy , thank you for your message! I think we will probably publish a new release before the end of next month (August 2020). It should contain the full set of endpoints from the user API, which we will be completed by #258 .