2024-03-22 12:42:48 +05:00
|
|
|
|
using AsbCloudApp.Data.WellOperation;
|
2024-02-05 08:54:18 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2024-03-22 12:42:48 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
2024-04-23 14:43:17 +05:00
|
|
|
|
using AsbCloudInfrastructure;
|
2024-03-22 12:42:48 +05:00
|
|
|
|
using AsbCloudWebApi.IntegrationTests.Clients;
|
2024-02-07 09:21:03 +05:00
|
|
|
|
using AsbCloudWebApi.IntegrationTests.Data;
|
2024-04-23 14:43:17 +05:00
|
|
|
|
using ClosedXML.Excel;
|
2024-03-11 15:19:50 +05:00
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-02-06 11:41:51 +05:00
|
|
|
|
using Refit;
|
2024-04-23 14:43:17 +05:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Reflection;
|
2024-01-25 10:35:16 +05:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
2024-03-22 12:42:48 +05:00
|
|
|
|
namespace AsbCloudWebApi.IntegrationTests.Controllers.WellOperations;
|
2024-01-25 10:35:16 +05:00
|
|
|
|
|
|
|
|
|
public class WellOperationControllerTest : BaseIntegrationTest
|
|
|
|
|
{
|
2024-04-23 14:43:17 +05:00
|
|
|
|
private IWellOperationClient client;
|
2024-03-11 15:19:50 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
public WellOperationControllerTest(WebAppFactoryFixture factory)
|
|
|
|
|
: base(factory)
|
|
|
|
|
{
|
|
|
|
|
client = factory.GetAuthorizedHttpClient<IWellOperationClient>(string.Empty);
|
2024-03-11 15:19:50 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
dbContext.CleanupDbSet<WellOperation>();
|
|
|
|
|
}
|
2024-03-11 15:19:50 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
/// <summary>
|
2024-04-25 11:19:16 +05:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
2024-04-23 14:43:17 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task InsertRange_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
|
|
|
|
var entity = CreateWellOperation(well.Id);
|
|
|
|
|
var dtos = new[] { entity.Adapt<WellOperationDto>() };
|
2024-02-05 08:54:18 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
//act
|
|
|
|
|
var response = await client.InsertRangeAsync(well.Id, false, dtos);
|
2024-02-05 08:54:18 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
}
|
2024-02-05 08:54:18 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
/// <summary>
|
2024-04-25 11:19:16 +05:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
2024-04-23 14:43:17 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task InsertRangeWithDeleteBefore_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
|
|
|
|
var entity = CreateWellOperation(well.Id);
|
|
|
|
|
var dtos = new[] { entity.Adapt<WellOperationDto>() };
|
2024-02-05 08:54:18 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
//act
|
|
|
|
|
var response = await client.InsertRangeAsync(well.Id, true, dtos);
|
2024-04-11 11:37:11 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
}
|
2024-02-05 08:54:18 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
/// <summary>
|
2024-04-25 11:19:16 +05:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-04-23 14:43:17 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task UpdateRangeAsync_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
|
|
|
|
var entity = CreateWellOperation(well.Id);
|
|
|
|
|
dbContext.WellOperations.Add(entity);
|
|
|
|
|
await dbContext.SaveChangesAsync();
|
2024-02-06 11:41:51 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
var dtos = new[] { entity.Adapt<WellOperationDto>() };
|
2024-02-06 11:41:51 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
//act
|
|
|
|
|
var response = await client.UpdateRangeAsync(well.Id, dtos);
|
2024-02-06 11:41:51 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
}
|
2024-03-11 15:19:50 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
/// <summary>
|
2024-04-25 11:19:16 +05:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-04-23 14:43:17 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetPageOperationsAsync_returns_first_page()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
const int pageSize = 10;
|
|
|
|
|
const int pageIndex = 0;
|
2024-02-06 11:41:51 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
|
|
|
|
var entity = CreateWellOperation(well.Id);
|
|
|
|
|
dbContext.WellOperations.Add(entity);
|
|
|
|
|
await dbContext.SaveChangesAsync();
|
2024-02-06 11:41:51 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
var dto = entity.Adapt<WellOperationDto>();
|
|
|
|
|
var timezoneOffset = TimeSpan.FromHours(well.Timezone.Hours);
|
|
|
|
|
dto.DateStart = dto.DateStart.ToOffset(timezoneOffset);
|
|
|
|
|
dto.LastUpdateDate = dto.LastUpdateDate?.ToOffset(timezoneOffset);
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
var request = new WellOperationRequestBase
|
|
|
|
|
{
|
|
|
|
|
OperationType = WellOperation.IdOperationTypePlan,
|
|
|
|
|
Skip = pageIndex,
|
|
|
|
|
Take = pageSize,
|
|
|
|
|
};
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
//act
|
|
|
|
|
var response = await client.GetPageOperationsAsync(well.Id, request);
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
//assert
|
2024-05-23 14:07:40 +05:00
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
2024-04-23 14:43:17 +05:00
|
|
|
|
Assert.NotNull(response.Content);
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
var totalExpected = response.Content.Count - pageSize * pageIndex;
|
|
|
|
|
Assert.Equal(totalExpected, response.Content.Items.Count());
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
Assert.Single(response.Content.Items);
|
|
|
|
|
var actualDto = response.Content.Items.First();
|
|
|
|
|
|
|
|
|
|
MatchHelper.Match(dto, actualDto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(WellOperation.IdOperationTypePlan, "PlanWellOperations.xlsx")]
|
|
|
|
|
[InlineData(WellOperation.IdOperationTypeFact, "FactWellOperations.xlsx")]
|
|
|
|
|
public async Task ParseAsync_returns_success(int idType, string fileName)
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
|
|
|
|
|
|
|
|
|
var expectedDto = new WellOperationDto
|
|
|
|
|
{
|
|
|
|
|
IdWell = well.Id,
|
|
|
|
|
IdWellSectionType = 2,
|
|
|
|
|
IdCategory = WellOperationCategory.IdSlide,
|
|
|
|
|
IdPlan = null,
|
2024-04-25 11:19:16 +05:00
|
|
|
|
CategoryInfo = "<22><><EFBFBD>.<2E><><EFBFBD><EFBFBD>",
|
2024-04-23 14:43:17 +05:00
|
|
|
|
IdType = idType,
|
|
|
|
|
DepthStart = 10.0,
|
|
|
|
|
DepthEnd = 20.0,
|
|
|
|
|
DateStart = new DateTimeOffset(new DateTime(2023, 1, 10), TimeSpan.FromHours(well.Timezone.Hours)),
|
|
|
|
|
DurationHours = 1.0,
|
|
|
|
|
Comment = "123",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var stream = Assembly.GetExecutingAssembly().GetFileCopyStream(fileName);
|
|
|
|
|
|
|
|
|
|
var streamPart = new StreamPart(stream, fileName, "application/octet-stream");
|
|
|
|
|
|
|
|
|
|
//act
|
|
|
|
|
var response = await client.ParseAsync(well.Id, idType, streamPart);
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
|
|
|
|
|
var actualDto = response.Content.Item.First().Item;
|
|
|
|
|
|
|
|
|
|
MatchHelper.Match(expectedDto, actualDto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(WellOperation.IdOperationTypePlan)]
|
|
|
|
|
[InlineData(WellOperation.IdOperationTypeFact)]
|
|
|
|
|
public async Task ExportAsync_returns_success(int idType)
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
2024-03-11 15:19:50 +05:00
|
|
|
|
|
2024-04-23 14:43:17 +05:00
|
|
|
|
var entity = CreateWellOperation(well.Id, idType);
|
|
|
|
|
dbContext.WellOperations.Add(entity);
|
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
//act
|
|
|
|
|
var response = await client.ExportAsync(well.Id, idType);
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
Assert.Equal("application/octet-stream", response.ContentHeaders?.ContentType?.MediaType);
|
|
|
|
|
Assert.True(response.ContentHeaders?.ContentLength > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(WellOperation.IdOperationTypePlan)]
|
|
|
|
|
[InlineData(WellOperation.IdOperationTypeFact)]
|
2024-04-23 14:43:51 +05:00
|
|
|
|
public async Task MatchCategoriesBetweenTemplateAndDb_returns_success(int idType)
|
2024-04-23 14:43:17 +05:00
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
|
|
|
|
var responseTemplate = await client.GetTemplate(well.Id, idType);
|
|
|
|
|
var stream = responseTemplate.Content;
|
|
|
|
|
|
|
|
|
|
using var workbook = new XLWorkbook(stream);
|
2024-04-25 11:19:16 +05:00
|
|
|
|
var sheet = workbook.GetWorksheet("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
2024-04-23 14:43:17 +05:00
|
|
|
|
|
|
|
|
|
var count = sheet.RowsUsed().Count() - 1;
|
|
|
|
|
|
|
|
|
|
var categoryCaptionsInTemplate = new List<string>();
|
|
|
|
|
for (var i = 0; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
var xlRow = sheet.Row(i + 2);
|
|
|
|
|
var rowNumber = xlRow.RowNumber();
|
|
|
|
|
|
|
|
|
|
var xlCell = xlRow.Cell(1);
|
|
|
|
|
var cellValue = xlCell.GetText().Trim();
|
|
|
|
|
|
|
|
|
|
categoryCaptionsInTemplate.Add(cellValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var responseCategories = await client.GetCategories(well.Id, false, false);
|
|
|
|
|
var categories = responseCategories.Content;
|
|
|
|
|
var categoryCaptionsInDb = categories!.Select(c => c.Name.Trim());
|
|
|
|
|
|
|
|
|
|
var notExistedInTemplate = categoryCaptionsInDb.Except(categoryCaptionsInTemplate);
|
|
|
|
|
var notExistedInDb = categoryCaptionsInTemplate.Except(categoryCaptionsInDb);
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.True(categoryCaptionsInDb.Count() == categoryCaptionsInTemplate.Count());
|
|
|
|
|
Assert.True(notExistedInTemplate.Count() == 0);
|
|
|
|
|
Assert.True(notExistedInDb.Count() == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 14:07:40 +05:00
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetPageOperationsAsyncWithDaysAndNpv_returns_success()
|
2024-04-24 14:41:46 +05:00
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
const int pageSize = 10;
|
|
|
|
|
const int pageIndex = 0;
|
|
|
|
|
|
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
|
|
|
|
var entity1 = CreateWellOperation(well.Id);
|
|
|
|
|
|
|
|
|
|
var entity2 = entity1.Adapt<WellOperation>();
|
|
|
|
|
entity2.DateStart = entity2.DateStart.AddDays(1);
|
2024-04-24 15:21:16 +05:00
|
|
|
|
entity2.IdCategory = WellOperationCategory.IdEquipmentDrillingRepair;
|
2024-04-24 14:41:46 +05:00
|
|
|
|
entity2.DurationHours = 2;
|
|
|
|
|
|
|
|
|
|
var entity3 = entity2.Adapt<WellOperation>();
|
|
|
|
|
entity3.DateStart = entity3.DateStart.AddDays(1);
|
2024-04-24 15:21:16 +05:00
|
|
|
|
entity3.IdCategory = WellOperationCategory.IdEquipmentDrillingRepair;
|
2024-04-24 14:41:46 +05:00
|
|
|
|
entity3.DurationHours = 3;
|
|
|
|
|
|
|
|
|
|
dbContext.WellOperations.Add(entity1);
|
|
|
|
|
dbContext.WellOperations.Add(entity2);
|
|
|
|
|
dbContext.WellOperations.Add(entity3);
|
|
|
|
|
|
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
var request = new WellOperationRequestBase
|
|
|
|
|
{
|
|
|
|
|
OperationType = WellOperation.IdOperationTypePlan,
|
|
|
|
|
Skip = pageIndex,
|
|
|
|
|
Take = pageSize,
|
2024-04-24 15:21:16 +05:00
|
|
|
|
SortFields = [nameof(WellOperation.DateStart)]
|
|
|
|
|
};
|
2024-04-24 14:41:46 +05:00
|
|
|
|
|
|
|
|
|
//act
|
|
|
|
|
var response = await client.GetPageOperationsAsync(well.Id, request);
|
|
|
|
|
|
|
|
|
|
//assert
|
2024-04-24 15:21:16 +05:00
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
2024-04-24 14:41:46 +05:00
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
|
|
|
|
|
var items = response.Content.Items.ToArray();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0, items[0].Day);
|
|
|
|
|
Assert.Equal(1, items[1].Day);
|
|
|
|
|
Assert.Equal(2, items[2].Day);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0, items[0].NptHours);
|
|
|
|
|
Assert.Equal(2, items[1].NptHours);
|
|
|
|
|
Assert.Equal(5, items[2].NptHours);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static WellOperation CreateWellOperation(int idWell, int idType = WellOperation.IdOperationTypePlan) =>
|
2024-03-11 15:19:50 +05:00
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
IdWellSectionType = 2,
|
2024-03-22 12:42:48 +05:00
|
|
|
|
IdCategory = WellOperationCategory.IdSlide,
|
2024-03-11 15:19:50 +05:00
|
|
|
|
IdPlan = null,
|
2024-04-24 17:15:20 +05:00
|
|
|
|
CategoryInfo = "<22><><EFBFBD>.<2E><><EFBFBD><EFBFBD>",
|
2024-03-22 12:42:48 +05:00
|
|
|
|
LastUpdateDate = new DateTimeOffset(new DateTime(2023, 1, 10)).ToUniversalTime(),
|
|
|
|
|
IdType = idType,
|
2024-03-11 15:19:50 +05:00
|
|
|
|
DepthStart = 10.0,
|
|
|
|
|
DepthEnd = 20.0,
|
|
|
|
|
DateStart = new DateTimeOffset(new DateTime(2023, 1, 10), TimeSpan.FromHours(Defaults.Timezone.Hours)).ToUniversalTime(),
|
|
|
|
|
DurationHours = 1.0,
|
|
|
|
|
Comment = "1",
|
2024-03-22 12:42:48 +05:00
|
|
|
|
IdUser = 1,
|
2024-03-11 15:19:50 +05:00
|
|
|
|
};
|
2024-01-25 10:35:16 +05:00
|
|
|
|
}
|