SensorCollectorTest.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Linq;
  2. using System.Runtime.InteropServices;
  3. using LibreHardwareMonitor.Hardware;
  4. using Xunit;
  5. namespace OhmGraphite.Test
  6. {
  7. public class SensorCollectorTest
  8. {
  9. [Fact]
  10. public void SensorsAddedWhenHardwareAdded()
  11. {
  12. if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
  13. {
  14. return;
  15. }
  16. var computer = new Computer();
  17. using var collector = new SensorCollector(computer, MetricConfig.ParseAppSettings(new BlankConfig()));
  18. collector.Open();
  19. var unused = collector.ReadAllSensors().Count();
  20. computer.IsCpuEnabled = true;
  21. computer.IsMotherboardEnabled = true;
  22. computer.IsStorageEnabled = true;
  23. computer.IsMemoryEnabled = true;
  24. var addedCount = collector.ReadAllSensors().Count();
  25. // On CI platforms there may be no detected hardware
  26. if (addedCount <= 0)
  27. {
  28. return;
  29. }
  30. computer.IsCpuEnabled = false;
  31. computer.IsMotherboardEnabled = false;
  32. computer.IsStorageEnabled = false;
  33. computer.IsMemoryEnabled = false;
  34. var removedCount = collector.ReadAllSensors().Count();
  35. Assert.True(addedCount > removedCount, "addedCount > removedCount");
  36. }
  37. }
  38. }