2024-01-25 10:35:16 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudWebApi.IntegrationTests.Clients;
|
|
|
|
|
using System.Net;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
private readonly WellOperationDto[] dtos = new WellOperationDto[]
|
2024-01-25 15:56:34 +05:00
|
|
|
|
{
|
|
|
|
|
new WellOperationDto()
|
|
|
|
|
{
|
|
|
|
|
Id = 2,
|
|
|
|
|
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-01-25 10:35:16 +05:00
|
|
|
|
|
2024-01-25 15:56:34 +05:00
|
|
|
|
private readonly WellOperationDto[] dtosWithError = new WellOperationDto[]
|
|
|
|
|
{
|
2024-01-25 10:35:16 +05:00
|
|
|
|
new WellOperationDto()
|
|
|
|
|
{
|
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
|
|
|
|
|
},
|
|
|
|
|
new WellOperationDto()
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private IWellOperationClient wellOperationClient;
|
|
|
|
|
|
|
|
|
|
public WellOperationControllerTest(WebAppFactoryFixture factory)
|
2024-01-25 15:56:34 +05:00
|
|
|
|
: base(factory)
|
|
|
|
|
{
|
2024-01-25 10:35:16 +05:00
|
|
|
|
wellOperationClient = factory.GetAuthorizedHttpClient<IWellOperationClient>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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 InsertRange_returns_success()
|
|
|
|
|
{
|
|
|
|
|
//act
|
|
|
|
|
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, dtos);
|
|
|
|
|
|
|
|
|
|
//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 InsertRange_returns_error()
|
|
|
|
|
{
|
2024-01-25 10:35:16 +05:00
|
|
|
|
//act
|
2024-01-25 15:56:34 +05:00
|
|
|
|
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, 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
|
|
|
|
|
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtos);
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
|
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtosWithError);
|
|
|
|
|
|
|
|
|
|
//assert
|
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
2024-01-25 10:35:16 +05:00
|
|
|
|
}
|
|
|
|
|
}
|