forked from ddrilling/AsbCloudServer
186 lines
5.4 KiB
C#
186 lines
5.4 KiB
C#
using AsbCloudApp.Data;
|
||
using AsbCloudDb.Model;
|
||
using AsbCloudWebApi.IntegrationTests.Clients;
|
||
using System.Net;
|
||
using Xunit;
|
||
|
||
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
||
|
||
|
||
public class WellOperationControllerTest : BaseIntegrationTest
|
||
{
|
||
private static int idWell = 1;
|
||
|
||
private readonly WellOperationDto[] dtos = new WellOperationDto[]
|
||
{
|
||
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
|
||
}
|
||
};
|
||
|
||
private readonly WellOperationDto[] dtosWithError = new WellOperationDto[]
|
||
{
|
||
new WellOperationDto()
|
||
{
|
||
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
|
||
}
|
||
};
|
||
|
||
private IWellOperationClient wellOperationClient;
|
||
|
||
public WellOperationControllerTest(WebAppFactoryFixture factory)
|
||
: base(factory)
|
||
{
|
||
wellOperationClient = factory.GetAuthorizedHttpClient<IWellOperationClient>();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Успешное добавление операций (без предварительной очистки данных)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Fact]
|
||
public async Task InsertRange_returns_success()
|
||
{
|
||
dbContext.CleanupDbSet<WellOperation>();
|
||
//act
|
||
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtos);
|
||
|
||
//assert
|
||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Неуспешное добавление операций (без предварительной очистки данных)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Fact]
|
||
public async Task InsertRange_returns_error()
|
||
{
|
||
//act
|
||
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtosWithError);
|
||
|
||
//assert
|
||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Успешное добавление операций (с предварительной очисткой данных)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Fact]
|
||
public async Task InsertRangeWithDeleteBefore_returns_success()
|
||
{
|
||
//act
|
||
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, dtos);
|
||
|
||
//assert
|
||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Неуспешное добавление операций (с предварительной очисткой данных)
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Fact]
|
||
public async Task InsertRangeWithDeleteBefore_returns_error()
|
||
{
|
||
//act
|
||
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, dtosWithError);
|
||
|
||
//assert
|
||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Успешное обновление операции
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Fact]
|
||
public async Task UpdateAsync_returns_success()
|
||
{
|
||
//act
|
||
var dto = dtos.FirstOrDefault()!;
|
||
var response = await wellOperationClient.UpdateAsync(idWell, 1, dto, CancellationToken.None);
|
||
|
||
//assert
|
||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Неуспешное обновление операции
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Fact]
|
||
public async Task UpdateAsync_returns_error()
|
||
{
|
||
//act
|
||
var dto = dtosWithError.LastOrDefault()!;
|
||
var response = await wellOperationClient.UpdateAsync(idWell, 1, dto, CancellationToken.None);
|
||
|
||
//assert
|
||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||
}
|
||
} |