Приведение DD.Persistence.Repository.Test в исходное состояние
This commit is contained in:
parent
032d783d40
commit
09cfccaa38
@ -1,132 +0,0 @@
|
||||
using DD.Persistence.Database.Model;
|
||||
using DD.Persistence.Database.Postgres.Repositories;
|
||||
using DD.Persistence.Database.Repositories;
|
||||
using DD.Persistence.Models.Common;
|
||||
using DD.Persistence.Models.Requests;
|
||||
using DD.Persistence.Models;
|
||||
using DD.Persistence.Repositories;
|
||||
using System.Text.Json;
|
||||
using UuidExtensions;
|
||||
using DD.Persistence.API.Services;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using DD.Persistence.Database;
|
||||
|
||||
namespace DD.Persistence.Repository.Test;
|
||||
public class ChangeLogRepositoryTest : IClassFixture<RepositoryTestFixture>
|
||||
{
|
||||
private readonly PersistencePostgresContext context;
|
||||
private readonly IChangeLogRepository repo;
|
||||
private readonly RepositoryTestFixture fixture;
|
||||
|
||||
public ChangeLogService service { get; }
|
||||
|
||||
public ChangeLogRepositoryTest(RepositoryTestFixture fixture, ChangeLogService changeLogService)
|
||||
{
|
||||
this.fixture = fixture;
|
||||
context = fixture.GetDbContext();
|
||||
//sut = new SetpointRepository(context);
|
||||
|
||||
//service = new ChangeLogService(cache, );
|
||||
}
|
||||
|
||||
//Task<int> MarkAsDeleted(Guid idEditor, IEnumerable<Guid> ids, string comment, CancellationToken token);
|
||||
|
||||
//Task<int> MarkAsDeleted(Guid idEditor, Guid idDiscriminator, string comment, CancellationToken token);
|
||||
//Task<int> ClearAndAddRange(Guid idDiscriminator, ChangeLogCommitDto commitDto, CancellationToken token);
|
||||
|
||||
private ChangeLogCommitDto CreateChangeLogItem(Guid idDiscriminator)
|
||||
{
|
||||
var idAuthor = Uuid7.Guid();
|
||||
var changeLogItems = new List<ChangeLogValuesDto>()
|
||||
{
|
||||
new ChangeLogValuesDto(){
|
||||
Id = Uuid7.Guid(),
|
||||
Value = new Dictionary<string, object>(){
|
||||
{ "1", 1 },
|
||||
{ "2", 2 },
|
||||
{ "3", 3 }
|
||||
}
|
||||
}
|
||||
};
|
||||
var commit = new ChangeLogCommitDto(idAuthor, "Комментарий 1", changeLogItems);
|
||||
return commit;
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddRangeReturnSuccess()
|
||||
{
|
||||
//act
|
||||
var id Discriminator = Uuid7.Guid();
|
||||
var commit = CreateChangeLogItem(idDiscriminator);
|
||||
var result = await service.AddRange(idDiscriminator, commit, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.Equal(2, result);
|
||||
}
|
||||
|
||||
|
||||
//[Fact]
|
||||
//public async Task UpdateRangeReturnSuccess()
|
||||
//{
|
||||
// var idDiscriminator = Uuid7.Guid();
|
||||
// var commit1 = await CreateChangeLogItem(idDiscriminator);
|
||||
// var result = await repo.AddRange(idDiscriminator, commit1, CancellationToken.None);
|
||||
|
||||
// var commit2 = await CreateChangeLogItem(idDiscriminator);
|
||||
// result = await repo.AddRange(idDiscriminator, commit2, CancellationToken.None);
|
||||
|
||||
// var items = await repo.GetGtDate(idDiscriminator, DateTimeOffset.UtcNow.AddDays(-1), CancellationToken.None);
|
||||
|
||||
// if (items == null)
|
||||
// Assert.Fail("Не найдены элементы changeLog");
|
||||
|
||||
// var updated = items.ToArray();
|
||||
// foreach (var item in updated)
|
||||
// {
|
||||
// item.Value.Add("4", 4);
|
||||
// }
|
||||
|
||||
// //act
|
||||
// var commit = new ChangeLogCommitDto(Uuid7.Guid(), "Комментарий 2", updated);
|
||||
// result = await repo.UpdateRange(commit, CancellationToken.None);
|
||||
|
||||
// //assert
|
||||
// //изменены 2 старые записи,
|
||||
// //добавлены 2 новые записи
|
||||
// //добавлен общий коммит
|
||||
// //итого = 2+2+1 = 5
|
||||
// Assert.Equal(5, result);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public async Task ClearAndAddRangeReturnSuccess()
|
||||
//{
|
||||
// var idDiscriminator = Uuid7.Guid();
|
||||
// var commit1 = await CreateChangeLogItem(idDiscriminator);
|
||||
// var result = await repo.AddRange(idDiscriminator, commit1, CancellationToken.None);
|
||||
|
||||
// var commit2 = await CreateChangeLogItem(idDiscriminator);
|
||||
// result = await repo.AddRange(idDiscriminator, commit2, CancellationToken.None);
|
||||
|
||||
// var commit3 = await CreateChangeLogItem(idDiscriminator);
|
||||
// result = await repo.AddRange(idDiscriminator, commit3, CancellationToken.None);
|
||||
|
||||
// //act
|
||||
// var commit4 = await CreateChangeLogItem(idDiscriminator);
|
||||
// var items = await repo.GetGtDate(idDiscriminator, DateTimeOffset.UtcNow.AddDays(-1), CancellationToken.None);
|
||||
// commit4.ChangeLogItems = items;
|
||||
// result = await repo.ClearAndAddRange(idDiscriminator, commit4, CancellationToken.None);
|
||||
|
||||
// //assert
|
||||
// //добавлены 3 записи и 3 коммита к ним,
|
||||
// //добавлена 1 новая запись и 1 коммит к ней
|
||||
// Assert.Equal(8, result);
|
||||
|
||||
// var paginationRequest = new PaginationRequest();
|
||||
// var items2 = await repo.GetByDate(idDiscriminator, DateTimeOffset.UtcNow.AddMinutes(-10), paginationRequest, CancellationToken.None);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
@ -20,7 +20,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DD.Persistence.API\DD.Persistence.API.csproj" />
|
||||
<ProjectReference Include="..\DD.Persistence.Database.Postgres\DD.Persistence.Database.Postgres.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -10,14 +10,7 @@ namespace DD.Persistence.Repository.Test;
|
||||
|
||||
public class RepositoryTestFixture : IAsyncLifetime
|
||||
{
|
||||
public readonly PostgreSqlContainer dbContainer = new PostgreSqlBuilder()
|
||||
.WithImage("timescale/timescaledb:latest-pg16")
|
||||
.WithHostname("localhost")
|
||||
.WithDatabase("persistence")
|
||||
.WithUsername("postgres")
|
||||
.WithPassword("postgres")
|
||||
//.WithPortBinding("5462")
|
||||
.Build();
|
||||
public readonly PostgreSqlContainer dbContainer = new PostgreSqlBuilder().Build();
|
||||
|
||||
|
||||
public PersistencePostgresContext GetDbContext() => new(new DbContextOptionsBuilder<PersistencePostgresContext>()
|
||||
|
Loading…
Reference in New Issue
Block a user