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-05 08:54:18 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2024-01-25 10:35:16 +05:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
|
|
|
|
|
|
|
|
|
public class WellOperationControllerTest : BaseIntegrationTest
|
|
|
|
|
{
|
2024-01-25 15:56:34 +05:00
|
|
|
|
private static int idWell = 1;
|
2024-01-25 10:35:16 +05:00
|
|
|
|
|
2024-02-05 08:54:18 +05:00
|
|
|
|
private readonly WellOperationDto[] dtos = new WellOperationDto[]
|
|
|
|
|
{
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
IdWell = 1,
|
|
|
|
|
IdWellSectionType = 1,
|
|
|
|
|
WellSectionTypeName = "Пилотный ствол",
|
|
|
|
|
IdCategory = 5000,
|
|
|
|
|
IdPlan = null,
|
|
|
|
|
CategoryName = "Разборка КНБК",
|
|
|
|
|
IdParentCategory = 4000,
|
|
|
|
|
CategoryInfo = "1",
|
|
|
|
|
IdType = 0,
|
|
|
|
|
DepthStart = 10.0,
|
|
|
|
|
DepthEnd = 20.0,
|
|
|
|
|
Day = 0.0,
|
|
|
|
|
NptHours = 0.0,
|
|
|
|
|
DateStart = new DateTimeOffset(new DateTime(2023, 02, 03, 1, 0, 0, DateTimeKind.Unspecified)),
|
|
|
|
|
DurationHours = 1.0,
|
|
|
|
|
Comment = "1",
|
|
|
|
|
IdUser = 1,
|
|
|
|
|
UserName = null,
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-01-25 10:35:16 +05:00
|
|
|
|
|
2024-01-25 15:56:34 +05:00
|
|
|
|
private readonly WellOperationDto[] dtosWithError = new WellOperationDto[]
|
|
|
|
|
{
|
2024-02-05 08:54:18 +05:00
|
|
|
|
new()
|
2024-01-25 10:35:16 +05:00
|
|
|
|
{
|
2024-01-25 15:56:34 +05:00
|
|
|
|
Id = 3,
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
IdType = 1,
|
|
|
|
|
DateStart = DateTimeOffset.Now,
|
|
|
|
|
CategoryInfo = "1",
|
|
|
|
|
CategoryName = "1",
|
|
|
|
|
Comment = "1",
|
|
|
|
|
Day = 1,
|
|
|
|
|
DepthEnd = 20,
|
|
|
|
|
DepthStart = 10,
|
|
|
|
|
DurationHours = 1,
|
|
|
|
|
IdCategory = 5000,
|
|
|
|
|
IdParentCategory = null,
|
|
|
|
|
IdPlan = null,
|
|
|
|
|
IdUser = 1,
|
|
|
|
|
IdWellSectionType = 1,
|
|
|
|
|
LastUpdateDate = DateTimeOffset.Now,
|
|
|
|
|
NptHours = 1,
|
|
|
|
|
WellSectionTypeName = null,
|
|
|
|
|
UserName = null
|
|
|
|
|
},
|
2024-02-05 08:54:18 +05:00
|
|
|
|
new()
|
2024-01-25 15:56:34 +05:00
|
|
|
|
{
|
|
|
|
|
Id = 4,
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
IdType = 1,
|
|
|
|
|
DateStart = DateTimeOffset.Now.AddDays(1000),
|
|
|
|
|
CategoryInfo = "1",
|
|
|
|
|
CategoryName = "1",
|
|
|
|
|
Comment = "1",
|
|
|
|
|
Day = 1,
|
|
|
|
|
DepthEnd = 20,
|
|
|
|
|
DepthStart = 10,
|
|
|
|
|
DurationHours = 1,
|
|
|
|
|
IdCategory = 5000,
|
|
|
|
|
IdParentCategory = null,
|
|
|
|
|
IdPlan = null,
|
|
|
|
|
IdUser = 1,
|
|
|
|
|
IdWellSectionType = 1,
|
|
|
|
|
LastUpdateDate = DateTimeOffset.Now,
|
|
|
|
|
NptHours = 1,
|
|
|
|
|
WellSectionTypeName = null,
|
|
|
|
|
UserName = null
|
2024-01-25 10:35:16 +05:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-05 08:54:18 +05:00
|
|
|
|
private IWellOperationClient client;
|
2024-01-25 10:35:16 +05:00
|
|
|
|
|
|
|
|
|
public WellOperationControllerTest(WebAppFactoryFixture factory)
|
2024-01-25 15:56:34 +05:00
|
|
|
|
: base(factory)
|
|
|
|
|
{
|
2024-02-05 08:54:18 +05:00
|
|
|
|
client = factory.GetAuthorizedHttpClient<IWellOperationClient>();
|
2024-01-25 10:35:16 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-01-26 09:49:00 +05:00
|
|
|
|
/// Успешное добавление операций (без предварительной очистки данных)
|
2024-01-25 10:35:16 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
2024-01-25 15:56:34 +05:00
|
|
|
|
public async Task InsertRange_returns_success()
|
|
|
|
|
{
|
2024-01-26 09:49:00 +05:00
|
|
|
|
dbContext.CleanupDbSet<WellOperation>();
|
2024-01-25 15:56:34 +05:00
|
|
|
|
//act
|
2024-02-05 08:54:18 +05:00
|
|
|
|
var response = await client.InsertRangeAsync(idWell, 1, false, dtos);
|
2024-01-25 15:56:34 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:35:16 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-01-26 09:49:00 +05:00
|
|
|
|
/// Неуспешное добавление операций (без предварительной очистки данных)
|
2024-01-25 10:35:16 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
2024-01-25 15:56:34 +05:00
|
|
|
|
public async Task InsertRange_returns_error()
|
|
|
|
|
{
|
2024-01-25 10:35:16 +05:00
|
|
|
|
//act
|
2024-02-05 08:54:18 +05:00
|
|
|
|
var response = await client.InsertRangeAsync(idWell, 1, false, dtosWithError);
|
2024-01-25 10:35:16 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
2024-01-25 15:56:34 +05:00
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
2024-01-25 10:35:16 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-01-25 15:56:34 +05:00
|
|
|
|
/// Успешное добавление операций (с предварительной очисткой данных)
|
2024-01-25 10:35:16 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
2024-01-25 15:56:34 +05:00
|
|
|
|
public async Task InsertRangeWithDeleteBefore_returns_success()
|
2024-01-25 10:35:16 +05:00
|
|
|
|
{
|
2024-01-25 15:56:34 +05:00
|
|
|
|
//act
|
2024-02-05 08:54:18 +05:00
|
|
|
|
var response = await client.InsertRangeAsync(idWell, 1, true, dtos);
|
2024-01-25 15:56:34 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
2024-01-25 10:35:16 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-01-25 15:56:34 +05:00
|
|
|
|
/// Неуспешное добавление операций (с предварительной очисткой данных)
|
2024-01-25 10:35:16 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
2024-01-25 15:56:34 +05:00
|
|
|
|
public async Task InsertRangeWithDeleteBefore_returns_error()
|
2024-01-25 10:35:16 +05:00
|
|
|
|
{
|
2024-01-25 15:56:34 +05:00
|
|
|
|
//act
|
2024-02-05 08:54:18 +05:00
|
|
|
|
var response = await client.InsertRangeAsync(idWell, 1, true, dtosWithError);
|
2024-01-25 15:56:34 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
2024-01-25 10:35:16 +05:00
|
|
|
|
}
|
2024-01-25 17:13:56 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Успешное обновление операции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task UpdateAsync_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//act
|
|
|
|
|
var dto = dtos.FirstOrDefault()!;
|
2024-02-05 08:54:18 +05:00
|
|
|
|
var response = await client.UpdateAsync(idWell, 1, dto, CancellationToken.None);
|
2024-01-25 17:13:56 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Неуспешное обновление операции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task UpdateAsync_returns_error()
|
|
|
|
|
{
|
|
|
|
|
//act
|
|
|
|
|
var dto = dtosWithError.LastOrDefault()!;
|
2024-02-05 08:54:18 +05:00
|
|
|
|
var response = await client.UpdateAsync(idWell, 1, dto, CancellationToken.None);
|
2024-01-25 17:13:56 +05:00
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
|
|
|
|
}
|
2024-02-05 08:54:18 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение плановых операций
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetPageOperationsPlanAsync_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//arrange
|
|
|
|
|
dbContext.CleanupDbSet<WellOperation>();
|
|
|
|
|
await client.InsertRangeAsync(idWell, WellOperation.IdOperationTypePlan, false, dtos);
|
|
|
|
|
|
|
|
|
|
var request = new WellOperationRequestBase
|
|
|
|
|
{
|
|
|
|
|
OperationType = WellOperation.IdOperationTypePlan
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//act
|
|
|
|
|
var response = await client.GetPageOperationsPlanAsync(idWell, request, CancellationToken.None);
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.NotNull(response.Content);
|
|
|
|
|
Assert.Single(response.Content.Items);
|
|
|
|
|
|
|
|
|
|
var dto = dtos[0];
|
|
|
|
|
var wellOperation = response.Content.Items.First();
|
|
|
|
|
|
|
|
|
|
var excludeProps = new[] { nameof(WellOperationDto.Id) };
|
|
|
|
|
MatchHelper.Match(dto, wellOperation, excludeProps);
|
|
|
|
|
}
|
2024-01-25 10:35:16 +05:00
|
|
|
|
}
|