コード例 #1
0
 public void WindowsServiceControlManagerShouldInstallService()
 {
     using (var tc = CreateTestContext())
     {
         var serviceControlManager = new WindowsServiceControlManager();
         serviceControlManager.Initialize(tc);
         var agentSettings = new AgentSettings { ServerUrl = "http://server.name", AgentName = "myagent" };
         var command = new CommandSettings(
             tc,
             new[]
             {
                 "--windowslogonaccount", _expectedLogonAccount,
                 "--windowslogonpassword", _expectedLogonPassword,
                 "--unattended"
             });
         serviceControlManager.ConfigureService(agentSettings, command);
         Assert.Equal("vstsagent.server.myagent", serviceControlManager.ServiceName);
         Assert.Equal("VSTS Agent (server.myagent)", serviceControlManager.ServiceDisplayName);
     }
 }
コード例 #2
0
        public void CheckServiceExistsShouldWorkCorrectly()
        {
            using (var tc = CreateTestContext())
            {
                var serviceControlManager = new WindowsServiceControlManager();
                serviceControlManager.Initialize(tc);

                Assert.Equal(serviceControlManager.CheckServiceExists("NoService" + Guid.NewGuid()), false);
                // TODO: qvoid creating testable and write a wrapper for ServiceController as it can't be mocked 
                _windowsServiceHelper.Setup(x => x.TryGetServiceController("test"))
                    .Returns(new ServiceController("test"));

                Assert.Equal(serviceControlManager.CheckServiceExists("test"), true);
            }
        }