using AsbCloudApp.Data.ProcessMaps; using AsbCloudDb.Model.ProcessMaps; using DocumentFormat.OpenXml.Drawing.Charts; using Mapster; using Microsoft.EntityFrameworkCore; using Xunit; namespace AsbCloudWebApi.IntegrationTests.Controllers.ProcessMapPlan; public class ProcessMapPlanRotorControllerTest : ProcessMapPlanBaseControllerTest { private readonly ProcessMapPlanRotorDto dto = new ProcessMapPlanRotorDto() { IdWell = 1, DepthStart = 1, DepthEnd = 2, RopLimitMax = 3, PressureLimitMax = 4, DifferentialPressure = 5, DifferentialPressureLimitMax = 6, WeightOnBit = 7, WeightOnBitLimitMax = 8, TopDriveTorque = 9, TopDriveTorqueLimit = 10, RevolutionsPerMinute = 11, RevolutionsPerMinuteLimitMax = 12, FlowRate = 13, FlowRateLimitMax = 14, Note = "15", Id = 0, IdWellSectionType = 1, }; private readonly ProcessMapPlanRotor entity = new ProcessMapPlanRotor() { IdWell = 1, DepthEnd = 10, DepthStart = 2, DifferentialPressure = 3, DifferentialPressureLimitMax = 4, FlowRate = 5, FlowRateLimitMax = 6, Id = 0, IdWellSectionType = 1, Note = "1", PressureLimitMax = 2, RevolutionsPerMinute = 3, RevolutionsPerMinuteLimitMax = 4, RopLimitMax = 5, TopDriveTorque = 6, TopDriveTorqueLimit = 7, WeightOnBit = 8, WeightOnBitLimitMax = 9, IdAuthor = 1, IdEditor = 1, Creation = DateTimeOffset.UtcNow }; public ProcessMapPlanRotorControllerTest(WebAppFactoryFixture factory) : base(factory, "ProcessMapPlanRotor") { } protected override ProcessMapPlanRotor? GetByWellId() { var entity = dbContext .Set() .Where(p => p.WeightOnBit == dto.WeightOnBit) .Where(p => p.WeightOnBitLimitMax == dto.WeightOnBitLimitMax) .Where(p => p.Note == dto.Note) .FirstOrDefault(p => p.IdWell == dto.IdWell); return entity; } protected override ProcessMapPlanRotor GetByNote( DbSet dbSet, ProcessMapPlanRotorDto dto) { var entity = dbSet.First(p => p.Note == dto.Note); return entity; } protected override ProcessMapPlanRotorDto GetByNote( IEnumerable dtos, ProcessMapPlanRotorDto dto) { var entity = dtos.First(p => p.Note == dto.Note); return entity; } [Fact] public async Task InsertRange_returns_success() { await InsertRangeSuccess(dto); } [Fact] public async Task InsertRange_returns_BadRequest_for_IdWellSectionType() { //arrange var badDto = dto.Adapt(); badDto.IdWellSectionType = int.MaxValue; await InsertRangeFailed(badDto); } [Fact] public async Task ClearAndInsertRange_returns_success() { await ClearAndInsertRange(entity, dto); } [Fact] public async Task UpdateOrInsertRange_returns_success() { var dtoUpdate = dto.Adapt(); dtoUpdate.IdWell = 0; dtoUpdate.Note = "nebuchadnezzar"; dtoUpdate.DifferentialPressureLimitMax++; dtoUpdate.DifferentialPressure++; dtoUpdate.FlowRate++; dtoUpdate.FlowRateLimitMax++; dtoUpdate.RopLimitMax++; dtoUpdate.WeightOnBit++; dtoUpdate.WeightOnBitLimitMax++; dtoUpdate.DepthStart++; dtoUpdate.DepthEnd++; dtoUpdate.RevolutionsPerMinute++; dtoUpdate.RevolutionsPerMinuteLimitMax++; dtoUpdate.TopDriveTorque++; dtoUpdate.TopDriveTorqueLimit++; var dtoInsert = dtoUpdate.Adapt(); dtoInsert.Id = 0; dtoInsert.Note = "nebuchad"; dtoInsert.DifferentialPressureLimitMax++; dtoInsert.DifferentialPressure++; dtoInsert.FlowRate++; dtoInsert.FlowRateLimitMax++; dtoInsert.RopLimitMax++; dtoInsert.WeightOnBit++; dtoInsert.WeightOnBitLimitMax++; dtoInsert.DepthStart++; dtoInsert.DepthEnd++; dtoInsert.RevolutionsPerMinute++; dtoInsert.RevolutionsPerMinuteLimitMax++; dtoInsert.TopDriveTorque++; dtoInsert.TopDriveTorqueLimit++; await UpdateOrInsertRange(entity, dtoUpdate, dtoInsert); } [Fact] public async Task DeleteRange_returns_success() { await DeleteRange(entity, dto); } [Fact] public async Task Clear_returns_success() { await Clear(entity, dto); } [Fact] public async Task GetDatesChange_returns_success() { await GetDatesChange(entity, dto); } [Fact] public async Task Get_actual_returns_success() { await Get(entity, dto); } [Fact] public async Task Get_at_moment_returns_success() { await GetAtMoment(entity, dto); } [Fact] public async Task Get_by_updated_from_returns_success() { await GetByUpdated(entity, dto); } [Fact] public async Task Get_updated_returns_success() { await GetUpdated(entity, dto); } [Fact] public async Task Parse_returns_success() { await Parse(dto.IdWell, "ProcessMapPlanRotorValid.xlsx", dto); } [Fact] public async Task Parse_returns_success_for_result_with_warnings() { await ParseWithWarnings(dto.IdWell, "ProcessMapPlanRotorInvalid.xlsx"); } }