Files
ServiceDashBored/EndpointTest/WmiEndpointTest.cs
T
2025-10-11 09:42:00 -04:00

142 lines
3.7 KiB
C#

using Endpoint;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EndpointTest
{
/// <summary>
/// Tests for WmiEndpoint
/// </summary>
[TestClass]
public class WmiEndpointTest
{
private const string MACHINENAME = @"\\localhost";
/// <summary>
/// Run GetStatus using "UpResult" expecting an up status.
/// </summary>
[TestMethod]
public void GetStatusUpPositiveTest()
{
var target = new WmiEndpoint
{
MachineName = MACHINENAME,
ObjectQueryString = "Select * from Win32_Process",
ResultPropertyName = "Name",
UpResult = "System Idle Process"
};
var status = target.GetStatus();
Assert.AreEqual(Status.Up, status);
Assert.AreEqual("System Idle Process", target.StatusDescription);
}
/// <summary>
/// Run GetStatus using "UpResult" expecting an error status.
/// </summary>
[TestMethod]
public void GetStatusUpNegativeTest()
{
var target = new WmiEndpoint
{
MachineName = MACHINENAME,
ObjectQueryString = "Select * from Win32_Process",
ResultPropertyName = "Name",
UpResult = "Not A Real Process"
};
var status = target.GetStatus();
Assert.AreEqual(Status.Error, status);
}
/// <summary>
/// Run GetStatus using "ErrorResult" expecting an error status.
/// </summary>
[TestMethod]
public void GetStatusErrorPositiveTest()
{
var target = new WmiEndpoint
{
MachineName = MACHINENAME,
ObjectQueryString = "Select * from Win32_Process",
ResultPropertyName = "Name",
ErrorResult = "System Idle Process"
};
var status = target.GetStatus();
Assert.AreEqual(Status.Error, status);
}
/// <summary>
/// Run GetStatus using "MinimumThreshold" expecting an up status.
/// </summary>
[TestMethod]
public void GetStatusMinimumThresholdPositiveTest()
{
var target = new WmiEndpoint
{
MachineName = MACHINENAME,
ObjectQueryString = "select FreeSpace from Win32_LogicalDisk where DeviceID='C:'",
ResultPropertyName = "FreeSpace",
MinimumThreshold = 10 // assume you have more than 10B free on C:
};
var status = target.GetStatus();
Assert.AreEqual(Status.Up, status);
}
/// <summary>
/// Run GetStatus using "MinimumThreshold" expecting an up status.
/// </summary>
[TestMethod]
public void GetStatusMinimumThresholdNegativeTest()
{
var target = new WmiEndpoint
{
MachineName = MACHINENAME,
ObjectQueryString = "select FreeSpace from Win32_LogicalDisk where DeviceID='C:'",
ResultPropertyName = "FreeSpace",
MinimumThreshold = 1e15 // assume you have less than a petabyte free on C:
};
var status = target.GetStatus();
Assert.AreEqual(Status.Error, status);
}
/// <summary>
/// Run GetStatus using "MaximumThreshold" expecting an up status.
/// </summary>
[TestMethod]
public void GetStatusMaximumThresholdPositiveTest()
{
var target = new WmiEndpoint
{
MachineName = MACHINENAME,
ObjectQueryString = "select FreeSpace from Win32_LogicalDisk where DeviceID='C:'",
ResultPropertyName = "FreeSpace",
MaximumThreshold = 1e15 // assume you have less than a petabyte free on C:
};
var status = target.GetStatus();
Assert.AreEqual(Status.Up, status);
}
/// <summary>
/// Run GetStatus using "MaximumThreshold" expecting an up status.
/// </summary>
[TestMethod]
public void GetStatusMaximumThresholdNegativeTest()
{
var target = new WmiEndpoint
{
MachineName = MACHINENAME,
ObjectQueryString = "select FreeSpace from Win32_LogicalDisk where DeviceID='C:'",
ResultPropertyName = "FreeSpace",
MaximumThreshold = 10 // assume you have less than a 10B free on C:
};
var status = target.GetStatus();
Assert.AreEqual(Status.Error, status);
}
}
}