using Endpoint;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace EndpointTest
{
///
/// Tests for WmiEndpoint
///
[TestClass]
public class WmiEndpointTest
{
private const string MACHINENAME = @"\\localhost";
///
/// Run GetStatus using "UpResult" expecting an up status.
///
[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);
}
///
/// Run GetStatus using "UpResult" expecting an error status.
///
[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);
}
///
/// Run GetStatus using "ErrorResult" expecting an error status.
///
[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);
}
///
/// Run GetStatus using "MinimumThreshold" expecting an up status.
///
[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);
}
///
/// Run GetStatus using "MinimumThreshold" expecting an up status.
///
[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);
}
///
/// Run GetStatus using "MaximumThreshold" expecting an up status.
///
[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);
}
///
/// Run GetStatus using "MaximumThreshold" expecting an up status.
///
[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);
}
}
}