Merge pull request 'Автотест для проверки категорий операций между файлом шаблона и базой данных' (#270) from feature/#32021538-match-categories-integration-test into dev

Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/270
This commit is contained in:
Никита Фролов 2024-04-23 17:19:48 +05:00
commit d517033415
5 changed files with 210 additions and 161 deletions

View File

@ -29,4 +29,10 @@ public interface IWellOperationClient
[Get(BaseRoute + "/export")] [Get(BaseRoute + "/export")]
Task<IApiResponse<PhysicalFileResult>> ExportAsync(int idWell, int idType); Task<IApiResponse<PhysicalFileResult>> ExportAsync(int idWell, int idType);
[Get(BaseRoute + "/template")]
Task<IApiResponse<Stream>> GetTemplate(int idWell, int idType);
[Get(BaseRoute + "/categories")]
Task<IApiResponse<IEnumerable<WellOperationCategoryDto>>> GetCategories(int idWell, bool includeParents, bool includeHidden);
} }

View File

@ -1,13 +1,15 @@
using System.Net;
using System.Reflection;
using AsbCloudApp.Data.WellOperation; using AsbCloudApp.Data.WellOperation;
using AsbCloudApp.Requests; using AsbCloudApp.Requests;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using AsbCloudInfrastructure;
using AsbCloudWebApi.IntegrationTests.Clients; using AsbCloudWebApi.IntegrationTests.Clients;
using AsbCloudWebApi.IntegrationTests.Data; using AsbCloudWebApi.IntegrationTests.Data;
using ClosedXML.Excel;
using Mapster; using Mapster;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Refit; using Refit;
using System.Net;
using System.Reflection;
using Xunit; using Xunit;
namespace AsbCloudWebApi.IntegrationTests.Controllers.WellOperations; namespace AsbCloudWebApi.IntegrationTests.Controllers.WellOperations;
@ -188,6 +190,46 @@ public class WellOperationControllerTest : BaseIntegrationTest
Assert.True(response.ContentHeaders?.ContentLength > 0); Assert.True(response.ContentHeaders?.ContentLength > 0);
} }
[Theory]
[InlineData(WellOperation.IdOperationTypePlan)]
[InlineData(WellOperation.IdOperationTypeFact)]
public async Task MatchCategoriesBetweenTemplateAndDb_returns_success(int idType)
{
//arrange
var well = await dbContext.Wells.FirstAsync();
var responseTemplate = await client.GetTemplate(well.Id, idType);
var stream = responseTemplate.Content;
using var workbook = new XLWorkbook(stream);
var sheet = workbook.GetWorksheet("Справочники");
var count = sheet.RowsUsed().Count() - 1;
var categoryCaptionsInTemplate = new List<string>();
for (var i = 0; i < count; i++)
{
var xlRow = sheet.Row(i + 2);
var rowNumber = xlRow.RowNumber();
var xlCell = xlRow.Cell(1);
var cellValue = xlCell.GetText().Trim();
categoryCaptionsInTemplate.Add(cellValue);
}
var responseCategories = await client.GetCategories(well.Id, false, false);
var categories = responseCategories.Content;
var categoryCaptionsInDb = categories!.Select(c => c.Name.Trim());
var notExistedInTemplate = categoryCaptionsInDb.Except(categoryCaptionsInTemplate);
var notExistedInDb = categoryCaptionsInTemplate.Except(categoryCaptionsInDb);
//assert
Assert.True(categoryCaptionsInDb.Count() == categoryCaptionsInTemplate.Count());
Assert.True(notExistedInTemplate.Count() == 0);
Assert.True(notExistedInDb.Count() == 0);
}
private static WellOperation CreateWellOperation(int idWell, int idType = WellOperation.IdOperationTypePlan) => private static WellOperation CreateWellOperation(int idWell, int idType = WellOperation.IdOperationTypePlan) =>
new() new()
{ {

View File

@ -36,6 +36,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
new(){Id = 5036, Name = "Промывка"}, new(){Id = 5036, Name = "Промывка"},
new(){Id = 5012, Name = "Подъем инструмента"}, new(){Id = 5012, Name = "Подъем инструмента"},
new(){Id = 5083, Name = "Проработка принудительная"}, new(){Id = 5083, Name = "Проработка принудительная"},
new(){Id = 5113, Name = "Бурение"},
}; };
private readonly static IEnumerable<WellSectionTypeDto> sectionTypes = new List<WellSectionTypeDto>() private readonly static IEnumerable<WellSectionTypeDto> sectionTypes = new List<WellSectionTypeDto>()
@ -224,7 +225,7 @@ namespace AsbCloudWebApi.Tests.Services.WellCompositeOperation
// assert // assert
var compositeWellOperations = result.WellOperationsComposite; var compositeWellOperations = result.WellOperationsComposite;
Assert.Single(compositeWellOperations); Assert.Single(compositeWellOperations);
Assert.Equal(5003, compositeWellOperations.FirstOrDefault()!.IdCategory); Assert.Equal(5113, compositeWellOperations.FirstOrDefault()!.IdCategory);
Assert.Equal(1.5, compositeWellOperations.FirstOrDefault()!.DurationHours); Assert.Equal(1.5, compositeWellOperations.FirstOrDefault()!.DurationHours);
Assert.Equal(10, compositeWellOperations.FirstOrDefault()!.DepthStart); Assert.Equal(10, compositeWellOperations.FirstOrDefault()!.DepthStart);
} }