forked from ddrilling/AsbCloudServer
136 lines
4.9 KiB
C#
136 lines
4.9 KiB
C#
|
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.Linq;
|
|||
|
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;
|
|||
|
|
|||
|
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();
|
|||
|
}
|
|||
|
|
|||
|
private readonly WellOperationDto[] operations = new WellOperationDto[2] {
|
|||
|
new WellOperationDto() {
|
|||
|
CategoryInfo = "1",
|
|||
|
Comment = "1",
|
|||
|
DateStart = DateTime.Now,
|
|||
|
Day = 0,
|
|||
|
DepthStart = 10,
|
|||
|
DurationHours = 10,
|
|||
|
DepthEnd = 20,
|
|||
|
IdCategory = 1,
|
|||
|
Id = 1,
|
|||
|
IdPlan = 1,
|
|||
|
IdType = 0,
|
|||
|
IdWell = idWell,
|
|||
|
IdWellSectionType = 1,
|
|||
|
NptHours = 10
|
|||
|
},
|
|||
|
new WellOperationDto() {
|
|||
|
CategoryInfo = "2",
|
|||
|
Comment = "2",
|
|||
|
DateStart = DateTime.Now.AddDays(1),
|
|||
|
Day = 0,
|
|||
|
DepthStart = 20,
|
|||
|
DurationHours = 20,
|
|||
|
DepthEnd = 30,
|
|||
|
IdCategory = 2,
|
|||
|
Id = 2,
|
|||
|
IdPlan = 1,
|
|||
|
IdType = 0,
|
|||
|
IdWell = idWell,
|
|||
|
IdWellSectionType = 2,
|
|||
|
NptHours = 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"
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
[Fact]
|
|||
|
public async Task Check_exported_dates()
|
|||
|
{
|
|||
|
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 expectedDates = operations.Select(o => o.DateStart.ToString("yyyy-MM-dd HH:mm:ss"));
|
|||
|
var realDates = result.Select(o => o.DateStart.ToString("yyyy-MM-dd HH:mm:ss"));
|
|||
|
Assert.Equal(expectedDates, realDates);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|