private ToolStripMenuItem createChangePasswordMenuItem(HostPwEntry hostPwEntry) { IPasswordChanger pwChanger = null; var hostTypeMapper = new HostTypeMapper(new HostTypeSafeConverter()); var hostType = hostTypeMapper.Get(hostPwEntry); if (hostType == HostType.ESXi && QuickConnectUtils.IsVSpherePowerCLIInstalled()) { pwChanger = new ESXiPasswordChanger(); } else if (hostType == HostType.Windows && !String.IsNullOrEmpty(this.Settings.PsPasswdPath) && File.Exists(this.Settings.PsPasswdPath) && PsPasswdWrapper.IsPsPasswdUtility(this.Settings.PsPasswdPath) && PsPasswdWrapper.IsSupportedVersion(this.Settings.PsPasswdPath) ) { pwChanger = new WindowsPasswordChanger(new PsPasswdWrapper(this.Settings.PsPasswdPath)); } else if (hostType == HostType.Linux) { PuttyOptions puttyOptions = null; bool success = PuttyOptionsParser.TryParse(hostPwEntry.AdditionalOptions, out puttyOptions); // Disable change password menu item if authentication is done using SSH key file. if (!success || (success && !puttyOptions.HasKeyFile())) { int?sshPort = null; if (success) { sshPort = puttyOptions.Port; } pwChanger = new LinuxPasswordChanger() { SshPort = sshPort }; } } var menuItem = new ToolStripMenuItem() { Text = ChangePasswordMenuItemText, Enabled = hostPwEntry.HasIPAddress && pwChanger != null }; menuItem.Click += new EventHandler( delegate(object obj, EventArgs ev) { try { var pwDatabase = new PasswordDatabase(this.pluginHost.Database); var pwChangerService = new PasswordChangerServiceWrapper(pwDatabase, pwChanger); using (var formPasswordChange = new FormPasswordChanger(hostPwEntry, pwChangerService)) { formPasswordChange.ShowDialog(); } } catch (Exception ex) { log(ex); } } ); return(menuItem); }
public void Get() { var hostTypeConverter = new Mock <IHostTypeConverter>(); hostTypeConverter.Setup(x => x.Convert(ConnectionMethodType.vSphereClient)).Returns(HostType.ESXi); hostTypeConverter.Setup(x => x.Convert(ConnectionMethodType.PuttySSH)).Returns(HostType.Linux); var hostPwEntry = new Mock <IHostPwEntry>(); hostPwEntry.SetupGet(x => x.HasConnectionMethods).Returns(true); hostPwEntry.SetupGet(x => x.ConnectionMethods).Returns( new Collection <ConnectionMethodType>() { ConnectionMethodType.vSphereClient, ConnectionMethodType.PuttySSH } ); var hostTypeMapper = new HostTypeMapper(hostTypeConverter.Object); Assert.AreEqual(HostType.ESXi, hostTypeMapper.Get(hostPwEntry.Object)); }