コード例 #1
0
        private async Task <WindowsInstanceCredentials> CreateOrResetCredentialsAsync(string user)
        {
            try
            {
                Debug.WriteLine("The user requested the password to be generated.");
                if (!UserPromptService.Default.ActionPrompt(
                        prompt: String.Format(Resources.ResetPasswordConfirmationPromptMessage, user, _instance.Name),
                        title: Resources.ResetPasswordConfirmationPromptTitle,
                        message: Resources.UiOperationCannotBeUndone,
                        actionCaption: Resources.UiResetButtonCaption,
                        isWarning: true))
                {
                    Debug.WriteLine("The user cancelled resetting the password.");
                    return(null);
                }

                Debug.WriteLine($"Resetting the password for the user {user}");
                if (!await GCloudWrapperUtils.VerifyGCloudDependenciesAsync())
                {
                    Debug.WriteLine("Gcloud dependencies not met, aborting change of password.");
                    return(null);
                }

                var context = new GCloudContext();
                return(await context.ResetWindowsCredentialsAsync(_instance.Name, _instance.GetZoneName(), user));
            }
            catch (GCloudException ex)
            {
                UserPromptService.Default.ErrorPrompt(
                    message: String.Format(Resources.ResetPasswordFailedPromptMessage, _instance.Name),
                    title: Resources.ResetPasswordConfirmationPromptTitle,
                    errorDetails: ex.Message);
                return(null);
            }
        }
コード例 #2
0
        public async Task TestMissingComponentPrompt()
        {
            _validateGCloudAsyncSource.SetResult(GCloudValidationResult.MissingComponent);

            _showCopyablePromptMock
            .Setup(a => a(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string, string>((title, message, copyableMessage) =>
            {
                Assert.AreEqual(s_missingComponentTitle, title);
                Assert.AreEqual(s_missingComponentMessage, message);
                Assert.AreEqual(s_missingComponentInstallCommand, copyableMessage, false);
            });

            await GCloudWrapperUtils.VerifyGCloudDependenciesAsync(GCloudComponent.Kubectl);

            _showCopyablePromptMock.Verify(a => a(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }