fix test Check_Exported_WellOperations_With_Operations_In_Db

This commit is contained in:
ngfrolov 2024-02-22 13:34:05 +05:00
parent 72669b0526
commit 2ec609b56f
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
6 changed files with 56 additions and 58 deletions

View File

@ -2,7 +2,6 @@
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -13,14 +12,6 @@ namespace AsbCloudApp.Repositories
/// </summary> /// </summary>
public interface IWellOperationRepository public interface IWellOperationRepository
{ {
//TODO: replace all references
/// <summary>
/// список названий операций
/// </summary>
/// <returns></returns>
[Obsolete("use IWellOperationCategoryRepository.GetCategories(bool includeParents)")]
IEnumerable<WellOperationCategoryDto> GetCategories(bool includeParents);
/// <summary> /// <summary>
/// Список секций /// Список секций
/// </summary> /// </summary>

View File

@ -23,7 +23,6 @@ namespace AsbCloudInfrastructure.Repository;
public class WellOperationRepository : IWellOperationRepository public class WellOperationRepository : IWellOperationRepository
{ {
private const string KeyCacheSections = "OperationsBySectionSummarties"; private const string KeyCacheSections = "OperationsBySectionSummarties";
private const int Gap = 90;
private readonly IAsbCloudDbContext db; private readonly IAsbCloudDbContext db;
private readonly IMemoryCache memoryCache; private readonly IMemoryCache memoryCache;
@ -38,13 +37,6 @@ public class WellOperationRepository : IWellOperationRepository
this.wellOperationCategoryRepository = wellOperationCategoryRepository; this.wellOperationCategoryRepository = wellOperationCategoryRepository;
} }
/// <inheritdoc/>
public IEnumerable<WellOperationCategoryDto> GetCategories(bool includeParents)
{
return wellOperationCategoryRepository.Get(includeParents);
}
/// <inheritdoc/>
public IEnumerable<WellSectionTypeDto> GetSectionTypes() => public IEnumerable<WellSectionTypeDto> GetSectionTypes() =>
memoryCache memoryCache
.GetOrCreateBasic(db.Set<WellSectionType>()) .GetOrCreateBasic(db.Set<WellSectionType>())
@ -272,7 +264,7 @@ public class WellOperationRepository : IWellOperationRepository
DurationDepth = o.DepthEnd - o.DepthStart DurationDepth = o.DepthEnd - o.DepthStart
}) })
.ToListAsync(token); .ToListAsync(token);
var parentRelationDictionary = GetCategories(true) var parentRelationDictionary = wellOperationCategoryRepository.Get(true)
.ToDictionary(c => c.Id, c => new .ToDictionary(c => c.Id, c => new
{ {
c.Name, c.Name,

View File

@ -19,15 +19,19 @@ public class WellOperationExportService : IWellOperationExportService
private readonly IWellOperationRepository wellOperationRepository; private readonly IWellOperationRepository wellOperationRepository;
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IWellOperationImportTemplateService wellOperationImportTemplateService; private readonly IWellOperationImportTemplateService wellOperationImportTemplateService;
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
public WellOperationExportService(IWellOperationRepository wellOperationRepository, public WellOperationExportService(
IWellOperationRepository wellOperationRepository,
IWellService wellService, IWellService wellService,
IWellOperationImportTemplateService wellOperationImportTemplateService) IWellOperationImportTemplateService wellOperationImportTemplateService,
IWellOperationCategoryRepository wellOperationCategoryRepository)
{ {
this.wellOperationRepository = wellOperationRepository; this.wellOperationRepository = wellOperationRepository;
this.wellService = wellService; this.wellService = wellService;
this.wellOperationImportTemplateService = wellOperationImportTemplateService; this.wellOperationImportTemplateService = wellOperationImportTemplateService;
} this.wellOperationCategoryRepository = wellOperationCategoryRepository;
}
public async Task<Stream> ExportAsync(int idWell, CancellationToken cancellationToken) public async Task<Stream> ExportAsync(int idWell, CancellationToken cancellationToken)
{ {
@ -76,7 +80,7 @@ public class WellOperationExportService : IWellOperationExportService
var operationsToArray = operations.ToArray(); var operationsToArray = operations.ToArray();
var sections = wellOperationRepository.GetSectionTypes(); var sections = wellOperationRepository.GetSectionTypes();
var categories = wellOperationRepository.GetCategories(false); var categories = wellOperationCategoryRepository.Get(false);
for (int i = 0; i < operationsToArray.Length; i++) for (int i = 0; i < operationsToArray.Length; i++)
{ {

View File

@ -14,24 +14,28 @@ public class WellOperationImportService : IWellOperationImportService
{ {
private readonly IWellService wellService; private readonly IWellService wellService;
private readonly IWellOperationRepository wellOperationRepository; private readonly IWellOperationRepository wellOperationRepository;
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
private static readonly DateTime dateLimitMin = new(2001, 1, 1, 0, 0, 0); private static readonly DateTime dateLimitMin = new(2001, 1, 1, 0, 0, 0);
private static readonly DateTime dateLimitMax = new(2099, 1, 1, 0, 0, 0); private static readonly DateTime dateLimitMax = new(2099, 1, 1, 0, 0, 0);
private static readonly TimeSpan drillingDurationLimitMax = TimeSpan.FromDays(366); private static readonly TimeSpan drillingDurationLimitMax = TimeSpan.FromDays(366);
public WellOperationImportService(IWellService wellService, public WellOperationImportService(
IWellOperationRepository wellOperationRepository) IWellService wellService,
IWellOperationRepository wellOperationRepository,
IWellOperationCategoryRepository wellOperationCategoryRepository
)
{ {
this.wellService = wellService; this.wellService = wellService;
this.wellOperationRepository = wellOperationRepository; this.wellOperationRepository = wellOperationRepository;
} this.wellOperationCategoryRepository = wellOperationCategoryRepository;
}
public IEnumerable<WellOperationDto> Import(int idWell, int idUser, int idType, SheetDto sheet) public IEnumerable<WellOperationDto> Import(int idWell, int idUser, int idType, SheetDto sheet)
{ {
var validationErrors = new List<string>(); var validationErrors = new List<string>();
var sections = wellOperationRepository.GetSectionTypes(); var sections = wellOperationRepository.GetSectionTypes();
var categories = wellOperationRepository.GetCategories(false); var categories = wellOperationCategoryRepository.Get(false);
var wellOperations = new List<WellOperationDto>(); var wellOperations = new List<WellOperationDto>();
@ -83,7 +87,9 @@ public class WellOperationImportService : IWellOperationImportService
IdUser = idUser, IdUser = idUser,
IdType = idType, IdType = idType,
IdWellSectionType = section.Id, IdWellSectionType = section.Id,
WellSectionTypeName = section.Caption,
IdCategory = category.Id, IdCategory = category.Id,
CategoryName = category.Name,
CategoryInfo = row.CategoryInfo, CategoryInfo = row.CategoryInfo,
DepthStart = row.DepthStart, DepthStart = row.DepthStart,
DepthEnd = row.DepthEnd, DepthEnd = row.DepthEnd,

View File

@ -5,6 +5,7 @@ using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudApp.Services.WellOperationImport; using AsbCloudApp.Services.WellOperationImport;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using AsbCloudInfrastructure.Repository;
using AsbCloudInfrastructure.Services.WellOperationImport; using AsbCloudInfrastructure.Services.WellOperationImport;
using AsbCloudInfrastructure.Services.WellOperationImport.FileParser; using AsbCloudInfrastructure.Services.WellOperationImport.FileParser;
using NSubstitute; using NSubstitute;
@ -27,6 +28,7 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport
private IWellService wellService; private IWellService wellService;
private IWellOperationRepository wellOperationRepository; private IWellOperationRepository wellOperationRepository;
private IWellOperationCategoryRepository wellOperationCategoryRepository;
private IWellOperationImportTemplateService wellOperationImportTemplateService; private IWellOperationImportTemplateService wellOperationImportTemplateService;
private WellOperationExportService wellOperationExportService; private WellOperationExportService wellOperationExportService;
private WellOperationImportService wellOperationImportService; private WellOperationImportService wellOperationImportService;
@ -114,46 +116,46 @@ namespace AsbCloudWebApi.Tests.Services.WellOperationExport
{ {
wellService = Substitute.For<IWellService>(); wellService = Substitute.For<IWellService>();
wellOperationRepository = Substitute.For<IWellOperationRepository>(); wellOperationRepository = Substitute.For<IWellOperationRepository>();
wellOperationCategoryRepository = Substitute.For<IWellOperationCategoryRepository>();
wellOperationImportTemplateService = new WellOperationImportTemplateService(); wellOperationImportTemplateService = new WellOperationImportTemplateService();
wellOperationExportService = new WellOperationExportService(wellOperationRepository, wellService, wellOperationImportTemplateService); wellOperationExportService = new WellOperationExportService(wellOperationRepository, wellService, wellOperationImportTemplateService, wellOperationCategoryRepository);
wellOperationImportService = new WellOperationImportService(wellService, wellOperationRepository); wellOperationImportService = new WellOperationImportService(wellService, wellOperationRepository, wellOperationCategoryRepository);
wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser(); wellOperationDefaultExcelParser = new WellOperationDefaultExcelParser();
this.output = output; this.output = output;
} }
#warning Test Check_Exported_WellOperations_With_Operations_In_Db Fails and commented for debug deployment task [Fact]
//[Fact] public async Task Check_Exported_WellOperations_With_Operations_In_Db()
//public async Task Check_Exported_WellOperations_With_Operations_In_Db() {
//{ wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto()
// wellService.GetTimezone(idWell).Returns(new SimpleTimezoneDto() {
// { Hours = 5
// Hours = 5 });
// });
// var localOperations = operations.ToArray(); var localOperations = operations.ToArray();
// foreach (var operation in localOperations) foreach (var operation in localOperations)
// operation.Id = 0; operation.Id = 0;
// wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>()) wellOperationRepository.GetAsync(Arg.Any<WellOperationRequest>(), Arg.Any<CancellationToken>())
// .ReturnsForAnyArgs(localOperations); .ReturnsForAnyArgs(localOperations);
// wellOperationRepository.GetSectionTypes().Returns(sectionTypes); wellOperationRepository.GetSectionTypes().Returns(sectionTypes);
// wellOperationRepository.GetCategories(false).Returns(categories); wellOperationCategoryRepository.Get(false).Returns(categories);
// var stream = await wellOperationExportService.ExportAsync(idWell, CancellationToken.None); var stream = await wellOperationExportService.ExportAsync(idWell, CancellationToken.None);
// var options = new WellOperationImportDefaultOptionsDto var options = new WellOperationImportDefaultOptionsDto
// { {
// IdType = WellOperation.IdOperationTypePlan IdType = WellOperation.IdOperationTypePlan
// }; };
// var sheet = wellOperationDefaultExcelParser.Parse(stream, options); var sheet = wellOperationDefaultExcelParser.Parse(stream, options);
// var result = wellOperationImportService.Import(idWell, 1, options.IdType, sheet); var result = wellOperationImportService.Import(idWell, 1, options.IdType, sheet);
// var expected = JsonSerializer.Serialize(localOperations); var expected = JsonSerializer.Serialize(localOperations);
// var actual = JsonSerializer.Serialize(result); var actual = JsonSerializer.Serialize(result);
// Assert.Equal(expected, actual); Assert.Equal(expected, actual);
//} }
[Fact] [Fact]
public void TestDataContainsNotDefaultProps() public void TestDataContainsNotDefaultProps()

View File

@ -35,6 +35,7 @@ namespace AsbCloudWebApi.Controllers
private readonly IWellOperationExportService wellOperationExportService; private readonly IWellOperationExportService wellOperationExportService;
private readonly IWellOperationImportTemplateService wellOperationImportTemplateService; private readonly IWellOperationImportTemplateService wellOperationImportTemplateService;
private readonly IWellOperationImportService wellOperationImportService; private readonly IWellOperationImportService wellOperationImportService;
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
private readonly IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser; private readonly IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser;
private readonly IWellOperationExcelParser<WellOperationImportGazpromKhantosOptionsDto> wellOperationGazpromKhantosExcelParser; private readonly IWellOperationExcelParser<WellOperationImportGazpromKhantosOptionsDto> wellOperationGazpromKhantosExcelParser;
private readonly IUserRepository userRepository; private readonly IUserRepository userRepository;
@ -44,6 +45,7 @@ namespace AsbCloudWebApi.Controllers
IWellOperationImportTemplateService wellOperationImportTemplateService, IWellOperationImportTemplateService wellOperationImportTemplateService,
IWellOperationExportService wellOperationExportService, IWellOperationExportService wellOperationExportService,
IWellOperationImportService wellOperationImportService, IWellOperationImportService wellOperationImportService,
IWellOperationCategoryRepository wellOperationCategoryRepository,
IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser, IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser,
IWellOperationExcelParser<WellOperationImportGazpromKhantosOptionsDto> wellOperationGazpromKhantosExcelParser, IWellOperationExcelParser<WellOperationImportGazpromKhantosOptionsDto> wellOperationGazpromKhantosExcelParser,
IUserRepository userRepository) IUserRepository userRepository)
@ -53,6 +55,7 @@ namespace AsbCloudWebApi.Controllers
this.wellOperationImportTemplateService = wellOperationImportTemplateService; this.wellOperationImportTemplateService = wellOperationImportTemplateService;
this.wellOperationExportService = wellOperationExportService; this.wellOperationExportService = wellOperationExportService;
this.wellOperationImportService = wellOperationImportService; this.wellOperationImportService = wellOperationImportService;
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
this.wellOperationDefaultExcelParser = wellOperationDefaultExcelParser; this.wellOperationDefaultExcelParser = wellOperationDefaultExcelParser;
this.wellOperationGazpromKhantosExcelParser = wellOperationGazpromKhantosExcelParser; this.wellOperationGazpromKhantosExcelParser = wellOperationGazpromKhantosExcelParser;
this.userRepository = userRepository; this.userRepository = userRepository;
@ -81,7 +84,7 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetCategories(bool includeParents = true) public IActionResult GetCategories(bool includeParents = true)
{ {
var result = operationRepository.GetCategories(includeParents); var result = wellOperationCategoryRepository.Get(includeParents);
return Ok(result); return Ok(result);
} }
@ -163,7 +166,7 @@ namespace AsbCloudWebApi.Controllers
} }
/// <summary> /// <summary>
/// Статистика операций по скважине, группированая по категориям /// Статистика операций по скважине, группированная по категориям
/// </summary> /// </summary>
/// <param name="idWell">id скважины</param> /// <param name="idWell">id скважины</param>
/// <param name="request"></param> /// <param name="request"></param>