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 dbMock; private readonly ILimitingParameterRepository limitingParameterRepository; private readonly Mock 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(); dbMock.AddDbSetMock(limitingParametersData); limitingParameterRepository = new LimitingParameterRepository(dbMock.Object); wellServiceMock = new Mock(); wellServiceMock.Setup(x => x.GetOrDefaultAsync(It.IsAny(), It.IsAny())) .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); } } }