Skip to content

Commit 5a8c822

Browse files
authored
refactor: Update existing service tests to use async operations
1 parent e403fe4 commit 5a8c822

File tree

53 files changed

+695
-7366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+695
-7366
lines changed
Lines changed: 72 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1-
using System;
1+
using Amazon.APIGateway;
2+
using Amazon.APIGateway.Model;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using System;
25
using System.Collections.Generic;
36
using System.Linq;
4-
using Microsoft.VisualStudio.TestTools.UnitTesting;
5-
6-
using AWSSDK_DotNet.IntegrationTests.Utils;
7-
8-
using Amazon.AWSSupport;
9-
using Amazon.AWSSupport.Model;
10-
using Amazon;
11-
using System.IO;
12-
using System.Text;
13-
using Amazon.APIGateway.Model;
14-
using Amazon.APIGateway;
7+
using System.Threading.Tasks;
158

169
namespace AWSSDK_DotNet.IntegrationTests.Tests
1710
{
1811
[TestClass]
19-
public class APIGatewayTests : TestBase<Amazon.APIGateway.AmazonAPIGatewayClient>
12+
[TestCategory("APIGateway")]
13+
public class APIGatewayTests : TestBase<AmazonAPIGatewayClient>
2014
{
2115
[ClassCleanup]
22-
public static void ClassCleanup()
16+
public static async Task ClassCleanup()
2317
{
2418
if (!string.IsNullOrEmpty(restApiId))
2519
{
26-
Client.DeleteRestApi(new DeleteRestApiRequest
20+
await Client.DeleteRestApiAsync(new DeleteRestApiRequest
2721
{
2822
RestApiId = restApiId
2923
});
@@ -38,12 +32,12 @@ public static void ClassCleanup()
3832
private static string apiDescription = "RestApi created by dotnet tests at " + timestamp;
3933

4034
[ClassInitialize]
41-
public static void ClassInitialize(TestContext testContext)
35+
public static async Task ClassInitialize(TestContext testContext)
4236
{
43-
var createRestApi = Client.CreateRestApi(new CreateRestApiRequest
37+
var createRestApi = await Client.CreateRestApiAsync(new CreateRestApiRequest
4438
{
4539
Name = apiName,
46-
Description = apiDescription
40+
Description = apiDescription
4741
});
4842
Assert.AreEqual(apiDescription, createRestApi.Description);
4943
Assert.AreEqual(apiName, createRestApi.Name);
@@ -53,36 +47,36 @@ public static void ClassInitialize(TestContext testContext)
5347
}
5448

5549
[TestMethod]
56-
[TestCategory("APIGateWay")]
57-
public void TestResources()
50+
public async Task TestResources()
5851
{
59-
var allResources = GetResources().ToList();
52+
var allResources = (await GetResources()).ToList();
6053
var rootResource = allResources.SingleOrDefault(r => r.ParentId == null);
6154
Assert.IsNotNull(rootResource);
6255

6356
var pathPart = "test";
64-
var resourceId = Client.CreateResource(new CreateResourceRequest
57+
var createResponse = await Client.CreateResourceAsync(new CreateResourceRequest
6558
{
6659
RestApiId = restApiId,
6760
ParentId = rootResource.Id,
6861
PathPart = pathPart
69-
}).Id;
62+
});
7063

71-
var resources = GetResources().ToList();
64+
var resourceId = createResponse.Id;
65+
var resources = (await GetResources()).ToList();
7266
var resource = resources.Single(r => r.Id == resourceId);
7367
Assert.AreEqual(pathPart, resource.PathPart);
7468
Assert.AreEqual(rootResource.Path + pathPart, resource.Path);
7569
Assert.AreEqual(2, resources.Count);
7670

77-
Client.PutMethod(new PutMethodRequest
71+
await Client.PutMethodAsync(new PutMethodRequest
7872
{
7973
RestApiId = restApiId,
8074
ResourceId = resourceId,
8175
AuthorizationType = "AWS_IAM",
8276
HttpMethod = "PUT"
8377
});
8478

85-
Client.PutIntegration(new PutIntegrationRequest
79+
await Client.PutIntegrationAsync(new PutIntegrationRequest
8680
{
8781
RestApiId = restApiId,
8882
ResourceId = resourceId,
@@ -93,37 +87,43 @@ public void TestResources()
9387
});
9488
}
9589

96-
private IEnumerable<Resource> GetResources()
90+
private async Task<IEnumerable<Resource>> GetResources()
9791
{
92+
var resources = new List<Resource>();
9893
var request = new GetResourcesRequest
9994
{
10095
RestApiId = restApiId
10196
};
97+
10298
do
10399
{
104-
var response = Client.GetResources(request);
100+
var response = await Client.GetResourcesAsync(request);
105101
request.Position = response.Position;
106102

107-
foreach (var r in response.Items)
108-
yield return r;
103+
if (response.Items != null)
104+
{
105+
foreach (var r in response.Items)
106+
{
107+
resources.Add(r);
108+
}
109+
}
109110

110111
} while (!string.IsNullOrEmpty(request.Position));
112+
return resources;
111113
}
112114

113115
[TestMethod]
114-
[TestCategory("APIGateWay")]
115-
public void TestRestApiCalls()
116+
public async Task TestRestApiCalls()
116117
{
117-
var apis = GetRestApis().ToList();
118+
var apis = (await GetRestApis()).ToList();
118119
var api = apis.Single(r => string.Equals(r.Id, restApiId));
119120
Assert.IsNotNull(api);
120121

121-
AssertExtensions.ExpectException(() => Client.GetRestApi(new GetRestApiRequest
122-
{
123-
RestApiId = "fakeid"
124-
}));
122+
await Assert.ThrowsExceptionAsync<NotFoundException>(() =>
123+
Client.GetRestApiAsync(new GetRestApiRequest { RestApiId = "fakeid" })
124+
);
125125

126-
var getRestApi = Client.GetRestApi(new GetRestApiRequest
126+
var getRestApi = await Client.GetRestApiAsync(new GetRestApiRequest
127127
{
128128
RestApiId = restApiId
129129
});
@@ -133,7 +133,7 @@ public void TestRestApiCalls()
133133
Assert.AreNotEqual(DateTime.SpecifyKind(default, DateTimeKind.Utc), getRestApi.CreatedDate);
134134

135135
var newDescription = "New description!";
136-
Client.UpdateRestApi(new UpdateRestApiRequest
136+
await Client.UpdateRestApiAsync(new UpdateRestApiRequest
137137
{
138138
RestApiId = restApiId,
139139
PatchOperations = new List<PatchOperation>
@@ -147,7 +147,7 @@ public void TestRestApiCalls()
147147
}
148148
});
149149

150-
getRestApi = Client.GetRestApi(new GetRestApiRequest
150+
getRestApi = await Client.GetRestApiAsync(new GetRestApiRequest
151151
{
152152
RestApiId = restApiId
153153
});
@@ -156,7 +156,7 @@ public void TestRestApiCalls()
156156
Assert.IsFalse(string.IsNullOrEmpty(getRestApi.Id));
157157
Assert.AreNotEqual(DateTime.SpecifyKind(default, DateTimeKind.Utc), getRestApi.CreatedDate);
158158

159-
Client.UpdateRestApi(new UpdateRestApiRequest
159+
await Client.UpdateRestApiAsync(new UpdateRestApiRequest
160160
{
161161
RestApiId = restApiId,
162162
PatchOperations = new List<PatchOperation>
@@ -171,32 +171,39 @@ public void TestRestApiCalls()
171171
});
172172
}
173173

174-
private IEnumerable<RestApi> GetRestApis()
174+
private async Task<IEnumerable<RestApi>> GetRestApis()
175175
{
176+
var apis = new List<RestApi>();
176177
var request = new GetRestApisRequest { Limit = 1 };
177178
do
178179
{
179-
var response = Client.GetRestApis(request);
180+
var response = await Client.GetRestApisAsync(request);
180181
request.Position = response.Position;
181-
foreach (var r in response.Items)
182-
yield return r;
182+
183+
if (response.Items != null)
184+
{
185+
foreach (var r in response.Items)
186+
{
187+
apis.Add(r);
188+
}
189+
}
183190
} while (!string.IsNullOrEmpty(request.Position));
191+
return apis;
184192
}
185193

186194
[TestMethod]
187-
[TestCategory("APIGateWay")]
188-
public void TestOtherOperations()
195+
public async Task TestOtherOperations()
189196
{
190-
var account = Client.GetAccount(new GetAccountRequest());
197+
var account = await Client.GetAccountAsync(new GetAccountRequest());
191198
Assert.IsNotNull(account);
192199
Assert.IsNotNull(account.ThrottleSettings);
193200
Assert.AreNotEqual(0, account.ThrottleSettings.BurstLimit);
194201
Assert.AreNotEqual(0, account.ThrottleSettings.RateLimit);
195202

196-
var allCerts = GetAllCerts().ToList();
197-
203+
var allCerts = (await GetAllCerts()).ToList();
198204
var certDescription = "something";
199-
var clientCert = Client.GenerateClientCertificate(new GenerateClientCertificateRequest
205+
206+
var clientCert = await Client.GenerateClientCertificateAsync(new GenerateClientCertificateRequest
200207
{
201208
Description = certDescription
202209
});
@@ -208,25 +215,33 @@ public void TestOtherOperations()
208215
Assert.IsFalse(string.IsNullOrEmpty(clientCert.PemEncodedCertificate));
209216
Assert.IsFalse(string.IsNullOrEmpty(clientCert.ClientCertificateId));
210217

211-
var updatedCerts = GetAllCerts().ToList();
218+
var updatedCerts = (await GetAllCerts()).ToList();
212219
Assert.AreNotEqual(allCerts.Count, updatedCerts.Count);
213220

214-
Client.DeleteClientCertificate(new DeleteClientCertificateRequest
221+
await Client.DeleteClientCertificateAsync(new DeleteClientCertificateRequest
215222
{
216223
ClientCertificateId = clientCert.ClientCertificateId
217224
});
218225
}
219226

220-
private static IEnumerable<ClientCertificate> GetAllCerts()
227+
private static async Task<IEnumerable<ClientCertificate>> GetAllCerts()
221228
{
229+
var certificates = new List<ClientCertificate>();
222230
var request = new GetClientCertificatesRequest();
223231
do
224232
{
225-
var response = Client.GetClientCertificates(request);
233+
var response = await Client.GetClientCertificatesAsync(request);
226234
request.Position = response.Position;
227-
foreach (var cert in response.Items)
228-
yield return cert;
235+
236+
if (response.Items != null)
237+
{
238+
foreach (var cert in response.Items)
239+
{
240+
certificates.Add(cert);
241+
}
242+
}
229243
} while (!string.IsNullOrEmpty(request.Position));
244+
return certificates;
230245
}
231246
}
232247
}

sdk/test/Services/CloudFormation/IntegrationTests/AWSSDK.IntegrationTests.CloudFormation.NetFramework.csproj

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)