Skip to content

Commit 54eff03

Browse files
authored
Merge pull request #377 from DiscoPYF/simplifyErrorHandlingIndexTestFixture
Simplify error handling in test fixture of Index API client
2 parents ecd9bf1 + 65ae1bc commit 54eff03

File tree

6 files changed

+49
-58
lines changed

6 files changed

+49
-58
lines changed

arangodb-net-standard.Test/AnalyzerApi/AnalyzerApiClientTest.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
3-
using System.Net;
4-
using System.Threading.Tasks;
5-
using ArangoDBNetStandard;
1+
using ArangoDBNetStandard;
62
using ArangoDBNetStandard.AnalyzerApi;
73
using ArangoDBNetStandard.AnalyzerApi.Models;
8-
using ArangoDBNetStandard.Transport;
9-
using Moq;
4+
using System.Collections.Generic;
5+
using System.Net;
6+
using System.Threading.Tasks;
107
using Xunit;
118

12-
namespace ArangoDBNetStandardTest.IndexApi
9+
namespace ArangoDBNetStandardTest.AnalyzerApi
1310
{
1411
public class AnalyzerApiClientTest : IClassFixture<AnalyzerApiClientTestFixture>, IAsyncLifetime
1512
{

arangodb-net-standard.Test/AnalyzerApi/AnalyzerApiClientTestFixture.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using ArangoDBNetStandard;
2-
using ArangoDBNetStandard.CollectionApi.Models;
3-
using ArangoDBNetStandard.AnalyzerApi.Models;
42
using System;
53
using System.Threading.Tasks;
64

7-
namespace ArangoDBNetStandardTest.IndexApi
5+
namespace ArangoDBNetStandardTest.AnalyzerApi
86
{
97
public class AnalyzerApiClientTestFixture : ApiClientTestFixtureBase
108
{

arangodb-net-standard.Test/IndexApi/IndexApiClientTestFixture.cs

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class IndexApiClientTestFixture : ApiClientTestFixtureBase
1111
public ArangoDBClient ArangoDBClient { get; internal set; }
1212
public string TestCollectionName { get; internal set; } = "OurIndexTestCollection";
1313
public string TestIndexName { get; internal set; } = "OurIndexTestCollection_FirstIndex";
14-
public string TestIndexId { get; internal set; }
14+
public string TestIndexId { get; internal set; }
1515

1616
public IndexApiClientTestFixture()
1717
{
@@ -24,52 +24,33 @@ public override async Task InitializeAsync()
2424
await CreateDatabase(dbName);
2525
Console.WriteLine("Database " + dbName + " created successfully");
2626
ArangoDBClient = GetArangoDBClient(dbName);
27-
try
28-
{
29-
var dbRes = await ArangoDBClient.Database.GetCurrentDatabaseInfoAsync();
30-
if (dbRes.Error)
31-
throw new Exception("GetCurrentDatabaseInfoAsync failed: " + dbRes.Code.ToString());
32-
else
27+
28+
var dbRes = await ArangoDBClient.Database.GetCurrentDatabaseInfoAsync();
29+
30+
Console.WriteLine("In database " + dbRes.Result.Name);
31+
var colRes = await ArangoDBClient.Collection.PostCollectionAsync(
32+
new PostCollectionBody() { Name = TestCollectionName });
33+
34+
Console.WriteLine("Collection " + TestCollectionName + " created successfully");
35+
var idxRes = await ArangoDBClient.Index.PostIndexAsync(
36+
IndexType.Persistent,
37+
new PostIndexQuery()
3338
{
34-
Console.WriteLine("In database " + dbRes.Result.Name);
35-
var colRes = await ArangoDBClient.Collection.PostCollectionAsync(new PostCollectionBody() { Name = TestCollectionName });
36-
if (colRes.Error)
37-
throw new Exception("PostCollectionAsync failed: " + colRes.Code.ToString());
38-
else
39-
{
40-
Console.WriteLine("Collection " + TestCollectionName + " created successfully");
41-
var idxRes = await ArangoDBClient.Index.PostIndexAsync(
42-
IndexType.Persistent,
43-
new PostIndexQuery()
44-
{
45-
CollectionName = TestCollectionName,
46-
},
47-
new PostIndexBody()
48-
{
49-
Name = TestIndexName,
50-
Fields = new string[] { "TestName" },
51-
Unique = true
52-
});
53-
if (idxRes.Error)
54-
throw new Exception("PostIndexAsync failed: " + idxRes.Code.ToString());
55-
else
56-
{
57-
TestIndexId = idxRes.Id;
58-
TestIndexName = idxRes.Name;
59-
60-
Console.WriteLine("DB: " + dbRes.Result.Name);
61-
Console.WriteLine("Collection: " + TestCollectionName);
62-
Console.WriteLine("Index: " + string.Format("{0} - {1}",TestIndexId, TestIndexName));
63-
}
64-
}
65-
}
66-
}
67-
catch (ApiErrorException ex)
68-
{
69-
Console.WriteLine(ex.Message);
70-
throw ex;
71-
}
39+
CollectionName = TestCollectionName,
40+
},
41+
new PostIndexBody()
42+
{
43+
Name = TestIndexName,
44+
Fields = new string[] { "TestName" },
45+
Unique = true
46+
});
47+
48+
TestIndexId = idxRes.Id;
49+
TestIndexName = idxRes.Name;
7250

51+
Console.WriteLine("DB: " + dbRes.Result.Name);
52+
Console.WriteLine("Collection: " + TestCollectionName);
53+
Console.WriteLine("Index: " + string.Format("{0} - {1}", TestIndexId, TestIndexName));
7354
}
7455
}
7556
}

arangodb-net-standard/CollectionApi/Models/PostCollectionResponse.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ namespace ArangoDBNetStandard.CollectionApi.Models
44
{
55
public class PostCollectionResponse
66
{
7+
/// <summary>
8+
/// Always false.
9+
/// </summary>
10+
/// <remarks>
11+
/// To handle errors, catch <see cref="ApiErrorException"/>
12+
/// thrown by API client methods.
13+
/// </remarks>
714
public bool Error { get; set; }
815

916
public HttpStatusCode Code { get; set; }

arangodb-net-standard/DatabaseApi/Models/GetDatabaseInfoResponse.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ namespace ArangoDBNetStandard.DatabaseApi.Models
88
public class GetCurrentDatabaseInfoResponse
99
{
1010
/// <summary>
11-
/// Indicates whether an error occurred (false in this case).
11+
/// Always false.
1212
/// </summary>
13+
/// <remarks>
14+
/// To handle errors, catch <see cref="ApiErrorException"/>
15+
/// thrown by API client methods.
16+
/// </remarks>
1317
public bool Error { get; set; }
1418

1519
/// <summary>

arangodb-net-standard/IndexApi/Models/ResponseBase.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ namespace ArangoDBNetStandard.IndexApi.Models
88
public class ResponseBase
99
{
1010
/// <summary>
11-
/// Indicates whether an error occurred
11+
/// Always false.
1212
/// </summary>
13+
/// <remarks>
14+
/// To handle errors, catch <see cref="ApiErrorException"/>
15+
/// thrown by API client methods.
16+
/// </remarks>
1317
public bool Error { get; set; }
1418

1519
/// <summary>

0 commit comments

Comments
 (0)