-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
494 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 }" | ||
}); | ||
await client.CreateQueueAsync(queueName); | ||
var sut = new SQSVoteRepository(client, queueName); | ||
|
||
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)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.