Compare commits

...

4 Commits

14 changed files with 286 additions and 122 deletions

View File

@ -1,4 +1,4 @@
using DD.Persistence.Models; using DD.Persistence.Models;
using DD.Persistence.Models.Common; using DD.Persistence.Models.Common;
namespace DD.Persistence.Client.Clients.Interfaces; namespace DD.Persistence.Client.Clients.Interfaces;
@ -37,18 +37,6 @@ public interface ITimestampedValuesClient : IDisposable
int take, int take,
CancellationToken token); CancellationToken token);
/// <summary>
/// Получить данные с фильтрацией для нескольких систем. Значение фильтра null - отключен
/// </summary>
/// <param name="discriminatorId"></param>
/// <param name="geTimestamp"></param>
/// <param name="filterTree"></param>
/// <param name="columnNames">Фильтр свойств набора</param>
/// <param name="skip"></param>
/// <param name="take"></param>
/// <param name="token"></param>
Task<IEnumerable<T>> Get<T>(Guid discriminatorId, DateTimeOffset? geTimestamp, string? filterTree, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token);
/// <summary> /// <summary>
/// Получить данные, начиная с заданной отметки времени /// Получить данные, начиная с заданной отметки времени
/// </summary> /// </summary>
@ -97,13 +85,6 @@ public interface ITimestampedValuesClient : IDisposable
/// <param name="token"></param> /// <param name="token"></param>
Task<DatesRangeDto?> GetDatesRange(Guid discriminatorId, CancellationToken token); Task<DatesRangeDto?> GetDatesRange(Guid discriminatorId, CancellationToken token);
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="idDiscriminator"></param>
/// <param name="take"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<T>> GetLast<T>(Guid idDiscriminator, int take, CancellationToken token);
} }

View File

@ -0,0 +1,6 @@
using DD.Persistence.Client.Clients.Interfaces;
namespace DD.Persistence.Client.Clients.Mapping.Abstractions;
public interface ISetpointMappingClient : ISetpointClient
{
}

View File

@ -0,0 +1,33 @@
using DD.Persistence.Client.Clients.Interfaces;
namespace DD.Persistence.Client.Clients.Mapping.Abstractions;
/// <summary>
///
/// </summary>
public interface ITimestampedMappingClient : ITimestampedValuesClient
{
/// <summary>
/// Получить данные с фильтрацией для нескольких систем. Значение фильтра null - отключен
/// </summary>
/// <param name="discriminatorId"></param>
/// <param name="geTimestamp"></param>
/// <param name="columnNames">Фильтр свойств набора</param>
/// <param name="filterTree"></param>
/// <param name="skip"></param>
/// <param name="take"></param>
/// <param name="token"></param>
Task<IEnumerable<T>> Get<T>(Guid discriminatorId, DateTimeOffset? geTimestamp, string? filterTree, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token);
Task<IDictionary<Guid, object>> Gett(IEnumerable<Guid> discriminatorIds, string? filterTree, DateTimeOffset? timestampBegin, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token);
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="idDiscriminator"></param>
/// <param name="take"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<T>> GetLast<T>(Guid idDiscriminator, int take, CancellationToken token);
}

View File

@ -0,0 +1,79 @@
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Mapping.Abstractions;
using DD.Persistence.Models;
using DD.Persistence.Models.Common;
using System.Text.Json;
namespace DD.Persistence.Client.Clients.Mapping.Clients;
internal class SetpointMappingClient(ISetpointClient setpointClient, Dictionary<Guid, Type> mappingConfigs) : ISetpointMappingClient
{
public async Task Add(Guid setpointKey, object newValue, CancellationToken token)
=> await setpointClient.Add(setpointKey, newValue, token);
public void Dispose()
{
setpointClient.Dispose();
}
public async Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token)
=> (await setpointClient.GetCurrent(setpointKeys, token))
.Select(x => new SetpointValueDto
{
Key = x.Key,
Value = DeserializeValue(x.Key, (JsonElement)x.Value)
});
public async Task<Dictionary<Guid, object>> GetCurrentDictionary(IEnumerable<Guid> setpointConfigs, CancellationToken token)
{
return (await setpointClient.GetCurrent(setpointConfigs, token))
.ToDictionary(x => x.Key, x => DeserializeValue(x.Key, (JsonElement)x.Value));
}
public async Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token)
=> await setpointClient.GetDatesRangeAsync(token);
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
{
var result = await setpointClient.GetHistory(setpointKeys, historyMoment, token);
foreach (var dto in result)
dto.Value = DeserializeValue(dto.Key, (JsonElement)dto.Value);
return result;
}
public async Task<Dictionary<Guid, IEnumerable<SetpointLogDto>>> GetLog(IEnumerable<Guid> setpointKeys, CancellationToken token)
{
var result = await setpointClient.GetLog(setpointKeys, token);
foreach (var item in result)
DeserializeList(result[item.Key]);
return result;
}
public async Task<IEnumerable<SetpointLogDto>> GetPart(DateTimeOffset dateBegin, int take, CancellationToken token)
{
var res = await setpointClient.GetPart(dateBegin, take, token);
DeserializeList(res);
return res;
}
private object DeserializeValue(Guid key, JsonElement value)
{
if (mappingConfigs.TryGetValue(key, out var type))
return value.Deserialize(type)!;
return value;
}
private void DeserializeList(IEnumerable<SetpointLogDto>? result)
{
foreach (var log in result)
log.Value = DeserializeValue(log.Key, (JsonElement)log.Value);
}
}

View File

@ -0,0 +1,95 @@
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Mapping.Abstractions;
using DD.Persistence.Models;
using DD.Persistence.Models.Common;
using System.Collections.Concurrent;
using System.Reflection;
namespace DD.Persistence.Client.Clients.Mapping.Clients;
public class TimestampedMappingClient(ITimestampedValuesClient client, Dictionary<Guid, Type>? mappingConfigs) : ITimestampedMappingClient
{
/// <inheritdoc/>
private readonly ConcurrentDictionary<Guid, TimestampedSetMapperBase> mapperCache = new();
public async Task<int> AddRange(Guid discriminatorId, IEnumerable<TimestampedValuesDto> dtos, CancellationToken token)
=> await client.AddRange(discriminatorId, dtos, token);
public async Task<int> Count(Guid discriminatorId, CancellationToken token)
=> await client.Count(discriminatorId, token);
public void Dispose()
{
client.Dispose();
}
/// <inheritdoc/>
public async Task<IEnumerable<T>> Get<T>(Guid discriminatorId, DateTimeOffset? geTimestamp, string? filterTree, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token)
{
var data = await Get([discriminatorId], geTimestamp, filterTree, columnNames, skip, take, token);
var mapper = GetMapper<T>(discriminatorId);
return data.Select(mapper.DeserializeTimeStampedData);
}
/// <inheritdoc/>
public async Task<IEnumerable<T>> GetLast<T>(Guid idDiscriminator, int take, CancellationToken token)
{
var data = await GetLast(idDiscriminator, take, token);
var mapper = GetMapper<T>(idDiscriminator);
return data.Select(mapper.DeserializeTimeStampedData);
}
public async Task<IDictionary<Guid, object>> Gett(IEnumerable<Guid> discriminatorIds, string? filterTree, DateTimeOffset? timestampBegin, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token)
{
var data = await client.Get(discriminatorIds, timestampBegin, filterTree, columnNames, skip, take, token);
// ToDo: рефакторинг
foreach (var discriminatorId in discriminatorIds)
{
if (mappingConfigs.TryGetValue(discriminatorId, out var type))
{
var genericType = typeof(TimestampedSetMapper<>).MakeGenericType(type);
var mapper =
typeof(TimestampedMappingClient)
.GetMethod(nameof(GetMapper))!
.MakeGenericMethod([type])
.Invoke(this, [discriminatorId]);
var mapperInstance = Activator.CreateInstance(genericType, mapper); // ToDo: возможно не нужно
var deserializeMethod = genericType
.GetMethod("DeserializeTimeStampedData")!;
var d = data.Select(e => deserializeMethod.Invoke(mapperInstance, [e]));
// ToDo: приводим к Dictionary
}
}
return new Dictionary<Guid, object>();
}
/// <inheritdoc/>
private TimestampedSetMapper<T> GetMapper<T>(Guid idDiscriminator)
{
return (TimestampedSetMapper<T>)mapperCache.GetOrAdd(idDiscriminator, name => new TimestampedSetMapper<T>(idDiscriminator));
}
public async Task<IEnumerable<TimestampedValuesDto>> Get(IEnumerable<Guid> discriminatorIds, DateTimeOffset? timestampBegin, string? filterTree, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token)
=> await client.Get(discriminatorIds, timestampBegin, filterTree, columnNames, skip, take, token);
public async Task<DatesRangeDto?> GetDatesRange(Guid discriminatorId, CancellationToken token)
=> await client.GetDatesRange(discriminatorId, token);
public async Task<IEnumerable<TimestampedValuesDto>> GetFirst(Guid discriminatorId, int take, CancellationToken token)
=> await client.GetFirst(discriminatorId, take, token);
public async Task<IEnumerable<TimestampedValuesDto>> GetGtDate(Guid discriminatorId, DateTimeOffset timestampBegin, CancellationToken token)
=> await client.GetGtDate(discriminatorId, timestampBegin, token);
public async Task<IEnumerable<TimestampedValuesDto>> GetLast(Guid discriminatorId, int take, CancellationToken token)
=> await client.GetLast(discriminatorId, take, token);
public async Task<IEnumerable<TimestampedValuesDto>> GetResampledData(Guid discriminatorId, DateTimeOffset timestampBegin, double intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
=> await client.GetResampledData(discriminatorId, timestampBegin, intervalSec, approxPointsCount, token);
}

View File

@ -4,7 +4,7 @@ using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text.Json; using System.Text.Json;
namespace DD.Persistence.Client; namespace DD.Persistence.Client.Clients.Mapping;
internal abstract class TimestampedSetMapperBase internal abstract class TimestampedSetMapperBase
{ {

View File

@ -3,9 +3,6 @@ using DD.Persistence.Client.Clients.Base;
using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Interfaces.Refit; using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Models; using DD.Persistence.Models;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Globalization;
using DD.Persistence.Models.Common; using DD.Persistence.Models.Common;
namespace DD.Persistence.Client.Clients; namespace DD.Persistence.Client.Clients;
@ -13,15 +10,12 @@ namespace DD.Persistence.Client.Clients;
public class SetpointClient : BaseClient, ISetpointClient public class SetpointClient : BaseClient, ISetpointClient
{ {
private readonly IRefitSetpointClient refitSetpointClient; private readonly IRefitSetpointClient refitSetpointClient;
private readonly ISetpointConfigStorage setpointConfigStorage;
public SetpointClient( public SetpointClient(
IRefitClientFactory<IRefitSetpointClient> refitSetpointClientFactory, IRefitClientFactory<IRefitSetpointClient> refitSetpointClientFactory,
ISetpointConfigStorage setpointConfigStorage,
ILogger<SetpointClient> logger) : base(logger) ILogger<SetpointClient> logger) : base(logger)
{ {
this.refitSetpointClient = refitSetpointClientFactory.Create(); this.refitSetpointClient = refitSetpointClientFactory.Create();
this.setpointConfigStorage = setpointConfigStorage;
} }
public async Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token) public async Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token)
@ -31,7 +25,7 @@ public class SetpointClient : BaseClient, ISetpointClient
return result!.Select(x => new SetpointValueDto { return result!.Select(x => new SetpointValueDto {
Key = x.Key, Key = x.Key,
Value = DeserializeValue(x.Key, x.Value) Value = x.Value
}); });
} }
@ -43,7 +37,7 @@ public class SetpointClient : BaseClient, ISetpointClient
async () => await refitSetpointClient.GetCurrent(setpointConfigs, token), token); async () => await refitSetpointClient.GetCurrent(setpointConfigs, token), token);
return result!.ToDictionary(x => x.Key,x => DeserializeValue(x.Key,x.Value)); return result!.ToDictionary(x => x.Key,x => (object)x.Value);
} }
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token) public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
@ -51,9 +45,6 @@ public class SetpointClient : BaseClient, ISetpointClient
var result = await ExecuteGetResponse( var result = await ExecuteGetResponse(
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token); async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
foreach(var dto in result)
dto.Value = DeserializeValue(dto.Key, (JsonElement)dto.Value);
return result!; return result!;
} }
@ -63,9 +54,6 @@ public class SetpointClient : BaseClient, ISetpointClient
var result = await ExecuteGetResponse( var result = await ExecuteGetResponse(
async () => await refitSetpointClient.GetLog(setpointKeys, token), token); async () => await refitSetpointClient.GetLog(setpointKeys, token), token);
foreach(var item in result)
DeserializeList(result[item.Key]);
return result!; return result!;
} }
@ -82,8 +70,6 @@ public class SetpointClient : BaseClient, ISetpointClient
var result = await ExecuteGetResponse( var result = await ExecuteGetResponse(
async () => await refitSetpointClient.GetPart(dateBegin, take, token), token); async () => await refitSetpointClient.GetPart(dateBegin, take, token), token);
DeserializeList(result);
return result!; return result!;
} }
@ -101,21 +87,4 @@ public class SetpointClient : BaseClient, ISetpointClient
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
private object DeserializeValue(Guid key, JsonElement value)
{
if (setpointConfigStorage.TryGetType(key, out var type))
return value.Deserialize(type)!;
return value;
}
private void DeserializeList(IEnumerable<SetpointLogDto>? result)
{
foreach (var log in result)
log.Value = DeserializeValue(log.Key, (JsonElement)log.Value);
}
} }

View File

@ -1,4 +1,4 @@
using DD.Persistence.Client.Clients.Base; using DD.Persistence.Client.Clients.Base;
using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Interfaces.Refit; using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Models; using DD.Persistence.Models;
@ -19,8 +19,7 @@ public class TimestampedValuesClient : BaseClient, ITimestampedValuesClient
this.refitTimestampedSetClient = refitTimestampedSetClientFactory.Create(); this.refitTimestampedSetClient = refitTimestampedSetClientFactory.Create();
} }
/// <inheritdoc/>
private readonly ConcurrentDictionary<Guid, TimestampedSetMapperBase> mapperCache = new();
/// <inheritdoc/> /// <inheritdoc/>
public async Task<int> AddRange(Guid discriminatorId, IEnumerable<TimestampedValuesDto> sets, CancellationToken token) public async Task<int> AddRange(Guid discriminatorId, IEnumerable<TimestampedValuesDto> sets, CancellationToken token)
@ -39,15 +38,6 @@ public class TimestampedValuesClient : BaseClient, ITimestampedValuesClient
return result!; return result!;
} }
/// <inheritdoc/>
public async Task<IEnumerable<T>> Get<T>(Guid discriminatorId, DateTimeOffset? geTimestamp, string? filterTree, IEnumerable<string>? columnNames, int skip, int take, CancellationToken token)
{
var data = await Get([discriminatorId], geTimestamp, filterTree, columnNames, skip, take, token);
var mapper = GetMapper<T>(discriminatorId);
return data.Select(mapper.DeserializeTimeStampedData);
}
/// <inheritdoc/> /// <inheritdoc/>
public async Task<IEnumerable<TimestampedValuesDto>> GetGtDate(Guid discriminatorId, DateTimeOffset timestampBegin, CancellationToken token) public async Task<IEnumerable<TimestampedValuesDto>> GetGtDate(Guid discriminatorId, DateTimeOffset timestampBegin, CancellationToken token)
{ {
@ -102,20 +92,7 @@ public class TimestampedValuesClient : BaseClient, ITimestampedValuesClient
return result; return result;
} }
/// <inheritdoc/>
public async Task<IEnumerable<T>> GetLast<T>(Guid idDiscriminator, int take, CancellationToken token)
{
var data = await GetLast(idDiscriminator, take, token);
var mapper = GetMapper<T>(idDiscriminator);
return data.Select(mapper.DeserializeTimeStampedData);
}
/// <inheritdoc/>
private TimestampedSetMapper<T> GetMapper<T>(Guid idDiscriminator)
{
return (TimestampedSetMapper<T>)mapperCache.GetOrAdd(idDiscriminator, name => new TimestampedSetMapper<T>(idDiscriminator));
}
/// <inheritdoc/> /// <inheritdoc/>
public void Dispose() public void Dispose()

View File

@ -1,5 +1,7 @@
using DD.Persistence.Client.Clients; using DD.Persistence.Client.Clients;
using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Mapping.Abstractions;
using DD.Persistence.Client.Clients.Mapping.Clients;
using DD.Persistence.Models; using DD.Persistence.Models;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -25,9 +27,21 @@ public static class DependencyInjection
services.AddTransient<ITimestampedValuesClient, TimestampedValuesClient>(); services.AddTransient<ITimestampedValuesClient, TimestampedValuesClient>();
services.AddTransient<IWitsDataClient, WitsDataClient>(); services.AddTransient<IWitsDataClient, WitsDataClient>();
services.AddSingleton<ISetpointConfigStorage, SetpointConfigStorage>(provider => return services;
}
public static IServiceCollection AddPersistenceMapping(this IServiceCollection services, Dictionary<Guid, Type>? mappingConfigs)
{ {
return new SetpointConfigStorage(setpointTypeConfigs); services.AddTransient<ISetpointMappingClient, SetpointMappingClient>(provider =>
{
var client = provider.GetRequiredService<ISetpointClient>();
return new SetpointMappingClient(client, mappingConfigs);
});
services.AddTransient<ITimestampedMappingClient, TimestampedMappingClient>(provider =>
{
var client = provider.GetRequiredService<ITimestampedValuesClient>();
return new TimestampedMappingClient(client, mappingConfigs);
}); });
return services; return services;
} }

View File

@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DD.Persistence.Client;
public interface ISetpointConfigStorage
{
bool TryGetType(Guid id, out Type type);
}

View File

@ -1,20 +0,0 @@
namespace DD.Persistence.Client;
internal class SetpointConfigStorage : ISetpointConfigStorage
{
private readonly Dictionary<Guid, Type> setpointTypeConfigs;
public SetpointConfigStorage(Dictionary<Guid, Type>? setpointTypeConfigs)
{
this.setpointTypeConfigs = setpointTypeConfigs?? new Dictionary<Guid, Type>();
}
public bool TryGetType(Guid id, out Type type)
{
return setpointTypeConfigs.TryGetValue(id, out type);
}
public void AddOrReplace(Guid id, Type type)
{
setpointTypeConfigs[id] = type;
}
}

View File

@ -1,10 +1,9 @@
using DD.Persistence.Client; using DD.Persistence.Client;
using DD.Persistence.Client.Clients;
using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Interfaces.Refit; using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Client.Clients.Mapping.Clients;
using DD.Persistence.Database.Entity; using DD.Persistence.Database.Entity;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Text.Json; using System.Text.Json;
using Xunit; using Xunit;
@ -13,17 +12,14 @@ namespace DD.Persistence.IntegrationTests.Controllers
public class SetpointControllerTest : BaseIntegrationTest public class SetpointControllerTest : BaseIntegrationTest
{ {
private readonly ISetpointClient setpointClient; private readonly ISetpointClient setpointClient;
private readonly SetpointConfigStorage configStorage;
public SetpointControllerTest(WebAppFactoryFixture factory) : base(factory) public SetpointControllerTest(WebAppFactoryFixture factory) : base(factory)
{ {
var refitClientFactory = scope.ServiceProvider var refitClientFactory = scope.ServiceProvider
.GetRequiredService<IRefitClientFactory<IRefitSetpointClient>>(); .GetRequiredService<IRefitClientFactory<IRefitSetpointClient>>();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<SetpointClient>>();
setpointClient = scope.ServiceProvider setpointClient = scope.ServiceProvider
.GetRequiredService<ISetpointClient>(); .GetRequiredService<ISetpointClient>();
configStorage = (SetpointConfigStorage)scope.ServiceProvider.GetRequiredService<ISetpointConfigStorage>();
} }
@ -32,12 +28,16 @@ namespace DD.Persistence.IntegrationTests.Controllers
{ {
var id = Guid.Parse("e0fcad22-1761-476e-a729-a3c59d51ba41"); var id = Guid.Parse("e0fcad22-1761-476e-a729-a3c59d51ba41");
configStorage.AddOrReplace(id, typeof(float)); var config = new Dictionary<Guid, Type>();
config[id] = typeof(float);
var setpointMapper = new SetpointMappingClient(setpointClient, config);
await setpointClient.Add(id, 48.3f, CancellationToken.None); await setpointClient.Add(id, 48.3f, CancellationToken.None);
//act //act
var response = await setpointClient.GetCurrent([id], CancellationToken.None); var response = await setpointMapper.GetCurrent([id], CancellationToken.None);
//assert //assert
Assert.NotNull(response); Assert.NotNull(response);

View File

@ -16,6 +16,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DD.Persistence.Client\DD.Persistence.Client.csproj" />
<ProjectReference Include="..\DD.Persistence.Database.Postgres\DD.Persistence.Database.Postgres.csproj" /> <ProjectReference Include="..\DD.Persistence.Database.Postgres\DD.Persistence.Database.Postgres.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,40 @@
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Mapping.Abstractions;
using DD.Persistence.Client.Clients.Mapping.Clients;
using DD.Persistence.Repositories;
using DD.Persistence.Services.Interfaces;
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DD.Persistence.Test;
public class MappingClientsTest
{
private readonly ITimestampedValuesClient timestampedValuesClient = Substitute.For<ITimestampedValuesClient>();
private readonly TimestampedMappingClient timestampedMappingClient;
public record TestDto
{
public int Id { get; set; }
public string? Value { get; set; }
}
private readonly Dictionary<Guid, Type> mappingConfigs = new Dictionary<Guid, Type>()
{
{ Guid.NewGuid(), typeof(TestDto) }
};
public MappingClientsTest()
{
timestampedMappingClient = new TimestampedMappingClient(timestampedValuesClient, mappingConfigs);
}
[Fact]
public async void Test()
{
var discriminatorIds = mappingConfigs.Keys;
var result = await timestampedMappingClient.Gett(discriminatorIds, null, null, null, 0, 1, CancellationToken.None);
}
}