115 lines
3.5 KiB
C#
115 lines
3.5 KiB
C#
using adas_core.Domain.Models.AppSettings;
|
|
using adas_core.Domain.Models.SystemAlerts;
|
|
using adas_core.Infrastructure.Services;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using Moq;
|
|
|
|
namespace adas_core.Test.Services;
|
|
|
|
[TestFixture]
|
|
public class SendAlertServiceTest
|
|
{
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_optionsRabbitMqSettings = Options.Create(_rabbitMqSettings);
|
|
|
|
_logger = new Mock<ILogger<SendAlertService>>();
|
|
|
|
_sendAlertService = new SendAlertService(
|
|
_optionsRabbitMqSettings,
|
|
_logger.Object
|
|
);
|
|
|
|
_windowsPlatforms =
|
|
[
|
|
PlatformID.Win32NT,
|
|
PlatformID.Win32S,
|
|
PlatformID.Win32Windows,
|
|
PlatformID.WinCE
|
|
];
|
|
}
|
|
|
|
private SendAlertService _sendAlertService = null!;
|
|
|
|
private readonly RabbitMqSettings _rabbitMqSettings = new();
|
|
private IOptions<RabbitMqSettings> _optionsRabbitMqSettings = null!;
|
|
|
|
private Mock<ILogger<SendAlertService>> _logger = null!;
|
|
|
|
private PlatformID[] _windowsPlatforms = null!;
|
|
|
|
[Ignore("Integration test to pull request")]
|
|
[Test]
|
|
public void GetConsumedCpu_Return_PerformanceCpu_data()
|
|
{
|
|
if (_windowsPlatforms.Contains(Environment.OSVersion.Platform))
|
|
{
|
|
var result = _sendAlertService.GetConsumedCpu();
|
|
//result = await sendAlertService.GetConsumedCpu();
|
|
|
|
Assert.That(result, Is.Not.Null);
|
|
Assert.That(result.ValueTotal, Is.GreaterThan(0));
|
|
}
|
|
else
|
|
{
|
|
Assert.Ignore("This test can only be run on Windows.");
|
|
}
|
|
}
|
|
|
|
|
|
[Ignore("Integration test to pull request")]
|
|
[Test]
|
|
public void GetConsumedRAM_Return_PerformanceRAM_data()
|
|
{
|
|
if (_windowsPlatforms.Contains(Environment.OSVersion.Platform))
|
|
{
|
|
var result = _sendAlertService.GetConsumedRam();
|
|
//result = await sendAlertService.GetConsumedRAM();
|
|
|
|
Assert.That(result, Is.Not.Null);
|
|
using (Assert.EnterMultipleScope())
|
|
{
|
|
Assert.That(result.PercentageConsumed, Is.GreaterThan(0));
|
|
Assert.That(result.ValueConsumed, Is.GreaterThan(0));
|
|
Assert.That(result.ValueTotal, Is.GreaterThan(0));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Assert.Ignore("This test can only be run on Windows.");
|
|
}
|
|
}
|
|
|
|
[Ignore("Integration test to pull request")]
|
|
[Test]
|
|
public void GetConsumedStorage_Return_PerformanceStorage_data()
|
|
{
|
|
if (_windowsPlatforms.Contains(Environment.OSVersion.Platform))
|
|
{
|
|
List<Performance> performanceList = [];
|
|
|
|
foreach (var drive in DriveInfo.GetDrives())
|
|
if (drive.IsReady)
|
|
{
|
|
var performance = _sendAlertService.GetConsumedStorage(drive);
|
|
|
|
performanceList.Add(performance);
|
|
}
|
|
|
|
Assert.That(performanceList, Is.Not.Null);
|
|
using (Assert.EnterMultipleScope())
|
|
{
|
|
Assert.That(performanceList, Is.Not.Empty);
|
|
Assert.That(performanceList[0].PercentageConsumed, Is.GreaterThan(0));
|
|
Assert.That(performanceList[0].ValueConsumed, Is.GreaterThan(0));
|
|
Assert.That(performanceList[0].ValueTotal, Is.GreaterThan(0));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Assert.Ignore("This test can only be run on Windows.");
|
|
}
|
|
}
|
|
} |