DD.WellWorkover.Cloud/AsbCloudWebApi.Tests/Services/LimitingParameterServiceTest.cs
2023-11-03 17:02:44 +05:00

95 lines
3.5 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
using AsbCloudInfrastructure.Services;
using Moq;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace AsbCloudWebApi.Tests.ServicesTests
{
public class LimitingParameterServiceTest
{
private readonly Mock<IAsbCloudDbContext> dbMock;
private readonly ILimitingParameterRepository limitingParameterRepository;
private readonly Mock<IWellService> wellServiceMock;
private readonly LimitingParameterService limitingParameterService;
private readonly WellDto[] wellDtos = new WellDto[] {
new WellDto {
Id = 64,
IdTelemetry = 139,
Timezone = new SimpleTimezoneDto {
Hours = 5,
IsOverride = false
}
}
};
private readonly LimitingParameter[] limitingParametersData = new LimitingParameter[] {
new LimitingParameter{
IdTelemetry = 139,
IdFeedRegulator = 1,
DateStart = DateTimeOffset.Parse("2022-01-02T10:00:00.286Z"),
DateEnd = DateTimeOffset.Parse("2022-01-12T10:00:00.286Z"),
DepthStart = 1000,
DepthEnd = 2000
},
new LimitingParameter{
IdTelemetry = 139,
IdFeedRegulator = 1,
DateStart = DateTimeOffset.Parse("2022-01-12T10:00:00.286Z"),
DateEnd = DateTimeOffset.Parse("2022-01-14T10:00:00.286Z"),
DepthStart = 2000,
DepthEnd = 2500
},
new LimitingParameter{
IdTelemetry = 139,
IdFeedRegulator = 1,
DateStart = DateTimeOffset.Parse("2022-01-14T10:00:00.286Z"),
DateEnd = DateTimeOffset.Parse("2022-01-18T10:00:00.286Z"),
DepthStart = 2500,
DepthEnd = 4000
}
};
private readonly LimitingParameterRequest limitingParameterRequest = new LimitingParameterRequest {
IdWell = 64,
GtDate = DateTime.Parse("2022-01-08T10:00:00.286Z"),
LtDate = DateTime.Parse("2022-01-15T10:00:00.286Z")
};
public LimitingParameterServiceTest()
{
dbMock = new Mock<IAsbCloudDbContext>();
dbMock.AddDbSetMock(limitingParametersData);
limitingParameterRepository = new LimitingParameterRepository(dbMock.Object);
wellServiceMock = new Mock<IWellService>();
wellServiceMock.Setup(x => x.GetOrDefaultAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
.Returns((int idWell, CancellationToken token) => {
var data = wellDtos.FirstOrDefault(x => x.Id == idWell);
return Task.FromResult(data);
});
limitingParameterService = new LimitingParameterService(limitingParameterRepository, wellServiceMock.Object);
}
[Fact]
public async Task GetList()
{
var data = await limitingParameterService.GetStatAsync(limitingParameterRequest, CancellationToken.None);
Assert.NotNull(data);
Assert.Single(data);
Assert.Equal(1275, data.First().Depth);
Assert.Equal(10080, data.First().TotalMinutes);
}
}
}