Добавлен ITimestampedSetClient.

Поправлены тесты.
Удален не используемый интерфейс IPersistenceDbContext.
This commit is contained in:
ngfrolov 2024-11-26 10:07:50 +05:00
parent 02def3a7d6
commit 2169e592e6
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
8 changed files with 20 additions and 46 deletions

View File

@ -1,7 +1,7 @@
using Persistence.Models;
using Refit;
namespace Persistence.IntegrationTests.Clients;
namespace Persistence.Client.Clients;
public interface ITimestampedSetClient
{
private const string baseUrl = "/api/TimestampedSet/{idDiscriminator}";
@ -10,7 +10,7 @@ public interface ITimestampedSetClient
Task<IApiResponse<int>> InsertRange(Guid idDiscriminator, IEnumerable<TimestampedSetDto> sets);
[Get(baseUrl)]
Task<IApiResponse<IEnumerable<TimestampedSetDto>>> Get(Guid idDiscriminator, [Query]DateTimeOffset? geTimestamp, [Query]IEnumerable<string>? props, int skip, int take);
Task<IApiResponse<IEnumerable<TimestampedSetDto>>> Get(Guid idDiscriminator, [Query] DateTimeOffset? geTimestamp, [Query] IEnumerable<string>? props, int skip, int take);
[Get($"{baseUrl}/last")]
Task<IApiResponse<IEnumerable<TimestampedSetDto>>> GetLast(Guid idDiscriminator, [Query] IEnumerable<string>? props, int take);

View File

@ -4,7 +4,7 @@ using Persistence.Database.Entity;
using System.Data.Common;
namespace Persistence.Database.Model;
public partial class PersistenceDbContext : DbContext, IPersistenceDbContext
public partial class PersistenceDbContext : DbContext
{
public DbSet<DataSaub> DataSaub => Set<DataSaub>();

View File

@ -1,13 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Persistence.Database.Entity;
using Persistence.Database.Model;
using System.Diagnostics.CodeAnalysis;
namespace Persistence.Database;
public interface IPersistenceDbContext : IDisposable
{
DbSet<DataSaub> DataSaub { get; }
DbSet<TimestampedSet> TimestampedSets { get; }
DbSet<TEntity> Set<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.Interfaces)] TEntity>() where TEntity : class;
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
}

View File

@ -1,17 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Persistence.Database.Model;
public interface IPersistenceDbContext : IDisposable
{
DbSet<DataSaub> DataSaub { get; }
DbSet<Setpoint> Setpoint { get; }
DatabaseFacade Database { get; }
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
}

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Persistence.IntegrationTests.Clients;
using Microsoft.Extensions.DependencyInjection;
using Persistence.Client;
using Persistence.Client.Clients;
using Persistence.Models;
using Xunit;
@ -10,8 +11,10 @@ public class TimestampedSetControllerTest : BaseIntegrationTest
public TimestampedSetControllerTest(WebAppFactoryFixture factory) : base(factory)
{
var persistenceClientFactory = scope.ServiceProvider
.GetRequiredService<PersistenceClientFactory>();
client = factory.GetAuthorizedHttpClient<ITimestampedSetClient>(string.Empty).Result;
client = persistenceClientFactory.GetClient<ITimestampedSetClient>();
}
[Fact]

View File

@ -43,9 +43,6 @@ public class WebAppFactoryFixture : WebApplicationFactory<Startup>
services.AddSingleton<PersistenceClientFactory>();
var serviceProvider = services.BuildServiceProvider();
services.AddScoped<IPersistenceDbContext>(provider => provider.GetRequiredService<PersistenceDbContext>());
var serviceProvider = services.BuildServiceProvider();
using var scope = serviceProvider.CreateScope();
var scopedServices = scope.ServiceProvider;

View File

@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Persistence.Database;
using Persistence.Database.Entity;
using Persistence.Models;
using Persistence.Repositories;
@ -14,9 +13,9 @@ namespace Persistence.Repository.Repositories;
/// </summary>
public class TimestampedSetRepository : ITimestampedSetRepository
{
private readonly IPersistenceDbContext db;
private readonly DbContext db;
public TimestampedSetRepository(IPersistenceDbContext db)
public TimestampedSetRepository(DbContext db)
{
this.db = db;
}
@ -37,6 +36,11 @@ public class TimestampedSetRepository : ITimestampedSetRepository
if (geTimestamp.HasValue)
query = ApplyGeTimestamp(query, geTimestamp.Value);
query = query
.OrderBy(item => item.Timestamp)
.Skip(skip)
.Take(take);
var data = await Materialize(query, token);
if (props is not null && props.Any())

View File

@ -21,7 +21,7 @@ public interface ITimestampedSetRepository
/// <summary>
/// Получение данных с фильтрацией. Значение фильтра null - отключен
/// </summary>
/// <param name="idDiscriminator">Идентификатор набора</param>
/// <param name="idDiscriminator">Дискриминатор (идентификатор) набора</param>
/// <param name="geTimestamp">Фильтр позднее даты</param>
/// <param name="props">Фильтр свойств набора. Можно запросить только некоторые свойства из набора</param>
/// <param name="skip"></param>
@ -41,8 +41,8 @@ public interface ITimestampedSetRepository
/// <summary>
/// Получить последние данные
/// </summary>
/// <param name="idDiscriminator"></param>
/// <param name="props"></param>
/// <param name="idDiscriminator">Дискриминатор (идентификатор) набора</param>
/// <param name="props">Фильтр свойств набора. Можно запросить только некоторые свойства из набора</param>
/// <param name="take"></param>
/// <param name="token"></param>
/// <returns></returns>
@ -51,7 +51,7 @@ public interface ITimestampedSetRepository
/// <summary>
/// Добавление новых данных
/// </summary>
/// <param name="idDiscriminator"></param>
/// <param name="idDiscriminator">Дискриминатор (идентификатор) набора</param>
/// <param name="sets"></param>
/// <param name="token"></param>
/// <returns></returns>