forked from ddrilling/AsbCloudServer
Fix Test for TelemetryController.PostMessagesAsync(..) Time to utc.
This commit is contained in:
parent
04f0b4e275
commit
d5deafeb0f
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user