using AsbCloudApp.Data.ProcessMapPlan; using AsbCloudDb.Model.ProcessMaps; using AsbCloudWebApi.IntegrationTests.Clients; using Mapster; using Microsoft.EntityFrameworkCore; using System.Net; using Xunit; namespace AsbCloudWebApi.IntegrationTests.Controllers; public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest { private IProcessMapPlanDrillingClient client; readonly ProcessMapPlanDrillingDto dto = new (){ Id = 0, IdAuthor = 0, IdEditor = null, Creation = new(), Obsolete = null, IdState = 0, IdPrevious = null, IdWell = 1, IdWellSectionType = 1, DepthStart = 0.5, DepthEnd = 1.5, IdMode = 1, AxialLoadPlan = 2.718281, AxialLoadLimitMax = 3.1415926, DeltaPressurePlan = 4, DeltaPressureLimitMax = 5, TopDriveTorquePlan = 6, TopDriveTorqueLimitMax = 7, TopDriveSpeedPlan = 8, TopDriveSpeedLimitMax = 9, FlowPlan = 10, FlowLimitMax = 11, RopPlan = 12, UsageSaub = 13, UsageSpin = 14, Comment = "это тестовая запись", }; public ProcessMapPlanDrillingControllerTest(WebAppFactoryFixture factory) : base(factory) { client = factory.GetAuthorizedHttpClient(); } [Fact] public async Task InsertRangeAsync_ReturnsSuccess_WhenNewItemIsValid() { //arrange var expected = dto; //act var response = await client.InsertRangeAsync(dto.IdWell, new[] { expected }); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(1, response.Content); var entity = await dbContext.Set() .Where(p => p.AxialLoadPlan == dto.AxialLoadPlan) .Where(p => p.AxialLoadLimitMax == dto.AxialLoadLimitMax) .Where(p => p.Comment == dto.Comment) .Where(p => p.IdWell == dto.IdWell) .FirstOrDefaultAsync(); Assert.NotNull(entity); var actual = entity.Adapt(); var excludeProps = new[] { nameof(ProcessMapPlanDrillingDto.Id), nameof(ProcessMapPlanDrillingDto.IdAuthor), nameof(ProcessMapPlanDrillingDto.Creation), }; MatchHelper.Match(expected, actual, excludeProps); } }