2024-01-25 10:35:16 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2024-01-26 09:49:00 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
2024-01-25 10:35:16 +05:00
|
|
|
|
using AsbCloudWebApi.IntegrationTests.Clients;
|
|
|
|
|
using System.Net;
|
2024-02-06 11:41:51 +05:00
|
|
|
|
using System.Reflection;
|
2024-02-05 08:54:18 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2024-02-07 09:21:03 +05:00
|
|
|
|
using AsbCloudWebApi.IntegrationTests.Data;
|
2024-03-11 15:19:50 +05:00
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-02-06 11:41:51 +05:00
|
|
|
|
using Refit;
|
2024-01-25 10:35:16 +05:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
|
|
|
|
|
|
|
|
|
public class WellOperationControllerTest : BaseIntegrationTest
|
|
|
|
|
{
|
2024-03-11 15:19:50 +05:00
|
|
|
|
private IWellOperationClient client;
|
2024-01-25 10:35:16 +05:00
|
|
|
|
|
2024-03-11 15:19:50 +05:00
|
|
|
|
public WellOperationControllerTest(WebAppFactoryFixture factory)
|
|
|
|
|
: base(factory)
|
2024-02-05 08:54:18 +05:00
|
|
|
|
{
|
2024-03-11 15:19:50 +05:00
|
|
|
|
client = factory.GetAuthorizedHttpClient<IWellOperationClient>(string.Empty);
|
2024-01-25 10:35:16 +05:00
|
|
|
|
|
2024-03-11 15:19:50 +05:00
|
|
|
|
dbContext.CleanupDbSet<WellOperation>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Успешное добавление операций (без предварительной очистки данных)
|
|
|
|
|
/// </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>() };
|
|
|
|
|
|
|
|
|
|
//act
|
|
|
|
|
var response = await client.InsertRangeAsync(well.Id, 1, false, dtos);
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Успешное добавление операций (с предварительной очисткой данных)
|
|
|
|
|
/// </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>() };
|
|
|
|
|
|
|
|
|
|
//act
|
|
|
|
|
var response = await client.InsertRangeAsync(well.Id, 1, true, dtos);
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Успешное обновление операции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task UpdateAsync_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
|
|
|
|
var entity = CreateWellOperation(well.Id);
|
|
|
|
|
dbContext.WellOperations.Add(entity);
|
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
var dto = entity.Adapt<WellOperationDto>();
|
|
|
|
|
|
|
|
|
|
//act
|
|
|
|
|
var response = await client.UpdateAsync(well.Id, entity.Id, dto, CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
}
|
2024-01-25 10:35:16 +05:00
|
|
|
|
|
2024-02-05 08:54:18 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение плановых операций
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetPageOperationsPlanAsync_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
2024-03-11 15:19:50 +05:00
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
|
|
|
|
var entity = CreateWellOperation(well.Id);
|
|
|
|
|
dbContext.WellOperations.Add(entity);
|
|
|
|
|
await dbContext.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
var dto = entity.Adapt<WellOperationDto>();
|
|
|
|
|
var timezoneOffset = TimeSpan.FromHours(well.Timezone.Hours);
|
|
|
|
|
dto.DateStart = dto.DateStart.ToOffset(timezoneOffset);
|
2024-02-05 08:54:18 +05:00
|
|
|
|
|
|
|
|
|
var request = new WellOperationRequestBase
|
|
|
|
|
{
|
|
|
|
|
OperationType = WellOperation.IdOperationTypePlan
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//act
|
2024-03-11 15:19:50 +05:00
|
|
|
|
var response = await client.GetPageOperationsPlanAsync(well.Id, request, CancellationToken.None);
|
2024-02-05 08:54:18 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
Assert.Single(response.Content.Items);
|
|
|
|
|
|
2024-03-11 15:19:50 +05:00
|
|
|
|
var actualDto = response.Content.Items.First();
|
2024-02-05 08:54:18 +05:00
|
|
|
|
|
2024-03-11 15:19:50 +05:00
|
|
|
|
var excludeProps = new[]
|
|
|
|
|
{
|
|
|
|
|
nameof(WellOperationDto.LastUpdateDate)
|
|
|
|
|
};
|
|
|
|
|
MatchHelper.Match(dto, actualDto, excludeProps);
|
2024-02-05 08:54:18 +05:00
|
|
|
|
}
|
2024-02-06 11:41:51 +05:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ImportPlanDefaultExcelFileAsync_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
2024-03-11 15:19:50 +05:00
|
|
|
|
var stream = Assembly.GetExecutingAssembly().GetFileCopyStream("WellOperationsPlan.xlsx");
|
2024-02-06 11:41:51 +05:00
|
|
|
|
|
|
|
|
|
var memoryStream = new MemoryStream();
|
2024-03-11 15:19:50 +05:00
|
|
|
|
await stream.CopyToAsync(memoryStream);
|
2024-02-06 11:41:51 +05:00
|
|
|
|
memoryStream.Position = 0;
|
|
|
|
|
|
2024-03-11 15:19:50 +05:00
|
|
|
|
var well = await dbContext.Wells.FirstAsync();
|
|
|
|
|
|
2024-02-06 11:41:51 +05:00
|
|
|
|
//act
|
|
|
|
|
var streamPart = new StreamPart(memoryStream, "WellOperations.xlsx", "application/octet-stream");
|
|
|
|
|
|
2024-03-11 15:19:50 +05:00
|
|
|
|
var response = await client.ImportPlanDefaultExcelFileAsync(well.Id, new[] { streamPart }, CancellationToken.None);
|
2024-02-06 11:41:51 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
Assert.Equal(4, response.Content.Count());
|
2024-03-11 15:19:50 +05:00
|
|
|
|
Assert.True(response.Content.All(w => Math.Abs(w.DateStart.Offset.Hours - Defaults.Timezone.Hours) < 0.1));
|
2024-02-06 11:41:51 +05:00
|
|
|
|
}
|
2024-03-11 15:19:50 +05:00
|
|
|
|
|
|
|
|
|
private static WellOperation CreateWellOperation(int idWell) =>
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
IdWellSectionType = 2,
|
|
|
|
|
LastUpdateDate = DateTimeOffset.UtcNow,
|
|
|
|
|
IdCategory = 5000,
|
|
|
|
|
IdPlan = null,
|
|
|
|
|
CategoryInfo = "1",
|
|
|
|
|
IdType = 0,
|
|
|
|
|
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",
|
|
|
|
|
IdUser = 1
|
|
|
|
|
};
|
2024-01-25 10:35:16 +05:00
|
|
|
|
}
|