fix integration test

This commit is contained in:
Frolov-Nikita 2024-01-20 15:38:37 +05:00
parent 9a2762ba60
commit 7eedf62419
No known key found for this signature in database
GPG Key ID: 719E3386D12B0760
6 changed files with 466 additions and 52 deletions

View File

@ -18,7 +18,7 @@ public interface IChangeLogRepository<T>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> InsertRangeAsync(int idUser, IEnumerable<T> dtos, CancellationToken token);
Task<int> InsertRange(int idUser, IEnumerable<T> dtos, CancellationToken token);
/// <summary>
/// Редактирование записей
@ -27,7 +27,7 @@ public interface IChangeLogRepository<T>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> UpdateRangeAsync(int idUser, IEnumerable<T> dtos, CancellationToken token);
Task<int> UpdateRange(int idUser, IEnumerable<T> dtos, CancellationToken token);
/// <summary>
/// Удаление записей
@ -36,6 +36,6 @@ public interface IChangeLogRepository<T>
/// <param name="ids"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteRangeAsync(int idUser, IEnumerable<int> ids, CancellationToken token);
Task<int> DeleteRange(int idUser, IEnumerable<int> ids, CancellationToken token);
}

View File

@ -22,7 +22,7 @@ public interface IProcessMapPlanBaseRepository<T>: IChangeLogRepository<T>
/// <param name="dtos"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> ClearAndInsertRangeAsync(int idUser, int idWell, IEnumerable<T> dtos, CancellationToken token);
Task<int> ClearAndInsertRange(int idUser, int idWell, IEnumerable<T> dtos, CancellationToken token);
/// <summary>
/// Получение дат изменений записей
@ -30,7 +30,7 @@ public interface IProcessMapPlanBaseRepository<T>: IChangeLogRepository<T>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<DateOnly>> GetDatesChangeAsync(int idWell, CancellationToken token);
Task<IEnumerable<DateOnly>> GetDatesChange(int idWell, CancellationToken token);
/// <summary>
/// Получение журнала изменений
@ -39,7 +39,7 @@ public interface IProcessMapPlanBaseRepository<T>: IChangeLogRepository<T>
/// <param name="date"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<T>> GetChangeLogAsync(int idWell, DateOnly? date, CancellationToken token);
Task<IEnumerable<T>> GetChangeLog(int idWell, DateOnly? date, CancellationToken token);
/// <summary>
/// Получение записей по параметрам
@ -47,5 +47,5 @@ public interface IProcessMapPlanBaseRepository<T>: IChangeLogRepository<T>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<IEnumerable<T>> GetAsync(ProcessMapPlanBaseRequest request, CancellationToken token);
Task<IEnumerable<T>> Get(ProcessMapPlanBaseRequest request, CancellationToken token);
}

View File

@ -28,7 +28,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : IProcessMapPlanBaseRe
this.wellService = wellService;
}
public async Task<int> InsertRangeAsync(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
public async Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
var result = 0;
if (dtos.Any())
@ -53,7 +53,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : IProcessMapPlanBaseRe
return result;
}
public async Task<int> ClearAndInsertRangeAsync(int idUser, int idWell, IEnumerable<TDto> dtos, CancellationToken token)
public async Task<int> ClearAndInsertRange(int idUser, int idWell, IEnumerable<TDto> dtos, CancellationToken token)
{
if (dtos.Any(d => d.IdWell != idWell))
throw new ArgumentInvalidException(nameof(dtos), $"Все записи должны относиться к скважине idWell = {idWell}");
@ -74,7 +74,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : IProcessMapPlanBaseRe
entity.IdEditor = idUser;
}
result += await context.SaveChangesAsync(token);
result += await InsertRangeAsync(idUser, dtos, token);
result += await InsertRange(idUser, dtos, token);
await transaction.CommitAsync(token);
}
catch
@ -86,7 +86,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : IProcessMapPlanBaseRe
return result;
}
public async Task<int> DeleteRangeAsync(int idUser, IEnumerable<int> ids, CancellationToken token)
public async Task<int> DeleteRange(int idUser, IEnumerable<int> ids, CancellationToken token)
{
var dbSet = context.Set<TEntity>();
var entitiesToMarkDeleted = dbSet
@ -103,7 +103,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : IProcessMapPlanBaseRe
return result;
}
public async Task<IEnumerable<TDto>> GetAsync(ProcessMapPlanBaseRequest request, CancellationToken token)
public async Task<IEnumerable<TDto>> Get(ProcessMapPlanBaseRequest request, CancellationToken token)
{
var timezone = wellService.GetTimezone(request.IdWell);
var offset = TimeSpan.FromHours(timezone.Hours);
@ -118,7 +118,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : IProcessMapPlanBaseRe
if (request.UpdateFrom.HasValue)
{
var from = request.UpdateFrom.Value.ToUniversalTime();
query = query.Where(e => e.Creation > from || e.Obsolete > from);
query = query.Where(e => e.Creation >= from || e.Obsolete >= from);
}
if (request.Moment.HasValue)
@ -134,7 +134,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : IProcessMapPlanBaseRe
return dtos;
}
public async Task<IEnumerable<TDto>> GetChangeLogAsync(int idWell, DateOnly? date, CancellationToken token)
public async Task<IEnumerable<TDto>> GetChangeLog(int idWell, DateOnly? date, CancellationToken token)
{
var query = context
.Set<TEntity>()
@ -160,7 +160,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : IProcessMapPlanBaseRe
return dtos;
}
public async Task<IEnumerable<DateOnly>> GetDatesChangeAsync(int idWell, CancellationToken token)
public async Task<IEnumerable<DateOnly>> GetDatesChange(int idWell, CancellationToken token)
{
var wellEntitiesQuery = context
.Set<TEntity>()
@ -191,7 +191,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : IProcessMapPlanBaseRe
return datesOnly;
}
public async Task<int> UpdateRangeAsync(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
public async Task<int> UpdateRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
if (dtos.Any(d => d.Id == 0))
throw new ArgumentInvalidException(nameof(dtos), "Отредактированные значения должны иметь id больше 0");

View File

@ -10,22 +10,22 @@ public interface IProcessMapPlanDrillingClient
private const string BaseRoute = "/api/well/{idWell}/ProcessMapPlanDrilling";
[Post(BaseRoute)]
Task<IApiResponse<int>> InsertRangeAsync(int idWell, IEnumerable<ProcessMapPlanDrillingDto> dtos);
Task<IApiResponse<int>> InsertRange(int idWell, [Body] IEnumerable<ProcessMapPlanDrillingDto> dtos);
[Post($"{BaseRoute}/replace")]
Task<IApiResponse<int>> ClearAndInsertRangeAsync(int idWell, IEnumerable<ProcessMapPlanDrillingDto> dtos);
Task<IApiResponse<int>> ClearAndInsertRange(int idWell, [Body] IEnumerable<ProcessMapPlanDrillingDto> dtos);
[Delete(BaseRoute)]
Task<IApiResponse<int>> DeleteRangeAsync(int idWell, IEnumerable<int> ids);
Task<IApiResponse<int>> DeleteRange(int idWell, [Body] IEnumerable<int> ids);
[Get(BaseRoute)]
Task<IApiResponse<IEnumerable<ProcessMapPlanDrillingDto>>> GetAsync(int idWell, [FromQuery] ProcessMapPlanBaseRequest request);
Task<IApiResponse<IEnumerable<ProcessMapPlanDrillingDto>>> Get(int idWell, ProcessMapPlanBaseRequest request);
[Get($"{BaseRoute}/changeLog")]
Task<IApiResponse<IEnumerable<ProcessMapPlanDrillingDto>>> GetChangeLogAsync(int idWell, [FromQuery] DateOnly? date);
Task<IApiResponse<IEnumerable<ProcessMapPlanDrillingDto>>> GetChangeLog(int idWell, DateOnly? date);
[Get($"{BaseRoute}/dates")]
Task<IApiResponse<IEnumerable<DateOnly>>> GetDatesChangeAsync(int idWell);
Task<IApiResponse<IEnumerable<DateOnly>>> GetDatesChange(int idWell);
[Put(BaseRoute)]
Task<IApiResponse<int>> UpdateRangeAsync(int idWell, IEnumerable<ProcessMapPlanDrillingDto> dtos);

View File

@ -1,4 +1,6 @@
using AsbCloudApp.Data.ProcessMapPlan;
using AsbCloudApp.Requests;
using AsbCloudDb.Model.ProcessMapPlan;
using AsbCloudDb.Model.ProcessMaps;
using AsbCloudWebApi.IntegrationTests.Clients;
using Mapster;
@ -11,8 +13,7 @@ namespace AsbCloudWebApi.IntegrationTests.Controllers;
public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
{
private IProcessMapPlanDrillingClient client;
readonly ProcessMapPlanDrillingDto dto = new (){
private readonly ProcessMapPlanDrillingDto dto = new (){
Id = 0,
IdAuthor = 0,
IdEditor = null,
@ -42,6 +43,37 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
UsageSpin = 14,
Comment = "это тестовая запись",
};
private readonly ProcessMapPlanDrilling entity = new ()
{
Id = 0,
IdAuthor = 1,
IdEditor = null,
Creation = DateTimeOffset.UtcNow,
Obsolete = null,
IdState = AsbCloudDb.Model.ChangeLogAbstract.IdStateActual,
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)
{
@ -49,29 +81,411 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
}
[Fact]
public async Task InsertRangeAsync_ReturnsSuccess_WhenNewItemIsValid()
public async Task InsertRange_returns_success()
{
//arrange
var expected = dto;
var dbset = dbContext.Set<ProcessMapPlanDrilling>();
var expected = dto.Adapt<ProcessMapPlanDrillingDto>();
//act
var response = await client.InsertRangeAsync(dto.IdWell, new[] { expected });
var response = await client.InsertRange(dto.IdWell, new[] { expected });
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(1, response.Content);
var entity = await dbContext.Set<ProcessMapPlanDrilling>()
var entity = dbContext.Set<ProcessMapPlanDrilling>()
.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();
.FirstOrDefault();
Assert.NotNull(entity);
var actual = entity.Adapt<ProcessMapPlanDrillingDto>();
Assert.Equal(ProcessMapPlanBase.IdStateActual, actual.IdState);
var excludeProps = new[] {
nameof(ProcessMapPlanDrillingDto.Id),
nameof(ProcessMapPlanDrillingDto.IdState),
nameof(ProcessMapPlanDrillingDto.IdAuthor),
nameof(ProcessMapPlanDrillingDto.Creation),
};
MatchHelper.Match(expected, actual, excludeProps);
}
[Fact]
public async Task ClearAndInsertRange_returns_success()
{
// arrange
var dbset = dbContext.Set<ProcessMapPlanDrilling>();
var startTime = DateTimeOffset.UtcNow;
dbset.RemoveRange(dbset);
dbContext.SaveChanges();
var entry = dbset.Add(entity);
dbContext.SaveChanges();
entry.State = EntityState.Detached;
// act
var result = await client.ClearAndInsertRange(entity.IdWell, new ProcessMapPlanDrillingDto[] { dto });
// assert
var doneTime = DateTimeOffset.UtcNow;
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
Assert.Equal(2, result.Content);
var count = dbset.Count();
Assert.Equal(2, count);
var oldEntity = dbset.First(p => p.Id == entry.Entity.Id);
Assert.Equal(ProcessMapPlanBase.IdClearedOnImport, oldEntity.IdState);
Assert.Equal(1, oldEntity.IdEditor);
Assert.NotNull(oldEntity.Obsolete);
Assert.InRange(oldEntity.Obsolete.Value, startTime, doneTime);
var newEntity = dbset.First(p => p.Id != entry.Entity.Id);
Assert.Equal(ProcessMapPlanBase.IdStateActual, newEntity.IdState);
Assert.Equal(1, newEntity.IdAuthor);
Assert.Null(newEntity.IdEditor);
Assert.Null(newEntity.Obsolete);
Assert.Null(newEntity.IdPrevious);
Assert.InRange(newEntity.Creation, startTime, doneTime);
}
[Fact]
public async Task UpdateRange_returns_success()
{
// arrange
var dbset = dbContext.Set<ProcessMapPlanDrilling>();
var startTime = DateTimeOffset.UtcNow;
dbset.RemoveRange(dbset);
dbContext.SaveChanges();
var entry = dbset.Add(entity);
dbContext.SaveChanges();
entry.State = EntityState.Detached;
var dtoCopy = dto.Adapt<ProcessMapPlanDrillingDto>();
dtoCopy.Id = entry.Entity.Id;
dtoCopy.Comment = "nebuchadnezzar";
dtoCopy.DeltaPressureLimitMax ++;
dtoCopy.DeltaPressurePlan ++;
dtoCopy.FlowPlan ++;
dtoCopy.FlowLimitMax ++;
dtoCopy.RopPlan ++;
dtoCopy.AxialLoadPlan ++;
dtoCopy.AxialLoadLimitMax ++;
dtoCopy.DepthStart ++;
dtoCopy.DepthEnd ++;
dtoCopy.TopDriveSpeedPlan ++;
dtoCopy.TopDriveSpeedLimitMax ++;
dtoCopy.TopDriveTorquePlan ++;
dtoCopy.TopDriveTorqueLimitMax ++;
// act
var result = await client.UpdateRangeAsync(entity.IdWell, new ProcessMapPlanDrillingDto[] { dtoCopy });
// assert
var doneTime = DateTimeOffset.UtcNow;
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
Assert.Equal(2, result.Content);
var count = dbset.Count();
Assert.Equal(2, count);
var oldEntity = dbset.First(p => p.Id == entry.Entity.Id);
Assert.Equal(ProcessMapPlanBase.IdStateReplaced, oldEntity.IdState);
Assert.Equal(1, oldEntity.IdEditor);
Assert.NotNull(oldEntity.Obsolete);
Assert.InRange(oldEntity.Obsolete.Value, startTime, doneTime);
var newEntity = dbset.First(p => p.Id != entry.Entity.Id);
Assert.Equal(ProcessMapPlanBase.IdStateActual, newEntity.IdState);
Assert.Equal(1, newEntity.IdAuthor);
Assert.Null(newEntity.IdEditor);
Assert.Null(newEntity.Obsolete);
Assert.Equal(oldEntity.Id, newEntity.IdPrevious);
Assert.InRange(newEntity.Creation, startTime, doneTime);
var expected = dtoCopy.Adapt<ProcessMapPlanDrilling>();
var excludeProps = new[] {
nameof(ProcessMapPlanDrillingDto.Id),
nameof(ProcessMapPlanDrillingDto.IdAuthor),
nameof(ProcessMapPlanDrillingDto.Creation),
};
MatchHelper.Match(expected, newEntity!, excludeProps);
}
[Fact]
public async Task DeleteRange_returns_success()
{
//arrange
var dbset = dbContext.Set<ProcessMapPlanDrilling>();
var startTime = DateTimeOffset.UtcNow;
dbset.RemoveRange(dbset);
dbContext.SaveChanges();
var entry = dbset.Add(entity);
dbContext.SaveChanges();
entry.State = EntityState.Detached;
//act
var response = await client.DeleteRange(dto.IdWell, new[] { entry.Entity.Id });
//assert
var doneTime = DateTimeOffset.UtcNow;
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal(1, response.Content);
var actual = dbContext.Set<ProcessMapPlanDrilling>()
.Where(p => p.Id == entry.Entity.Id)
.FirstOrDefault();
Assert.NotNull(actual);
Assert.Equal(ProcessMapPlanBase.IdStateDeleted, actual.IdState);
Assert.Equal(1, actual.IdEditor);
Assert.NotNull(actual.Obsolete);
Assert.InRange(actual.Obsolete.Value, startTime, doneTime);
}
[Fact]
public async Task GetDatesChange_returns_success()
{
//arrange
var dbset = dbContext.Set<ProcessMapPlanDrilling>();
dbset.RemoveRange(dbset);
dbContext.SaveChanges();
var entity2 = entity.Adapt<ProcessMapPlanDrilling>();
entity2.Creation = entity.Creation.AddDays(1);
dbset.Add(entity);
dbset.Add(entity2);
dbContext.SaveChanges();
var timezoneHours = Data.Defaults.Wells[0].Timezone.Hours;
var offset = TimeSpan.FromHours(timezoneHours);
var dates = new[] { entity.Creation, entity2.Creation }
.Select(d => d.ToOffset(offset))
.Select(d => new DateOnly(d.Year, d.Month, d.Day));
//act
var response = await client.GetDatesChange(dto.IdWell);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
Assert.Equal(2, response.Content.Count());
Assert.All(response.Content, d => dates.Contains(d));
}
[Fact]
public async Task Get_all_returns_success()
{
//arrange
var dbset = dbContext.Set<ProcessMapPlanDrilling>();
dbset.RemoveRange(dbset);
dbContext.SaveChanges();
dbset.Add(entity);
var entityDeleted = entity.Adapt<ProcessMapPlanDrilling>();
entityDeleted.Creation = entity.Creation.AddDays(-1);
entityDeleted.Obsolete = entity.Creation;
entityDeleted.IdState = ProcessMapPlanBase.IdStateDeleted;
entityDeleted.IdEditor = 1;
dbset.Add(entityDeleted);
dbContext.SaveChanges();
var timezoneHours = Data.Defaults.Wells[0].Timezone.Hours;
var offset = TimeSpan.FromHours(timezoneHours);
//act
var request = new ProcessMapPlanBaseRequest
{
IdWell = dto.IdWell,
};
var response = await client.Get(dto.IdWell, request);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
Assert.Equal(2, response.Content.Count());
}
[Fact]
public async Task Get_actual_returns_success()
{
//arrange
var dbset = dbContext.Set<ProcessMapPlanDrilling>();
dbset.RemoveRange(dbset);
dbContext.SaveChanges();
dbset.Add(entity);
var entityDeleted = entity.Adapt<ProcessMapPlanDrilling>();
entityDeleted.Creation = entity.Creation.AddDays(-1);
entityDeleted.Obsolete = entity.Creation;
entityDeleted.IdState = ProcessMapPlanBase.IdStateDeleted;
entityDeleted.IdEditor = 1;
entityDeleted.Comment = "nothing";
dbset.Add(entityDeleted);
dbContext.SaveChanges();
var timezoneHours = Data.Defaults.Wells[0].Timezone.Hours;
var offset = TimeSpan.FromHours(timezoneHours);
//act
var request = new ProcessMapPlanBaseRequest {
IdWell = dto.IdWell,
Moment = new DateTimeOffset(3000, 1, 1, 0, 0, 0, 0, TimeSpan.Zero)
};
var response = await client.Get(dto.IdWell, request);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
Assert.Single(response.Content);
var actual = response.Content.First()!;
var expected = entity.Adapt<ProcessMapPlanDrillingDto>()!;
var excludeProps = new[] {
nameof(ProcessMapPlanDrillingDto.Id),
nameof(ProcessMapPlanDrillingDto.IdAuthor),
nameof(ProcessMapPlanDrillingDto.Creation),
};
MatchHelper.Match(expected, actual, excludeProps);
}
[Fact]
public async Task Get_at_moment_returns_success()
{
//arrange
var dbset = dbContext.Set<ProcessMapPlanDrilling>();
dbset.RemoveRange(dbset);
dbContext.SaveChanges();
var entityDeleted = entity.Adapt<ProcessMapPlanDrilling>();
entityDeleted.Creation = entity.Creation.AddDays(-1);
entityDeleted.Obsolete = entity.Creation;
entityDeleted.IdState = ProcessMapPlanBase.IdStateDeleted;
entityDeleted.IdEditor = 1;
entityDeleted.Comment = "nothing";
dbset.Add(entityDeleted);
var entityDeleted2 = entity.Adapt<ProcessMapPlanDrilling>();
entityDeleted2.Obsolete = entity.Creation.AddSeconds(1);
entityDeleted2.IdState = ProcessMapPlanBase.IdStateDeleted;
entityDeleted2.IdEditor = 1;
entityDeleted2.Comment = "nothing";
dbset.Add(entityDeleted2);
dbContext.SaveChanges();
var timezoneHours = Data.Defaults.Wells[0].Timezone.Hours;
var offset = TimeSpan.FromHours(timezoneHours);
//act
var request = new ProcessMapPlanBaseRequest
{
IdWell = dto.IdWell,
Moment = entityDeleted.Creation
};
var response = await client.Get(dto.IdWell, request);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
Assert.Equal(2, response.Content.Count());
}
[Fact]
public async Task Get_section_returns_success()
{
//arrange
var dbset = dbContext.Set<ProcessMapPlanDrilling>();
dbset.RemoveRange(dbset);
dbContext.SaveChanges();
dbset.Add(entity);
var entity2 = entity.Adapt<ProcessMapPlanDrilling>();
entity2.IdWellSectionType = 2;
entity2.Comment = "IdWellSectionType = 2";
dbset.Add(entity2);
dbContext.SaveChanges();
var timezoneHours = Data.Defaults.Wells[0].Timezone.Hours;
var offset = TimeSpan.FromHours(timezoneHours);
//act
var request = new ProcessMapPlanBaseRequest
{
IdWell = dto.IdWell,
IdWellSectionType = 2,
};
var response = await client.Get(dto.IdWell, request);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
Assert.Single(response.Content);
var actual = response.Content.First()!;
var expected = entity2.Adapt<ProcessMapPlanDrillingDto>()!;
var excludeProps = new[] {
nameof(ProcessMapPlanDrillingDto.Id),
nameof(ProcessMapPlanDrillingDto.IdAuthor),
nameof(ProcessMapPlanDrillingDto.Creation),
};
MatchHelper.Match(expected, actual, excludeProps);
}
[Fact]
public async Task Get_updated_returns_success()
{
//arrange
var dbset = dbContext.Set<ProcessMapPlanDrilling>();
dbset.RemoveRange(dbset);
dbContext.SaveChanges();
dbset.Add(entity);
var entity2 = entity.Adapt<ProcessMapPlanDrilling>();
entity2.Creation = entity.Creation.AddHours(1);
entity2.Comment = "IdWellSectionType = 2";
dbset.Add(entity2);
var entity3 = entity.Adapt<ProcessMapPlanDrilling>();
entity3.Obsolete = entity.Creation.AddHours(1);
entity3.Comment = "IdWellSectionType = 3";
dbset.Add(entity3);
dbContext.SaveChanges();
var timezoneHours = Data.Defaults.Wells[0].Timezone.Hours;
var offset = TimeSpan.FromHours(timezoneHours);
var updateFrom = entity.Creation.ToOffset(offset).AddHours(0.5);
//act
var request = new ProcessMapPlanBaseRequest
{
IdWell = dto.IdWell,
UpdateFrom = updateFrom,
};
var response = await client.Get(dto.IdWell, request);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
Assert.Equal(2, response.Content.Count());
var actual = response.Content
.Where(p=>p.Comment == entity2.Comment)
.First();
var expected = entity2.Adapt<ProcessMapPlanDrillingDto>();
var excludeProps = new[] {
nameof(ProcessMapPlanDrillingDto.Id),
nameof(ProcessMapPlanDrillingDto.IdAuthor),

View File

@ -42,13 +42,13 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[HttpPost]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> InsertRangeAsync([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
public async Task<IActionResult> InsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
{
if (idWell == 0 || dtos.Any(d => d.IdWell != idWell))
return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell");
var idUser = await AssertUserHasAccessToWellAsync(idWell, token);
var result = await repository.InsertRangeAsync(idUser, dtos, token);
var idUser = await AssertUserHasAccessToWell(idWell, token);
var result = await repository.InsertRange(idUser, dtos, token);
return Ok(result);
}
@ -62,13 +62,13 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[HttpPost("replace")]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> ClearAndInsertRangeAsync([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
public async Task<IActionResult> ClearAndInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
{
if (idWell == 0 || dtos.Any(d => d.IdWell != idWell))
return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell");
var idUser = await AssertUserHasAccessToWellAsync(idWell, token);
var result = await repository.ClearAndInsertRangeAsync(idUser, idWell, dtos, token);
var idUser = await AssertUserHasAccessToWell(idWell, token);
var result = await repository.ClearAndInsertRange(idUser, idWell, dtos, token);
return Ok(result);
}
@ -82,10 +82,10 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[HttpDelete]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> DeleteRangeAsync([FromRoute]int idWell, IEnumerable<int> ids, CancellationToken token)
public async Task<IActionResult> DeleteRange([FromRoute]int idWell, IEnumerable<int> ids, CancellationToken token)
{
var idUser = await AssertUserHasAccessToWellAsync(idWell, token);
var result = await repository.DeleteRangeAsync(idUser, ids, token);
var idUser = await AssertUserHasAccessToWell(idWell, token);
var result = await repository.DeleteRange(idUser, ids, token);
return Ok(result);
}
@ -99,11 +99,11 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<IEnumerable<TDto>>> GetAsync([FromRoute] int idWell, [FromQuery]ProcessMapPlanBaseRequest request, CancellationToken token)
public async Task<ActionResult<IEnumerable<TDto>>> Get([FromRoute] int idWell, [FromQuery]ProcessMapPlanBaseRequest request, CancellationToken token)
{
request.IdWell = idWell;
await AssertUserHasAccessToWellAsync(request.IdWell, token);
var result = await repository.GetAsync(request, token);
await AssertUserHasAccessToWell(request.IdWell, token);
var result = await repository.Get(request, token);
return Ok(result);
}
@ -117,10 +117,10 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[HttpGet("changeLog")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<IEnumerable<TDto>>> GetChangeLogAsync([FromRoute] int idWell, [FromQuery] DateOnly? date, CancellationToken token)
public async Task<ActionResult<IEnumerable<TDto>>> GetChangeLog([FromRoute] int idWell, [FromQuery] DateOnly? date, CancellationToken token)
{
await AssertUserHasAccessToWellAsync(idWell, token);
var result = await repository.GetChangeLogAsync(idWell, date, token);
await AssertUserHasAccessToWell(idWell, token);
var result = await repository.GetChangeLog(idWell, date, token);
return Ok(result);
}
@ -133,10 +133,10 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[HttpGet("dates")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<IEnumerable<DateOnly>>> GetDatesChangeAsync([FromRoute] int idWell, CancellationToken token)
public async Task<ActionResult<IEnumerable<DateOnly>>> GetDatesChange([FromRoute] int idWell, CancellationToken token)
{
await AssertUserHasAccessToWellAsync(idWell, token);
var result = await repository.GetDatesChangeAsync(idWell, token);
await AssertUserHasAccessToWell(idWell, token);
var result = await repository.GetDatesChange(idWell, token);
return Ok(result);
}
@ -150,7 +150,7 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[HttpPut]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> UpdateRangeAsync([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
public async Task<IActionResult> UpdateRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
{
var first = dtos.FirstOrDefault();
if(first is null)
@ -159,9 +159,9 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
if (idWell == 0 || dtos.Any(d => d.IdWell != idWell))
return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell");
var idUser = await AssertUserHasAccessToWellAsync(idWell, token);
var idUser = await AssertUserHasAccessToWell(idWell, token);
var result = await repository.UpdateRangeAsync(idUser, dtos, token);
var result = await repository.UpdateRange(idUser, dtos, token);
return Ok(result);
}
@ -172,7 +172,7 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
/// <param name="token"></param>
/// <returns></returns>
/// <exception cref="ForbidException"></exception>
private async Task<int> AssertUserHasAccessToWellAsync(int idWell, CancellationToken token)
private async Task<int> AssertUserHasAccessToWell(int idWell, CancellationToken token)
{
var idUser = GetUserId();
var idCompany = User.GetCompanyId();