forked from ddrilling/AsbCloudServer
77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
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);
|
|
}
|
|
} |