Инжект новой фабрики клиентов вместо PersistenceClientFactory в интеграционных тестах
Some checks failed
Unit tests / test (push) Failing after 1m16s
Some checks failed
Unit tests / test (push) Failing after 1m16s
This commit is contained in:
parent
4ec4ec17eb
commit
6873a32667
@ -6,7 +6,7 @@ namespace DD.Persistence.Client.Clients.Interfaces;
|
||||
/// Клиент для работы с временными данными
|
||||
/// </summary>
|
||||
/// <typeparam name="TDto"></typeparam>
|
||||
public interface ITimeSeriesClient<TDto> : IDisposable where TDto : class, new()
|
||||
public interface ITimeSeriesClient<TDto> : IDisposable where TDto : class, ITimeSeriesAbstractDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавление записей
|
||||
|
@ -5,7 +5,7 @@ using Refit;
|
||||
|
||||
namespace DD.Persistence.Client.Clients.Interfaces.Refit
|
||||
{
|
||||
public interface IRefitTechMessagesClient : IDisposable
|
||||
public interface IRefitTechMessagesClient : IRefitClient, IDisposable
|
||||
{
|
||||
private const string BaseRoute = "/api/techMessages";
|
||||
|
||||
|
@ -2,8 +2,8 @@ using DD.Persistence.Models;
|
||||
using Refit;
|
||||
|
||||
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
public interface IRefitTimeSeriesClient<TDto> : IDisposable
|
||||
where TDto : class, new()
|
||||
public interface IRefitTimeSeriesClient<TDto> : IRefitClient, IDisposable
|
||||
where TDto : class, ITimeSeriesAbstractDto
|
||||
{
|
||||
private const string BaseRoute = "/api/dataSaub";
|
||||
|
||||
|
@ -3,7 +3,7 @@ using Refit;
|
||||
|
||||
namespace DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
|
||||
public interface IRefitTimestampedSetClient : IDisposable
|
||||
public interface IRefitTimestampedSetClient : IRefitClient, IDisposable
|
||||
{
|
||||
private const string baseUrl = "/api/TimestampedSet/{idDiscriminator}";
|
||||
|
||||
|
@ -11,9 +11,9 @@ public class TechMessagesClient : BaseClient, ITechMessagesClient
|
||||
{
|
||||
private readonly IRefitTechMessagesClient refitTechMessagesClient;
|
||||
|
||||
public TechMessagesClient(IRefitTechMessagesClient refitTechMessagesClient, ILogger<TechMessagesClient> logger) : base(logger)
|
||||
public TechMessagesClient(IRefitClientFactory<IRefitTechMessagesClient> refitTechMessagesClientFactory, ILogger<TechMessagesClient> logger) : base(logger)
|
||||
{
|
||||
this.refitTechMessagesClient = refitTechMessagesClient;
|
||||
this.refitTechMessagesClient = refitTechMessagesClientFactory.Create();
|
||||
}
|
||||
|
||||
public async Task<PaginationContainer<TechMessageDto>> GetPage(PaginationRequest request, CancellationToken token)
|
||||
|
@ -5,13 +5,13 @@ using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
using DD.Persistence.Models;
|
||||
|
||||
namespace DD.Persistence.Client.Clients;
|
||||
public class TimeSeriesClient<TDto> : BaseClient, ITimeSeriesClient<TDto> where TDto : class, new()
|
||||
public class TimeSeriesClient<TDto> : BaseClient, ITimeSeriesClient<TDto> where TDto : class, ITimeSeriesAbstractDto
|
||||
{
|
||||
private readonly IRefitTimeSeriesClient<TDto> timeSeriesClient;
|
||||
|
||||
public TimeSeriesClient(IRefitTimeSeriesClient<TDto> refitTechMessagesClient, ILogger<TimeSeriesClient<TDto>> logger) : base(logger)
|
||||
public TimeSeriesClient(IRefitClientFactory<IRefitTimeSeriesClient<TDto>> refitTechMessagesClientFactory, ILogger<TimeSeriesClient<TDto>> logger) : base(logger)
|
||||
{
|
||||
this.timeSeriesClient = refitTechMessagesClient;
|
||||
this.timeSeriesClient = refitTechMessagesClientFactory.Create();
|
||||
}
|
||||
|
||||
public async Task<int> AddRange(IEnumerable<TDto> dtos, CancellationToken token)
|
||||
|
@ -9,9 +9,9 @@ public class TimestampedSetClient : BaseClient, ITimestampedSetClient
|
||||
{
|
||||
private readonly IRefitTimestampedSetClient refitTimestampedSetClient;
|
||||
|
||||
public TimestampedSetClient(IRefitTimestampedSetClient refitTimestampedSetClient, ILogger<TimestampedSetClient> logger) : base(logger)
|
||||
public TimestampedSetClient(IRefitClientFactory<IRefitTimestampedSetClient> refitTimestampedSetClientFactory, ILogger<TimestampedSetClient> logger) : base(logger)
|
||||
{
|
||||
this.refitTimestampedSetClient = refitTimestampedSetClient;
|
||||
this.refitTimestampedSetClient = refitTimestampedSetClientFactory.Create();
|
||||
}
|
||||
|
||||
public async Task<int> AddRange(Guid idDiscriminator, IEnumerable<TimestampedSetDto> sets, CancellationToken token)
|
||||
|
@ -9,9 +9,9 @@ public class WitsDataClient : BaseClient, IWitsDataClient
|
||||
{
|
||||
private readonly IRefitWitsDataClient refitWitsDataClient;
|
||||
|
||||
public WitsDataClient(IRefitWitsDataClient refitWitsDataClient, ILogger<WitsDataClient> logger) : base(logger)
|
||||
public WitsDataClient(IRefitClientFactory<IRefitWitsDataClient> refitWitsDataClientFactory, ILogger<WitsDataClient> logger) : base(logger)
|
||||
{
|
||||
this.refitWitsDataClient = refitWitsDataClient;
|
||||
this.refitWitsDataClient = refitWitsDataClientFactory.Create();
|
||||
}
|
||||
|
||||
public async Task<int> AddRange(IEnumerable<WitsDataDto> dtos, CancellationToken token)
|
||||
|
@ -1,5 +1,6 @@
|
||||
using DD.Persistence.Client.Clients;
|
||||
using DD.Persistence.Client.Clients.Interfaces;
|
||||
using DD.Persistence.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DD.Persistence.Client;
|
||||
@ -16,14 +17,14 @@ public static class DependencyInjection
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddPersistenceClients(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton(typeof(IRefitClientFactory<>), typeof(RefitClientFactory<>));
|
||||
services.AddTransient(typeof(IRefitClientFactory<>), typeof(RefitClientFactory<>));
|
||||
services.AddTransient<IChangeLogClient, ChangeLogClient>();
|
||||
services.AddTransient<IDataSourceSystemClient, DataSourceSystemClient>();
|
||||
services.AddTransient<ISetpointClient, SetpointClient>();
|
||||
//services.AddTransient<ITechMessagesClient, TechMessagesClient>();
|
||||
//services.AddTransient<ITimeSeriesClient<>, TimeSeriesClient<>>();
|
||||
//services.AddTransient<ITimeSeriesClient, TimeSeriesClient>();
|
||||
//services.AddTransient<IWitsDataClient, WitsDataClient>();
|
||||
services.AddTransient<ITechMessagesClient, TechMessagesClient>();
|
||||
services.AddTransient<ITimeSeriesClient<DataSaubDto>, TimeSeriesClient<DataSaubDto>>();
|
||||
services.AddTransient<ITimestampedSetClient, TimestampedSetClient>();
|
||||
services.AddTransient<IWitsDataClient, WitsDataClient>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
@ -1,146 +1,146 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using DD.Persistence.Client.Clients.Interfaces;
|
||||
using DD.Persistence.Client.Clients;
|
||||
using DD.Persistence.Client.Helpers;
|
||||
using Refit;
|
||||
using DD.Persistence.Factories;
|
||||
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Text.Json;
|
||||
//using Microsoft.Extensions.Configuration;
|
||||
//using DD.Persistence.Client.Clients.Interfaces;
|
||||
//using DD.Persistence.Client.Clients;
|
||||
//using DD.Persistence.Client.Helpers;
|
||||
//using Refit;
|
||||
//using DD.Persistence.Factories;
|
||||
//using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
//using Microsoft.Extensions.DependencyInjection;
|
||||
//using System.Text.Json;
|
||||
|
||||
namespace DD.Persistence.Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Фабрика клиентов для доступа к Persistence - сервису
|
||||
/// </summary>
|
||||
public class PersistenceClientFactory
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonSerializerOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
private static readonly RefitSettings RefitSettings = new(new SystemTextJsonContentSerializer(JsonSerializerOptions));
|
||||
private readonly IServiceProvider provider;
|
||||
private HttpClient httpClient;
|
||||
public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IServiceProvider provider, IConfiguration configuration)
|
||||
{
|
||||
this.provider = provider;
|
||||
//namespace DD.Persistence.Client
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// Фабрика клиентов для доступа к Persistence - сервису
|
||||
// /// </summary>
|
||||
// public class PersistenceClientFactory
|
||||
// {
|
||||
// private static readonly JsonSerializerOptions JsonSerializerOptions = new()
|
||||
// {
|
||||
// PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
// PropertyNameCaseInsensitive = true
|
||||
// };
|
||||
// private static readonly RefitSettings RefitSettings = new(new SystemTextJsonContentSerializer(JsonSerializerOptions));
|
||||
// private readonly IServiceProvider provider;
|
||||
// private HttpClient httpClient;
|
||||
// public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IServiceProvider provider, IConfiguration configuration)
|
||||
// {
|
||||
// this.provider = provider;
|
||||
|
||||
httpClient = httpClientFactory.CreateClient();
|
||||
// httpClient = httpClientFactory.CreateClient();
|
||||
|
||||
httpClient.Authorize(configuration);
|
||||
}
|
||||
// httpClient.Authorize(configuration);
|
||||
// }
|
||||
|
||||
public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IAuthTokenFactory authTokenFactory, IServiceProvider provider, IConfiguration configuration)
|
||||
{
|
||||
this.provider = provider;
|
||||
// public PersistenceClientFactory(IHttpClientFactory httpClientFactory, IAuthTokenFactory authTokenFactory, IServiceProvider provider, IConfiguration configuration)
|
||||
// {
|
||||
// this.provider = provider;
|
||||
|
||||
httpClient = httpClientFactory.CreateClient();
|
||||
// httpClient = httpClientFactory.CreateClient();
|
||||
|
||||
var token = authTokenFactory.GetToken();
|
||||
httpClient.Authorize(token);
|
||||
}
|
||||
// var token = authTokenFactory.GetToken();
|
||||
// httpClient.Authorize(token);
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Получить клиент для работы с уставками
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//public ISetpointClient GetSetpointClient()
|
||||
//{
|
||||
// var logger = provider.GetRequiredService<ILogger<SetpointClient>>();
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы с уставками
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public ISetpointClient GetSetpointClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<SetpointClient>>();
|
||||
|
||||
// var restClient = RestService.For<IRefitSetpointClient>(httpClient, RefitSettings);
|
||||
// var client = new SetpointClient(restClient, logger);
|
||||
// // var restClient = RestService.For<IRefitSetpointClient>(httpClient, RefitSettings);
|
||||
// // var client = new SetpointClient(restClient, logger);
|
||||
|
||||
// return client;
|
||||
//}
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
/// <summary>
|
||||
/// Получить клиент для работы с технологическими сообщениями
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ITechMessagesClient GetTechMessagesClient()
|
||||
{
|
||||
var logger = provider.GetRequiredService<ILogger<TechMessagesClient>>();
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы с технологическими сообщениями
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public ITechMessagesClient GetTechMessagesClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<TechMessagesClient>>();
|
||||
|
||||
var restClient = RestService.For<IRefitTechMessagesClient>(httpClient, RefitSettings);
|
||||
var client = new TechMessagesClient(restClient, logger);
|
||||
// // var restClient = RestService.For<IRefitTechMessagesClient>(httpClient, RefitSettings);
|
||||
// // var client = new TechMessagesClient(restClient, logger);
|
||||
|
||||
return client;
|
||||
}
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
/// <summary>
|
||||
/// Получить клиент для работы с временными данными
|
||||
/// </summary>
|
||||
/// <typeparam name="TDto"></typeparam>
|
||||
/// <returns></returns>
|
||||
public ITimeSeriesClient<TDto> GetTimeSeriesClient<TDto>()
|
||||
where TDto : class, new()
|
||||
{
|
||||
var logger = provider.GetRequiredService<ILogger<TimeSeriesClient<TDto>>>();
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы с временными данными
|
||||
// /// </summary>
|
||||
// /// <typeparam name="TDto"></typeparam>
|
||||
// /// <returns></returns>
|
||||
// //public ITimeSeriesClient<TDto> GetTimeSeriesClient<TDto>()
|
||||
// // where TDto : class, new()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<TimeSeriesClient<TDto>>>();
|
||||
|
||||
var restClient = RestService.For<IRefitTimeSeriesClient<TDto>>(httpClient, RefitSettings);
|
||||
var client = new TimeSeriesClient<TDto>(restClient, logger);
|
||||
// // var restClient = RestService.For<IRefitTimeSeriesClient<TDto>>(httpClient, RefitSettings);
|
||||
// // var client = new TimeSeriesClient<TDto>(restClient, logger);
|
||||
|
||||
return client;
|
||||
}
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
/// <summary>
|
||||
/// Получить клиент для работы с данными с отметкой времени
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ITimestampedSetClient GetTimestampedSetClient()
|
||||
{
|
||||
var logger = provider.GetRequiredService<ILogger<TimestampedSetClient>>();
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы с данными с отметкой времени
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public ITimestampedSetClient GetTimestampedSetClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<TimestampedSetClient>>();
|
||||
|
||||
var restClient = RestService.For<IRefitTimestampedSetClient>(httpClient, RefitSettings);
|
||||
var client = new TimestampedSetClient(restClient, logger);
|
||||
// // var restClient = RestService.For<IRefitTimestampedSetClient>(httpClient, RefitSettings);
|
||||
// // var client = new TimestampedSetClient(restClient, logger);
|
||||
|
||||
return client;
|
||||
}
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
/// <summary>
|
||||
/// Получить клиент для работы с записями ChangeLog
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//public IChangeLogClient GetChangeLogClient()
|
||||
//{
|
||||
// var logger = provider.GetRequiredService<ILogger<ChangeLogClient>>();
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы с записями ChangeLog
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public IChangeLogClient GetChangeLogClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<ChangeLogClient>>();
|
||||
|
||||
// var restClient = RestService.For<IRefitChangeLogClient>(httpClient, RefitSettings);
|
||||
// var client = new ChangeLogClient(restClient, logger);
|
||||
// // var restClient = RestService.For<IRefitChangeLogClient>(httpClient, RefitSettings);
|
||||
// // var client = new ChangeLogClient(restClient, logger);
|
||||
|
||||
// return client;
|
||||
//}
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
/// <summary>
|
||||
/// Получить клиент для работы c параметрами Wits
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IWitsDataClient GetWitsDataClient()
|
||||
{
|
||||
var logger = provider.GetRequiredService<ILogger<WitsDataClient>>();
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы c параметрами Wits
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public IWitsDataClient GetWitsDataClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<WitsDataClient>>();
|
||||
|
||||
var restClient = RestService.For<IRefitWitsDataClient>(httpClient, RefitSettings);
|
||||
var client = new WitsDataClient(restClient, logger);
|
||||
// // var restClient = RestService.For<IRefitWitsDataClient>(httpClient, RefitSettings);
|
||||
// // var client = new WitsDataClient(restClient, logger);
|
||||
|
||||
return client;
|
||||
}
|
||||
// // return client;
|
||||
// //}
|
||||
|
||||
/// <summary>
|
||||
/// Получить клиент для работы c системами
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//public IDataSourceSystemClient GetDataSourceSystemClient()
|
||||
//{
|
||||
// var logger = provider.GetRequiredService<ILogger<DataSourceSystemClient>>();
|
||||
// /// <summary>
|
||||
// /// Получить клиент для работы c системами
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// //public IDataSourceSystemClient GetDataSourceSystemClient()
|
||||
// //{
|
||||
// // var logger = provider.GetRequiredService<ILogger<DataSourceSystemClient>>();
|
||||
|
||||
// var restClient = RestService.For<IRefitDataSourceSystemClient>(httpClient, RefitSettings);
|
||||
// var client = new DataSourceSystemClient(restClient, logger);
|
||||
// // var restClient = RestService.For<IRefitDataSourceSystemClient>(httpClient, RefitSettings);
|
||||
// // var client = new DataSourceSystemClient(restClient, logger);
|
||||
|
||||
// return client;
|
||||
//}
|
||||
}
|
||||
}
|
||||
// // return client;
|
||||
// //}
|
||||
// }
|
||||
//}
|
||||
|
@ -1,38 +1,41 @@
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
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.Refit;
|
||||
using DD.Persistence.Database.Entity;
|
||||
using DD.Persistence.Models;
|
||||
using DD.Persistence.Models.Enumerations;
|
||||
using DD.Persistence.Models.Requests;
|
||||
using System.Net;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Xunit;
|
||||
|
||||
namespace DD.Persistence.IntegrationTests.Controllers
|
||||
{
|
||||
public class TechMessagesControllerTest : BaseIntegrationTest
|
||||
{
|
||||
private static readonly string SystemCacheKey = $"{typeof(Database.Entity.DataSourceSystem).FullName}CacheKey";
|
||||
private readonly ITechMessagesClient techMessagesClient;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
public TechMessagesControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||
{
|
||||
var scope = factory.Services.CreateScope();
|
||||
var persistenceClientFactory = scope.ServiceProvider
|
||||
.GetRequiredService<PersistenceClientFactory>();
|
||||
public class TechMessagesControllerTest : BaseIntegrationTest
|
||||
{
|
||||
private static readonly string SystemCacheKey = $"{typeof(Database.Entity.DataSourceSystem).FullName}CacheKey";
|
||||
private readonly ITechMessagesClient techMessagesClient;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
public TechMessagesControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||
{
|
||||
var refitClientFactory = scope.ServiceProvider
|
||||
.GetRequiredService<IRefitClientFactory<IRefitTechMessagesClient>>();
|
||||
var logger = scope.ServiceProvider.GetRequiredService<ILogger<TechMessagesClient>>();
|
||||
|
||||
techMessagesClient = persistenceClientFactory.GetTechMessagesClient();
|
||||
memoryCache = scope.ServiceProvider.GetRequiredService<IMemoryCache>();
|
||||
}
|
||||
techMessagesClient = scope.ServiceProvider
|
||||
.GetRequiredService<ITechMessagesClient>();
|
||||
memoryCache = scope.ServiceProvider.GetRequiredService<IMemoryCache>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPage_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
[Fact]
|
||||
public async Task GetPage_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
var requestDto = new PaginationRequest()
|
||||
{
|
||||
@ -44,235 +47,235 @@ namespace DD.Persistence.IntegrationTests.Controllers
|
||||
//act
|
||||
var response = await techMessagesClient.GetPage(requestDto, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response.Items);
|
||||
Assert.Equal(requestDto.Skip, response.Skip);
|
||||
Assert.Equal(requestDto.Take, response.Take);
|
||||
}
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response.Items);
|
||||
Assert.Equal(requestDto.Skip, response.Skip);
|
||||
Assert.Equal(requestDto.Take, response.Take);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPage_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var dtos = await InsertRange(Guid.NewGuid());
|
||||
var dtosCount = dtos.Count();
|
||||
var requestDto = new PaginationRequest()
|
||||
{
|
||||
Skip = 0,
|
||||
Take = 2,
|
||||
SortSettings = nameof(TechMessage.CategoryId)
|
||||
};
|
||||
[Fact]
|
||||
public async Task GetPage_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var dtos = await InsertRange(Guid.NewGuid());
|
||||
var dtosCount = dtos.Count();
|
||||
var requestDto = new PaginationRequest()
|
||||
{
|
||||
Skip = 0,
|
||||
Take = 2,
|
||||
SortSettings = nameof(TechMessage.CategoryId)
|
||||
};
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetPage(requestDto, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(dtosCount, response.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertRange_returns_success()
|
||||
{
|
||||
await InsertRange(Guid.NewGuid());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertRange_returns_BadRequest()
|
||||
{
|
||||
//arrange
|
||||
const string exceptionMessage = "Ошибка валидации, формата или маршрутизации запроса";
|
||||
var systemId = Guid.NewGuid();
|
||||
var dtos = new List<TechMessageDto>()
|
||||
{
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = -1, // < 0
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = string.Empty, // length < 0
|
||||
EventState = EventState.Triggered
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
//act
|
||||
var response = await techMessagesClient.AddRange(systemId, dtos, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//assert
|
||||
Assert.Equal(exceptionMessage, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSystems_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetSystems(CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSystems_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
await InsertRange(Guid.NewGuid());
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetSystems(CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
var expectedSystemCount = 1;
|
||||
Assert.Equal(expectedSystemCount, response!.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetStatistics_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
var categoryIds = new [] { 1, 2 };
|
||||
var systemIds = new [] { Guid.NewGuid() };
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetStatistics(systemIds, categoryIds, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetStatistics_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var categoryIds = new[] { 1 };
|
||||
var systemId = Guid.NewGuid();
|
||||
var dtos = await InsertRange(systemId);
|
||||
var filteredDtos = dtos.Where(e => categoryIds.Contains(e.CategoryId));
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetStatistics([systemId], categoryIds, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotEmpty(response);
|
||||
var categories = response
|
||||
.FirstOrDefault()!.Categories
|
||||
.Count();
|
||||
Assert.Equal(filteredDtos.Count(), categories);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDatesRange_returns_NoContent()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.Null(response);
|
||||
}
|
||||
Assert.NotNull(response);
|
||||
Assert.Equal(dtosCount, response.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDatesRange_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
await InsertRange(Guid.NewGuid());
|
||||
[Fact]
|
||||
public async Task InsertRange_returns_success()
|
||||
{
|
||||
await InsertRange(Guid.NewGuid());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertRange_returns_BadRequest()
|
||||
{
|
||||
//arrange
|
||||
const string exceptionMessage = "Ошибка валидации, формата или маршрутизации запроса";
|
||||
var systemId = Guid.NewGuid();
|
||||
var dtos = new List<TechMessageDto>()
|
||||
{
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = -1, // < 0
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = string.Empty, // length < 0
|
||||
EventState = EventState.Triggered
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
//act
|
||||
var response = await techMessagesClient.AddRange(systemId, dtos, CancellationToken.None);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//assert
|
||||
Assert.Equal(exceptionMessage, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSystems_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetSystems(CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetSystems_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
await InsertRange(Guid.NewGuid());
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetSystems(CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
var expectedSystemCount = 1;
|
||||
Assert.Equal(expectedSystemCount, response!.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetStatistics_returns_success()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
var categoryIds = new[] { 1, 2 };
|
||||
var systemIds = new[] { Guid.NewGuid() };
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetStatistics(systemIds, categoryIds, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.Empty(response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetStatistics_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var categoryIds = new[] { 1 };
|
||||
var systemId = Guid.NewGuid();
|
||||
var dtos = await InsertRange(systemId);
|
||||
var filteredDtos = dtos.Where(e => categoryIds.Contains(e.CategoryId));
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetStatistics([systemId], categoryIds, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotEmpty(response);
|
||||
var categories = response
|
||||
.FirstOrDefault()!.Categories
|
||||
.Count();
|
||||
Assert.Equal(filteredDtos.Count(), categories);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDatesRange_returns_NoContent()
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotNull(response?.From);
|
||||
Assert.NotNull(response?.To);
|
||||
}
|
||||
//assert
|
||||
Assert.Null(response);
|
||||
}
|
||||
|
||||
// [Fact]
|
||||
// public async Task GetPart_returns_success()
|
||||
// {
|
||||
// //arrange
|
||||
// var dateBegin = DateTimeOffset.UtcNow;
|
||||
// var take = 2;
|
||||
[Fact]
|
||||
public async Task GetDatesRange_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
await InsertRange(Guid.NewGuid());
|
||||
|
||||
// //act
|
||||
// var response = await techMessagesClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||
//act
|
||||
var response = await techMessagesClient.GetDatesRangeAsync(CancellationToken.None);
|
||||
|
||||
// //assert
|
||||
// Assert.NotNull(response);
|
||||
// Assert.Empty(response);
|
||||
//}
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotNull(response?.From);
|
||||
Assert.NotNull(response?.To);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPart_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var dateBegin = DateTimeOffset.UtcNow;
|
||||
var take = 1;
|
||||
await InsertRange(Guid.NewGuid());
|
||||
// [Fact]
|
||||
// public async Task GetPart_returns_success()
|
||||
// {
|
||||
// //arrange
|
||||
// var dateBegin = DateTimeOffset.UtcNow;
|
||||
// var take = 2;
|
||||
|
||||
// //act
|
||||
// var response = await techMessagesClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||
|
||||
// //assert
|
||||
// Assert.NotNull(response);
|
||||
// Assert.Empty(response);
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public async Task GetPart_AfterSave_returns_success()
|
||||
{
|
||||
//arrange
|
||||
var dateBegin = DateTimeOffset.UtcNow;
|
||||
var take = 1;
|
||||
await InsertRange(Guid.NewGuid());
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.GetPart(dateBegin, take, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotEmpty(response);
|
||||
}
|
||||
//assert
|
||||
Assert.NotNull(response);
|
||||
Assert.NotEmpty(response);
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<TechMessageDto>> InsertRange(Guid systemId)
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
private async Task<IEnumerable<TechMessageDto>> InsertRange(Guid systemId)
|
||||
{
|
||||
//arrange
|
||||
memoryCache.Remove(SystemCacheKey);
|
||||
dbContext.CleanupDbSet<TechMessage>();
|
||||
dbContext.CleanupDbSet<DataSourceSystem>();
|
||||
|
||||
var dtos = new List<TechMessageDto>()
|
||||
{
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = 1,
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = nameof(TechMessageDto.Text),
|
||||
EventState = Models.Enumerations.EventState.Triggered
|
||||
},
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = 2,
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = nameof(TechMessageDto.Text),
|
||||
EventState = Models.Enumerations.EventState.Triggered
|
||||
}
|
||||
};
|
||||
var dtos = new List<TechMessageDto>()
|
||||
{
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = 1,
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = nameof(TechMessageDto.Text),
|
||||
EventState = Models.Enumerations.EventState.Triggered
|
||||
},
|
||||
new TechMessageDto()
|
||||
{
|
||||
EventId = Guid.NewGuid(),
|
||||
CategoryId = 2,
|
||||
Timestamp = DateTimeOffset.UtcNow,
|
||||
Text = nameof(TechMessageDto.Text),
|
||||
EventState = Models.Enumerations.EventState.Triggered
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//act
|
||||
var response = await techMessagesClient.AddRange(systemId, dtos, CancellationToken.None);
|
||||
//act
|
||||
var response = await techMessagesClient.AddRange(systemId, dtos, CancellationToken.None);
|
||||
|
||||
//assert
|
||||
Assert.Equal(dtos.Count, response);
|
||||
//assert
|
||||
Assert.Equal(dtos.Count, response);
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
@ -1,16 +1,19 @@
|
||||
using DD.Persistence.Client;
|
||||
using DD.Persistence.Client.Clients;
|
||||
using DD.Persistence.Client.Clients.Interfaces;
|
||||
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
using DD.Persistence.Database.Model;
|
||||
using DD.Persistence.Models;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using DD.Persistence.Client;
|
||||
using DD.Persistence.Client.Clients.Interfaces;
|
||||
using DD.Persistence.Database.Model;
|
||||
using System.Net;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Xunit;
|
||||
|
||||
namespace DD.Persistence.IntegrationTests.Controllers;
|
||||
|
||||
public abstract class TimeSeriesBaseControllerTest<TEntity, TDto> : BaseIntegrationTest
|
||||
where TEntity : class, ITimestampedData, new()
|
||||
where TDto : class, new()
|
||||
where TDto : class, ITimeSeriesAbstractDto, new()
|
||||
{
|
||||
private readonly ITimeSeriesClient<TDto> timeSeriesClient;
|
||||
|
||||
@ -18,11 +21,12 @@ public abstract class TimeSeriesBaseControllerTest<TEntity, TDto> : BaseIntegrat
|
||||
{
|
||||
dbContext.CleanupDbSet<TEntity>();
|
||||
|
||||
var scope = factory.Services.CreateScope();
|
||||
var persistenceClientFactory = scope.ServiceProvider
|
||||
.GetRequiredService<PersistenceClientFactory>();
|
||||
var refitClientFactory = scope.ServiceProvider
|
||||
.GetRequiredService<IRefitClientFactory<IRefitTimeSeriesClient<TDto>>>();
|
||||
var logger = scope.ServiceProvider.GetRequiredService<ILogger<TimeSeriesClient<TDto>>>();
|
||||
|
||||
timeSeriesClient = persistenceClientFactory.GetTimeSeriesClient<TDto>();
|
||||
timeSeriesClient = scope.ServiceProvider
|
||||
.GetRequiredService<ITimeSeriesClient<TDto>>();
|
||||
}
|
||||
|
||||
public async Task InsertRangeSuccess(TDto dto)
|
||||
|
@ -3,6 +3,9 @@ using DD.Persistence.Client;
|
||||
using DD.Persistence.Client.Clients.Interfaces;
|
||||
using DD.Persistence.Models;
|
||||
using Xunit;
|
||||
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
using DD.Persistence.Client.Clients;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace DD.Persistence.IntegrationTests.Controllers;
|
||||
public class TimestampedSetControllerTest : BaseIntegrationTest
|
||||
@ -11,10 +14,12 @@ public class TimestampedSetControllerTest : BaseIntegrationTest
|
||||
|
||||
public TimestampedSetControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||
{
|
||||
var persistenceClientFactory = scope.ServiceProvider
|
||||
.GetRequiredService<PersistenceClientFactory>();
|
||||
var refitClientFactory = scope.ServiceProvider
|
||||
.GetRequiredService<IRefitClientFactory<IRefitTimestampedSetClient>>();
|
||||
var logger = scope.ServiceProvider.GetRequiredService<ILogger<TimestampedSetClient>>();
|
||||
|
||||
client = persistenceClientFactory.GetTimestampedSetClient();
|
||||
client = scope.ServiceProvider
|
||||
.GetRequiredService<ITimestampedSetClient>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -1,13 +1,12 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using DD.Persistence.Client;
|
||||
using DD.Persistence.Client.Clients;
|
||||
using DD.Persistence.Client.Clients.Interfaces;
|
||||
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
using DD.Persistence.Database.Entity;
|
||||
using DD.Persistence.Models;
|
||||
using System.Net;
|
||||
using Xunit;
|
||||
using DD.Persistence.Client.Clients.Interfaces;
|
||||
using DD.Persistence.Client;
|
||||
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||
using DD.Persistence.Client.Clients;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Xunit;
|
||||
|
||||
namespace DD.Persistence.IntegrationTests.Controllers;
|
||||
public class WitsDataControllerTest : BaseIntegrationTest
|
||||
@ -17,7 +16,7 @@ public class WitsDataControllerTest : BaseIntegrationTest
|
||||
public WitsDataControllerTest(WebAppFactoryFixture factory) : base(factory)
|
||||
{
|
||||
var refitClientFactory = scope.ServiceProvider
|
||||
.GetRequiredService<IRefitClientFactory<IRefitWitsDataClient>>();
|
||||
.GetRequiredService<IRefitClientFactory<IRefitWitsDataClient>>();
|
||||
var logger = scope.ServiceProvider.GetRequiredService<ILogger<WitsDataClient>>();
|
||||
|
||||
witsDataClient = scope.ServiceProvider
|
||||
|
Loading…
Reference in New Issue
Block a user