From 2954f2f024ad16863b4e7afcb52345e4a2d5d185 Mon Sep 17 00:00:00 2001 From: Milad Kardgar <40167363+milad176@users.noreply.github.com> Date: Tue, 21 Jul 2026 10:39:22 +0300 Subject: [PATCH] Implement test database for integration test for catalog service. --- .../Catalog.API.IntegrationTests.csproj | 2 +- .../Database/TestDatabase.cs | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Services/Catalog/Catalog.API.IntegrationTests/Catalog.API.IntegrationTests.csproj b/src/Services/Catalog/Catalog.API.IntegrationTests/Catalog.API.IntegrationTests.csproj index 18af8c3..771956d 100644 --- a/src/Services/Catalog/Catalog.API.IntegrationTests/Catalog.API.IntegrationTests.csproj +++ b/src/Services/Catalog/Catalog.API.IntegrationTests/Catalog.API.IntegrationTests.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/Services/Catalog/Catalog.API.IntegrationTests/Database/TestDatabase.cs b/src/Services/Catalog/Catalog.API.IntegrationTests/Database/TestDatabase.cs index c12950d..09376bb 100644 --- a/src/Services/Catalog/Catalog.API.IntegrationTests/Database/TestDatabase.cs +++ b/src/Services/Catalog/Catalog.API.IntegrationTests/Database/TestDatabase.cs @@ -1,6 +1,25 @@ +using Testcontainers.PostgreSql; + namespace Catalog.API.IntegrationTests.Database; -public class TestDatabase +public sealed class TestDatabase { - + private readonly PostgreSqlContainer _container = + new PostgreSqlBuilder() + .WithDatabase("CatalogDb") + .WithUsername("postgres") + .WithPassword("postgres") + .Build(); + + public string ConnectionString => _container.GetConnectionString(); + + public async Task StartAsync() + { + await _container.StartAsync(); + } + + public async Task StopAsync() + { + await _container.StopAsync(); + } } \ No newline at end of file