2024-02-01 16:35:29 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
using AsbCloudApp.Data.Trajectory;
|
2024-02-01 16:35:29 +05:00
|
|
|
|
using AsbCloudApp.Requests.ParserOptions;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services;
|
2024-02-01 16:35:29 +05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using NSubstitute;
|
2024-01-29 15:03:53 +05:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Tests.Services.Trajectory;
|
|
|
|
|
|
|
|
|
|
public class TrajectoryParserTest
|
|
|
|
|
{
|
|
|
|
|
private const string UsingTemplateFile = "AsbCloudWebApi.Tests.Services.Trajectory.Templates";
|
2024-02-01 16:35:29 +05:00
|
|
|
|
|
|
|
|
|
private readonly IServiceProvider serviceProviderMock = Substitute.For<IServiceProvider, ISupportRequiredService>();
|
|
|
|
|
private readonly IServiceScope serviceScopeMock = Substitute.For<IServiceScope>();
|
|
|
|
|
private readonly IServiceScopeFactory serviceScopeFactoryMock = Substitute.For<IServiceScopeFactory>();
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
private readonly ParserServiceFactory parserServiceFactory;
|
|
|
|
|
|
|
|
|
|
public TrajectoryParserTest()
|
|
|
|
|
{
|
|
|
|
|
serviceScopeFactoryMock.CreateScope().Returns(serviceScopeMock);
|
|
|
|
|
((ISupportRequiredService)serviceProviderMock).GetRequiredService(typeof(IServiceScopeFactory)).Returns(serviceScopeFactoryMock);
|
|
|
|
|
|
|
|
|
|
parserServiceFactory = new ParserServiceFactory(serviceProviderMock);
|
|
|
|
|
}
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Parse_trajectory_plan()
|
|
|
|
|
{
|
|
|
|
|
var stream = System.Reflection.Assembly.GetExecutingAssembly()
|
|
|
|
|
.GetManifestResourceStream($"{UsingTemplateFile}.TrajectoryPlanTemplate.xlsx");
|
|
|
|
|
|
|
|
|
|
if (stream is null)
|
|
|
|
|
Assert.Fail("Файла для импорта не существует");
|
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
var parserService = parserServiceFactory.Create<TrajectoryGeoPlanDto, IParserOptionsRequest>(
|
|
|
|
|
ParserServiceFactory.IdTrajectoryPlanParserService);
|
|
|
|
|
|
|
|
|
|
var trajectoryRows = parserService.Parse(stream, IParserOptionsRequest.Empty());
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
|
|
|
|
Assert.Equal(3, trajectoryRows.Item.Count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Parse_trajectory_fact_manual()
|
|
|
|
|
{
|
|
|
|
|
var stream = System.Reflection.Assembly.GetExecutingAssembly()
|
|
|
|
|
.GetManifestResourceStream($"{UsingTemplateFile}.TrajectoryFactManualTemplate.xlsx");
|
|
|
|
|
|
|
|
|
|
if (stream is null)
|
|
|
|
|
Assert.Fail("Файла для импорта не существует");
|
|
|
|
|
|
2024-02-01 16:35:29 +05:00
|
|
|
|
var parserService = parserServiceFactory.Create<TrajectoryGeoFactDto, IParserOptionsRequest>(
|
|
|
|
|
ParserServiceFactory.IdTrajectoryFactManualParserService);
|
|
|
|
|
|
|
|
|
|
var trajectoryRows = parserService.Parse(stream, IParserOptionsRequest.Empty());
|
2024-01-29 15:03:53 +05:00
|
|
|
|
|
|
|
|
|
Assert.Equal(4, trajectoryRows.Item.Count());
|
|
|
|
|
}
|
|
|
|
|
}
|