Тесты парсинга РТК

This commit is contained in:
Степанов Дмитрий 2024-02-09 09:33:03 +03:00
parent f2ca89dc8d
commit 06d3e9851a
5 changed files with 79 additions and 7 deletions

View File

@ -22,4 +22,9 @@
<ProjectReference Include="..\AsbCloudWebApi\AsbCloudWebApi.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Controllers\ProcessMapPlan\Files\ProcessMapPlanDrillingInvalid.xlsx" />
<EmbeddedResource Include="Controllers\ProcessMapPlan\Files\ProcessMapPlanDrillingValid.xlsx" />
</ItemGroup>
</Project>

View File

@ -1,6 +1,6 @@
using AsbCloudApp.Data.ProcessMapPlan;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMapPlan;
using AsbCloudApp.Requests;
using Microsoft.AspNetCore.Mvc;
using Refit;
namespace AsbCloudWebApi.IntegrationTests.Clients;
@ -32,4 +32,8 @@ public interface IProcessMapPlanDrillingClient
[Put(BaseRoute)]
Task<IApiResponse<int>> UpdateOrInsertRange(int idWell, IEnumerable<ProcessMapPlanDrillingDto> dtos);
[Multipart]
[Post(BaseRoute + "/parse")]
Task<IApiResponse<ParserResultDto<ProcessMapPlanDrillingDto>>> Parse(int idWell, [AliasAs("files")] IEnumerable<StreamPart> streams);
}

View File

@ -1,31 +1,35 @@
using AsbCloudApp.Data.ProcessMapPlan;
using AsbCloudApp.Requests;
using AsbCloudDb.Model.ProcessMapPlan;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudWebApi.IntegrationTests.Clients;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System.Net;
using System.Reflection;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudWebApi.IntegrationTests.Data;
using Refit;
using Xunit;
namespace AsbCloudWebApi.IntegrationTests.Controllers;
namespace AsbCloudWebApi.IntegrationTests.Controllers.ProcessMapPlan;
public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
{
private IProcessMapPlanDrillingClient client;
private readonly ProcessMapPlanDrillingDto dto = new (){
Id = 0,
Creation = new(),
Obsolete = null,
IdState = 0,
IdPrevious = null,
IdWell = 1,
IdWellSectionType = 1,
Section = "Кондуктор",
IdWellSectionType = 3,
DepthStart = 0.5,
DepthEnd = 1.5,
IdMode = 1,
Mode = "ротор",
AxialLoadPlan = 2.718281,
AxialLoadLimitMax = 3.1415926,
DeltaPressurePlan = 4,
@ -73,6 +77,8 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
Comment = "это тестовая запись",
};
private IProcessMapPlanDrillingClient client;
public ProcessMapPlanDrillingControllerTest(WebAppFactoryFixture factory) : base(factory)
{
dbContext.CleanupDbSet<ProcessMapPlanDrilling>();
@ -109,6 +115,8 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
nameof(ProcessMapPlanDrillingDto.IdState),
nameof(ProcessMapPlanDrillingDto.Author),
nameof(ProcessMapPlanDrillingDto.Creation),
nameof(ProcessMapPlanDrillingDto.Mode),
nameof(ProcessMapPlanDrillingDto.Section)
};
MatchHelper.Match(expected, actual, excludeProps);
}
@ -556,4 +564,59 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
};
MatchHelper.Match(expected, actual, excludeProps);
}
[Fact]
public async Task Parse_returns_success()
{
//arrange
const string fileName = "ProcessMapPlanDrillingValid.xlsx";
var stream = Assembly.GetExecutingAssembly().GetFileCopyStream(fileName);
//act
var streamPart = new StreamPart(stream, fileName, "application/octet-stream");
var response = await client.Parse(Defaults.Wells[0].Id, new[] { streamPart });
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var parserResult = response.Content;
Assert.NotNull(parserResult);
Assert.Single(parserResult.Item);
Assert.True(parserResult.IsValid);
var row = parserResult.Item.First();
var dtoActual = row.Item;
Assert.True(row.IsValid);
var excludeProps = new[] { nameof(ProcessMapPlanDrillingDto.IdWell) };
MatchHelper.Match(dto, dtoActual, excludeProps);
}
[Fact]
public async Task Parse_returns_success_for_result_with_warnings()
{
//arrange
const string fileName = "ProcessMapPlanDrillingInvalid.xlsx";
var stream = Assembly.GetExecutingAssembly().GetFileCopyStream(fileName);
//act
var streamPart = new StreamPart(stream, fileName, "application/octet-stream");
var response = await client.Parse(Defaults.Wells[0].Id, new[] { streamPart });
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var parserResult = response.Content;
Assert.NotNull(parserResult);
Assert.False(parserResult.IsValid);
Assert.Single(parserResult.Warnings);
Assert.Single(parserResult.Item);
var row = parserResult.Item.First();
Assert.False(row.IsValid);
Assert.Equal(2, row.Warnings.Count());
}
}