feat(dal): ShortcodesService добавлена обработка динамичесих составляющих "%СВЯЗИ%", "%ТНК-КРАТКО%"
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.DomainServices.Implementations;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
using Xunit;
|
||||
|
||||
namespace PARR.DAL.Tests
|
||||
{
|
||||
public class UnitFilterServiceTests : IDisposable
|
||||
{
|
||||
private readonly DbContextOptions<DataContext> _options;
|
||||
private readonly DataContext _context;
|
||||
private readonly UnitFilterService _service;
|
||||
|
||||
public UnitFilterServiceTests()
|
||||
{
|
||||
_options = new DbContextOptionsBuilder<DataContext>()
|
||||
.UseInMemoryDatabase($"TestDb_{Guid.NewGuid()}")
|
||||
.EnableSensitiveDataLogging()
|
||||
.Options;
|
||||
|
||||
_context = new DataContext(_options);
|
||||
_context.Database.EnsureCreated();
|
||||
TestDataGenerator.Seed(_context);
|
||||
|
||||
var logger = Mock.Of<ILogger<UnitFilterService>>();
|
||||
|
||||
// Используем реальные сервисы, работающие с _context
|
||||
var jobServiceMock = new Mock<IJobService>();
|
||||
jobServiceMock.Setup(x => x.Get()).Returns(() => _context.Jobs);
|
||||
|
||||
var unitServiceMock = new Mock<IUnitService>();
|
||||
unitServiceMock.Setup(x => x.Get()).Returns(() => _context.Units);
|
||||
|
||||
_service = new UnitFilterService(logger, jobServiceMock.Object, unitServiceMock.Object);
|
||||
}
|
||||
|
||||
public void Dispose() => _context.Dispose();
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetRelatedUnitNamesAsync_WithChildRelationshipFilter_ShouldReturnExpectedNames()
|
||||
{
|
||||
// Arrange
|
||||
var jobId = _context.Jobs.First(j => j.Name == "TestJob_2").Id;
|
||||
var unitId = TestDataGenerator.UnitWId; // Родитель
|
||||
|
||||
// rf.IsParent = false
|
||||
// Ищем юниты, у которых ParentUnitId = UnitWId (т.е. это дети UnitWId)
|
||||
// и у этих юнитов (детей) есть FieldId1 = "коммутатор"
|
||||
// Это UnitXId и UnitYId -> имена: "СХД-КМТ-CISCO-MDS9148-1-ДВС", "СХД-КМТ-CISCO-MDS9148-3-ДВС"
|
||||
|
||||
// Act
|
||||
var result = await _service.GetRelatedUnitNamesAsync(jobId, unitId);
|
||||
|
||||
// Assert
|
||||
result.Should().Contain(new[] { "СХД-КМТ-CISCO-MDS9148-1-ДВС", "СХД-КМТ-CISCO-MDS9148-3-ДВС" });
|
||||
}
|
||||
//[Fact]
|
||||
//public async Task GetRelatedUnitNamesAsync_WithChildRelationshipFilter_ShouldReturnExpectedNames()
|
||||
//{
|
||||
// // Arrange
|
||||
// var jobId = _context.Jobs.First(j => j.Name == "TestJob_2").Id;
|
||||
// var unitId = TestDataGenerator.UnitWId;
|
||||
|
||||
// // Проверим связи вручную
|
||||
// var childLinks = await _context.UnitInUnits
|
||||
// .Where(u => u.ParentUnitId == unitId)
|
||||
// .ToListAsync();
|
||||
|
||||
// var childIds = childLinks.Select(l => l.ChildUnitId).ToList();
|
||||
// var childUnits = await _context.Units
|
||||
// .Where(u => childIds.Contains(u.Id))
|
||||
// .ToListAsync();
|
||||
|
||||
// Console.WriteLine($"Child units of {unitId}:");
|
||||
// foreach (var u in childUnits)
|
||||
// {
|
||||
// Console.WriteLine($" - {u.Id} ({u.Name})");
|
||||
|
||||
// var values = await _context.UnitInValues
|
||||
// .Where(v => v.UnitId == u.Id && v.FieldId == TestDataGenerator.FieldId1)
|
||||
// .ToListAsync();
|
||||
|
||||
// foreach (var v in values)
|
||||
// {
|
||||
// var val = await _context.UnitFieldValues.FindAsync(v.ValueId);
|
||||
// Console.WriteLine($" FieldId1 = {val?.Value}");
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Act
|
||||
// var result = await _service.GetRelatedUnitNamesAsync(jobId, unitId);
|
||||
|
||||
// Console.WriteLine($"Result: [{string.Join(", ", result)}]");
|
||||
|
||||
// // Assert
|
||||
// result.Should().Contain(new[] { "СХД-КМТ-CISCO-MDS9148-1-ДВС", "СХД-КМТ-CISCO-MDS9148-3-ДВС" });
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user