Skip to content

Commit

Permalink
add tests for basic postgres operation
Browse files Browse the repository at this point in the history
  • Loading branch information
paule96 committed Aug 30, 2024
1 parent 794312f commit 427b16f
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<ConfigurationContext>(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);
}


}

0 comments on commit 427b16f

Please sign in to comment.