forked from ddrilling/AsbCloudServer
Правки по ПР. Тесты
This commit is contained in:
parent
80bad5bbe2
commit
fa4d113221
@ -17,6 +17,13 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
{
|
||||
private readonly AsbCloudDbContext context;
|
||||
private readonly CacheDb cacheDb;
|
||||
private Driller driller = new Driller
|
||||
{
|
||||
Id = 1,
|
||||
Name = "Тестовый",
|
||||
Patronymic = "Тест",
|
||||
Surname = "Тестович"
|
||||
};
|
||||
private DrillerDto drillerObj = new DrillerDto
|
||||
{
|
||||
Id = 0,
|
||||
@ -24,12 +31,15 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
Patronymic = "Тест",
|
||||
Surname = "Тестович"
|
||||
};
|
||||
private DrillerService service;
|
||||
|
||||
public DrillerServiceTest()
|
||||
public DrillerServiceTest()
|
||||
{
|
||||
|
||||
context = TestHelpter.MakeTestContext();
|
||||
cacheDb = new CacheDb();
|
||||
context.SaveChanges();
|
||||
service = new DrillerService(context);
|
||||
}
|
||||
|
||||
~DrillerServiceTest()
|
||||
@ -39,7 +49,6 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
[Fact]
|
||||
public async Task GetListAsync_count()
|
||||
{
|
||||
var service = new DrillerService(context);
|
||||
|
||||
///Добавляем элемент
|
||||
var id = await service.InsertAsync(drillerObj, CancellationToken.None);
|
||||
@ -53,7 +62,6 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
[Fact]
|
||||
public async Task InsertAsync_returns_id()
|
||||
{
|
||||
var service = new DrillerService(context);
|
||||
var id = await service.InsertAsync(drillerObj, CancellationToken.None);
|
||||
Assert.NotEqual(0, id);
|
||||
}
|
||||
@ -61,8 +69,6 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
[Fact]
|
||||
public async Task UpdateAsync_not_add_if_exists()
|
||||
{
|
||||
var service = new DrillerService(context);
|
||||
|
||||
///Добавляем элемент
|
||||
var id = await service.InsertAsync(drillerObj, CancellationToken.None);
|
||||
var oldCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
@ -78,8 +84,6 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
[Fact]
|
||||
public async Task DeleteAsync_decrement_count()
|
||||
{
|
||||
var service = new DrillerService(context);
|
||||
|
||||
///Добавляем элемент
|
||||
var id = await service.InsertAsync(drillerObj, CancellationToken.None);
|
||||
var oldCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
|
@ -3,6 +3,7 @@ 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;
|
||||
@ -17,12 +18,40 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
{
|
||||
private readonly AsbCloudDbContext context;
|
||||
private readonly CacheDb cacheDb;
|
||||
private readonly ScheduleService service;
|
||||
|
||||
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
|
||||
{
|
||||
Id = 1,
|
||||
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")
|
||||
};
|
||||
private ScheduleDto entity = new ScheduleDto
|
||||
{
|
||||
ShiftStart = DateTime.Parse("2022-05-16T10:00:00"),
|
||||
ShiftEnd = DateTime.Parse("2022-05-16T18:00:00"),
|
||||
DrillStart = DateTime.Parse("2022-05-16T10:00:00"),
|
||||
DrillEnd = DateTime.Parse("2022-05-16T18:00:00")
|
||||
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")
|
||||
};
|
||||
private Well well = new Well {
|
||||
Id=1,
|
||||
Caption = "Test well 1",
|
||||
IdCluster = 1
|
||||
};
|
||||
private Driller driller = new Driller
|
||||
{
|
||||
Id = 1,
|
||||
Name = "Тестовый",
|
||||
Patronymic = "Тест",
|
||||
Surname = "Тестович"
|
||||
};
|
||||
|
||||
public ScheduleServiceTest()
|
||||
@ -30,6 +59,13 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
context = TestHelpter.MakeTestContext();
|
||||
cacheDb = new CacheDb();
|
||||
context.SaveChanges();
|
||||
|
||||
context.Deposits.Add(deposit);
|
||||
context.Clusters.Add(clater);
|
||||
context.Wells.Add(well);
|
||||
context.Drillers.Add(driller);
|
||||
|
||||
service=new ScheduleService(context);
|
||||
}
|
||||
|
||||
~ScheduleServiceTest()
|
||||
@ -52,8 +88,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
|
||||
[Fact]
|
||||
public async Task InsertAsync_returns_id()
|
||||
{
|
||||
var service = new ScheduleService(context);
|
||||
{
|
||||
var id = await service.InsertAsync(entity, CancellationToken.None);
|
||||
Assert.NotEqual(0, id);
|
||||
}
|
||||
@ -61,35 +96,28 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
[Fact]
|
||||
public async Task UpdateAsync_not_add_if_exists()
|
||||
{
|
||||
var service = new ScheduleService(context);
|
||||
|
||||
///Добавляем элемент
|
||||
var id = await service.InsertAsync(entity, CancellationToken.None);
|
||||
context.Schedule.Add(scd);
|
||||
var oldCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
|
||||
//Обновляем
|
||||
entity.Id = id;
|
||||
entity.Id = 1;
|
||||
entity.DrillEnd = entity.DrillEnd.AddHours(-3);
|
||||
await service.UpdateAsync(id, entity, CancellationToken.None);
|
||||
await service.UpdateAsync(entity.Id, entity, CancellationToken.None);
|
||||
var newCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
Assert.Equal(newCount, oldCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeleteAsync_decrement_count()
|
||||
public async Task GetDriller_by_workTime()
|
||||
{
|
||||
var service = new ScheduleService(context);
|
||||
|
||||
///Добавляем элемент
|
||||
var id = await service.InsertAsync(entity, CancellationToken.None);
|
||||
var oldCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
|
||||
//Удаляем его
|
||||
await service.DeleteAsync(id, CancellationToken.None);
|
||||
var newCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
Assert.Equal(newCount, oldCount-1);
|
||||
//Обновляем
|
||||
var res = await service.GetSchedule(well.Id, entity.DrillEnd.AddHours(-2), CancellationToken.None);
|
||||
Assert.Equal(scd.IdDriller, res.Id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user