Skip to content

Commit c35c505

Browse files
authored
fix: Replaced useless .ContinueWith in Api by direct call (#108) (#110)
1 parent 126a7be commit c35c505

21 files changed

+95
-105
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
### Bug Fixes
77
1. [#106](https://github.com/influxdata/influxdb-client-csharp/pull/106): Fixed serialization of `\n`, `\r` and `\t` to Line Protocol, `=` is valid sign for measurement name
8+
1. [#108](https://github.com/influxdata/influxdb-client-csharp/issues/108): Replaced useless .ContinueWith in Api by direct call
89

910
## 1.9.0 [2020-06-19]
1011

Client.Legacy/FluxClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ public async Task<string> VersionAsync()
389389
{
390390
try
391391
{
392-
var response = ExecuteAsync(PingRequest());
392+
var response = await ExecuteAsync(PingRequest());
393393

394-
return await response.ContinueWith(t => GetVersion(t.Result));
394+
return GetVersion(response);
395395
}
396396
catch (Exception e)
397397
{

Client.Test/ItBucketsApiTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public void CloneBucketNotFound()
6969
var ioe = Assert.ThrowsAsync<AggregateException>(async () =>
7070
await _bucketsApi.CloneBucketAsync(GenerateName("bucket"), "020f755c3c082000"));
7171

72-
Assert.AreEqual(typeof(HttpException), ioe.InnerException.InnerException.GetType());
73-
Assert.AreEqual("bucket not found", ioe.InnerException.InnerException.Message);
72+
Assert.AreEqual(typeof(HttpException), ioe.InnerException?.GetType());
73+
Assert.AreEqual("bucket not found", ioe.InnerException?.Message);
7474
}
7575

7676
[Test]

Client.Test/ItLabelsApiTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public void CloneLabelNotFound()
5050
Assert.ThrowsAsync<AggregateException>(async () => await _labelsApi.CloneLabelAsync(GenerateName("bucket"), "020f755c3c082000"));
5151

5252
Assert.IsNotNull(exception);
53-
Assert.AreEqual(typeof(HttpException), exception.InnerException.InnerException.GetType());
54-
Assert.AreEqual("label not found", exception.InnerException.InnerException.Message);
53+
Assert.AreEqual(typeof(HttpException), exception.InnerException.GetType());
54+
Assert.AreEqual("label not found", exception.InnerException.Message);
5555
}
5656

5757
[Test]
@@ -99,11 +99,11 @@ public async Task DeleteLabel()
9999
// delete user
100100
await _labelsApi.DeleteLabelAsync(createdLabel);
101101

102-
var exception = Assert.ThrowsAsync<AggregateException>(async () => await _labelsApi.FindLabelByIdAsync(createdLabel.Id));
102+
var exception = Assert.ThrowsAsync<HttpException>(async () => await _labelsApi.FindLabelByIdAsync(createdLabel.Id));
103103

104104
Assert.IsNotNull(exception);
105-
Assert.AreEqual("label not found", exception.InnerException.Message);
106-
Assert.AreEqual(typeof(HttpException), exception.InnerException.GetType());
105+
Assert.AreEqual("label not found", exception.Message);
106+
Assert.AreEqual(typeof(HttpException), exception.GetType());
107107
}
108108

109109
[Test]
@@ -122,11 +122,11 @@ public async Task FindLabelById()
122122
[Test]
123123
public void FindLabelByIdNull()
124124
{
125-
var exception = Assert.ThrowsAsync<AggregateException>(async () => await _labelsApi.FindLabelByIdAsync("020f755c3c082000"));
125+
var exception = Assert.ThrowsAsync<HttpException>(async () => await _labelsApi.FindLabelByIdAsync("020f755c3c082000"));
126126

127127
Assert.IsNotNull(exception);
128-
Assert.AreEqual("label not found", exception.InnerException.Message);
129-
Assert.AreEqual(typeof(HttpException), exception.InnerException.GetType());
128+
Assert.AreEqual("label not found", exception.Message);
129+
Assert.AreEqual(typeof(HttpException), exception.GetType());
130130
}
131131

132132
[Test]

Client.Test/ItNotificationEndpointsApiTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,27 +431,27 @@ public void CloneNotFound()
431431
var ioe = Assert.ThrowsAsync<AggregateException>(async () => await _notificationEndpointsApi
432432
.CloneSlackEndpointAsync("not-found-cloned", "token", "020f755c3c082000"));
433433

434-
Assert.AreEqual("notification endpoint not found for key \"020f755c3c082000\"", ioe.InnerException?.InnerException?.Message);
434+
Assert.AreEqual("notification endpoint not found for key \"020f755c3c082000\"", ioe.InnerException?.Message);
435435

436436
ioe = Assert.ThrowsAsync<AggregateException>(async () => await _notificationEndpointsApi
437437
.ClonePagerDutyEndpointAsync("not-found-cloned", "token", "020f755c3c082000"));
438438

439-
Assert.AreEqual("notification endpoint not found for key \"020f755c3c082000\"", ioe.InnerException?.InnerException?.Message);
439+
Assert.AreEqual("notification endpoint not found for key \"020f755c3c082000\"", ioe.InnerException?.Message);
440440

441441
ioe = Assert.ThrowsAsync<AggregateException>(async () => await _notificationEndpointsApi
442442
.CloneHttpEndpointAsync("not-found-cloned", "020f755c3c082000"));
443443

444-
Assert.AreEqual("notification endpoint not found for key \"020f755c3c082000\"", ioe.InnerException?.InnerException?.Message);
444+
Assert.AreEqual("notification endpoint not found for key \"020f755c3c082000\"", ioe.InnerException?.Message);
445445

446446
ioe = Assert.ThrowsAsync<AggregateException>(async () => await _notificationEndpointsApi
447447
.CloneHttpEndpointBearerAsync("not-found-cloned", "token", "020f755c3c082000"));
448448

449-
Assert.AreEqual("notification endpoint not found for key \"020f755c3c082000\"", ioe.InnerException?.InnerException?.Message);
449+
Assert.AreEqual("notification endpoint not found for key \"020f755c3c082000\"", ioe.InnerException?.Message);
450450

451451
ioe = Assert.ThrowsAsync<AggregateException>(async () => await _notificationEndpointsApi
452452
.CloneHttpEndpointBasicAuthAsync("not-found-cloned", "username", "password", "020f755c3c082000"));
453453

454-
Assert.AreEqual("notification endpoint not found for key \"020f755c3c082000\"", ioe.InnerException?.InnerException?.Message);
454+
Assert.AreEqual("notification endpoint not found for key \"020f755c3c082000\"", ioe.InnerException?.Message);
455455
}
456456

457457
[Test]

Client.Test/ItSourcesApiTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ public async Task FindBucketsBySource()
137137
[Test]
138138
public void FindBucketsBySourceByUnknownSource()
139139
{
140-
var nfe = Assert.ThrowsAsync<AggregateException>(async () =>
140+
var nfe = Assert.ThrowsAsync<HttpException>(async () =>
141141
await _sourcesApi.FindBucketsBySourceIdAsync("020f755c3d082000"));
142142

143143
Assert.IsNotNull(nfe);
144-
Assert.AreEqual("source not found", nfe.InnerException.Message);
145-
Assert.AreEqual(typeof(HttpException), nfe.InnerException.GetType());
144+
Assert.AreEqual("source not found", nfe.Message);
145+
Assert.AreEqual(typeof(HttpException), nfe.GetType());
146146
}
147147

148148
[Test]

Client.Test/ItTasksApiTest.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,10 @@ public async Task GetLogs()
331331
[Test]
332332
public void GetLogsNotExist()
333333
{
334-
var ioe = Assert.ThrowsAsync<AggregateException>(async () => await _tasksApi.GetLogsAsync("020f755c3c082000"));
334+
var ioe = Assert.ThrowsAsync<HttpException>(async () => await _tasksApi.GetLogsAsync("020f755c3c082000"));
335335

336-
Assert.NotNull(ioe.InnerException, "ioe.InnerException != null");
337-
Assert.AreEqual("failed to find task logs: task not found", ioe.InnerException.Message);
336+
Assert.NotNull(ioe, "ioe.InnerException != null");
337+
Assert.AreEqual("failed to find task logs: task not found", ioe.Message);
338338
}
339339

340340
[Test]
@@ -372,10 +372,10 @@ public async Task GetRunLogsNotExist()
372372
{
373373
var task = await _tasksApi.CreateTaskEveryAsync(GenerateName("it task"), TaskFlux, "1s", _organization);
374374

375-
var ioe = Assert.ThrowsAsync<AggregateException>(async () => await _tasksApi.GetRunLogsAsync(task.Id, "020f755c3c082000"));
375+
var ioe = Assert.ThrowsAsync<HttpException>(async () => await _tasksApi.GetRunLogsAsync(task.Id, "020f755c3c082000"));
376376

377-
Assert.NotNull(ioe.InnerException, "ioe.InnerException != null");
378-
Assert.AreEqual("failed to find task logs: run not found", ioe.InnerException.Message);
377+
Assert.NotNull(ioe, "ioe.InnerException != null");
378+
Assert.AreEqual("failed to find task logs: run not found", ioe.Message);
379379
}
380380

381381
[Test]
@@ -570,11 +570,11 @@ public async Task RunsLimit()
570570
[Test]
571571
public void RunsNotExist()
572572
{
573-
var ioe = Assert.ThrowsAsync<AggregateException>(async () =>
573+
var ioe = Assert.ThrowsAsync<HttpException>(async () =>
574574
await _tasksApi.GetRunsAsync("020f755c3c082000", _organization.Id));
575575

576-
Assert.NotNull(ioe.InnerException, "ioe.InnerException != null");
577-
Assert.AreEqual("failed to find runs: task not found", ioe.InnerException.Message);
576+
Assert.NotNull(ioe, "ioe.InnerException != null");
577+
Assert.AreEqual("failed to find runs: task not found", ioe.Message);
578578
}
579579

580580
[Test]

Client.Test/ItUsersApiTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public async Task FindUsers()
8484

8585
var users = await _usersApi.FindUsersAsync();
8686

87-
Assert.AreEqual(users.Count, size + 1);
87+
Assert.AreEqual(size + 1, users.Count);
8888
}
8989

9090
[Test]

Client/AuthorizationsApi.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ public async Task<List<Authorization>> FindAuthorizationsByUserNameAsync(string
186186

187187
private async Task<List<Authorization>> FindAuthorizationsByAsync(string userId, string userName)
188188
{
189-
return await _service.GetAuthorizationsAsync(null, userId, userName)
190-
.ContinueWith(t => t.Result._Authorizations);
189+
return (await _service.GetAuthorizationsAsync(null, userId, userName))._Authorizations;
191190
}
192191
}
193192
}

Client/BucketsApi.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public async Task<Bucket> CloneBucketAsync(string clonedName, string bucketId)
155155
Arguments.CheckNonEmptyString(clonedName, nameof(clonedName));
156156
Arguments.CheckNonEmptyString(bucketId, nameof(bucketId));
157157

158-
return await FindBucketByIdAsync(bucketId).ContinueWith(t => t.Result)
158+
return await FindBucketByIdAsync(bucketId)
159159
.ContinueWith(t => CloneBucketAsync(clonedName, t.Result)).Unwrap();
160160
}
161161

@@ -209,9 +209,8 @@ public async Task<Bucket> FindBucketByNameAsync(string bucketName)
209209
{
210210
Arguments.CheckNonEmptyString(bucketName, nameof(bucketName));
211211

212-
return await _service
213-
.GetBucketsAsync(null, null, null, null, null, bucketName)
214-
.ContinueWith(t => t.Result._Buckets.FirstOrDefault());
212+
return (await _service.GetBucketsAsync(null, null, null, null, null, bucketName))
213+
._Buckets.FirstOrDefault();
215214
}
216215

217216
/// <summary>
@@ -233,9 +232,7 @@ public async Task<List<Bucket>> FindBucketsByOrganizationAsync(Organization orga
233232
/// <returns>A list of buckets</returns>
234233
public async Task<List<Bucket>> FindBucketsByOrgNameAsync(string orgName)
235234
{
236-
var buckets = FindBucketsAsync(orgName, new FindOptions());
237-
238-
return await buckets.ContinueWith(t => t.Result._Buckets);
235+
return (await FindBucketsAsync(orgName, new FindOptions()))._Buckets;
239236
}
240237

241238
/// <summary>
@@ -280,7 +277,7 @@ public async Task<List<ResourceMember>> GetMembersAsync(string bucketId)
280277
{
281278
Arguments.CheckNonEmptyString(bucketId, nameof(bucketId));
282279

283-
return await _service.GetBucketsIDMembersAsync(bucketId).ContinueWith(t => t.Result.Users);
280+
return (await _service.GetBucketsIDMembersAsync(bucketId)).Users;
284281
}
285282

286283
/// <summary>
@@ -362,7 +359,7 @@ public async Task<List<ResourceOwner>> GetOwnersAsync(string bucketId)
362359
{
363360
Arguments.CheckNonEmptyString(bucketId, nameof(bucketId));
364361

365-
return await _service.GetBucketsIDOwnersAsync(bucketId).ContinueWith(t => t.Result.Users);
362+
return (await _service.GetBucketsIDOwnersAsync(bucketId)).Users;
366363
}
367364

368365
/// <summary>
@@ -444,7 +441,7 @@ public async Task<List<Label>> GetLabelsAsync(string bucketId)
444441
{
445442
Arguments.CheckNonEmptyString(bucketId, nameof(bucketId));
446443

447-
return await _service.GetBucketsIDLabelsAsync(bucketId).ContinueWith(t => t.Result.Labels);
444+
return (await _service.GetBucketsIDLabelsAsync(bucketId)).Labels;
448445
}
449446

450447
/// <summary>
@@ -474,7 +471,7 @@ public async Task<Label> AddLabelAsync(string labelId, string bucketId)
474471

475472
var mapping = new LabelMapping(labelId);
476473

477-
return await _service.PostBucketsIDLabelsAsync(bucketId, mapping).ContinueWith(t => t.Result.Label);
474+
return (await _service.PostBucketsIDLabelsAsync(bucketId, mapping)).Label;
478475
}
479476

480477
/// <summary>

0 commit comments

Comments
 (0)