forked from ddrilling/AsbCloudServer
This commit is contained in:
parent
b00b4f3781
commit
40dac37aa4
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@ -21,29 +22,37 @@ namespace AsbCloudInfrastructure.Repository
|
||||
}
|
||||
public async Task<IEnumerable<LimitingParameterDataDto>> GetStatOrDefaultAsync(LimitingParameterRequest request, WellDto wellDto, CancellationToken token)
|
||||
{
|
||||
var query = BuildQuery(request, wellDto);
|
||||
try
|
||||
{
|
||||
var query = BuildQuery(request, wellDto);
|
||||
|
||||
if (query is null)
|
||||
if (query is null)
|
||||
return Enumerable.Empty<LimitingParameterDataDto>();
|
||||
|
||||
var data = (await query.ToListAsync(token))
|
||||
.Select(x => new LimitingParameterDataDto
|
||||
{
|
||||
IdWell = wellDto.Id,
|
||||
IdTelemetry = x.IdTelemetry,
|
||||
IdFeedRegulator = x.IdFeedRegulator,
|
||||
DateStart = x.DateStart,
|
||||
DateEnd = x.DateEnd,
|
||||
DepthStart = x.DepthStart,
|
||||
DepthEnd = x.DepthEnd
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return Enumerable.Empty<LimitingParameterDataDto>();
|
||||
|
||||
var data = (await query.ToListAsync(token))
|
||||
.Select(x => new LimitingParameterDataDto {
|
||||
IdWell = wellDto.Id,
|
||||
IdTelemetry = x.IdTelemetry,
|
||||
IdFeedRegulator = x.IdFeedRegulator,
|
||||
DateStart = x.DateStart,
|
||||
DateEnd = x.DateEnd,
|
||||
DepthStart = x.DepthStart,
|
||||
DepthEnd = x.DepthEnd
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
private IQueryable<LimitingParameter> BuildQuery(LimitingParameterRequest request, WellDto wellDto)
|
||||
{
|
||||
var query = context.LimitingParameter
|
||||
.OrderBy(x => x.Id)
|
||||
//.OrderBy(x => x.Id)
|
||||
.Where(x => x.IdTelemetry == wellDto.IdTelemetry)
|
||||
.AsNoTracking();
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -0,0 +1,93 @@
|
||||
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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
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.GetStatOrDefaultAsync(limitingParameterRequest, CancellationToken.None);
|
||||
Assert.NotNull(data);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user