using AsbCloudApp.Data.ProcessMaps; using AsbCloudDb.Model.ProcessMaps; using Mapster; using Microsoft.EntityFrameworkCore; using Xunit; namespace AsbCloudWebApi.IntegrationTests.Controllers.ProcessMapPlan; public class ProcessMapPlanSlideControllerTest : ProcessMapPlanBaseControllerTest { private readonly ProcessMapPlanSlideDto dto = new ProcessMapPlanSlideDto() { IdWell = 1, DepthStart = 1, DepthEnd = 2, RopLimitMax = 3, PressureLimitMax = 4, DifferentialPressure = 5, DifferentialPressureLimitMax = 6, WeightOnBit = 7, WeightOnBitLimitMax = 8, FlowRate = 9, FlowRateLimitMax = 10, Spring = 11, ToolBuckling = 12, Id = 0, IdWellSectionType = 1, Note = "13" }; private readonly ProcessMapPlanSlide entity = new ProcessMapPlanSlide() { IdWell = 1, DepthEnd = 10, DepthStart = 2, DifferentialPressure = 3, DifferentialPressureLimitMax = 4, FlowRate = 5, FlowRateLimitMax = 6, Id = 0, IdWellSectionType = 1, Note = "1", PressureLimitMax = 2, RopLimitMax = 5, WeightOnBit = 8, WeightOnBitLimitMax = 9, IdAuthor = 1, IdEditor = 1, Creation = DateTimeOffset.UtcNow, Spring = 10, ToolBuckling = 11, }; public ProcessMapPlanSlideControllerTest(WebAppFactoryFixture factory) : base(factory, "ProcessMapPlanSlide") { } protected override ProcessMapPlanSlide? 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 ProcessMapPlanSlide GetByNote( DbSet dbSet, ProcessMapPlanSlideDto dto) { var entity = dbSet.First(p => p.Note == dto.Note); return entity; } protected override ProcessMapPlanSlideDto GetByNote( IEnumerable dtos, ProcessMapPlanSlideDto 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.Spring++; dtoUpdate.ToolBuckling++; 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++; dtoUpdate.Spring++; dtoUpdate.ToolBuckling++; 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, "ProcessMapPlanSlideValid.xlsx", dto); } [Fact] public async Task Parse_returns_success_for_result_with_warnings() { await ParseWithWarnings(dto.IdWell, "ProcessMapPlanSlideInvalid.xlsx"); } }