From 9bf70f7351a896d8fa304e7447b06194ca0f505e Mon Sep 17 00:00:00 2001 From: paule96 Date: Thu, 29 Aug 2024 11:47:51 +0200 Subject: [PATCH 1/3] change return type of the PK the return type of the number for the ID of postgres, is int64 and not int --- .../ResourceRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DbLocalizationProvider.Storage.PostgreSQL/ResourceRepository.cs b/src/DbLocalizationProvider.Storage.PostgreSQL/ResourceRepository.cs index baf6166a..e7c3d684 100644 --- a/src/DbLocalizationProvider.Storage.PostgreSQL/ResourceRepository.cs +++ b/src/DbLocalizationProvider.Storage.PostgreSQL/ResourceRepository.cs @@ -384,7 +384,7 @@ public void InsertResource(LocalizationResource resource) cmd.Parameters.AddSafeWithValue("notes", resource.Notes); // get inserted resource ID - var resourcePk = (int)cmd.ExecuteScalar(); + var resourcePk = (long)cmd.ExecuteScalar(); // if there are also provided translations - execute those in the same connection also if (resource.Translations.Any()) From 794312f5fcb172bf8d24848ba303b3c27f5624ca Mon Sep 17 00:00:00 2001 From: paule96 Date: Fri, 30 Aug 2024 06:24:24 +0000 Subject: [PATCH 2/3] fix build under linux --- .../DbLocalizationProvider.Storage.PostgreSql.Tests.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/DbLocalizationProvider.Storage.PostgreSql.Tests/DbLocalizationProvider.Storage.PostgreSql.Tests.csproj b/Tests/DbLocalizationProvider.Storage.PostgreSql.Tests/DbLocalizationProvider.Storage.PostgreSql.Tests.csproj index 28343fd9..3efd2ea1 100644 --- a/Tests/DbLocalizationProvider.Storage.PostgreSql.Tests/DbLocalizationProvider.Storage.PostgreSql.Tests.csproj +++ b/Tests/DbLocalizationProvider.Storage.PostgreSql.Tests/DbLocalizationProvider.Storage.PostgreSql.Tests.csproj @@ -13,6 +13,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + all @@ -21,7 +22,7 @@ - + From 427b16f06511f2529f7c0aedadc4f93e934e9eca Mon Sep 17 00:00:00 2001 From: paule96 Date: Fri, 30 Aug 2024 06:24:51 +0000 Subject: [PATCH 3/3] 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); + } + + +}