forked from ddrilling/AsbCloudServer
Fix DrillTestController.PostDataAsync(..). Теперь можно добавлять повторяющиеся дрилтесты.
This commit is contained in:
parent
c6a9797255
commit
d0eeddaca4
@ -227,7 +227,7 @@ namespace AsbCloudDb
|
|||||||
DateTime vDate => $"'{FormatDateValue(vDate)}'",
|
DateTime vDate => $"'{FormatDateValue(vDate)}'",
|
||||||
DateTimeOffset vDate => $"'{FormatDateValue(vDate.UtcDateTime)}'",
|
DateTimeOffset vDate => $"'{FormatDateValue(vDate.UtcDateTime)}'",
|
||||||
IFormattable vFormattable => FormatFormattableValue(vFormattable),
|
IFormattable vFormattable => FormatFormattableValue(vFormattable),
|
||||||
_ => System.Text.Json.JsonSerializer.Serialize(v),
|
_ => $"'{EscapeCurlyBraces(JsonSerializer.Serialize(v))}'",
|
||||||
};
|
};
|
||||||
|
|
||||||
private static string EscapeCurlyBraces(string vStr)
|
private static string EscapeCurlyBraces(string vStr)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudDb;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -68,11 +69,12 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
var entities = dtos.Select(dto =>
|
var entities = dtos.Select(dto =>
|
||||||
{
|
{
|
||||||
var entity = dto.Adapt<DrillTest>();
|
var entity = dto.Adapt<DrillTest>();
|
||||||
|
entity.TimeStampStart = dto.TimeStampStart.ToUniversalTime();
|
||||||
entity.IdTelemetry = idTelemetry;
|
entity.IdTelemetry = idTelemetry;
|
||||||
return entity;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
}
|
@ -1,9 +1,6 @@
|
|||||||
using AsbCloudApp.Data;
|
|
||||||
using AsbCloudApp.Requests;
|
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudWebApi.IntegrationTests.Clients;
|
using AsbCloudWebApi.IntegrationTests.Clients;
|
||||||
using AsbCloudWebApi.IntegrationTests.Data;
|
using AsbCloudWebApi.IntegrationTests.Data;
|
||||||
using System;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user