forked from ddrilling/AsbCloudServer
1b3c06c927
1. Добавлен шаблон для сообщений 2. Поправлен naming у сервисов парсинга траекторий 3. Удалена регистрация зависимостей парсеров траекторий 4. Внутри фабрики добавлено создание отдельного scope. Фикс нейминга констант
63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using AsbCloudApp.Data.Trajectory;
|
|
using AsbCloudApp.Requests.ParserOptions;
|
|
using AsbCloudInfrastructure.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
|
|
namespace AsbCloudWebApi.Tests.Services.Trajectory;
|
|
|
|
public class TrajectoryParserTest
|
|
{
|
|
private const string UsingTemplateFile = "AsbCloudWebApi.Tests.Services.Trajectory.Templates";
|
|
|
|
private readonly IServiceProvider serviceProviderMock = Substitute.For<IServiceProvider, ISupportRequiredService>();
|
|
private readonly IServiceScope serviceScopeMock = Substitute.For<IServiceScope>();
|
|
private readonly IServiceScopeFactory serviceScopeFactoryMock = Substitute.For<IServiceScopeFactory>();
|
|
|
|
private readonly ParserServiceFactory parserServiceFactory;
|
|
|
|
public TrajectoryParserTest()
|
|
{
|
|
serviceScopeFactoryMock.CreateScope().Returns(serviceScopeMock);
|
|
((ISupportRequiredService)serviceProviderMock).GetRequiredService(typeof(IServiceScopeFactory)).Returns(serviceScopeFactoryMock);
|
|
|
|
parserServiceFactory = new ParserServiceFactory(serviceProviderMock);
|
|
}
|
|
|
|
[Fact]
|
|
public void Parse_trajectory_plan()
|
|
{
|
|
var stream = System.Reflection.Assembly.GetExecutingAssembly()
|
|
.GetManifestResourceStream($"{UsingTemplateFile}.TrajectoryPlanTemplate.xlsx");
|
|
|
|
if (stream is null)
|
|
Assert.Fail("Файла для импорта не существует");
|
|
|
|
var parserService = parserServiceFactory.Create<TrajectoryGeoPlanDto, IParserOptionsRequest>(
|
|
ParserServiceFactory.IdTrajectoryPlanParser);
|
|
|
|
var trajectoryRows = parserService.Parse(stream, IParserOptionsRequest.Empty());
|
|
|
|
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("Файла для импорта не существует");
|
|
|
|
var parserService = parserServiceFactory.Create<TrajectoryGeoFactDto, IParserOptionsRequest>(
|
|
ParserServiceFactory.IdTrajectoryFactManualParser);
|
|
|
|
var trajectoryRows = parserService.Parse(stream, IParserOptionsRequest.Empty());
|
|
|
|
Assert.Equal(4, trajectoryRows.Item.Count());
|
|
}
|
|
} |