-
Notifications
You must be signed in to change notification settings - Fork 102
/
ProcessEmployeeTests.cs
70 lines (59 loc) · 2.2 KB
/
ProcessEmployeeTests.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
using System.Net;
using FluentAssertions;
using SqsEventHandler.IntegrationTests.Utilities;
using xRetry;
using Xunit;
using Xunit.Abstractions;
using JsonSerializer = System.Text.Json.JsonSerializer;
namespace SqsEventHandler.IntegrationTests;
[TestCaseOrderer(
ordererTypeName: "SqsEventHandler.IntegrationTests.Utilities.PriorityOrderer",
ordererAssemblyName: "SqsEventHandler.IntegrationTests")]
public class ProcessEmployeeTests : IClassFixture<ProcessEmployeeFixture>, IDisposable
{
private readonly ProcessEmployeeFixture _processEmployeeFixture;
private readonly ITestOutputHelper _testOutputHelper;
private const string EmployeeId = "569c13fc-1435-45cb-847d-38e89a86e5a0";
private bool _disposed;
public ProcessEmployeeTests(ProcessEmployeeFixture processEmployeeFixture, ITestOutputHelper testOutputHelper)
{
_processEmployeeFixture = processEmployeeFixture;
_testOutputHelper = testOutputHelper;
}
public void Dispose()
{
if (_disposed)
{
return;
}
_disposed = true;
_processEmployeeFixture.SqsClient.Dispose();
}
[Fact, TestPriority(1)]
public async Task PublishToProcessEmployeeQueue_Should_ReturnSuccess()
{
//Arrange
var sqsMessage = new EmployeeBuilder().WithEmployeeId(EmployeeId);
//Act
var response = await _processEmployeeFixture.SendMessageAsync(
_processEmployeeFixture.SqsEventQueueUrl,
JsonSerializer.Serialize(sqsMessage)
);
//Assert
response.Should().NotBeNull();
response.HttpStatusCode.Should().Be(HttpStatusCode.OK);
}
[RetryFact(3, 5000), TestPriority(2)]
public async Task PublishToProcessEmployeeQueue_Should_UpsertEmployee()
{
//Act
using var cts = new CancellationTokenSource();
var response = await _processEmployeeFixture.TestEmployeeRepository!.GetItemAsync(EmployeeId, cts.Token);
//Assert
response.Should().NotBeNull();
response!.EmployeeId.Should().Be(EmployeeId);
_testOutputHelper.WriteLine(response.ToString());
//Dispose
_processEmployeeFixture.CreatedEmployeeIds.Add(EmployeeId);
}
}