2024-07-04 11:02:45 +05:00
|
|
|
using AsbCloudApp.Data;
|
2024-06-21 09:53:45 +05:00
|
|
|
using AsbCloudApp.Data.ProcessMaps;
|
|
|
|
using AsbCloudApp.Data.User;
|
|
|
|
using AsbCloudApp.Requests;
|
|
|
|
using AsbCloudDb.Model;
|
2024-05-21 09:12:22 +05:00
|
|
|
using AsbCloudDb.Model.ProcessMapPlan;
|
|
|
|
using AsbCloudWebApi.IntegrationTests.Clients;
|
2024-06-21 09:53:45 +05:00
|
|
|
using AsbCloudWebApi.IntegrationTests.Data;
|
2024-05-21 09:12:22 +05:00
|
|
|
using Mapster;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-06-21 09:53:45 +05:00
|
|
|
using Refit;
|
2024-05-21 09:12:22 +05:00
|
|
|
using System.Net;
|
|
|
|
using System.Reflection;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.IntegrationTests.Controllers.ProcessMapPlan;
|
2024-06-21 09:53:45 +05:00
|
|
|
public abstract class ProcessMapPlanBaseControllerTest<TEntity, TDto> : BaseIntegrationTest
|
|
|
|
where TEntity : ProcessMapPlanBase
|
|
|
|
where TDto : ProcessMapPlanBaseDto
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
2024-06-21 09:53:45 +05:00
|
|
|
private IProcessMapPlanClient<TDto> client;
|
|
|
|
private string controllerName;
|
2024-05-21 09:12:22 +05:00
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
protected abstract TEntity? GetByWellId();
|
|
|
|
protected abstract TEntity GetByNote(DbSet<TEntity> dbSet, TDto dto);
|
|
|
|
protected abstract TDto GetByNote(IEnumerable<TDto> dtos, TDto dto);
|
|
|
|
|
|
|
|
public ProcessMapPlanBaseControllerTest(WebAppFactoryFixture factory, string controllerName) : base(factory)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
2024-06-21 09:53:45 +05:00
|
|
|
dbContext.CleanupDbSet<TEntity>();
|
|
|
|
client = factory.GetAuthorizedHttpClient<IProcessMapPlanClient<TDto>>(string.Empty);
|
|
|
|
this.controllerName = controllerName;
|
2024-05-21 09:12:22 +05:00
|
|
|
}
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task InsertRangeSuccess(TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//arrange
|
2024-06-21 09:53:45 +05:00
|
|
|
var expected = dto.Adapt<TDto>();
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//act
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.InsertRange(dto.IdWell, controllerName, new TDto[] { expected });
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//assert
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
Assert.Equal(1, response.Content);
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var entity = GetByWellId();
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
Assert.NotNull(entity);
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var actual = entity.Adapt<ChangeLogDto<TDto>>();
|
2024-05-21 09:12:22 +05:00
|
|
|
Assert.Equal(ProcessMapPlanBase.IdStateActual, actual.IdState);
|
|
|
|
|
|
|
|
var excludeProps = new[] {
|
2024-06-21 09:53:45 +05:00
|
|
|
nameof(ProcessMapPlanBaseDto.Id),
|
|
|
|
nameof(ProcessMapPlanBaseDto.Section)
|
2024-05-21 09:12:22 +05:00
|
|
|
};
|
|
|
|
MatchHelper.Match(expected, actual.Item, excludeProps);
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task InsertRangeFailed(TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//act
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.InsertRange(dto.IdWell, controllerName, new[] { dto });
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//assert
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task ClearAndInsertRange(TEntity entity, TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
// arrange
|
2024-06-21 09:53:45 +05:00
|
|
|
var dbset = dbContext.Set<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
var entry = dbset.Add(entity);
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
entry.State = EntityState.Detached;
|
|
|
|
|
|
|
|
var startTime = DateTimeOffset.UtcNow;
|
|
|
|
|
|
|
|
// act
|
2024-06-21 09:53:45 +05:00
|
|
|
var result = await client.ClearAndInsertRange(entity.IdWell, controllerName, new TDto[] { dto });
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
// 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.IdCleared, 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);
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task UpdateOrInsertRange(TEntity entity, TDto dtoUpdate, TDto dtoInsert)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
// arrange
|
|
|
|
var startTime = DateTimeOffset.UtcNow;
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var dbset = dbContext.Set<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
var user = dbContext.Set<User>().First().Adapt<UserDto>();
|
|
|
|
user.Surname = "userSurname";
|
|
|
|
user.Email = "user@mail.domain";
|
|
|
|
|
|
|
|
var entry = dbset.Add(entity);
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
entry.State = EntityState.Detached;
|
|
|
|
|
|
|
|
dtoUpdate.Id = entry.Entity.Id;
|
|
|
|
|
|
|
|
// act
|
2024-06-21 09:53:45 +05:00
|
|
|
var result = await client.UpdateOrInsertRange(entity.IdWell, controllerName, new TDto[] { dtoUpdate, dtoInsert });
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
// assert
|
|
|
|
var doneTime = DateTimeOffset.UtcNow;
|
|
|
|
Assert.Equal(HttpStatusCode.OK, result.StatusCode);
|
|
|
|
Assert.Equal(3, result.Content);
|
|
|
|
|
|
|
|
var count = dbset.Count();
|
|
|
|
Assert.Equal(3, 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);
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var newEntity = GetByNote(dbset, dtoUpdate);
|
2024-05-21 09:12:22 +05:00
|
|
|
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);
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var expected = dtoUpdate.Adapt<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
var excludeProps = new[] {
|
2024-06-21 09:53:45 +05:00
|
|
|
nameof(ProcessMapPlanBase.Id),
|
|
|
|
nameof(ProcessMapPlanBase.IdWell),
|
|
|
|
nameof(ProcessMapPlanBase.Author),
|
|
|
|
nameof(ProcessMapPlanBase.IdAuthor),
|
|
|
|
nameof(ProcessMapPlanBase.Editor),
|
|
|
|
nameof(ProcessMapPlanBase.Creation),
|
|
|
|
};
|
2024-05-21 09:12:22 +05:00
|
|
|
MatchHelper.Match(expected, newEntity!, excludeProps);
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task DeleteRange(TEntity entity, TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//arrange
|
2024-06-21 09:53:45 +05:00
|
|
|
var dbset = dbContext.Set<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
var entry = dbset.Add(entity);
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
entry.State = EntityState.Detached;
|
|
|
|
|
|
|
|
var startTime = DateTimeOffset.UtcNow;
|
|
|
|
|
|
|
|
//act
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.DeleteRange(dto.IdWell, controllerName, new[] { entry.Entity.Id });
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//assert
|
|
|
|
var doneTime = DateTimeOffset.UtcNow;
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
Assert.Equal(1, response.Content);
|
|
|
|
|
|
|
|
var actual = dbContext
|
2024-06-21 09:53:45 +05:00
|
|
|
.Set<TEntity>()
|
2024-05-21 09:12:22 +05:00
|
|
|
.FirstOrDefault(p => p.Id == entry.Entity.Id);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task Clear(TEntity entity, TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//arrange
|
2024-06-21 09:53:45 +05:00
|
|
|
var dbset = dbContext.Set<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
var entry = dbset.Add(entity);
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
entry.State = EntityState.Detached;
|
|
|
|
|
|
|
|
var startTime = DateTimeOffset.UtcNow;
|
|
|
|
|
|
|
|
//act
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.Clear(dto.IdWell, controllerName);
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//assert
|
|
|
|
var doneTime = DateTimeOffset.UtcNow;
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
Assert.Equal(1, response.Content);
|
|
|
|
|
|
|
|
var actual = dbContext
|
2024-06-21 09:53:45 +05:00
|
|
|
.Set<TEntity>()
|
2024-05-21 09:12:22 +05:00
|
|
|
.FirstOrDefault(p => p.Id == entry.Entity.Id);
|
|
|
|
|
|
|
|
Assert.NotNull(actual);
|
|
|
|
Assert.Equal(ProcessMapPlanBase.IdCleared, actual.IdState);
|
|
|
|
Assert.Equal(1, actual.IdEditor);
|
|
|
|
Assert.NotNull(actual.Obsolete);
|
|
|
|
Assert.InRange(actual.Obsolete.Value, startTime, doneTime);
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task GetDatesChange(TEntity entity, TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//arrange
|
2024-06-21 09:53:45 +05:00
|
|
|
var dbset = dbContext.Set<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var entity2 = entity.Adapt<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
entity2.Creation = entity.Creation.AddDays(1);
|
|
|
|
dbset.Add(entity);
|
|
|
|
dbset.Add(entity2);
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
var timezoneHours = Defaults.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
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.GetDatesChange(dto.IdWell, controllerName);
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//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));
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task Get(TEntity entity, TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//arrange
|
2024-06-21 09:53:45 +05:00
|
|
|
var dbset = dbContext.Set<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
dbset.Add(entity);
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var entityDeleted = entity.Adapt<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
entityDeleted.Creation = entity.Creation.AddDays(-1);
|
|
|
|
entityDeleted.Obsolete = entity.Creation;
|
|
|
|
entityDeleted.IdState = ProcessMapPlanBase.IdStateDeleted;
|
|
|
|
entityDeleted.IdEditor = 1;
|
|
|
|
dbset.Add(entityDeleted);
|
|
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.Get(dto.IdWell, controllerName);
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//assert
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
Assert.Single(response.Content);
|
|
|
|
|
|
|
|
var actual = response.Content.First()!;
|
2024-05-30 13:40:10 +05:00
|
|
|
Assert.NotNull(actual.Section);
|
|
|
|
Assert.NotEmpty(actual.Section);
|
2024-06-21 09:53:45 +05:00
|
|
|
|
|
|
|
var expected = entity.Adapt<TDto>()!;
|
2024-05-21 09:12:22 +05:00
|
|
|
var excludeProps = new[] {
|
2024-06-21 09:53:45 +05:00
|
|
|
nameof(ProcessMapPlanBaseDto.Id),
|
|
|
|
};
|
2024-05-21 09:12:22 +05:00
|
|
|
MatchHelper.Match(expected, actual, excludeProps);
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task GetAtMoment(TEntity entity, TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//arrange
|
2024-06-21 09:53:45 +05:00
|
|
|
var dbset = dbContext.Set<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
var now = DateTimeOffset.UtcNow;
|
2024-06-21 09:53:45 +05:00
|
|
|
var entityDeleted = entity.Adapt<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
entityDeleted.Creation = now;
|
|
|
|
entityDeleted.Obsolete = now.AddMinutes(1);
|
|
|
|
entityDeleted.IdState = ProcessMapPlanBase.IdStateDeleted;
|
|
|
|
entityDeleted.IdEditor = 1;
|
|
|
|
dbset.Add(entityDeleted);
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var entityDeleted2 = entity.Adapt<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
entityDeleted2.Creation = now.AddMinutes(1);
|
|
|
|
entityDeleted2.Obsolete = now.AddMinutes(2);
|
|
|
|
entityDeleted2.IdState = ProcessMapPlanBase.IdStateDeleted;
|
|
|
|
entityDeleted2.IdEditor = 1;
|
|
|
|
dbset.Add(entityDeleted2);
|
|
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
|
|
//act
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.Get(dto.IdWell, controllerName, now.AddMinutes(0.5));
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//assert
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
Assert.Single(response.Content);
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task GetByUpdated(TEntity entity, TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//arrange
|
2024-06-21 09:53:45 +05:00
|
|
|
var dbset = dbContext.Set<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
dbset.Add(entity);
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var entity2 = entity.Adapt<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
entity2.Obsolete = DateTimeOffset.UtcNow;
|
|
|
|
dbset.Add(entity2);
|
|
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
|
|
//act
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.Get(Defaults.RemoteUid, controllerName, DateTimeOffset.UtcNow.AddHours(-1));
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//assert
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
Assert.Equal(2, response.Content.Count());
|
|
|
|
}
|
2024-06-21 09:53:45 +05:00
|
|
|
|
|
|
|
public async Task GetUpdated(TEntity entity, TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//arrange
|
2024-06-21 09:53:45 +05:00
|
|
|
var dbset = dbContext.Set<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
dbset.Add(entity);
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var entity2 = entity.Adapt<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
entity2.Creation = entity.Creation.AddHours(1);
|
|
|
|
dbset.Add(entity2);
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var entity3 = entity.Adapt<TEntity>();
|
2024-05-21 09:12:22 +05:00
|
|
|
entity3.Obsolete = entity.Creation.AddHours(1);
|
|
|
|
dbset.Add(entity3);
|
|
|
|
|
|
|
|
dbContext.SaveChanges();
|
|
|
|
|
|
|
|
var timezoneHours = Defaults.Timezone.Hours;
|
|
|
|
var offset = TimeSpan.FromHours(timezoneHours);
|
|
|
|
var updateFrom = entity.Creation.ToOffset(offset).AddHours(0.5);
|
|
|
|
|
|
|
|
//act
|
|
|
|
var request = new ProcessMapPlanBaseRequest
|
|
|
|
{
|
|
|
|
UpdateFrom = updateFrom,
|
|
|
|
};
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.Get(dto.IdWell, controllerName);
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//assert
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
Assert.Equal(2, response.Content.Count());
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var entity2Dto = entity2.Adapt<TDto>();
|
|
|
|
var actual = GetByNote(response.Content, entity2Dto);
|
2024-05-21 09:12:22 +05:00
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var expected = entity2.Adapt<TDto>();
|
2024-05-21 09:12:22 +05:00
|
|
|
var excludeProps = new[] {
|
2024-06-21 09:53:45 +05:00
|
|
|
nameof(ProcessMapPlanBaseDto.Id),
|
|
|
|
};
|
2024-05-21 09:12:22 +05:00
|
|
|
MatchHelper.Match(expected, actual, excludeProps);
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task Parse(int IdWell, string fileName, TDto dto)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//arrange
|
|
|
|
var stream = Assembly.GetExecutingAssembly().GetFileCopyStream(fileName);
|
|
|
|
|
|
|
|
var streamPart = new StreamPart(stream, fileName, "application/octet-stream");
|
|
|
|
|
|
|
|
//act
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.Parse(IdWell, controllerName, streamPart);
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
//assert
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
|
|
|
var parserResult = response.Content;
|
|
|
|
|
|
|
|
Assert.NotNull(parserResult);
|
|
|
|
Assert.Single(parserResult.Item);
|
|
|
|
Assert.True(parserResult.IsValid);
|
|
|
|
|
|
|
|
var row = parserResult.Item.First();
|
|
|
|
var dtoActual = row.Item;
|
|
|
|
|
|
|
|
Assert.True(row.IsValid);
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
var excludeProps = new[] { nameof(ProcessMapPlanBaseDto.IdWell) };
|
2024-05-21 09:12:22 +05:00
|
|
|
MatchHelper.Match(dto, dtoActual, excludeProps);
|
|
|
|
}
|
|
|
|
|
2024-06-21 09:53:45 +05:00
|
|
|
public async Task ParseWithWarnings(int IdWell, string fileName)
|
2024-05-21 09:12:22 +05:00
|
|
|
{
|
|
|
|
//arrange
|
|
|
|
var stream = Assembly.GetExecutingAssembly().GetFileCopyStream(fileName);
|
|
|
|
|
|
|
|
var streamPart = new StreamPart(stream, fileName, "application/octet-stream");
|
|
|
|
|
|
|
|
//act
|
2024-06-21 09:53:45 +05:00
|
|
|
var response = await client.Parse(IdWell, controllerName, streamPart);
|
2024-05-21 09:12:22 +05:00
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
|
|
|
var parserResult = response.Content;
|
|
|
|
|
|
|
|
Assert.NotNull(parserResult);
|
|
|
|
Assert.False(parserResult.IsValid);
|
|
|
|
Assert.Single(parserResult.Warnings);
|
|
|
|
Assert.Single(parserResult.Item);
|
|
|
|
|
|
|
|
var row = parserResult.Item.First();
|
|
|
|
|
|
|
|
Assert.False(row.IsValid);
|
|
|
|
Assert.Equal(2, row.Warnings.Count());
|
|
|
|
}
|
2024-06-21 09:53:45 +05:00
|
|
|
}
|