public static string CollectPasssword(IPasswordCollector passwordCollector, EnvironmentInfo environmentInfo, string machineName, string userId, out EnvironmentUser environmentUser) { if (passwordCollector == null) { throw new ArgumentNullException("passwordCollector"); } if (environmentInfo == null) { throw new ArgumentNullException("environmentInfo"); } if (string.IsNullOrEmpty(machineName)) { throw new ArgumentException("Argument can't be null nor empty.", "machineName"); } if (string.IsNullOrEmpty(userId)) { throw new ArgumentException("Argument can't be null nor empty.", "userId"); } environmentUser = environmentInfo.GetEnvironmentUserByName(userId); if (environmentUser == null) { throw new InvalidOperationException(string.Format("There's no environment user with id '{0}' defined in environment named '{1}'.", userId, environmentInfo.Name)); } string environmentUserPassword = passwordCollector.CollectPasswordForUser( environmentInfo.Name, machineName, environmentUser.UserName); if (string.IsNullOrEmpty(environmentUserPassword)) { throw new InvalidOperationException(string.Format("Couldn't obtain password for user named '{0}' for environment named '{1}'.", environmentUser.UserName, environmentInfo.Name)); } return environmentUserPassword; }
public void Test_InstallNtServiceDeploymentStepServiceDirPathDoesntExist() { const string serviceName = "serviceName"; const string serviceDir = "serviceDir"; const string artifactsRepo = "artifactsRepo"; const string projectName = "projectName"; const string buildID = "id"; const string envName = "envName"; const string baseDirPath = "c:\\basedir"; string machine = Environment.MachineName; var ntServiceProjectInfo = new NtServiceProjectInfo( "name", artifactsRepo, "artifactsRepoDir", false, serviceName, serviceDir, "serviceDisplayed", "exeName", "Sample.User"); var envInfo = new EnvironmentInfo( "name", "templates", machine, "failover", new[] { "webmachine" }, "terminalmachine", "databasemachine", baseDirPath, "webbasedir", "scheduler", "terminal", false, _EnvironmentUsers, _ProjectToFailoverClusterGroupMappings); _environmentInfoRepository .Setup(e => e.GetByName(envName)) .Returns(envInfo); _passwordCollector .Setup(pc => pc.CollectPasswordForUser(envInfo.Name, envInfo.AppServerMachineName, envInfo.GetEnvironmentUserByName(ntServiceProjectInfo.NtServiceUserId).UserName)) .Returns("some password"); _ntServiceManager .Setup(n => n.DoesServiceExist(machine, serviceName)) .Returns(false); _artifactsRepository .Setup(a => a.GetArtifacts(artifactsRepo,projectName, buildID, It.IsAny<string>())); var deployNTService = new DeployNtServiceDeploymentTask( _environmentInfoRepository.Object, _artifactsRepository.Object, _ntServiceManager.Object, _passwordCollector.Object, _failoverClusterManager.Object, ntServiceProjectInfo, projectName, buildID, envName); Assert.Throws<DeploymentTaskException>(deployNTService.PrepareAndExecute); }