Skip to content

Instantly share code, notes, and snippets.

@oguzhancagliyan
Created September 30, 2020 00:22
Show Gist options
  • Save oguzhancagliyan/3a57cd39ce9ac43c004a7b1c5fda420b to your computer and use it in GitHub Desktop.
Save oguzhancagliyan/3a57cd39ce9ac43c004a7b1c5fda420b to your computer and use it in GitHub Desktop.
public abstract class BaseScenario
{
protected internal readonly TestServer TestServer;
protected internal readonly HttpClient HttpClient;
internal readonly IDynamoDBContext DynamoDbContext;
internal readonly IAmazonSQS SqsClient;
protected BaseScenario(TestServerFixture testServerFixture)
{
TestServer = testServerFixture.Server;
HttpClient = testServerFixture.CreateClient();
DynamoDbContext = TestServer.Services.GetRequiredService<IDynamoDBContext>();
SqsClient = TestServer.Services.GetRequiredService<IAmazonSQS>();
}
protected async Task<bool> CheckMovieByMovieIdAsync(Guid movieId, CancellationToken token = default)
{
DynamoDBOperationConfig operationConfig = new DynamoDBOperationConfig
{
IndexName = Constants.MoiveTableMovieIdGsi,
};
List<MovieEntity> result = await DynamoDbContext.QueryAsync<MovieEntity>(movieId, operationConfig)
.GetRemainingAsync(token);
return result.Any(b => b.MovieId == movieId);
}
protected async Task<bool> IsItemInQueueAsync(Guid id)
{
GetQueueUrlResponse getQueueUrlResponse = await SqsClient.GetQueueUrlAsync(TestConstants.QueueName);
ReceiveMessageRequest req = new ReceiveMessageRequest
{
MaxNumberOfMessages = 1,
QueueUrl = getQueueUrlResponse.QueueUrl
};
ReceiveMessageResponse receiveMessages = await SqsClient.ReceiveMessageAsync(req);
Message currentMessage = receiveMessages.Messages.FirstOrDefault();
CommentModel deserializedObject = JsonSerializer.Deserialize<CommentModel>(currentMessage?.Body);
return deserializedObject.MovieId == id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment