forked from ddrilling/AsbCloudServer
Merge branch 'dev' into fix/#33138657-composite-well-with-right-sections
This commit is contained in:
commit
06caa01f27
@ -227,7 +227,7 @@ namespace AsbCloudDb
|
||||
DateTime vDate => $"'{FormatDateValue(vDate)}'",
|
||||
DateTimeOffset vDate => $"'{FormatDateValue(vDate.UtcDateTime)}'",
|
||||
IFormattable vFormattable => FormatFormattableValue(vFormattable),
|
||||
_ => System.Text.Json.JsonSerializer.Serialize(v),
|
||||
_ => $"'{EscapeCurlyBraces(JsonSerializer.Serialize(v))}'",
|
||||
};
|
||||
|
||||
private static string EscapeCurlyBraces(string vStr)
|
||||
|
@ -2,6 +2,7 @@
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -68,11 +69,12 @@ namespace AsbCloudInfrastructure.Repository
|
||||
var entities = dtos.Select(dto =>
|
||||
{
|
||||
var entity = dto.Adapt<DrillTest>();
|
||||
entity.TimeStampStart = dto.TimeStampStart.ToUniversalTime();
|
||||
entity.IdTelemetry = idTelemetry;
|
||||
return entity;
|
||||
});
|
||||
db.DrillTests.AddRange(entities);
|
||||
var result = await db.SaveChangesAsync(token);
|
||||
|
||||
var result = await db.Database.ExecInsertOrUpdateAsync(db.Set<DrillTest>(), entities, token);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -136,8 +136,18 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
{
|
||||
EnsureValidWellOperations(dtos);
|
||||
|
||||
var result = 0;
|
||||
|
||||
if (!deleteBeforeInsert)
|
||||
return await InsertRangeAsync(dtos, token);
|
||||
{
|
||||
result = await InsertRangeAsync(dtos, token);
|
||||
|
||||
if (result > 0)
|
||||
memoryCache.Remove(cacheKeyWellOperations);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
var idType = dtos.First().IdType;
|
||||
var idWell = dtos.First().IdWell;
|
||||
@ -149,7 +159,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
|
||||
await DeleteRangeAsync(existingOperationIds, token);
|
||||
|
||||
var result = await InsertRangeAsync(dtos, token);
|
||||
result = await InsertRangeAsync(dtos, token);
|
||||
|
||||
if (result > 0)
|
||||
memoryCache.Remove(cacheKeyWellOperations);
|
||||
|
@ -102,7 +102,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
if (dateBegin == default)
|
||||
{
|
||||
var dateRange = telemetryDataCache.GetOrDefaultDataDateRange(telemetry.Id);
|
||||
dateBeginUtc = (dateRange?.To ?? DateTimeOffset.UtcNow)
|
||||
dateBeginUtc = (dateRange?.To.ToUniversalTime() ?? DateTimeOffset.UtcNow)
|
||||
.AddSeconds(-intervalSec);
|
||||
}
|
||||
else
|
||||
|
@ -0,0 +1,29 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.DrillTestReport;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Requests;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Refit;
|
||||
|
||||
namespace AsbCloudWebApi.IntegrationTests.Clients;
|
||||
|
||||
public interface IDrillTestControllerClient
|
||||
{
|
||||
[Post("/api/telemetry/{uid}/DrillTest")]
|
||||
Task<IApiResponse> PostDataAsync(
|
||||
string uid,
|
||||
IEnumerable<DrillTestBaseDto> dtos,
|
||||
CancellationToken token);
|
||||
|
||||
[Get("/api/well/{idWell}/DrillTest")]
|
||||
Task<IApiResponse<PhysicalFileResult>> GenerateReportAsync(
|
||||
int idWell,
|
||||
int id,
|
||||
CancellationToken cancellationToken);
|
||||
|
||||
[HttpGet("/api/well/{idWell}/DrillTest/all")]
|
||||
Task<IApiResponse<PaginationContainer<DrillTestReportInfoDto>>> GetListAsync(
|
||||
int idWell,
|
||||
FileReportRequest request,
|
||||
CancellationToken cancellationToken);
|
||||
}
|
12
AsbCloudWebApi.IntegrationTests/Clients/IWellClient.cs
Normal file
12
AsbCloudWebApi.IntegrationTests/Clients/IWellClient.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using AsbCloudApp.Data;
|
||||
using Refit;
|
||||
|
||||
namespace AsbCloudWebApi.IntegrationTests.Clients;
|
||||
|
||||
public interface IWellClient
|
||||
{
|
||||
private const string BaseRoute = "/api/well";
|
||||
|
||||
[Get(BaseRoute)]
|
||||
Task<IApiResponse<IEnumerable<WellDto>>> GetWellsAsync();
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudWebApi.IntegrationTests.Clients;
|
||||
using AsbCloudWebApi.IntegrationTests.Data;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
||||
|
@ -0,0 +1,77 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudWebApi.IntegrationTests.Clients;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
||||
|
||||
public class DrillTestControllerTest : BaseIntegrationTest
|
||||
{
|
||||
private readonly IDrillTestControllerClient client;
|
||||
static readonly string uid = DateTime.UtcNow.ToString("yyyyMMdd_HHmmssfff");
|
||||
private static readonly SimpleTimezone timezone = new() { TimezoneId = "a", Hours = 5 };
|
||||
private static readonly Telemetry telemetry = new Telemetry() { Id = 1, RemoteUid = uid, TimeZone = timezone, Info = new() };
|
||||
private readonly IEnumerable<DrillTestBaseDto> drillTests = [new DrillTestBaseDto {
|
||||
DepthStart = 12,
|
||||
Id = 1,
|
||||
Params = [ new DrillTestParamsDto() {
|
||||
DepthDrillStep = 1,
|
||||
DepthSpeed = 2,
|
||||
Speed = 3,
|
||||
Step = 4,
|
||||
TimeDrillStep = 5,
|
||||
Workload = 6,
|
||||
}, new DrillTestParamsDto() {
|
||||
DepthDrillStep = 7,
|
||||
DepthSpeed = 8,
|
||||
Speed = 9,
|
||||
Step = 10,
|
||||
TimeDrillStep = 11,
|
||||
Workload = 12,
|
||||
}],
|
||||
TimeStampStart = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(5))
|
||||
}];
|
||||
|
||||
public DrillTestControllerTest(WebAppFactoryFixture factory)
|
||||
: base(factory)
|
||||
{
|
||||
client = factory.GetAuthorizedHttpClient<IDrillTestControllerClient>(string.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostDataAsync()
|
||||
{
|
||||
// arrange
|
||||
dbContext.CleanupDbSet<DrillTest>();
|
||||
dbContext.CleanupDbSet<Telemetry>();
|
||||
dbContext.Set<Telemetry>().Add(telemetry);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
// act
|
||||
var response = await client.PostDataAsync(uid, drillTests, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||
var count = dbContext.Set<DrillTest>().Count();
|
||||
Assert.Equal(1, count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostDataAsync_twice_should_be_ok()
|
||||
{
|
||||
// arrange
|
||||
dbContext.CleanupDbSet<DrillTest>();
|
||||
dbContext.CleanupDbSet<Telemetry>();
|
||||
dbContext.Set<Telemetry>().Add(telemetry);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
// act
|
||||
_ = await client.PostDataAsync(uid, drillTests, CancellationToken.None);
|
||||
var response = await client.PostDataAsync(uid, drillTests, CancellationToken.None);
|
||||
|
||||
// assert
|
||||
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||
var count = dbContext.Set<DrillTest>().Count();
|
||||
Assert.Equal(1, count);
|
||||
}
|
||||
}
|
@ -24,6 +24,12 @@ public class TelemetryControllerTest : BaseIntegrationTest
|
||||
BlockPosition = 5,
|
||||
BlockSpeed = 5,
|
||||
}];
|
||||
private readonly TelemetryInfoDto telemetryInfoDto = new()
|
||||
{
|
||||
TimeZoneId = timezone.TimezoneId,
|
||||
TimeZoneOffsetTotalHours = timezone.Hours,
|
||||
Cluster = "cluster1",
|
||||
};
|
||||
|
||||
public TelemetryControllerTest(WebAppFactoryFixture factory)
|
||||
: base(factory)
|
||||
@ -48,12 +54,69 @@ public class TelemetryControllerTest : BaseIntegrationTest
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostUsersAsync()
|
||||
public async Task PostInfoAsync()
|
||||
{
|
||||
// arrange
|
||||
dbContext.CleanupDbSet<Telemetry>();
|
||||
|
||||
// act
|
||||
var response = await client.PostInfoAsync(uid, telemetryInfoDto, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||
var telemetriesCount = dbContext.Set<Telemetry>().Count();
|
||||
|
||||
Assert.Equal(1, telemetriesCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostInfoAsync_twice_should_be_ok()
|
||||
{
|
||||
// arrange
|
||||
dbContext.CleanupDbSet<Telemetry>();
|
||||
|
||||
// act
|
||||
_ = await client.PostInfoAsync(uid, telemetryInfoDto, CancellationToken.None);
|
||||
var response = await client.PostInfoAsync(uid, telemetryInfoDto, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||
var telemetriesCount = dbContext.Set<Telemetry>().Count();
|
||||
|
||||
Assert.Equal(1, telemetriesCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostUsersAsync()
|
||||
{
|
||||
// arrange
|
||||
dbContext.CleanupDbSet<Telemetry>();
|
||||
dbContext.Set<Telemetry>().Add(telemetry);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
// act
|
||||
var response = await client.PostUsersAsync(uid, users, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||
var telemetriesCount = dbContext.Set<Telemetry>().Count();
|
||||
var telemetryUserCount = dbContext.Set<TelemetryUser>().Count();
|
||||
|
||||
Assert.Equal(1, telemetriesCount);
|
||||
Assert.Equal(1, telemetryUserCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostUsers_twice_should_be_ok()
|
||||
{
|
||||
// arrange
|
||||
dbContext.CleanupDbSet<TelemetryUser>();
|
||||
dbContext.CleanupDbSet<Telemetry>();
|
||||
dbContext.Set<Telemetry>().Add(telemetry);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
// act
|
||||
_ = await client.PostUsersAsync(uid, users, CancellationToken.None);
|
||||
var response = await client.PostUsersAsync(uid, users, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
@ -69,7 +132,10 @@ public class TelemetryControllerTest : BaseIntegrationTest
|
||||
public async Task PostEventsAsync()
|
||||
{
|
||||
// arrange
|
||||
dbContext.CleanupDbSet<TelemetryEvent>();
|
||||
dbContext.CleanupDbSet<Telemetry>();
|
||||
dbContext.Set<Telemetry>().Add(telemetry);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
// act
|
||||
var response = await client.PostEventsAsync(uid, events, CancellationToken.None);
|
||||
@ -83,12 +149,40 @@ public class TelemetryControllerTest : BaseIntegrationTest
|
||||
Assert.Equal(1, telemetryEventCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostEventsAsync_twice_should_be_ok()
|
||||
{
|
||||
// arrange
|
||||
dbContext.CleanupDbSet<TelemetryEvent>();
|
||||
dbContext.CleanupDbSet<Telemetry>();
|
||||
dbContext.Set<Telemetry>().Add(telemetry);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
// act
|
||||
_ = await client.PostEventsAsync(uid, events, CancellationToken.None);
|
||||
var response = await client.PostEventsAsync(uid, events, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||
var telemetriesCount = dbContext.Set<Telemetry>().Count();
|
||||
var telemetryEventCount = dbContext.Set<TelemetryEvent>().Count();
|
||||
|
||||
Assert.Equal(1, telemetriesCount);
|
||||
Assert.Equal(1, telemetryEventCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostMessagesAsync()
|
||||
{
|
||||
// arrange
|
||||
dbContext.CleanupDbSet<TelemetryMessage>();
|
||||
dbContext.CleanupDbSet<TelemetryEvent>();
|
||||
dbContext.CleanupDbSet<TelemetryUser>();
|
||||
dbContext.CleanupDbSet<Telemetry>();
|
||||
|
||||
dbContext.Set<Telemetry>().Add(telemetry);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
// act
|
||||
_ = await client.PostEventsAsync(uid, events, CancellationToken.None);
|
||||
_ = await client.PostUsersAsync(uid, users, CancellationToken.None);
|
||||
@ -106,4 +200,34 @@ public class TelemetryControllerTest : BaseIntegrationTest
|
||||
Assert.Equal(1, telemetryUserCount);
|
||||
Assert.Equal(1, telemetryMessageCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PostMessagesAsync_twice_should_be_ok()
|
||||
{
|
||||
// arrange
|
||||
dbContext.CleanupDbSet<TelemetryMessage>();
|
||||
dbContext.CleanupDbSet<TelemetryEvent>();
|
||||
dbContext.CleanupDbSet<TelemetryUser>();
|
||||
dbContext.CleanupDbSet<Telemetry>();
|
||||
dbContext.Set<Telemetry>().Add(telemetry);
|
||||
dbContext.SaveChanges();
|
||||
|
||||
// act
|
||||
_ = await client.PostEventsAsync(uid, events, CancellationToken.None);
|
||||
_ = await client.PostUsersAsync(uid, users, CancellationToken.None);
|
||||
_ = await client.PostMessagesAsync(uid, messages, CancellationToken.None);
|
||||
var response = await client.PostMessagesAsync(uid, messages, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
|
||||
var telemetriesCount = dbContext.Set<Telemetry>().Count();
|
||||
var telemetryEventCount = dbContext.Set<TelemetryEvent>().Count();
|
||||
var telemetryUserCount = dbContext.Set<TelemetryUser>().Count();
|
||||
var telemetryMessageCount = dbContext.Set<TelemetryMessage>().Count();
|
||||
|
||||
Assert.Equal(1, telemetriesCount);
|
||||
Assert.Equal(1, telemetryEventCount);
|
||||
Assert.Equal(1, telemetryUserCount);
|
||||
Assert.Equal(2, telemetryMessageCount);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.WellOperation;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure;
|
||||
using AsbCloudWebApi.IntegrationTests.Clients;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Net;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
||||
|
||||
public class WellControllerTest : BaseIntegrationTest
|
||||
{
|
||||
|
||||
private static readonly WellOperationDto wellOperationDto = new()
|
||||
{
|
||||
DateStart = DateTimeOffset.UtcNow,
|
||||
Day = 1,
|
||||
DepthEnd = 1000,
|
||||
DepthStart = 500,
|
||||
DurationHours = 5,
|
||||
Id = 1,
|
||||
IdCategory = 5095,
|
||||
IdPlan = null,
|
||||
IdType = 1,
|
||||
IdUser = 1,
|
||||
IdWell = 1,
|
||||
IdWellSectionType = 1,
|
||||
NptHours = 5
|
||||
};
|
||||
|
||||
private readonly IWellClient wellClient;
|
||||
private readonly IWellOperationClient wellOperationClient;
|
||||
|
||||
public WellControllerTest(WebAppFactoryFixture factory)
|
||||
: base(factory)
|
||||
{
|
||||
wellClient = factory.GetAuthorizedHttpClient<IWellClient>(string.Empty);
|
||||
wellOperationClient = factory.GetAuthorizedHttpClient<IWellOperationClient>(string.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CheckDateStartForWell_returns_success()
|
||||
{
|
||||
//act
|
||||
var wellOperationDto1 = wellOperationDto.Adapt<WellOperationDto>();
|
||||
wellOperationDto1.DateStart = DateTimeOffset.UtcNow;
|
||||
wellOperationDto1.Id = 2;
|
||||
|
||||
var wellOperations = new List<WellOperationDto>() { wellOperationDto, wellOperationDto1 };
|
||||
var insertedRedult = await wellOperationClient.InsertRangeAsync(1, false, wellOperations);
|
||||
|
||||
var wellResponse = await wellClient.GetWellsAsync();
|
||||
|
||||
//assert
|
||||
Assert.Equal(HttpStatusCode.OK, wellResponse.StatusCode);
|
||||
Assert.NotNull(wellResponse.Content);
|
||||
|
||||
var expectedCount = await dbContext.Wells.CountAsync();
|
||||
Assert.Equal(expectedCount, wellResponse.Content.Count());
|
||||
|
||||
var actualFirstStartDate = wellResponse.Content.ElementAt(0).StartDate!.Value.ToUniversalTime();
|
||||
var expectedFirstStartDate = wellOperations.MinByOrDefault(o => o.DateStart)!.DateStart.ToUniversalTime();
|
||||
Assert.Equal(expectedFirstStartDate.ToString(), actualFirstStartDate.ToString());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user