-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSQSVoteRepositoryTests.cs
55 lines (51 loc) · 2.09 KB
/
SQSVoteRepositoryTests.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
using Amazon.SQS;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SuperSurvey.UseCases.Ports.In;
using System.Text.Json;
namespace SuperSurvey.Adapters.Tests
{
[TestClass]
public class SQSVoteRepositoryTests
{
[TestMethod]
[TestCategory("Integration")]
public async Task Should_PostMessage_When_VoteCommandIsSaved()
{
int randomPort = Random.Shared.Next(49152, 65535);
var testcontainersBuilder = new TestcontainersBuilder<TestcontainersContainer>()
.WithImage("localstack/localstack:latest")
.WithEnvironment("SERVICES", "sqs")
.WithEnvironment("EDGE_PORT", "4566")
.WithPortBinding(randomPort, 4566)
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(4566))
;
await using (var testcontainer = testcontainersBuilder.Build())
{
string queueName = "my-queue";
await testcontainer.StartAsync();
var client = new AmazonSQSClient("test", "test", new AmazonSQSConfig()
{
ServiceURL = $"http://localhost:{ randomPort }"
});
var queue = await client.CreateQueueAsync(queueName);
var sut = new SQSVoteRepository(client, queue.QueueUrl);
var voteCommand = new VoteCommand()
{
PollId = 1,
SelectedOption = 999,
UserId = 2,
CreatedAt = DateTime.Now
};
await sut.Save(voteCommand);
string queueUrl = (await client.GetQueueUrlAsync(queueName)).QueueUrl;
var result = await client.ReceiveMessageAsync(queueUrl);
result.Messages.Count.Should().Be(1);
var message = result.Messages[0];
message.Body.Should().Be(JsonSerializer.Serialize(voteCommand));
}
}
}
}