forked from ddrilling/AsbCloudServer
This commit is contained in:
parent
b00b4f3781
commit
40dac37aa4
@ -1,9 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Data
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
|
@ -3,6 +3,7 @@ using AsbCloudApp.Repositories;
|
|||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -20,6 +21,8 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
public async Task<IEnumerable<LimitingParameterDataDto>> GetStatOrDefaultAsync(LimitingParameterRequest request, WellDto wellDto, CancellationToken token)
|
public async Task<IEnumerable<LimitingParameterDataDto>> GetStatOrDefaultAsync(LimitingParameterRequest request, WellDto wellDto, CancellationToken token)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var query = BuildQuery(request, wellDto);
|
var query = BuildQuery(request, wellDto);
|
||||||
|
|
||||||
@ -27,7 +30,8 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return Enumerable.Empty<LimitingParameterDataDto>();
|
return Enumerable.Empty<LimitingParameterDataDto>();
|
||||||
|
|
||||||
var data = (await query.ToListAsync(token))
|
var data = (await query.ToListAsync(token))
|
||||||
.Select(x => new LimitingParameterDataDto {
|
.Select(x => new LimitingParameterDataDto
|
||||||
|
{
|
||||||
IdWell = wellDto.Id,
|
IdWell = wellDto.Id,
|
||||||
IdTelemetry = x.IdTelemetry,
|
IdTelemetry = x.IdTelemetry,
|
||||||
IdFeedRegulator = x.IdFeedRegulator,
|
IdFeedRegulator = x.IdFeedRegulator,
|
||||||
@ -39,11 +43,16 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return Enumerable.Empty<LimitingParameterDataDto>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private IQueryable<LimitingParameter> BuildQuery(LimitingParameterRequest request, WellDto wellDto)
|
private IQueryable<LimitingParameter> BuildQuery(LimitingParameterRequest request, WellDto wellDto)
|
||||||
{
|
{
|
||||||
var query = context.LimitingParameter
|
var query = context.LimitingParameter
|
||||||
.OrderBy(x => x.Id)
|
//.OrderBy(x => x.Id)
|
||||||
.Where(x => x.IdTelemetry == wellDto.IdTelemetry)
|
.Where(x => x.IdTelemetry == wellDto.IdTelemetry)
|
||||||
.AsNoTracking();
|
.AsNoTracking();
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
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