|
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PostDeploymentTests
{
[TestClass]
public class WindowsServiceTest
{
[TestMethod]
[TestCategory("PostDeployment")]
public void TestSimpleWindowsService()
{
// This value is updated by the build workflow
string hostName = ConfigurationManager.AppSettings["TestEnvironment"];
TestWindowsService("SimpleWindowsService", hostName);
}
private void TestWindowsService(string serviceName, string hostName)
{
using (ServiceController sc = new ServiceController(serviceName, hostName))
{
// Ensure the service is running
if (!(sc.Status == ServiceControllerStatus.Running))
{
WindowsServiceHelper.StartService(serviceName, hostName);
// This will wait up to a minute for the service to be started
bool isRunning = WindowsServiceHelper.PollServiceStatus(serviceName, hostName, 60, 1000, ServiceControllerStatus.Running);
if(!isRunning)
throw new AssertFailedException(string.Format("Service {0} is not running and cannot be started", serviceName));
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.