diff --git a/AsbCloudWebApi.IntegrationTests/BaseIntegrationTest.cs b/AsbCloudWebApi.IntegrationTests/BaseIntegrationTest.cs index d18c54bf..add2e07b 100644 --- a/AsbCloudWebApi.IntegrationTests/BaseIntegrationTest.cs +++ b/AsbCloudWebApi.IntegrationTests/BaseIntegrationTest.cs @@ -6,7 +6,7 @@ namespace AsbCloudWebApi.IntegrationTests; public abstract class BaseIntegrationTest : IClassFixture { - private readonly IServiceScope scope; + protected readonly IServiceScope scope; protected readonly IAsbCloudDbContext dbContext; diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs b/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs index 6192d306..43497d6c 100644 --- a/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs +++ b/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs @@ -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> InsertRangeAsync(int idWell, int idType, bool deleteBeforeInsert, [Body] IEnumerable dtos); - [Post(BaseRoute)] - Task> InsertRange(int idWell, [Body] IEnumerable dtos); } \ No newline at end of file diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs index 17130b5e..2651243f 100644 --- a/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs +++ b/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs @@ -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(); - var rep = factory.Get } /// - /// Успешное добавление операции с предварительной очисткой + /// Успешное добавление операций (с предварительной очисткой данных) /// /// [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); - } /// - /// Успешное добавление операции без очистки + /// Неуспешное добавление операций (с предварительной очисткой данных) /// /// [Fact] - public async Task InsertRange_returns_success() { - //arrange - var dbset = dbContext.Set(); - 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); + } + + /// + /// Успешное добавление операций (с предварительной очисткой данных) + /// + /// + [Fact] + public async Task InsertRangeWithDeleteBefore_returns_success() + { + //act + var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtos); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); } /// - /// Неуспешное добавление операции с предварительной очисткой + /// Неуспешное добавление операций (с предварительной очисткой данных) /// /// [Fact] public async Task InsertRangeWithDeleteBefore_returns_error() { - } + //act + var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtosWithError); - /// - /// Неуспешное добавление операции без очистки - /// - /// - [Fact] - public async Task InsertRange_returns_error() - { + //assert + Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); } } \ No newline at end of file diff --git a/AsbCloudWebApi.IntegrationTests/Data/Defaults.cs b/AsbCloudWebApi.IntegrationTests/Data/Defaults.cs index ddb7dbe7..fc36eb3f 100644 --- a/AsbCloudWebApi.IntegrationTests/Data/Defaults.cs +++ b/AsbCloudWebApi.IntegrationTests/Data/Defaults.cs @@ -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() { diff --git a/AsbCloudWebApi.IntegrationTests/WebAppFactoryFixture.cs b/AsbCloudWebApi.IntegrationTests/WebAppFactoryFixture.cs index a0111303..af7303b6 100644 --- a/AsbCloudWebApi.IntegrationTests/WebAppFactoryFixture.cs +++ b/AsbCloudWebApi.IntegrationTests/WebAppFactoryFixture.cs @@ -60,7 +60,8 @@ public class WebAppFactoryFixture : WebApplicationFactory, 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()