feat(dal): ShortcodesService добавлена обработка динамичесих составляющих "%СВЯЗИ%", "%ТНК-КРАТКО%"
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.DomainServices.Implementations;
|
||||
// Предположим, что у вас есть реализации IJobService и IUnitService
|
||||
// Если нет, можно создать моки, но лучше использовать реальные, если они просты
|
||||
using PARR.DAL.Services.Implementations.Job; // Пример: JobService
|
||||
using PARR.DAL.Services.Implementations.Unit; // Пример: UnitService
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace PARR.DAL.IntegrationTests.Integration
|
||||
{
|
||||
public class UnitFilterServiceIntegrationTests : IAsyncLifetime
|
||||
{
|
||||
private DbContextOptions<DataContext> _options;
|
||||
private DataContext _context;
|
||||
private UnitFilterService _service;
|
||||
|
||||
public UnitFilterServiceIntegrationTests()
|
||||
{
|
||||
_options = new DbContextOptionsBuilder<DataContext>()
|
||||
.UseInMemoryDatabase($"IntegrationTestDb_{Guid.NewGuid()}")
|
||||
.EnableSensitiveDataLogging()
|
||||
.Options;
|
||||
}
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
// Создаём контекст
|
||||
_context = new DataContext(_options);
|
||||
await _context.Database.EnsureCreatedAsync();
|
||||
|
||||
// Заполняем тестовые данные (убедитесь, что TestDataGenerator доступен)
|
||||
TestDataGenerator.Seed(_context); // или async, если вы его переделаете
|
||||
|
||||
// Создаём ServiceProvider с реальными сервисами
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddLogging(builder => builder.AddConsole()); // или Mock.Of<ILogger>
|
||||
|
||||
// Регистрируем контекст
|
||||
serviceCollection.AddScoped<DataContext>(provider => _context);
|
||||
|
||||
serviceCollection.AddScoped<IJobService, JobService>();
|
||||
serviceCollection.AddScoped<IUnitService, UnitService>();
|
||||
|
||||
// Добавляем новые сервисы
|
||||
serviceCollection.AddScoped<IUnitInUnitService, UnitInUnitService>();
|
||||
serviceCollection.AddScoped<IUnitInValueService, UnitInValueService>();
|
||||
|
||||
// Регистрируем тестируемый сервис
|
||||
serviceCollection.AddScoped<UnitFilterService>();
|
||||
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
// Получаем сервис
|
||||
_service = serviceProvider.GetRequiredService<UnitFilterService>();
|
||||
}
|
||||
|
||||
public async Task DisposeAsync()
|
||||
{
|
||||
if (_context != null)
|
||||
{
|
||||
await _context.DisposeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetRelatedUnitNamesAsync_WithChildRelationshipFilter_ShouldReturnExpectedNames()
|
||||
{
|
||||
// Arrange
|
||||
var jobId = _context.Jobs.First(j => j.Name == "TestJob_2").Id;
|
||||
var unitId = TestDataGenerator.UnitWId;
|
||||
|
||||
// Act
|
||||
var result = await _service.GetRelatedUnitNamesAsync(jobId, unitId);
|
||||
|
||||
// Assert
|
||||
result.Should().Contain(new[] { "СХД-КМТ-CISCO-MDS9148-1-ДВС", "СХД-КМТ-CISCO-MDS9148-3-ДВС" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetUnitsIdByJobFilterAsync_WithExistingJobId_ShouldReturnExpectedUnits()
|
||||
{
|
||||
// Arrange
|
||||
var jobId = _context.Jobs.First(j => j.Name == "TestJob_1").Id;
|
||||
var expectedUnitIds = new[] { TestDataGenerator.UnitAId, TestDataGenerator.UnitBId };
|
||||
|
||||
// Act
|
||||
var result = await _service.GetUnitsIdByJobFilterAsync(jobId, takeCount: 10);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull()
|
||||
.And.HaveCount(2)
|
||||
.And.Contain(expectedUnitIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user