From 427b16f06511f2529f7c0aedadc4f93e934e9eca Mon Sep 17 00:00:00 2001 From: paule96 Date: Fri, 30 Aug 2024 06:24:51 +0000 Subject: [PATCH] add tests for basic postgres operation --- .../ResourceRepositoryTests.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Tests/DbLocalizationProvider.Storage.PostgreSql.Tests/ResourceRepositoryTests.cs diff --git a/Tests/DbLocalizationProvider.Storage.PostgreSql.Tests/ResourceRepositoryTests.cs b/Tests/DbLocalizationProvider.Storage.PostgreSql.Tests/ResourceRepositoryTests.cs new file mode 100644 index 00000000..3388b743 --- /dev/null +++ b/Tests/DbLocalizationProvider.Storage.PostgreSql.Tests/ResourceRepositoryTests.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; +using DbLocalizationProvider.Abstractions; +using Microsoft.Extensions.Options; +using Testcontainers.PostgreSql; +using Xunit; + +namespace DbLocalizationProvider.Storage.PostgreSql.Tests; + +public class ResourceRepositoryTests : IAsyncLifetime +{ + private readonly PostgreSqlContainer _postgreSqlContainer = new PostgreSqlBuilder().Build(); + + public async Task InitializeAsync() + { + await _postgreSqlContainer.StartAsync(); + Settings.DbContextConnectionString = _postgreSqlContainer.GetConnectionString(); + new SchemaUpdater().Execute(null); + } + + public Task DisposeAsync() + { + return _postgreSqlContainer.DisposeAsync().AsTask(); + } + + [Fact] + public void CanSaveNewResource() + { + var ctx = new ConfigurationContext(); + var wrapper = new OptionsWrapper(ctx); + var repo = new ResourceRepository(wrapper); + var original = new LocalizationResource("testKey", false){ + IsHidden = false, + FromCode = false, + IsModified = true, + Notes = "a test describtion", + Author = "test", + ModificationDate = DateTime.Now + }; + repo.InsertResource(original); + var fromDB = repo.GetByKey(original.ResourceKey); + Assert.Equal(original.Notes, fromDB.Notes); + } + + +}