forked from ddrilling/AsbCloudServer
fix unit test
This commit is contained in:
parent
e0d199380f
commit
d416d77573
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Background;
|
||||
using AsbCloudInfrastructure.Services.SAUB;
|
||||
@ -14,6 +15,7 @@ namespace AsbCloudInfrastructure.Tests.Services.SAUB;
|
||||
|
||||
public class TelemetryDataSaubCacheTests
|
||||
{
|
||||
private static object _lock = new object();
|
||||
private const int idTelemetry = 1;
|
||||
|
||||
private readonly IEnumerable<TelemetryDataSaubDto> fakeTelemetries = new[]
|
||||
@ -29,20 +31,22 @@ public class TelemetryDataSaubCacheTests
|
||||
public TelemetryDataSaubCacheTests()
|
||||
{
|
||||
serviceProviderMock.GetService<BackgroundWorker>().Returns(new BackgroundWorker(serviceProviderMock));
|
||||
|
||||
telemetryDataCache = TelemetryDataCache<TelemetryDataSaubDto>.GetInstance<TelemetryDataSaub>(serviceProviderMock);
|
||||
|
||||
telemetryDataCacheType = telemetryDataCache.GetType();
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddRange_ShouldReturn_AddedElementToCache()
|
||||
{
|
||||
//arrange
|
||||
telemetryDataCacheType.GetField("isLoading", BindingFlags.NonPublic | BindingFlags.Instance)?.SetValue(telemetryDataCache, false);
|
||||
telemetryDataCache.AddRange(idTelemetry, fakeTelemetries);
|
||||
|
||||
telemetryDataCacheType
|
||||
.GetField("isLoading", BindingFlags.NonPublic | BindingFlags.Instance)!
|
||||
.SetValue(telemetryDataCache, false);
|
||||
|
||||
//act
|
||||
telemetryDataCache.AddRange(idTelemetry, fakeTelemetries);
|
||||
var lastTelemetry = telemetryDataCache.GetLastOrDefault(idTelemetry);
|
||||
|
||||
//assert
|
||||
@ -53,10 +57,12 @@ public class TelemetryDataSaubCacheTests
|
||||
public void AddRange_ShouldReturn_NotAddedToCache()
|
||||
{
|
||||
//arrange
|
||||
telemetryDataCacheType.GetField("isLoading", BindingFlags.NonPublic | BindingFlags.Instance)?.SetValue(telemetryDataCache, true);
|
||||
telemetryDataCache.AddRange(idTelemetry, fakeTelemetries);
|
||||
telemetryDataCacheType
|
||||
.GetField("isLoading", BindingFlags.NonPublic | BindingFlags.Instance)!
|
||||
.SetValue(telemetryDataCache, true);
|
||||
|
||||
//act
|
||||
telemetryDataCache.AddRange(idTelemetry, fakeTelemetries);
|
||||
var lastTelemetry = telemetryDataCache.GetLastOrDefault(idTelemetry);
|
||||
|
||||
//assert
|
||||
|
@ -139,6 +139,9 @@ public class TelemetryDataCache<TDto> : ITelemetryDataCache<TDto> where TDto : A
|
||||
|
||||
public virtual TDto? GetLastOrDefault(int idTelemetry)
|
||||
{
|
||||
if (isLoading)
|
||||
return default;
|
||||
|
||||
if (!caches.TryGetValue(idTelemetry, out TelemetryDataCacheItem? cacheItem))
|
||||
return default;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user