Skip to content

Simplify error handling in test fixture of Index API client #377

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions arangodb-net-standard.Test/AnalyzerApi/AnalyzerApiClientTest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using ArangoDBNetStandard;
using ArangoDBNetStandard;
using ArangoDBNetStandard.AnalyzerApi;
using ArangoDBNetStandard.AnalyzerApi.Models;
using ArangoDBNetStandard.Transport;
using Moq;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Xunit;

namespace ArangoDBNetStandardTest.IndexApi
namespace ArangoDBNetStandardTest.AnalyzerApi
{
public class AnalyzerApiClientTest : IClassFixture<AnalyzerApiClientTestFixture>, IAsyncLifetime
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using ArangoDBNetStandard;
using ArangoDBNetStandard.CollectionApi.Models;
using ArangoDBNetStandard.AnalyzerApi.Models;
using System;
using System.Threading.Tasks;

namespace ArangoDBNetStandardTest.IndexApi
namespace ArangoDBNetStandardTest.AnalyzerApi
{
public class AnalyzerApiClientTestFixture : ApiClientTestFixtureBase
{
Expand Down
71 changes: 26 additions & 45 deletions arangodb-net-standard.Test/IndexApi/IndexApiClientTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class IndexApiClientTestFixture : ApiClientTestFixtureBase
public ArangoDBClient ArangoDBClient { get; internal set; }
public string TestCollectionName { get; internal set; } = "OurIndexTestCollection";
public string TestIndexName { get; internal set; } = "OurIndexTestCollection_FirstIndex";
public string TestIndexId { get; internal set; }
public string TestIndexId { get; internal set; }

public IndexApiClientTestFixture()
{
Expand All @@ -24,52 +24,33 @@ public override async Task InitializeAsync()
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

var dbRes = await ArangoDBClient.Database.GetCurrentDatabaseInfoAsync();

Console.WriteLine("In database " + dbRes.Result.Name);
var colRes = await ArangoDBClient.Collection.PostCollectionAsync(
new PostCollectionBody() { Name = TestCollectionName });

Console.WriteLine("Collection " + TestCollectionName + " created successfully");
var idxRes = await ArangoDBClient.Index.PostIndexAsync(
IndexType.Persistent,
new PostIndexQuery()
{
Console.WriteLine("In database " + dbRes.Result.Name);
var colRes = await ArangoDBClient.Collection.PostCollectionAsync(new PostCollectionBody() { Name = TestCollectionName });
if (colRes.Error)
throw new Exception("PostCollectionAsync failed: " + colRes.Code.ToString());
else
{
Console.WriteLine("Collection " + TestCollectionName + " created successfully");
var idxRes = await ArangoDBClient.Index.PostIndexAsync(
IndexType.Persistent,
new PostIndexQuery()
{
CollectionName = TestCollectionName,
},
new PostIndexBody()
{
Name = TestIndexName,
Fields = new string[] { "TestName" },
Unique = true
});
if (idxRes.Error)
throw new Exception("PostIndexAsync failed: " + idxRes.Code.ToString());
else
{
TestIndexId = idxRes.Id;
TestIndexName = idxRes.Name;

Console.WriteLine("DB: " + dbRes.Result.Name);
Console.WriteLine("Collection: " + TestCollectionName);
Console.WriteLine("Index: " + string.Format("{0} - {1}",TestIndexId, TestIndexName));
}
}
}
}
catch (ApiErrorException ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
CollectionName = TestCollectionName,
},
new PostIndexBody()
{
Name = TestIndexName,
Fields = new string[] { "TestName" },
Unique = true
});

TestIndexId = idxRes.Id;
TestIndexName = idxRes.Name;

Console.WriteLine("DB: " + dbRes.Result.Name);
Console.WriteLine("Collection: " + TestCollectionName);
Console.WriteLine("Index: " + string.Format("{0} - {1}", TestIndexId, TestIndexName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ namespace ArangoDBNetStandard.CollectionApi.Models
{
public class PostCollectionResponse
{
/// <summary>
/// Always false.
/// </summary>
/// <remarks>
/// To handle errors, catch <see cref="ApiErrorException"/>
/// thrown by API client methods.
/// </remarks>
public bool Error { get; set; }

public HttpStatusCode Code { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ namespace ArangoDBNetStandard.DatabaseApi.Models
public class GetCurrentDatabaseInfoResponse
{
/// <summary>
/// Indicates whether an error occurred (false in this case).
/// Always false.
/// </summary>
/// <remarks>
/// To handle errors, catch <see cref="ApiErrorException"/>
/// thrown by API client methods.
/// </remarks>
public bool Error { get; set; }

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion arangodb-net-standard/IndexApi/Models/ResponseBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ namespace ArangoDBNetStandard.IndexApi.Models
public class ResponseBase
{
/// <summary>
/// Indicates whether an error occurred
/// Always false.
/// </summary>
/// <remarks>
/// To handle errors, catch <see cref="ApiErrorException"/>
/// thrown by API client methods.
/// </remarks>
public bool Error { get; set; }

/// <summary>
Expand Down