forked from ddrilling/AsbCloudServer
98 lines
3.1 KiB
C#
98 lines
3.1 KiB
C#
using AsbCloudApp.Data;
|
||
using AsbCloudApp.Data.SAUB;
|
||
using AsbCloudApp.Services;
|
||
using AsbCloudDb.Model;
|
||
using AsbCloudInfrastructure.Services;
|
||
using AsbCloudInfrastructure.Services.Cache;
|
||
using AsbCloudInfrastructure.Services.DetectOperations;
|
||
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 DetectedOperationServiceTest
|
||
{
|
||
private readonly AsbCloudDbContext context;
|
||
private readonly CacheDb cacheDb;
|
||
private readonly DetectedOperationService service;
|
||
#region Задача данных
|
||
private Deposit deposit = new Deposit { Id = 1, Caption = "Депозит 1" };
|
||
private Cluster cluster = new Cluster { Id = 1, Caption = "Кластер 1", IdDeposit = 1, Timezone = new SimpleTimezone() };
|
||
private Well well = new Well
|
||
{
|
||
Id = 1,
|
||
Caption = "Test well 1",
|
||
IdTelemetry=1,
|
||
IdCluster = 1,
|
||
Timezone = new SimpleTimezone { Hours = 5 }
|
||
};
|
||
private Driller driller = new Driller
|
||
{
|
||
Id = 1,
|
||
Name = "Тестовый",
|
||
Patronymic = "Тест",
|
||
Surname = "Тестович"
|
||
};
|
||
private DetectedOperation do1 = new DetectedOperation
|
||
{
|
||
Id = 1,
|
||
IdCategory = 1,
|
||
IdTelemetry = 1,
|
||
DateStart = DateTimeOffset.Parse("2022-05-16T10:00:00.286Z"),
|
||
DateEnd = DateTimeOffset.Parse("2022-05-16T18:00:00.286Z"),
|
||
DepthStart = 100,
|
||
DepthEnd = 1000
|
||
};
|
||
private Telemetry telemetry = new Telemetry
|
||
{
|
||
Id=1,
|
||
RemoteUid = Guid.NewGuid().ToString()
|
||
};
|
||
#endregion
|
||
|
||
public DetectedOperationServiceTest()
|
||
{
|
||
context = TestHelpter.MakeTestContext();
|
||
context.SaveChanges();
|
||
|
||
context.Telemetries.Add(telemetry);
|
||
context.Deposits.Add(deposit);
|
||
context.Clusters.Add(cluster);
|
||
context.Wells.Add(well);
|
||
context.Drillers.Add(driller);
|
||
context.DetectedOperations.Add(do1);
|
||
|
||
context.SaveChanges();
|
||
|
||
var timezone = new SimpleTimezoneDto { Hours = 5 };
|
||
var wellServiceMock = new Mock<IWellService>();
|
||
wellServiceMock.Setup(s => s.GetTimezone(It.IsAny<int>())).Returns(timezone);
|
||
var operationValueService = new OperationValueService(context);
|
||
var scheduleService = new ScheduleService(context, wellServiceMock.Object);
|
||
|
||
service = new DetectedOperationService(context, wellServiceMock.Object, operationValueService, scheduleService);
|
||
AsbCloudInfrastructure.DependencyInjection.MapsterSetup();
|
||
}
|
||
|
||
~DetectedOperationServiceTest()
|
||
{
|
||
|
||
}
|
||
|
||
[Fact]
|
||
public async Task Count_grouping_by_driller()
|
||
{
|
||
var count = 10;
|
||
var list = await service.GetAsync(1, null, CancellationToken.None);
|
||
Assert.Equal(3, count);
|
||
}
|
||
|
||
}
|
||
}
|