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 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(string.Empty); } [Fact] public async Task PostDataAsync() { // arrange dbContext.CleanupDbSet(); dbContext.CleanupDbSet(); dbContext.Set().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().Count(); Assert.Equal(1, count); } [Fact] public async Task PostDataAsync_twice_should_be_ok() { // arrange dbContext.CleanupDbSet(); dbContext.CleanupDbSet(); dbContext.Set().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().Count(); Assert.Equal(1, count); } }