DD.WellWorkover.Cloud/AsbCloudWebApi.Tests/ServicesTests/TelemetryDataSaubServiceTest.cs

89 lines
3.2 KiB
C#
Raw Normal View History

2022-01-09 11:46:27 +05:00
using AsbCloudApp.Data;
2022-04-08 13:10:06 +05:00
using AsbCloudApp.Data.SAUB;
2022-01-09 11:46:27 +05:00
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
2022-04-11 18:00:34 +05:00
using AsbCloudInfrastructure.Services.SAUB;
2022-01-09 11:46:27 +05:00
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace AsbCloudWebApi.Tests.ServicesTests
{
public class TelemetryDataSaubServiceTest
{
private readonly Mock<ITelemetryTracker> telemetryTracker;
private readonly Mock<ITimezoneService> timezoneService;
private readonly SimpleTimezoneDto timezone;
private readonly AsbCloudDbContext context;
private readonly CacheDb cacheDb;
private readonly TelemetryService telemetryService;
private readonly DateTime drillingStartDate;
2022-06-15 14:57:37 +05:00
private readonly string uuid;
2022-01-09 11:46:27 +05:00
public TelemetryDataSaubServiceTest()
{
timezone = new() { Hours = 7 };
drillingStartDate = new DateTime(2022, 1, 1, 0, 0, 0, DateTimeKind.Unspecified);
uuid = drillingStartDate.ToString("yyyyMMdd_HHmmssfff");
AsbCloudInfrastructure.DependencyInjection.MapsterSetup();
telemetryTracker = new Mock<ITelemetryTracker>();
timezoneService = new Mock<ITimezoneService>();
timezoneService.Setup(s => s.GetByCoordinatesAsync(It.IsAny<double>(), It.IsAny<double>(), It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(timezone));
timezoneService.Setup(s => s.GetByCoordinates(It.IsAny<double>(), It.IsAny<double>()))
.Returns(timezone);
context = TestHelpter.MakeTestContext();
cacheDb = new CacheDb();
telemetryService = new TelemetryService(context, telemetryTracker.Object, timezoneService.Object, cacheDb);
var info = new TelemetryInfoDto
{
TimeZoneOffsetTotalHours = timezone.Hours,
DrillingStartDate = drillingStartDate,
};
telemetryService.UpdateInfoAsync(uuid, info, CancellationToken.None).Wait();
}
~TelemetryDataSaubServiceTest()
{
var ts = context.Telemetries.Where(t => t.RemoteUid == uuid);
context.Telemetries.RemoveRange(ts);
context.SaveChanges();
context?.Dispose();
}
[Fact]
public async Task UpdateDataAsync()
{
// Arrange
var telemetryDataSaubService = new TelemetryDataSaubService(context, telemetryService, cacheDb);
2022-06-15 14:57:37 +05:00
2022-01-09 11:46:27 +05:00
var now = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(timezone.Hours)).DateTime;
var tuser = "Завулон";
var newData = new List<TelemetryDataSaubDto>
2022-06-15 14:57:37 +05:00
{
2022-01-09 11:46:27 +05:00
new TelemetryDataSaubDto{
2022-04-08 13:10:06 +05:00
DateTime = now,
2022-01-09 11:46:27 +05:00
AxialLoad = 1,
MseState = 1,
User = tuser,
2022-06-15 14:57:37 +05:00
}
2022-01-09 11:46:27 +05:00
};
// act
var affected = await telemetryDataSaubService.UpdateDataAsync(uuid, newData, CancellationToken.None);
2022-06-15 14:57:37 +05:00
2022-01-09 11:46:27 +05:00
// assert
Assert.Equal(1, affected);
}
}
}