fix tests.

This commit is contained in:
ngfrolov 2022-06-20 12:43:59 +05:00
parent d6b5a9507b
commit f2f16221c8
5 changed files with 25 additions and 9 deletions

View File

@ -10,6 +10,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
const double minRotorSpeed = 5; //об/мин
const double ticksPerHour = 60 * 60 * 10_000_000d;
const double minPressure = 25;
const double minDeltaDepth = 0.02;
public DetectorDrillingRotor() : base(2)
{
@ -22,7 +23,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
var firstItem = telemetry[position];
var deltaDepth = firstItem.WellDepth - firstItem.BitDepth;
if (deltaDepth is not null &&
System.Math.Abs((float)deltaDepth) > 1d)
System.Math.Abs((float)deltaDepth) > minDeltaDepth)
return false;
if(firstItem.RotorSpeed > minRotorSpeed)

View File

@ -10,6 +10,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
const double minRotorSpeed = 5; //об/мин
const double ticksPerHour = 60 * 60 * 10_000_000d;
const double minPressure = 25;
const double minDeltaDepth = 0.02;
public DetectorDrillingSlide() : base(3)
{
@ -21,7 +22,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations.Detectors
var firstItem = telemetry[position];
var deltaDepth = firstItem.WellDepth - firstItem.BitDepth;
if (deltaDepth is not null &&
System.Math.Abs((float)deltaDepth) > 1d)
System.Math.Abs((float)deltaDepth) > minDeltaDepth)
return false;
if(firstItem.RotorSpeed < minRotorSpeed)

View File

@ -7,6 +7,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="xunit" Version="2.4.1" />

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services;
@ -19,6 +20,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
private readonly AsbCloudDbContext context;
private readonly CacheDb cacheDb;
private readonly DetectedOperationService service;
private readonly DetectedOperationRequest request;
private Deposit deposit = new Deposit { Id = 1, Caption = "Депозит 1" };
private Cluster cluster = new Cluster { Id = 1, Caption = "Кластер 1", IdDeposit = 1, Timezone = new SimpleTimezone() };
private WellDto wellDto = new WellDto
@ -126,6 +128,11 @@ namespace AsbCloudWebApi.Tests.ServicesTests
var scheduleService = new ScheduleService(context, wellServiceMock.Object);
service = new DetectedOperationService(context, wellServiceMock.Object, operationValueService, scheduleService);
request = new DetectedOperationRequest
{
IdWell = 1,
IdCategory = 1
};
AsbCloudInfrastructure.DependencyInjection.MapsterSetup();
}
@ -137,39 +144,39 @@ namespace AsbCloudWebApi.Tests.ServicesTests
[Fact]
public async Task Count_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
var list = await service.GetAsync(request, CancellationToken.None);
Assert.Equal(2, list.Stats.First().Count);
}
[Fact]
public async Task AvgVal_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
var list = await service.GetAsync(request, CancellationToken.None);
Assert.Equal(30, list.Stats.First().AverageValue);
}
[Fact]
public async Task AvgTargetVal_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
var list = await service.GetAsync(request, CancellationToken.None);
Assert.Equal(100, list.Stats.First().AverageTargetValue);
}
[Fact]
public async Task Loss_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
var list = await service.GetAsync(request, CancellationToken.None);
Assert.Equal(0, list.Stats.First().Loss);
}
[Fact]
public async Task Efficiency_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
var list = await service.GetAsync(request, CancellationToken.None);
Assert.Equal(100, list.Stats.First().Efficiency);
}
[Fact]
public async Task GroupCount_grouping_by_driller()
{
var list = await service.GetAsync(1, null, CancellationToken.None);
var list = await service.GetAsync(request, CancellationToken.None);
Assert.Equal(1, list.Stats.Count());
}

View File

@ -1,5 +1,6 @@
using AsbCloudDb.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace AsbCloudWebApi.Tests
{
@ -8,10 +9,13 @@ namespace AsbCloudWebApi.Tests
public static AsbCloudDbContext MakeTestContext()
{
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
//.UseInMemoryDatabase(System.Guid.NewGuid().ToString())
//.ConfigureWarnings(configBuilder =>
// configBuilder.Ignore(InMemoryEventId.TransactionIgnoredWarning))
.UseNpgsql("Host=localhost;Database=tests;Username=postgres;Password=q;Persist Security Info=True;Include Error Detail=True")
.Options;
var context = new AsbCloudDbContext(options);
context.Database.EnsureDeleted();
//context.Database.EnsureDeleted();
context.Database.EnsureCreated();
return context;
}