forked from ddrilling/AsbCloudServer
65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Reflection;
|
||
|
using AsbCloudApp.Data.SAUB;
|
||
|
using AsbCloudDb.Model;
|
||
|
using AsbCloudInfrastructure.Background;
|
||
|
using AsbCloudInfrastructure.Services.SAUB;
|
||
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
using NSubstitute;
|
||
|
using Xunit;
|
||
|
|
||
|
namespace AsbCloudWebApi.Tests.Services.SAUB;
|
||
|
|
||
|
public class TelemetryDataSaubCacheTests
|
||
|
{
|
||
|
private const int idTelemetry = 1;
|
||
|
|
||
|
private readonly IEnumerable<TelemetryDataSaubDto> fakeTelemetries = new[]
|
||
|
{
|
||
|
new TelemetryDataSaubDto()
|
||
|
};
|
||
|
|
||
|
private readonly IServiceProvider serviceProviderMock = Substitute.For<IServiceProvider>();
|
||
|
|
||
|
private readonly TelemetryDataCache<TelemetryDataSaubDto> telemetryDataCache;
|
||
|
private readonly Type telemetryDataCacheType;
|
||
|
|
||
|
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);
|
||
|
|
||
|
//act
|
||
|
telemetryDataCache.AddRange(idTelemetry, fakeTelemetries);
|
||
|
var lastTelemetry = telemetryDataCache.GetLastOrDefault(idTelemetry);
|
||
|
|
||
|
//assert
|
||
|
Assert.Equal(lastTelemetry, fakeTelemetries.Last());
|
||
|
}
|
||
|
|
||
|
[Fact]
|
||
|
public void AddRange_ShouldReturn_NotAddedToCache()
|
||
|
{
|
||
|
//arrange
|
||
|
telemetryDataCacheType.GetField("isLoading", BindingFlags.NonPublic | BindingFlags.Instance)?.SetValue(telemetryDataCache, true);
|
||
|
|
||
|
//act
|
||
|
telemetryDataCache.AddRange(idTelemetry, fakeTelemetries);
|
||
|
var lastTelemetry = telemetryDataCache.GetLastOrDefault(idTelemetry);
|
||
|
|
||
|
//assert
|
||
|
Assert.Null(lastTelemetry );
|
||
|
}
|
||
|
}
|