2023-12-20 10:51:42 +05:00
|
|
|
|
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;
|
2023-12-20 14:04:00 +05:00
|
|
|
|
using System.Text.Json;
|
2023-12-20 10:51:42 +05:00
|
|
|
|
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() {
|
2023-12-20 14:04:00 +05:00
|
|
|
|
IdWell = idWell,
|
|
|
|
|
IdUser = 1,
|
|
|
|
|
IdType = 0,
|
|
|
|
|
IdWellSectionType = 1,
|
|
|
|
|
IdCategory = 1,
|
2023-12-20 10:51:42 +05:00
|
|
|
|
CategoryInfo = "1",
|
|
|
|
|
DepthStart = 10,
|
|
|
|
|
DepthEnd = 20,
|
2023-12-20 14:04:00 +05:00
|
|
|
|
DateStart = getDate(days: 0),
|
|
|
|
|
DurationHours = 10,
|
2023-12-21 12:02:29 +05:00
|
|
|
|
Comment = "Комментарий 1",
|
2023-12-20 10:51:42 +05:00
|
|
|
|
},
|
|
|
|
|
new WellOperationDto() {
|
2023-12-20 14:04:00 +05:00
|
|
|
|
IdWell = idWell,
|
|
|
|
|
IdUser = 1,
|
|
|
|
|
IdType = 0,
|
|
|
|
|
IdWellSectionType = 2,
|
|
|
|
|
IdCategory = 2,
|
2023-12-20 10:51:42 +05:00
|
|
|
|
CategoryInfo = "2",
|
|
|
|
|
DepthStart = 20,
|
|
|
|
|
DepthEnd = 30,
|
2023-12-20 14:04:00 +05:00
|
|
|
|
DateStart = getDate(days: 1),
|
|
|
|
|
DurationHours = 20,
|
2023-12-21 12:02:29 +05:00
|
|
|
|
Comment = "Комментарий 2",
|
2023-12-20 10:51:42 +05:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-20 14:04:00 +05:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-20 10:51:42 +05:00
|
|
|
|
[Fact]
|
2023-12-20 14:04:00 +05:00
|
|
|
|
public async Task Check_Exported_WellOperations_With_Operations_In_Db()
|
2023-12-20 10:51:42 +05:00
|
|
|
|
{
|
2023-12-20 14:04:00 +05:00
|
|
|
|
wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto()
|
|
|
|
|
{
|
|
|
|
|
Hours = 5
|
|
|
|
|
});
|
2023-12-20 10:51:42 +05:00
|
|
|
|
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);
|
|
|
|
|
|
2023-12-20 14:04:00 +05:00
|
|
|
|
var expected = JsonSerializer.Serialize(operations);
|
|
|
|
|
var actual = JsonSerializer.Serialize(result);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(expected, actual);
|
2023-12-20 10:51:42 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|