public void NtServiceDescriptorConstructor_WhenEverythinkIsOk_AllPropertiesHavaCorrectValues() { // Arrange string serviceName = "serviceName"; string serviceExecutablePath = "serviceExecutablePath"; ServiceAccount serviceAccount = ServiceAccount.LocalSystem; ServiceStartMode serviceStartMode = ServiceStartMode.Automatic; string serviceDisplayName = "serviceDisplayName"; string serviceUserName = "******"; string servicePassword = "******"; // Act var ntServiceDescriptor = new NtServiceDescriptor(serviceName, serviceExecutablePath, serviceAccount, serviceStartMode, serviceDisplayName, serviceUserName, servicePassword); // Assert Assert.AreEqual(serviceName, ntServiceDescriptor.ServiceName); Assert.AreEqual(serviceExecutablePath, ntServiceDescriptor.ServiceExecutablePath); Assert.AreEqual(serviceAccount, ntServiceDescriptor.ServiceAccount); Assert.AreEqual(serviceStartMode, ntServiceDescriptor.ServiceStartMode); Assert.AreEqual(serviceDisplayName, ntServiceDescriptor.ServiceDisplayName); Assert.AreEqual(serviceUserName, ntServiceDescriptor.ServiceUserName); Assert.AreEqual(servicePassword, ntServiceDescriptor.ServicePassword); }
public void Test_InstallNtServiceDeploymentStep_Thows_When_MachineName_null() { var ntServiceDescriptor = new NtServiceDescriptor( "serviceName", "serviceExecutablePath", new ServiceAccount(), ServiceStartMode.Automatic); var ntServiceManager = new Mock <INtServiceManager>(MockBehavior.Strict); Assert.Throws <ArgumentException>( () => { new InstallNtServiceDeploymentStep(ntServiceManager.Object, null, ntServiceDescriptor); }); }
public void Test_InstallNtServiceDeploymentStep() { const string machineName = "machine"; var ntServiceDescriptor = new NtServiceDescriptor( "serviceName", "serviceExecutablePath", new ServiceAccount(), ServiceStartMode.Automatic); var ntServiceManager = new Mock <INtServiceManager>(MockBehavior.Strict); var installNTServiceStep = new InstallNtServiceDeploymentStep(ntServiceManager.Object, machineName, ntServiceDescriptor); ntServiceManager.Setup(k => k.InstallService(machineName, ntServiceDescriptor)); installNTServiceStep.PrepareAndExecute(); }
public InstallNtServiceDeploymentStep(INtServiceManager ntServiceManager, string machineName, NtServiceDescriptor ntServiceDescriptor) { if (ntServiceManager == null) { throw new ArgumentNullException("ntServiceManager"); } if (string.IsNullOrEmpty(machineName)) { throw new ArgumentException("Argument can't be null nor empty.", "machineName"); } if (ntServiceDescriptor == null) { throw new ArgumentNullException("ntServiceDescriptor"); } _ntServiceManager = ntServiceManager; _machineName = machineName; _ntServiceDescriptor = ntServiceDescriptor; }
private void DoPrepareCommonDeploymentSteps(string ntServiceName, string appServerMachineName, string ntServicesBaseDirPath, Func <string, string> getAppServerNetworkPathFunc, Lazy <string> artifactsBinariesDirPathProvider, Func <CollectedCredentials> collectCredentialsFunc, bool startServiceAfterDeployment) { // check if the service is present on the target machine bool serviceExists = _ntServiceManager .DoesServiceExist(appServerMachineName, ntServiceName); if (serviceExists) { // create a step for stopping the service AddSubTask( new StopNtServiceDeploymentStep( _ntServiceManager, appServerMachineName, _projectInfo.NtServiceName)); } // create a step for copying the binaries to the target machine string targetDirPath = Path.Combine(ntServicesBaseDirPath, _projectInfo.NtServiceDirName); /* // TODO IMM HI: xxx we don't need this for now - should we parameterize this somehow? * // create a backup step if needed * string targetDirNetworkPath = getAppServerNetworkPathFunc(targetDirPath); * * if (Directory.Exists(targetDirNetworkPath)) * { * AddSubTask( * new BackupFilesDeploymentStep( * targetDirNetworkPath)); * } */ string[] excludedDirs = string.IsNullOrEmpty(_projectInfo.ExtensionsDirName) ? new string[0] : new string[] { _projectInfo.ExtensionsDirName }; AddSubTask( new CleanDirectoryDeploymentStep( _directoryAdapter, _fileAdapter, new Lazy <string>(() => getAppServerNetworkPathFunc(targetDirPath)), excludedDirs: excludedDirs)); AddSubTask( new CopyFilesDeploymentStep( _directoryAdapter, artifactsBinariesDirPathProvider, new Lazy <string>(() => getAppServerNetworkPathFunc(targetDirPath)))); if (!serviceExists) { // collect credentials CollectedCredentials collectedCredentials = collectCredentialsFunc(); // create a step for installing the service, string serviceExecutablePath = Path.Combine(targetDirPath, _projectInfo.NtServiceExeName); var ntServiceDescriptor = new NtServiceDescriptor( _projectInfo.NtServiceName, serviceExecutablePath, ServiceAccount.NetworkService, ServiceStartMode.Automatic, _projectInfo.NtServiceDisplayName, collectedCredentials.UserName, collectedCredentials.Password); AddSubTask( new InstallNtServiceDeploymentStep( _ntServiceManager, appServerMachineName, ntServiceDescriptor)); } if (startServiceAfterDeployment) { // create a step for starting the service AddSubTask( new StartNtServiceDeploymentStep( _ntServiceManager, appServerMachineName, _projectInfo.NtServiceName)); } }