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.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using AsbCloudApp.Data.SAUB;
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.Background;
|
using AsbCloudInfrastructure.Background;
|
||||||
using AsbCloudInfrastructure.Services.SAUB;
|
using AsbCloudInfrastructure.Services.SAUB;
|
||||||
@ -14,6 +15,7 @@ namespace AsbCloudInfrastructure.Tests.Services.SAUB;
|
|||||||
|
|
||||||
public class TelemetryDataSaubCacheTests
|
public class TelemetryDataSaubCacheTests
|
||||||
{
|
{
|
||||||
|
private static object _lock = new object();
|
||||||
private const int idTelemetry = 1;
|
private const int idTelemetry = 1;
|
||||||
|
|
||||||
private readonly IEnumerable<TelemetryDataSaubDto> fakeTelemetries = new[]
|
private readonly IEnumerable<TelemetryDataSaubDto> fakeTelemetries = new[]
|
||||||
@ -29,20 +31,22 @@ public class TelemetryDataSaubCacheTests
|
|||||||
public TelemetryDataSaubCacheTests()
|
public TelemetryDataSaubCacheTests()
|
||||||
{
|
{
|
||||||
serviceProviderMock.GetService<BackgroundWorker>().Returns(new BackgroundWorker(serviceProviderMock));
|
serviceProviderMock.GetService<BackgroundWorker>().Returns(new BackgroundWorker(serviceProviderMock));
|
||||||
|
|
||||||
telemetryDataCache = TelemetryDataCache<TelemetryDataSaubDto>.GetInstance<TelemetryDataSaub>(serviceProviderMock);
|
telemetryDataCache = TelemetryDataCache<TelemetryDataSaubDto>.GetInstance<TelemetryDataSaub>(serviceProviderMock);
|
||||||
|
|
||||||
telemetryDataCacheType = telemetryDataCache.GetType();
|
telemetryDataCacheType = telemetryDataCache.GetType();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AddRange_ShouldReturn_AddedElementToCache()
|
public void AddRange_ShouldReturn_AddedElementToCache()
|
||||||
{
|
{
|
||||||
//arrange
|
//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
|
//act
|
||||||
telemetryDataCache.AddRange(idTelemetry, fakeTelemetries);
|
|
||||||
var lastTelemetry = telemetryDataCache.GetLastOrDefault(idTelemetry);
|
var lastTelemetry = telemetryDataCache.GetLastOrDefault(idTelemetry);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
@ -53,10 +57,12 @@ public class TelemetryDataSaubCacheTests
|
|||||||
public void AddRange_ShouldReturn_NotAddedToCache()
|
public void AddRange_ShouldReturn_NotAddedToCache()
|
||||||
{
|
{
|
||||||
//arrange
|
//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
|
//act
|
||||||
telemetryDataCache.AddRange(idTelemetry, fakeTelemetries);
|
|
||||||
var lastTelemetry = telemetryDataCache.GetLastOrDefault(idTelemetry);
|
var lastTelemetry = telemetryDataCache.GetLastOrDefault(idTelemetry);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
|
@ -139,6 +139,9 @@ public class TelemetryDataCache<TDto> : ITelemetryDataCache<TDto> where TDto : A
|
|||||||
|
|
||||||
public virtual TDto? GetLastOrDefault(int idTelemetry)
|
public virtual TDto? GetLastOrDefault(int idTelemetry)
|
||||||
{
|
{
|
||||||
|
if (isLoading)
|
||||||
|
return default;
|
||||||
|
|
||||||
if (!caches.TryGetValue(idTelemetry, out TelemetryDataCacheItem? cacheItem))
|
if (!caches.TryGetValue(idTelemetry, out TelemetryDataCacheItem? cacheItem))
|
||||||
return default;
|
return default;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user