Creado apartir del commit b888de6c92056de294456f581a56e25e734d4ab7 de develop
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
using adas_core.Application.Repositories.Interfaces;
|
||||
using adas_core.Application.Services;
|
||||
using adas_core.Application.Services.Interfaces;
|
||||
using adas_core.Domain.Enums;
|
||||
using adas_core.Domain.Models;
|
||||
using adas_core.Domain.Models.AppSettings;
|
||||
using adas_core.Domain.Models.MongoModels;
|
||||
using adas_core.Domain.Models.Pumps;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using Options = Microsoft.Extensions.Options.Options;
|
||||
|
||||
namespace adas_core.Test.Services;
|
||||
|
||||
[TestFixture]
|
||||
public class ConfigPumpsServiceTest
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
//configPumpsServiceMock = new Mock<IConfigPumpsService>();
|
||||
_configPumpsRepositoryMock = new Mock<IConfigPumpsRepository>();
|
||||
|
||||
_optionsApiSettings = Options.Create(_apiSettings);
|
||||
|
||||
_logger = new Mock<ILogger<ConfigPumpsService>>();
|
||||
|
||||
_configPumpsService = new ConfigPumpsService(
|
||||
_configPumpsRepositoryMock.Object,
|
||||
_optionsApiSettings,
|
||||
_logger.Object,
|
||||
_httpContextAccessor.Object,
|
||||
_auditService.Object);
|
||||
}
|
||||
|
||||
private ConfigPumpsService _configPumpsService;
|
||||
|
||||
//Mock<IConfigPumpsService> configPumpsServiceMock;
|
||||
private Mock<IConfigPumpsRepository> _configPumpsRepositoryMock;
|
||||
|
||||
private readonly ApiSettings _apiSettings = new()
|
||||
{
|
||||
ConfigPumpsRequired = true,
|
||||
ConfigPumpsKey = "PV1",
|
||||
ConfigObservation = new ConfigObservationSettings
|
||||
{
|
||||
Refresh = null
|
||||
}
|
||||
};
|
||||
|
||||
private IOptions<ApiSettings> _optionsApiSettings;
|
||||
|
||||
private Mock<ILogger<ConfigPumpsService>> _logger;
|
||||
|
||||
private readonly Mock<IHttpContextAccessor> _httpContextAccessor = new();
|
||||
private readonly Mock<ILocalAuditService> _auditService = new();
|
||||
|
||||
private static readonly DateTime Now = DateTime.Now;
|
||||
|
||||
[Test]
|
||||
public async Task Map_configPumpsRequired_false_Return_same_pump()
|
||||
{
|
||||
_optionsApiSettings.Value.ConfigPumpsRequired = false;
|
||||
|
||||
var pump = new PumpObservation
|
||||
{
|
||||
Code = "code",
|
||||
Name = "name",
|
||||
Time = Now
|
||||
};
|
||||
|
||||
var configPumpsService = new ConfigPumpsService(
|
||||
_configPumpsRepositoryMock.Object,
|
||||
_optionsApiSettings,
|
||||
_logger.Object,
|
||||
_httpContextAccessor.Object,
|
||||
_auditService.Object);
|
||||
|
||||
var result = await configPumpsService.Map(pump);
|
||||
|
||||
Assert.That(pump, Is.EqualTo(result));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Map_not_alarmType_Return_same_pump()
|
||||
{
|
||||
_optionsApiSettings.Value.ConfigPumpsRequired = true;
|
||||
|
||||
var pump = new PumpObservation
|
||||
{
|
||||
Code = "code",
|
||||
Name = "name",
|
||||
Time = Now
|
||||
};
|
||||
|
||||
var result = await _configPumpsService.Map(pump);
|
||||
|
||||
Assert.That(pump, Is.EqualTo(result));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Map_Not_uiConfiguration_Return_same_pump()
|
||||
{
|
||||
_optionsApiSettings.Value.ConfigPumpsRequired = true;
|
||||
|
||||
var pump = new PumpObservation
|
||||
{
|
||||
Code = "code",
|
||||
Name = "name",
|
||||
Time = Now,
|
||||
AlarmType = PumpEnum.AlarmType.Attention
|
||||
};
|
||||
|
||||
var configPumpItem = new ConfigPumpItem();
|
||||
|
||||
var configPumps = new ConfigPumps
|
||||
{
|
||||
Id = "PV1",
|
||||
Items = [configPumpItem]
|
||||
};
|
||||
_configPumpsRepositoryMock.Setup(c => c.FindById(It.IsAny<string>())).ReturnsAsync(configPumps);
|
||||
|
||||
var result = await _configPumpsService.Map(pump);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(pump, Is.EqualTo(result));
|
||||
Assert.That(result.UiConfiguration, Is.Null);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Map_uiConfiguration_Return_pump_uiConfiguration()
|
||||
{
|
||||
_optionsApiSettings.Value.ConfigPumpsRequired = true;
|
||||
|
||||
var pump = new PumpObservation
|
||||
{
|
||||
Code = "code",
|
||||
Name = "name",
|
||||
Time = Now,
|
||||
AlarmType = PumpEnum.AlarmType.AirInLine
|
||||
};
|
||||
|
||||
|
||||
var configPumpItem = new ConfigPumpItem
|
||||
{
|
||||
AlarmType = PumpEnum.AlarmType.AirInLine,
|
||||
UiConfiguration = new Dictionary<string, object> { { "screenAlarmLabel", PumpEnum.AlarmType.AirInLine } }
|
||||
};
|
||||
|
||||
var configPumps = new ConfigPumps
|
||||
{
|
||||
Id = "PV1",
|
||||
Items = [configPumpItem]
|
||||
};
|
||||
|
||||
_configPumpsRepositoryMock.Setup(c => c.FindById(It.IsAny<string>())).ReturnsAsync(configPumps);
|
||||
|
||||
var result = await _configPumpsService.Map(pump);
|
||||
|
||||
Assert.That(result.UiConfiguration, Is.Not.Null);
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(result.UiConfiguration, Has.Count.EqualTo(1));
|
||||
Assert.That(result.UiConfiguration!["screenAlarmLabel"], Is.EqualTo(PumpEnum.AlarmType.AirInLine));
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user