Интеграционный тест для сопоставления категорий между шаблонами импорта/экспорта ГГД и записями в БД

This commit is contained in:
Olga Nemt 2024-04-23 14:43:17 +05:00
parent 0b4fbe34ce
commit dc96d03740
4 changed files with 208 additions and 160 deletions

View File

@ -29,4 +29,10 @@ public interface IWellOperationClient
[Get(BaseRoute + "/export")]
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.Requests;
using AsbCloudDb.Model;
using AsbCloudInfrastructure;
using AsbCloudWebApi.IntegrationTests.Clients;
using AsbCloudWebApi.IntegrationTests.Data;
using ClosedXML.Excel;
using Mapster;
using Microsoft.EntityFrameworkCore;
using Refit;
using System.Net;
using System.Reflection;
using Xunit;
namespace AsbCloudWebApi.IntegrationTests.Controllers.WellOperations;
@ -188,6 +190,46 @@ public class WellOperationControllerTest : BaseIntegrationTest
Assert.True(response.ContentHeaders?.ContentLength > 0);
}
[Theory]
[InlineData(WellOperation.IdOperationTypePlan)]
[InlineData(WellOperation.IdOperationTypeFact)]
public async Task MatchCategoriesFromTemplateAndDb_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) =>
new()
{