using AsbCloudApp.Data.Trajectory; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudInfrastructure.Services.Trajectory.Export; using NSubstitute; using System; using System.Threading; using System.Threading.Tasks; using Xunit; namespace AsbCloudWebApi.Tests.UnitTests.Services.Trajectory { public class TrajectoryExportTest { private IWellService wellService; private readonly ITrajectoryEditableRepository trajectoryPlannedRepository; private readonly TrajectoryPlannedExportService trajectoryPlannedExportService; private readonly ITrajectoryEditableRepository trajectoryFactManualReposirory; private readonly TrajectoryFactManualExportService trajectoryFactManualExportService; private readonly ITrajectoryNnbRepository trajectoryFactNnbRepository; private readonly TrajectoryFactNnbExportService trajectoryFactNnbExportService; private readonly int idWell = 4; private readonly TrajectoryGeoPlanDto[] trajectoryPlannedRows = new TrajectoryGeoPlanDto[2] { new TrajectoryGeoPlanDto() { Id = 1, AzimuthGeo = 1, AzimuthMagnetic = 2, Comment = "комментарий", IdUser = 1, IdWell = 4, Radius = 3, UpdateDate = DateTime.Now, VerticalDepth = 100, WellboreDepth = 100, ZenithAngle = 10 }, new TrajectoryGeoPlanDto() { Id = 2, AzimuthGeo = 1, AzimuthMagnetic = 2, Comment = "комментарий", IdUser = 1, IdWell = 4, Radius = 3, UpdateDate = DateTime.Now, VerticalDepth = 100, WellboreDepth = 100, ZenithAngle = 10 }, }; private readonly TrajectoryGeoFactDto[] trajectoryFactRows = new TrajectoryGeoFactDto[2] { new TrajectoryGeoFactDto() { Id = 1, AzimuthGeo = 1, AzimuthMagnetic = 2, Comment = "комментарий", IdUser = 1, IdWell = 4, UpdateDate = DateTime.Now, VerticalDepth = 100, WellboreDepth = 100, ZenithAngle = 10 }, new TrajectoryGeoFactDto() { Id = 2, AzimuthGeo = 1, AzimuthMagnetic = 2, Comment = "комментарий", IdUser = 1, IdWell = 4, UpdateDate = DateTime.Now, VerticalDepth = 100, WellboreDepth = 100, ZenithAngle = 10 }, }; public TrajectoryExportTest() { wellService = Substitute.For(); trajectoryPlannedRepository = Substitute.For>(); trajectoryPlannedExportService = new TrajectoryPlannedExportService(wellService, trajectoryPlannedRepository); trajectoryFactManualReposirory = Substitute.For>(); trajectoryFactManualExportService = new TrajectoryFactManualExportService(wellService, trajectoryFactManualReposirory); trajectoryFactNnbRepository = Substitute.For(); trajectoryFactNnbExportService = new TrajectoryFactNnbExportService(wellService, trajectoryFactNnbRepository); } [Fact] public async Task Export_trajectory_planned() { trajectoryPlannedRepository.GetAsync(idWell, CancellationToken.None) .Returns(trajectoryPlannedRows); var stream = await trajectoryPlannedExportService.ExportAsync(idWell, CancellationToken.None); Assert.True(stream.Length > 0); } [Fact] public async Task Export_trajectory_fact_manual() { trajectoryFactManualReposirory.GetAsync(idWell, CancellationToken.None) .Returns(trajectoryFactRows); var stream = await trajectoryFactManualExportService.ExportAsync(idWell, CancellationToken.None); Assert.True(stream.Length > 0); } [Fact] public async Task Export_trajectory_fact_nnb() { trajectoryFactNnbRepository.GetAsync(idWell, CancellationToken.None) .Returns(trajectoryFactRows); var stream = await trajectoryFactNnbExportService.ExportAsync(idWell, CancellationToken.None); Assert.True(stream.Length > 0); } } }