forked from ddrilling/AsbCloudServer
Интеграционный тест (InsertRangeAsync)
This commit is contained in:
parent
eaa10e129a
commit
ff208a6aa8
@ -6,7 +6,7 @@ namespace AsbCloudWebApi.IntegrationTests;
|
||||
|
||||
public abstract class BaseIntegrationTest : IClassFixture<WebAppFactoryFixture>
|
||||
{
|
||||
private readonly IServiceScope scope;
|
||||
protected readonly IServiceScope scope;
|
||||
|
||||
protected readonly IAsbCloudDbContext dbContext;
|
||||
|
||||
|
@ -1,14 +1,13 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMapPlan;
|
||||
using AsbCloudApp.Requests;
|
||||
using Refit;
|
||||
|
||||
namespace AsbCloudWebApi.IntegrationTests.Clients;
|
||||
|
||||
public interface IWellOperationClient
|
||||
{
|
||||
private const string BaseRoute = "/api/wellOperation";
|
||||
private const string BaseRoute = "/api/well/{idWell}/wellOperations";
|
||||
|
||||
[Post(BaseRoute + "/{idType}/{deleteBeforeInsert}")]
|
||||
Task<IApiResponse<int>> InsertRangeAsync(int idWell, int idType, bool deleteBeforeInsert, [Body] IEnumerable<WellOperationDto> dtos);
|
||||
|
||||
[Post(BaseRoute)]
|
||||
Task<IApiResponse<int>> InsertRange(int idWell, [Body] IEnumerable<WellOperationDto> dtos);
|
||||
}
|
@ -1,8 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMapPlan;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudDb.Model.ProcessMaps;
|
||||
using AsbCloudWebApi.IntegrationTests.Clients;
|
||||
using System.Net;
|
||||
using Xunit;
|
||||
@ -12,104 +8,147 @@ namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
||||
|
||||
public class WellOperationControllerTest : BaseIntegrationTest
|
||||
{
|
||||
private readonly int idWell = 4;
|
||||
private static int idWell = 1;
|
||||
|
||||
private readonly WellOperationDto[] dtos = new WellOperationDto[]
|
||||
{
|
||||
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)
|
||||
{
|
||||
: base(factory)
|
||||
{
|
||||
wellOperationClient = factory.GetAuthorizedHttpClient<IWellOperationClient>();
|
||||
var rep = factory.Get
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Успешное добавление операции с предварительной очисткой
|
||||
/// Успешное добавление операций (с предварительной очисткой данных)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task InsertRangeWithDeleteBefore_returns_success()
|
||||
{
|
||||
////arrange
|
||||
//dbContext.WellOperations.Add(wellOperation);
|
||||
//dbContext.SaveChanges();
|
||||
public async Task InsertRange_returns_success()
|
||||
{
|
||||
//act
|
||||
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, dtos);
|
||||
|
||||
//var request = new OperationStatRequest
|
||||
//{
|
||||
// DateStartUTC = schedule.DrillStart.DateTime,
|
||||
// DateEndUTC = schedule.DrillEnd.DateTime,
|
||||
// DurationMinutesMin = 0,
|
||||
// DurationMinutesMax = 5
|
||||
//};
|
||||
//assert
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
}
|
||||
|
||||
//var dtoExpected = new SlipsStatDto
|
||||
//{
|
||||
// DrillerName = $"{Data.Defaults.Drillers[0].Surname} {Data.Defaults.Drillers[0].Name} {Data.Defaults.Drillers[0].Patronymic}",
|
||||
// WellCount = 1,
|
||||
// SectionCaption = "Пилотный ствол",
|
||||
// SlipsCount = 1,
|
||||
// SlipsTimeInMinutes = (detectedOperation.DateEnd - detectedOperation.DateStart).TotalMinutes,
|
||||
// SectionDepth = factWellOperation.DepthEnd - factWellOperation.DepthStart,
|
||||
//};
|
||||
|
||||
////act
|
||||
//var response = await slipsTimeClient.GetAll(request);
|
||||
|
||||
////assert
|
||||
//Assert.NotNull(response.Content);
|
||||
//Assert.Single(response.Content);
|
||||
|
||||
//var dtoActual = response.Content.First();
|
||||
//MatchHelper.Match(dtoExpected, dtoActual);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Успешное добавление операции без очистки
|
||||
/// Неуспешное добавление операций (с предварительной очисткой данных)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task InsertRange_returns_success() {
|
||||
//arrange
|
||||
var dbset = dbContext.Set<WellOperation>();
|
||||
dbset.RemoveRange(dbset);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
operationRepository.Validate(dtos);
|
||||
|
||||
public async Task InsertRange_returns_error()
|
||||
{
|
||||
//act
|
||||
var response = await wellOperationClient.InsertRange(idWell, dtos);
|
||||
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, 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, false, 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, false, dtosWithError);
|
||||
|
||||
/// <summary>
|
||||
/// Неуспешное добавление операции без очистки
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Fact]
|
||||
public async Task InsertRange_returns_error()
|
||||
{
|
||||
//assert
|
||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
}
|
||||
}
|
@ -14,7 +14,28 @@ namespace AsbCloudWebApi.IntegrationTests.Data
|
||||
Surname = "test"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static WellOperation[] WellOperations = new WellOperation[]
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 2,
|
||||
IdWell = 1,
|
||||
IdType = 1,
|
||||
DateStart = DateTimeOffset.UtcNow.AddDays(-1),
|
||||
CategoryInfo = "1",
|
||||
Comment = "1",
|
||||
DepthEnd = 20,
|
||||
DepthStart = 10,
|
||||
DurationHours = 1,
|
||||
IdCategory = 5000,
|
||||
IdPlan = null,
|
||||
IdUser = 1,
|
||||
IdWellSectionType = 1,
|
||||
LastUpdateDate = DateTimeOffset.UtcNow
|
||||
}
|
||||
};
|
||||
|
||||
public static Deposit[] Deposits = new Deposit[] {
|
||||
new()
|
||||
{
|
||||
|
@ -60,7 +60,8 @@ public class WebAppFactoryFixture : WebApplicationFactory<Startup>,
|
||||
dbContext.AddRange(Data.Defaults.RelationsCompanyWell);
|
||||
dbContext.AddRange(Data.Defaults.Telemetries);
|
||||
dbContext.AddRange(Data.Defaults.Drillers);
|
||||
await dbContext.SaveChangesAsync();
|
||||
dbContext.AddRange(Data.Defaults.WellOperations);
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public new async Task DisposeAsync()
|
||||
|
Loading…
Reference in New Issue
Block a user