-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #358 from arangodb/feature-3.8/DE-194-support-for-…
…views-api Support for Views API
- Loading branch information
Showing
21 changed files
with
1,044 additions
and
2 deletions.
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
arangodb-net-standard.Test/ViewApi/ViewApiClientTest.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,141 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using ArangoDBNetStandard; | ||
using ArangoDBNetStandard.ViewApi; | ||
using ArangoDBNetStandard.ViewApi.Models; | ||
using ArangoDBNetStandard.Transport; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace ArangoDBNetStandardTest.ViewApi | ||
{ | ||
public class ViewApiClientTest : IClassFixture<ViewApiClientTestFixture>, IAsyncLifetime | ||
{ | ||
private ViewApiClient _viewApi; | ||
private ArangoDBClient _adb; | ||
|
||
public ViewApiClientTest(ViewApiClientTestFixture fixture) | ||
{ | ||
_adb = fixture.ArangoDBClient; | ||
_viewApi = _adb.View; | ||
} | ||
|
||
public Task InitializeAsync() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
[Fact] | ||
public async Task GetAllViewsAsync_ShouldSucceed() | ||
{ | ||
var testName = "GetAllViewsAsyncShouldSucceedView"; | ||
var createResponse = await _viewApi.PostCreateViewAsync( | ||
new ViewDetails() | ||
{ | ||
Name = testName, | ||
Type = "arangosearch" | ||
}); | ||
var res = await _viewApi.GetAllViewsAsync(); | ||
|
||
Assert.Equal(HttpStatusCode.OK, res.Code); | ||
Assert.False(res.Error); | ||
Assert.NotNull(res.Result); | ||
Assert.NotEmpty(res.Result); | ||
} | ||
|
||
[Fact] | ||
public async Task PostCreateViewAsync_ShouldSucceed() | ||
{ | ||
var testName = "PostCreateViewAsyncShouldSucceedView"; | ||
var res = await _viewApi.PostCreateViewAsync( | ||
new ViewDetails() | ||
{ | ||
Name = testName, | ||
Type = "arangosearch" | ||
}); | ||
Assert.NotNull(res); | ||
Assert.NotNull(res.GloballyUniqueId); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteViewAsync_ShouldSucceed() | ||
{ | ||
var testName = "DeleteViewAsyncShouldSucceedView"; | ||
var createResponse = await _viewApi.PostCreateViewAsync( | ||
new ViewDetails() | ||
{ | ||
Name = testName, | ||
Type = "arangosearch" | ||
}); | ||
var res = await _viewApi.DeleteViewAsync(testName); | ||
|
||
Assert.Equal(HttpStatusCode.OK, res.Code); | ||
Assert.False(res.Error); | ||
Assert.True(res.Result); | ||
} | ||
|
||
[Fact] | ||
public async Task GetViewAsync_ShouldSucceed() | ||
{ | ||
var testName = "GetViewAsyncShouldSucceedView"; | ||
var createResponse = await _viewApi.PostCreateViewAsync( | ||
new ViewDetails() | ||
{ | ||
Name = testName, | ||
Type = "arangosearch" | ||
}); | ||
var res = await _viewApi.GetViewAsync(testName); | ||
|
||
Assert.Equal(HttpStatusCode.OK, res.Code); | ||
Assert.False(res.Error); | ||
} | ||
|
||
[Fact] | ||
public async Task GetViewPropertiesAsync_ShouldSucceed() | ||
{ | ||
var testName = "GetViewPropertiesAsyncShouldSucceedView"; | ||
var createResponse = await _viewApi.PostCreateViewAsync( | ||
new ViewDetails() | ||
{ | ||
Name = testName, | ||
Type = "arangosearch" | ||
}); | ||
var res = await _viewApi.GetViewPropertiesAsync(testName); | ||
|
||
Assert.Equal(HttpStatusCode.OK, res.Code); | ||
Assert.False(res.Error); | ||
Assert.NotNull(res.GloballyUniqueId); | ||
} | ||
|
||
[Fact] | ||
public async Task PutRenameViewAsync_ShouldSucceed() | ||
{ | ||
var testName = "PutRenameViewAsyncShouldSucceedView"; | ||
var newName = "PutRenameViewAsyncShouldSucceedViewRenamed"; | ||
var createResponse = await _viewApi.PostCreateViewAsync( | ||
new ViewDetails() | ||
{ | ||
Name = testName, | ||
Type = "arangosearch" | ||
}); | ||
var res = await _viewApi.PutRenameViewAsync( | ||
testName, | ||
new PutRenameViewBody() | ||
{ | ||
Name = newName | ||
}); | ||
|
||
Assert.Equal(HttpStatusCode.OK, res.Code); | ||
Assert.False(res.Error); | ||
Assert.NotNull(res.GloballyUniqueId); | ||
Assert.Equal(newName, res.Name); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
arangodb-net-standard.Test/ViewApi/ViewApiClientTestFixture.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,46 @@ | ||
using ArangoDBNetStandard; | ||
using ArangoDBNetStandard.CollectionApi.Models; | ||
using ArangoDBNetStandard.ViewApi.Models; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace ArangoDBNetStandardTest.ViewApi | ||
{ | ||
public class ViewApiClientTestFixture : ApiClientTestFixtureBase | ||
{ | ||
public ArangoDBClient ArangoDBClient { get; internal set; } | ||
|
||
public ViewApiClientTestFixture() | ||
{ | ||
} | ||
|
||
public override async Task InitializeAsync() | ||
{ | ||
await base.InitializeAsync(); | ||
|
||
Console.WriteLine("ViewApiClientTestFixture.InitializeAsync() started."); | ||
|
||
string dbName = nameof(ViewApiClientTestFixture); | ||
await CreateDatabase(dbName); | ||
Console.WriteLine("Database " + dbName + " created successfully"); | ||
|
||
ArangoDBClient = GetArangoDBClient(dbName); | ||
try | ||
{ | ||
var dbRes = await ArangoDBClient.Database.GetCurrentDatabaseInfoAsync(); | ||
if (dbRes.Error) | ||
throw new Exception("GetCurrentDatabaseInfoAsync failed: " + dbRes.Code.ToString()); | ||
else | ||
{ | ||
Console.WriteLine("In database " + dbRes.Result.Name); | ||
} | ||
} | ||
catch (ApiErrorException ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
throw ex; | ||
} | ||
|
||
} | ||
} | ||
} |
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,79 @@ | ||
using ArangoDBNetStandard.ViewApi.Models; | ||
using System.Threading.Tasks; | ||
|
||
namespace ArangoDBNetStandard.ViewApi | ||
{ | ||
/// <summary> | ||
/// Defines a client to access the ArangoDB API for Views. | ||
/// </summary> | ||
public interface IViewApiClient | ||
{ | ||
/// <summary> | ||
/// Gets a list of all views in a database, | ||
/// regardless of their type. | ||
/// GET /_api/view | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<GetAllViewsResponse> GetAllViewsAsync(); | ||
|
||
/// <summary> | ||
/// Create a new View | ||
/// POST /_api/view | ||
/// </summary> | ||
/// <param name="body">The body of the request containing required properties.</param> | ||
/// <returns></returns> | ||
Task<ViewResponse> PostCreateViewAsync(ViewDetails body); | ||
|
||
/// <summary> | ||
/// Delete / drop a view | ||
/// DELETE /_api/view/{view-name} | ||
/// </summary> | ||
/// <param name="viewNameOrId">The name or identifier of the view to drop.</param> | ||
/// <returns></returns> | ||
Task<DeleteViewResponse> DeleteViewAsync(string viewNameOrId); | ||
|
||
/// <summary> | ||
/// Get information about a view | ||
/// GET /_api/view/{view-name} | ||
/// </summary> | ||
/// <param name="viewNameOrId">The name or identifier of the view to drop.</param> | ||
/// <returns></returns> | ||
Task<GetViewResponse> GetViewAsync(string viewNameOrId); | ||
|
||
/// <summary> | ||
/// Get the properties of a view | ||
/// GET /_api/view/{view-name}/properties | ||
/// </summary> | ||
/// <param name="viewNameOrId">The name or identifier of the view to drop.</param> | ||
/// <returns></returns> | ||
Task<GetViewPropertiesResponse> GetViewPropertiesAsync(string viewNameOrId); | ||
|
||
/// <summary> | ||
/// Partially changes properties of a view | ||
/// PATCH /_api/view/{view-name}/properties | ||
/// </summary> | ||
/// <param name="viewNameOrId">The name or identifier of the view.</param> | ||
/// <param name="body">The body of the request containing required properties.</param> | ||
/// <returns></returns> | ||
Task<ViewResponse> PatchViewPropertiesAsync(string viewNameOrId, ViewDetails body); | ||
|
||
/// <summary> | ||
/// Changes all properties of a view | ||
/// PUT /_api/view/{view-name}/properties | ||
/// </summary> | ||
/// <param name="viewName">The name of the view.</param> | ||
/// <param name="body">The body of the request containing required properties.</param> | ||
/// <returns></returns> | ||
Task<ViewResponse> PutViewPropertiesAsync(string viewName, ViewDetails body); | ||
|
||
/// <summary> | ||
/// Renames a view | ||
/// PUT /_api/view/{view-name}/rename | ||
/// </summary> | ||
/// <param name="viewName">The name of the view.</param> | ||
/// <param name="body">The body of the request containing required properties.</param> | ||
/// <returns></returns> | ||
/// <remarks>Note: This method is not available in a cluster.</remarks> | ||
Task<PutRenameViewResponse> PutRenameViewAsync(string viewName, PutRenameViewBody body); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
arangodb-net-standard/ViewApi/Models/DeleteViewResponse.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,14 @@ | ||
namespace ArangoDBNetStandard.ViewApi.Models | ||
{ | ||
/// <summary> | ||
/// Response from <see cref="IViewApiClient.DeleteViewAsync(string)"/> | ||
/// </summary> | ||
public class DeleteViewResponse :ResponseBase | ||
{ | ||
/// <summary> | ||
/// Indicates whether the delete | ||
/// operation was successful. | ||
/// </summary> | ||
public bool Result { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
arangodb-net-standard/ViewApi/Models/GetAllViewsResponse.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,15 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ArangoDBNetStandard.ViewApi.Models | ||
{ | ||
/// <summary> | ||
/// Response from <see cref="IViewApiClient.GetAllViewsAsync"/> | ||
/// </summary> | ||
public class GetAllViewsResponse : ResponseBase | ||
{ | ||
/// <summary> | ||
/// List of views | ||
/// </summary> | ||
public List<ViewSummary> Result { get; set; } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
arangodb-net-standard/ViewApi/Models/GetViewPropertiesResponse.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,20 @@ | ||
using System.Net; | ||
|
||
namespace ArangoDBNetStandard.ViewApi.Models | ||
{ | ||
/// <summary> | ||
/// Response from <see cref="IViewApiClient.GetViewPropertiesAsync(string)"/> | ||
/// </summary> | ||
public class GetViewPropertiesResponse : ViewResponse | ||
{ | ||
/// <summary> | ||
/// Indicates whether an error occurred | ||
/// </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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Net; | ||
|
||
namespace ArangoDBNetStandard.ViewApi.Models | ||
{ | ||
/// <summary> | ||
/// Response from <see cref="IViewApiClient.GetViewAsync(string)"/> | ||
/// </summary> | ||
public class GetViewResponse : ViewSummary | ||
{ | ||
/// <summary> | ||
/// Indicates whether an error occurred | ||
/// </summary> | ||
public bool Error { get; set; } | ||
|
||
/// <summary> | ||
/// The HTTP status code. | ||
/// </summary> | ||
public HttpStatusCode Code { get; set; } | ||
} | ||
} |
Oops, something went wrong.