-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathAwsServiceTests.cs
97 lines (82 loc) · 3.44 KB
/
AwsServiceTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection.PortableExecutable;
using System.Threading.Tasks;
using Amazon.Lambda.TestTool.Services;
using Xunit;
using Amazon.SQS;
using Amazon.SQS.Model;
using Newtonsoft.Json;
namespace Amazon.Lambda.TestTool.Tests
{
public class AwsServiceTests
{
[Fact]
public void ListProfiles()
{
if (!TestUtils.ProfileTestsEnabled)
return;
var aws = new AWSServiceImpl();
var profiles = aws.ListProfiles();
Assert.NotEmpty(profiles);
foreach (var profile in profiles)
{
Assert.False(string.IsNullOrWhiteSpace(profile));
}
Assert.True(profiles.Contains(TestUtils.TestProfile));
}
[Fact]
public async Task ListQueuesAsync()
{
if (!TestUtils.ProfileTestsEnabled)
return;
var queueName = "local-reader-list-queue-test-" + DateTime.Now.Ticks;
using (var client = new AmazonSQSClient(TestUtils.GetAWSCredentials(), TestUtils.TestRegion))
{
var createResponse = await client.CreateQueueAsync(new CreateQueueRequest {QueueName = queueName});
await TestUtils.WaitTillQueueIsCreatedAsync(client, createResponse.QueueUrl);
try
{
var aws = new AWSServiceImpl();
var queues = await aws.ListQueuesAsync(TestUtils.TestProfile, TestUtils.TestRegion.SystemName);
Assert.True(queues.Contains(createResponse.QueueUrl));
}
finally
{
await client.DeleteQueueAsync(createResponse.QueueUrl);
}
}
}
[Fact]
public async Task ReadMessageAsync()
{
if (!TestUtils.ProfileTestsEnabled)
return;
var queueName = "local-reader-read-message-test-" + DateTime.Now.Ticks;
using (var client = new AmazonSQSClient(TestUtils.GetAWSCredentials(), TestUtils.TestRegion))
{
var createResponse = await client.CreateQueueAsync(new CreateQueueRequest {QueueName = queueName});
await TestUtils.WaitTillQueueIsCreatedAsync(client, createResponse.QueueUrl);
try
{
var aws = new AWSServiceImpl();
var message = await aws.ReadMessageAsync(TestUtils.TestProfile, TestUtils.TestRegion.SystemName, createResponse.QueueUrl);
Assert.Null(message);
await client.SendMessageAsync(new SendMessageRequest
{
MessageBody = "data",
QueueUrl = createResponse.QueueUrl
});
message = await aws.ReadMessageAsync(TestUtils.TestProfile, TestUtils.TestRegion.SystemName, createResponse.QueueUrl);
Assert.NotNull(message);
await aws.DeleteMessageAsync(TestUtils.TestProfile, TestUtils.TestRegion.SystemName, createResponse.QueueUrl, message.ReceiptHandle);
}
finally
{
await client.DeleteQueueAsync(createResponse.QueueUrl);
}
}
}
}
}