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
{
///
/// Initializes test dependencies for unit tests, including
/// RabbitMQ options, a mocked logger, an instance of the service under test, and the set
/// of Windows platform identifiers used to validate platform-specific behavior.
///
[SetUp]
public void Setup()
{
_optionsRabbitMqSettings = Options.Create(_rabbitMqSettings);
_logger = new Mock>();
_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 _optionsRabbitMqSettings = null!;
private Mock> _logger = null!;
private PlatformID[] _windowsPlatforms = null!;
///
/// Verifies that .GetConsumedCpu returns a valid performance CPU
/// reading (non-null with a positive ValueTotal) when executed on a Windows platform. When the
/// host operating system is not Windows, the test is skipped with an ignore notice.
///
[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.");
}
}
///
/// Verifies that GetConsumedRam returns a non-null performance RAM data object with positive values
/// for PercentageConsumed, ValueConsumed, and ValueTotal. The test only executes on
/// Windows platforms and is ignored on other operating systems.
///
[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.");
}
}
///
/// Integration test that verifies the GetConsumedStorage method returns valid Performance data with positive percentage and value metrics for all ready drives on Windows platforms. The test is ignored when executed on a non-Windows platform.
///
[Ignore("Integration test to pull request")]
[Test]
public void GetConsumedStorage_Return_PerformanceStorage_data()
{
if (_windowsPlatforms.Contains(Environment.OSVersion.Platform))
{
List 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.");
}
}
}