52 lines
2.1 KiB
C#
52 lines
2.1 KiB
C#
using Microsoft.Extensions.Logging;
|
||
using MockQueryable;
|
||
using Moq;
|
||
using PARR.DAL.Contracts;
|
||
using PARR.DAL.DomainServices.Implementations;
|
||
using PARR.DAL.DomainServices.Interfaces;
|
||
using PARR.DAL.Models.Job;
|
||
using PARR.DAL.Models.Unit;
|
||
using PARR.DAL.Services.Interfaces.Job;
|
||
using PARR.DAL.Services.Interfaces.Unit;
|
||
|
||
namespace PARR.DAL.Tests.DomainServices.Implementations
|
||
{
|
||
public class ShortcodesServiceTests
|
||
{
|
||
private readonly Mock<ILogger<ShortcodesService>> loggerMock = new();
|
||
private readonly Mock<SettingsFromDb> settingsMock = new();
|
||
private readonly Mock<IJobService> jobServiceMock = new();
|
||
private readonly Mock<IUnitService> unitServiceMock = new();
|
||
private readonly Mock<IUnitInValueService> unitInValueServiceMock = new();
|
||
private readonly Mock<IUnitFieldService> unitFieldServiceMock = new();
|
||
private readonly Mock<IUnitFilterService> unitFilterServiceMock = new();
|
||
|
||
private ShortcodesService CreateService()
|
||
=> new(loggerMock.Object, settingsMock.Object, jobServiceMock.Object,
|
||
unitServiceMock.Object, unitFilterServiceMock.Object,
|
||
unitInValueServiceMock.Object, unitFieldServiceMock.Object);
|
||
|
||
[Fact]
|
||
public async Task ApplyShortcodesAsync_WithEc_ShouldReplaceEc()
|
||
{
|
||
// Arrange
|
||
var unitId = Guid.NewGuid();
|
||
var jobId = Guid.NewGuid();
|
||
|
||
var unit = new Unit { Id = unitId, Name = "Сервер_01" };
|
||
var job = new Job { Id = jobId, Name = "SAN ТО-1 Проверка работы фабрики SAN", TemplateNameMask = "%ЭК%", WorkGroupMask = "", WorkName = "Аудит" };
|
||
|
||
// ✅ БЕЗ .Object — ключевое!
|
||
unitServiceMock.Setup(x => x.Get()).Returns(new[] { unit }.BuildMock());
|
||
jobServiceMock.Setup(x => x.Get()).Returns(new[] { job }.BuildMock());
|
||
|
||
var service = CreateService();
|
||
|
||
// Act
|
||
var result = await service.ApplyShortcodesAsync("%ЭК%", unitId, jobId);
|
||
|
||
// Assert
|
||
Assert.Equal("Сервер_01", result);
|
||
}
|
||
}
|
||
} |