forked from ddrilling/AsbCloudServer
Merge pull request 'Тестирование дат при выгрузке отчета ГГД (план)' (#177) from fix/ggd-exported-dates-tests into dev
Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/177
This commit is contained in:
commit
3aad5ba825
@ -0,0 +1,139 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.WellOperationImport.Options;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Services.WellOperationImport;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.WellOperationImport;
|
||||
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.UnitTests.Services.WellOperationExport
|
||||
{
|
||||
public class WellOperationExportServiceTest
|
||||
{
|
||||
private const int idWell = 4;
|
||||
|
||||
private IWellService wellService;
|
||||
private IWellOperationRepository wellOperationRepository;
|
||||
private IWellOperationImportTemplateService wellOperationImportTemplateService;
|
||||
private WellOperationExportService wellOperationExportService;
|
||||
private WellOperationImportService wellOperationImportService;
|
||||
private IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser;
|
||||
|
||||
|
||||
private readonly WellOperationDto[] operations = new WellOperationDto[2] {
|
||||
new WellOperationDto() {
|
||||
IdWell = idWell,
|
||||
IdUser = 1,
|
||||
IdType = 0,
|
||||
IdWellSectionType = 1,
|
||||
IdCategory = 1,
|
||||
CategoryInfo = "1",
|
||||
DepthStart = 10,
|
||||
DepthEnd = 20,
|
||||
DateStart = getDate(days: 0),
|
||||
DurationHours = 10,
|
||||
},
|
||||
new WellOperationDto() {
|
||||
IdWell = idWell,
|
||||
IdUser = 1,
|
||||
IdType = 0,
|
||||
IdWellSectionType = 2,
|
||||
IdCategory = 2,
|
||||
CategoryInfo = "2",
|
||||
DepthStart = 20,
|
||||
DepthEnd = 30,
|
||||
DateStart = getDate(days: 1),
|
||||
DurationHours = 20,
|
||||
}
|
||||
};
|
||||
|
||||
private readonly WellSectionTypeDto[] sectionTypes = new WellSectionTypeDto[2]
|
||||
{
|
||||
new WellSectionTypeDto()
|
||||
{
|
||||
Caption = "1",
|
||||
Id = 1,
|
||||
Order = 0
|
||||
},
|
||||
new WellSectionTypeDto()
|
||||
{
|
||||
Caption = "2",
|
||||
Id = 2,
|
||||
Order = 1
|
||||
}
|
||||
};
|
||||
|
||||
private readonly WellOperationCategoryDto[] categories = new WellOperationCategoryDto[2]
|
||||
{
|
||||
new WellOperationCategoryDto()
|
||||
{
|
||||
Id = 1,
|
||||
IdParent = 1,
|
||||
KeyValueName = "1",
|
||||
KeyValueUnits = "1",
|
||||
Name = "1"
|
||||
},
|
||||
new WellOperationCategoryDto()
|
||||
{
|
||||
Id = 2,
|
||||
IdParent = 2,
|
||||
KeyValueName = "2",
|
||||
KeyValueUnits = "2",
|
||||
Name = "2"
|
||||
}
|
||||
};
|
||||
|
||||
private static DateTime getDate(int days)
|
||||
{
|
||||
var date = DateTime.Now.AddDays(days);
|
||||
return new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);
|
||||
}
|
||||
|
||||
public WellOperationExportServiceTest()
|
||||
{
|
||||
wellService = Substitute.For<IWellService>();
|
||||
wellOperationRepository = Substitute.For<IWellOperationRepository>();
|
||||
wellOperationImportTemplateService = new WellOperationImportTemplateService();
|
||||
wellOperationExportService = new WellOperationExportService(wellOperationRepository, wellService, wellOperationImportTemplateService);
|
||||
|
||||
wellOperationImportService = new WellOperationImportService(wellOperationRepository);
|
||||
wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Check_Exported_WellOperations_With_Operations_In_Db()
|
||||
{
|
||||
wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto()
|
||||
{
|
||||
Hours = 5
|
||||
});
|
||||
wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
|
||||
.ReturnsForAnyArgs(operations);
|
||||
wellOperationRepository.GetSectionTypes().Returns(sectionTypes);
|
||||
wellOperationRepository.GetCategories(false).Returns(categories);
|
||||
|
||||
var stream = await wellOperationExportService.ExportAsync(idWell, CancellationToken.None);
|
||||
|
||||
var options = new WellOperationImportDefaultOptionsDto
|
||||
{
|
||||
IdType = WellOperation.IdOperationTypePlan
|
||||
};
|
||||
var sheet = wellOperationDefaultExcelParser.Parse(stream, options);
|
||||
var result = wellOperationImportService.Import(idWell, 1, options.IdType, sheet);
|
||||
|
||||
var expected = JsonSerializer.Serialize(operations);
|
||||
var actual = JsonSerializer.Serialize(result);
|
||||
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user