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 @@ - + 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); + } + + +} 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())