forked from ddrilling/AsbCloudServer
починил тесты.
This commit is contained in:
parent
eabec7e7ee
commit
9d59dd3b30
@ -2,11 +2,8 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using AsbCloudInfrastructure.Services.SAUB;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -17,34 +14,38 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
public class ScheduleServiceTest
|
||||
{
|
||||
private readonly AsbCloudDbContext context;
|
||||
private readonly CacheDb cacheDb;
|
||||
private readonly ScheduleService service;
|
||||
|
||||
private readonly ScheduleService scheduleService;
|
||||
private Deposit deposit = new Deposit { Id = 1, Caption = "Депозит 1" };
|
||||
private Cluster clater = new Cluster { Id = 1, Caption = "Кластер 1", IdDeposit = 1, Timezone = new SimpleTimezone() };
|
||||
private ScheduleItem scd = new ScheduleItem
|
||||
private Schedule scd = new Schedule
|
||||
{
|
||||
Id = 1,
|
||||
IdWell = 1,
|
||||
IdDriller = 1,
|
||||
ShiftStart = DateTimeOffset.Parse("2022-05-16T10:00:00.286Z"),
|
||||
ShiftEnd = DateTimeOffset.Parse("2022-05-16T18:00:00.286Z"),
|
||||
ShiftStart = new TimeOnly(10, 00),
|
||||
ShiftEnd = new TimeOnly(18, 00),
|
||||
DrillStart = DateTimeOffset.Parse("2022-05-16T10:00:00.286Z"),
|
||||
DrillEnd = DateTimeOffset.Parse("2022-05-16T18:00:00.286Z")
|
||||
};
|
||||
private ScheduleDto entity = new ScheduleDto
|
||||
|
||||
private ScheduleDto MakeScheduleDto(ScheduleDto? dto = null)
|
||||
{
|
||||
IdWell=1,
|
||||
IdDriller=1,
|
||||
ShiftStart = DateTimeOffset.Parse("2022-05-16T10:00:00.286Z"),
|
||||
ShiftEnd = DateTimeOffset.Parse("2022-05-16T18:00:00.286Z"),
|
||||
DrillStart = DateTimeOffset.Parse("2022-05-16T10:00:00.286Z"),
|
||||
DrillEnd = DateTimeOffset.Parse("2022-05-16T18:00:00.286Z")
|
||||
};
|
||||
return new ScheduleDto
|
||||
{
|
||||
IdWell = dto?.IdWell ?? 1,
|
||||
IdDriller = dto?.IdDriller ?? 1,
|
||||
ShiftStart = dto?.ShiftStart ?? new TimeOnly(10, 00),
|
||||
ShiftEnd = dto?.ShiftEnd ?? new TimeOnly(18, 00),
|
||||
DrillStart = dto?.DrillStart ?? DateTime.Parse("2022-05-16T10:00:00.286Z"),
|
||||
DrillEnd = dto?.DrillEnd ?? DateTime.Parse("2022-05-16T18:00:00.286Z")
|
||||
};
|
||||
}
|
||||
|
||||
private Well well = new Well {
|
||||
Id=1,
|
||||
Caption = "Test well 1",
|
||||
IdCluster = 1
|
||||
IdCluster = 1,
|
||||
Timezone = new SimpleTimezone { Hours = 5 }
|
||||
};
|
||||
private Driller driller = new Driller
|
||||
{
|
||||
@ -57,7 +58,6 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
public ScheduleServiceTest()
|
||||
{
|
||||
context = TestHelpter.MakeTestContext();
|
||||
cacheDb = new CacheDb();
|
||||
context.SaveChanges();
|
||||
|
||||
context.Deposits.Add(deposit);
|
||||
@ -65,7 +65,13 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
context.Wells.Add(well);
|
||||
context.Drillers.Add(driller);
|
||||
|
||||
service=new ScheduleService(context);
|
||||
context.SaveChanges();
|
||||
|
||||
var timezone = new SimpleTimezoneDto { Hours = 5 };
|
||||
var wellServiceMock = new Mock<IWellService>();
|
||||
wellServiceMock.Setup(s => s.GetTimezone(It.IsAny<int>())).Returns(timezone);
|
||||
scheduleService = new ScheduleService(context, wellServiceMock.Object);
|
||||
AsbCloudInfrastructure.DependencyInjection.MapsterSetup();
|
||||
}
|
||||
|
||||
~ScheduleServiceTest()
|
||||
@ -75,49 +81,65 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
[Fact]
|
||||
public async Task GetListAsync_count()
|
||||
{
|
||||
var service = new ScheduleService(context);
|
||||
var id = await scheduleService.InsertAsync(MakeScheduleDto(), CancellationToken.None);
|
||||
id = await scheduleService.InsertAsync(MakeScheduleDto(), CancellationToken.None);
|
||||
id = await scheduleService.InsertAsync(MakeScheduleDto(), CancellationToken.None);
|
||||
|
||||
///Добавляем элемент
|
||||
var id = await service.InsertAsync(entity, CancellationToken.None);
|
||||
id = await service.InsertAsync(entity, CancellationToken.None);
|
||||
id = await service.InsertAsync(entity, CancellationToken.None);
|
||||
|
||||
var newCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
var newCount = (await scheduleService.GetAllAsync(CancellationToken.None)).Count();
|
||||
Assert.Equal(3, newCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertAsync_returns_id()
|
||||
{
|
||||
var id = await service.InsertAsync(entity, CancellationToken.None);
|
||||
var id = await scheduleService.InsertAsync(MakeScheduleDto(), CancellationToken.None);
|
||||
Assert.NotEqual(0, id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_not_add_if_exists()
|
||||
{
|
||||
///Добавляем элемент
|
||||
context.Schedule.Add(scd);
|
||||
var oldCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
var oldCount = (await scheduleService.GetAllAsync(CancellationToken.None)).Count();
|
||||
|
||||
//Обновляем
|
||||
entity.Id = 1;
|
||||
entity.DrillEnd = entity.DrillEnd.AddHours(-3);
|
||||
await service.UpdateAsync(entity.Id, entity, CancellationToken.None);
|
||||
var newCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
var dto = MakeScheduleDto();
|
||||
dto.Id = 1;
|
||||
dto.DrillEnd = dto.DrillEnd.AddHours(-3);
|
||||
await scheduleService.UpdateAsync(dto.Id, dto, CancellationToken.None);
|
||||
var newCount = (await scheduleService.GetAllAsync(CancellationToken.None)).Count();
|
||||
Assert.Equal(newCount, oldCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDriller_by_workTime()
|
||||
public async Task GetDriller_by_workTime_shift1()
|
||||
{
|
||||
///Добавляем элемент
|
||||
var id = await service.InsertAsync(entity, CancellationToken.None);
|
||||
|
||||
//Обновляем
|
||||
var res = await service.GetSchedule(well.Id, entity.DrillEnd.AddHours(-2), CancellationToken.None);
|
||||
Assert.Equal(scd.IdDriller, res.Id);
|
||||
var dto = MakeScheduleDto();
|
||||
dto.ShiftStart = new TimeOnly(8, 00);
|
||||
dto.ShiftEnd = new TimeOnly(20, 00);
|
||||
var id = await scheduleService.InsertAsync(dto, CancellationToken.None);
|
||||
var drillerWorkTime = new DateTime(
|
||||
dto.DrillStart.Year,
|
||||
dto.DrillStart.Month,
|
||||
dto.DrillStart.Day,
|
||||
16, 1, 0, DateTimeKind.Unspecified);
|
||||
var res = await scheduleService.GetDrillerAsync(well.Id, drillerWorkTime, CancellationToken.None);
|
||||
Assert.Equal(id, res?.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetDriller_by_workTime_shift2()
|
||||
{
|
||||
var dto = MakeScheduleDto();
|
||||
dto.ShiftStart = new TimeOnly(20, 00);
|
||||
dto.ShiftEnd = new TimeOnly(8, 00);
|
||||
var id = await scheduleService.InsertAsync(dto, CancellationToken.None);
|
||||
var drillerWorkTime = new DateTime(
|
||||
dto.DrillStart.Year,
|
||||
dto.DrillStart.Month,
|
||||
dto.DrillStart.Day,
|
||||
20, 1, 0, DateTimeKind.Unspecified);
|
||||
var res = await scheduleService.GetDrillerAsync(well.Id, drillerWorkTime, CancellationToken.None);
|
||||
Assert.Equal(id, res?.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user