Skip to content

Instantly share code, notes, and snippets.

View oguzhancagliyan's full-sized avatar

Oğuzhan Çağlıyan oguzhancagliyan

View GitHub Profile
@oguzhancagliyan
oguzhancagliyan / ApiCollection.cs
Last active September 29, 2020 23:57
Collection for fixture
[CollectionDefinition(nameof(ApiTestCollection))]
public class ApiTestCollection : ICollectionFixture<LocalStackFixture>, ICollectionFixture<TestServerFixture>
{
}
@oguzhancagliyan
oguzhancagliyan / LocalStackFixture.cs
Last active October 6, 2020 06:31
fixture for localstack
public class LocalStackFixture : IAsyncLifetime
{
private readonly TestcontainersContainer _localStackContainer;
public LocalStackFixture()
{
var localStackBuilder = new TestcontainersBuilder<TestcontainersContainer>()
.WithImage("localstack/localstack:0.10.9")
.WithCleanUp(true)
.WithEnvironment("DEFAULT_REGION", "eu-central-1")
@oguzhancagliyan
oguzhancagliyan / TestServerFixture.cs
Created September 30, 2020 00:07
fixture for testserver
public class TestServerFixture : WebApplicationFactory<Startup>
{
private const string DynamoDbServiceUrl = "http://localhost:4566/";
private const string SqsServiceUrl = "http://localhost:4566/";
protected override IHostBuilder CreateHostBuilder()
{
var hostBuilder = base.CreateHostBuilder()
.UseEnvironment("Testing")
.ConfigureAppConfiguration(builder =>
@oguzhancagliyan
oguzhancagliyan / MovieEntity.cs
Created September 30, 2020 00:09
MovieEntity
[DynamoDBTable("Movies")]
public class MovieEntity
{
[DynamoDBHashKey]
public Guid DirectorId { get; set; }
[DynamoDBRangeKey]
public string CreateDate { get; set; }
public Guid MovieId { get; set; }
public class DynamoDbSeeder
{
public static void Seed(AmazonDynamoDBClient client)
{
var installers = typeof(DynamoDbMovieSeeder).Assembly.ExportedTypes
.Where(m => typeof(IDynamoDbSeeder).IsAssignableFrom(m) && !m.IsInterface && !m.IsAbstract)
.Select(Activator.CreateInstance)
.Cast<IDynamoDbSeeder>()
.ToList();
public class DynamoDbMovieSeeder : IDynamoDbSeeder
{
public void Seed(AmazonDynamoDBClient client)
{
MovieEntity model = new MovieEntity
{
MovieId = TestConstants.GetMovieId(),
DirectorId = TestConstants.GetDirectorId(),
MovieName = TestConstants.GetMovieName(),
CreateDate = DateTime.UtcNow.ToComparableDateString()
public class SqsSeeder
{
public static void CreateQueue(AmazonSQSClient client)
{
var installers = typeof(MovieLikeSeeder).Assembly.ExportedTypes
.Where(m => typeof(ISqsSeeder).IsAssignableFrom(m) && !m.IsInterface && !m.IsAbstract)
.Select(Activator.CreateInstance)
.Cast<ISqsSeeder>()
.ToList();
public class MovieLikeSeeder : ISqsSeeder
{
public void CreateQueue(AmazonSQSClient client)
{
CreateQueueRequest createDlqRequest = new CreateQueueRequest
{
QueueName = "ArmutLocalStack-Test-DLQ.fifo",
Attributes = new Dictionary<string, string>
{
{
[Route("api/movies")]
[ApiController]
public class MovieController : ControllerBase
{
private readonly IMovieService _movieService;
public MovieController(IMovieService movieService)
{
_movieService = movieService;
}
public class MovieService : IMovieService
{
private readonly IMovieRepository _movieRepository;
private readonly IValidatorService _validatorService;
private readonly IAmazonSQS _amazonSqs;
private readonly SqsQueueConfig _sqsQueueConfig;
public MovieService(IMovieRepository movieRepository, IValidatorService validatorService, IAmazonSQS amazonSqs, IOptions<SqsQueueConfig> options)
{
_movieRepository = movieRepository;