forked from ddrilling/AsbCloudServer
Merge pull request '#7053070 Перенос справочника бурильщиков в репозиторий' (#8) from feature/driller_repository into dev
Reviewed-on: http://46.146.209.148:8080/DDrilling/AsbCloudServer/pulls/8
This commit is contained in:
commit
25cd263598
@ -1,12 +0,0 @@
|
||||
using AsbCloudApp.Data;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Сервис добавления бурильщиков
|
||||
/// </summary>
|
||||
public interface IDrillerService : ICrudService<DrillerDto>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -128,7 +128,7 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<IScheduleReportService, ScheduleReportService>();
|
||||
services.AddTransient<IDailyReportService, DailyReportService>();
|
||||
services.AddTransient<IDetectedOperationService, DetectedOperationService>();
|
||||
services.AddTransient<IDrillerService, DrillerService>();
|
||||
//services.AddTransient<IDrillerService, DrillerService>();
|
||||
|
||||
services.AddTransient<ISubsystemOperationTimeService, SubsystemOperationTimeService>();
|
||||
services.AddTransient<IScheduleRepository, ScheduleRepository>();
|
||||
@ -159,6 +159,9 @@ namespace AsbCloudInfrastructure
|
||||
dbSet => dbSet
|
||||
.Include(c => c.Wells)
|
||||
.Include(c => c.Deposit))); // может быть включен в сервис ClusterService
|
||||
|
||||
services.AddTransient<ICrudService<DrillerDto>, CrudCacheServiceBase<DrillerDto, Driller>>();
|
||||
|
||||
services.AddTransient<IFileRepository, FileRepository>();
|
||||
services.AddTransient<IFileStorageRepository, FileStorageRepository>();
|
||||
services.AddTransient<IWellCompositeRepository, WellCompositeRepository>();
|
||||
|
@ -1,14 +0,0 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class DrillerService : CrudServiceBase<DrillerDto, Driller>, IDrillerService
|
||||
{
|
||||
public DrillerService(IAsbCloudDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,12 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using Moq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -11,31 +16,49 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
{
|
||||
public class DrillerServiceTest
|
||||
{
|
||||
private readonly AsbCloudDbContext context;
|
||||
private readonly CacheDb cacheDb;
|
||||
private Driller driller = new Driller
|
||||
{
|
||||
Id = 1,
|
||||
Name = "Тестовый",
|
||||
Patronymic = "Тест",
|
||||
Surname = "Тестович"
|
||||
private static List<DrillerDto> Drillers = new List<DrillerDto> {
|
||||
new DrillerDto
|
||||
{
|
||||
Id = 1,
|
||||
Name = "Тестовый",
|
||||
Patronymic = "Тест",
|
||||
Surname = "Тестович"
|
||||
},
|
||||
new DrillerDto
|
||||
{
|
||||
Id = 1,
|
||||
Name = "Тестовый",
|
||||
Patronymic = "Тест",
|
||||
Surname = "Тестович"
|
||||
}
|
||||
};
|
||||
private DrillerDto drillerObj = new DrillerDto
|
||||
{
|
||||
Id = 0,
|
||||
Name = "Тестовый",
|
||||
Patronymic = "Тест",
|
||||
Surname = "Тестович"
|
||||
};
|
||||
private DrillerService service;
|
||||
private ICrudService<DrillerDto> service;
|
||||
|
||||
public DrillerServiceTest()
|
||||
{
|
||||
var repositoryMock = RepositoryFactory.Make<ICrudService<DrillerDto>, DrillerDto>(Drillers);
|
||||
|
||||
context = TestHelpter.MakeTestContext();
|
||||
cacheDb = new CacheDb();
|
||||
context.SaveChanges();
|
||||
service = new DrillerService(context);
|
||||
repositoryMock.Setup(x => x.GetAllAsync(It.IsAny<CancellationToken>()))
|
||||
.Returns(() => {
|
||||
var data = Drillers;
|
||||
return Task.FromResult(data.AsEnumerable());
|
||||
});
|
||||
repositoryMock.Setup(x => x.InsertAsync(It.IsAny<DrillerDto>(), It.IsAny<CancellationToken>()))
|
||||
.Returns((DrillerDto dto, CancellationToken token) => {
|
||||
Drillers.Add(dto);
|
||||
return Task.FromResult(Drillers.Count());
|
||||
});
|
||||
repositoryMock.Setup(x => x.UpdateAsync(It.IsAny<DrillerDto>(), It.IsAny<CancellationToken>()))
|
||||
.Returns((DrillerDto dto, CancellationToken token) => {
|
||||
var baseDto = Drillers.First(x => x.Id == dto.Id);
|
||||
|
||||
Drillers.Remove(baseDto);
|
||||
Drillers.Add(dto);
|
||||
|
||||
return Task.FromResult(Drillers.Count());
|
||||
});
|
||||
|
||||
service = repositoryMock.Object;
|
||||
}
|
||||
|
||||
~DrillerServiceTest()
|
||||
@ -45,36 +68,31 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
[Fact]
|
||||
public async Task GetListAsync_count()
|
||||
{
|
||||
|
||||
///Добавляем элемент
|
||||
var id = await service.InsertAsync(drillerObj, CancellationToken.None);
|
||||
id = await service.InsertAsync(drillerObj, CancellationToken.None);
|
||||
id = await service.InsertAsync(drillerObj, CancellationToken.None);
|
||||
|
||||
var newCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
Assert.Equal(3, newCount);
|
||||
var data = await service.GetAllAsync(CancellationToken.None);
|
||||
Assert.Equal(2, data.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InsertAsync_returns_id()
|
||||
{
|
||||
var id = await service.InsertAsync(drillerObj, CancellationToken.None);
|
||||
Assert.NotEqual(0, id);
|
||||
var dto = new DrillerDto {
|
||||
Id = 3,
|
||||
Name = "Тестовый",
|
||||
Patronymic = "Тест",
|
||||
Surname = "Тестович"
|
||||
};
|
||||
var cnt = await service.InsertAsync(dto, CancellationToken.None);
|
||||
Assert.Equal(3, cnt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_not_add_if_exists()
|
||||
{
|
||||
///Добавляем элемент
|
||||
context.Drillers.Add(driller);
|
||||
var oldCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
|
||||
//Обновляем
|
||||
drillerObj.Id = driller.Id;
|
||||
drillerObj.Name = "Исправлено";
|
||||
await service.UpdateAsync(drillerObj, CancellationToken.None);
|
||||
var newCount = (await service.GetAllAsync(CancellationToken.None)).Count();
|
||||
Assert.Equal(newCount, oldCount);
|
||||
var dto = Drillers.First(x => x.Id == 1);
|
||||
dto.Name = "Edit";
|
||||
var oldCount = Drillers.Count();
|
||||
var count = await service.UpdateAsync(dto, CancellationToken.None);
|
||||
Assert.Equal(oldCount, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,10 @@ namespace AsbCloudWebApi.Controllers
|
||||
[Route("api/driller")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class DrillerController : CrudController<DrillerDto, IDrillerService>
|
||||
public class DrillerController : CrudController<DrillerDto, ICrudService<DrillerDto>>
|
||||
{
|
||||
public DrillerController(IDrillerService drillerService)
|
||||
: base(drillerService)
|
||||
public DrillerController(ICrudService<DrillerDto> service)
|
||||
: base(service)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user