public void ConnectionInformationDialog_CreateConnectionInformation_ValidModel_ReturnsConnectionInformation()
        {
            // Setup
            var serverUrl = "https://localhost";
            var username  = "******";
            var inputPlaintextPassword = "******";
            var securePassword         = inputPlaintextPassword.ConvertToSecureString();

            ConnectionInfoDialogViewModel viewModel = ConnectionInformationDialog.CreateViewModel(null);

            viewModel.ServerUrlRaw = serverUrl;
            viewModel.Username     = username;
            viewModel.ValidateCredentials(securePassword);

            // Act
            ConnectionInformation connInfo = ConnectionInformationDialog.CreateConnectionInformation(viewModel, securePassword);

            // Verify
            Assert.IsNotNull(connInfo, "ConnectionInformation should be returned");
            Assert.AreEqual(new Uri(serverUrl), connInfo.ServerUri, "Server URI returned was different");
            Assert.AreEqual(username, connInfo.UserName, "Username returned was different");

            string outputPlaintextPassword = connInfo.Password.ConvertToUnsecureString();

            Assert.AreEqual(inputPlaintextPassword, outputPlaintextPassword, "Password returned was different");
        }
Beispiel #2
0
        public void ConnectionInformationDialog_CreateConnectionInformation_ValidModel_ReturnsConnectionInformation()
        {
            // Arrange
            var serverUrl = "https://localhost";
            var username  = "******";
            var inputPlaintextPassword = "******";
            var securePassword         = inputPlaintextPassword.ToSecureString();

            ConnectionInfoDialogViewModel viewModel = ConnectionInformationDialog.CreateViewModel(null);

            viewModel.ServerUrlRaw = serverUrl;
            viewModel.Username     = username;
            viewModel.ValidateCredentials(securePassword);

            // Act
            ConnectionInformation connInfo = ConnectionInformationDialog.CreateConnectionInformation(viewModel, securePassword);

            // Assert
            connInfo.Should().NotBeNull("ConnectionInformation should be returned");
            connInfo.ServerUri.Should().Be(new Uri(serverUrl), "Server URI returned was different");
            connInfo.UserName.Should().Be(username, "Username returned was different");

            string outputPlaintextPassword = connInfo.Password.ToUnsecureString();

            outputPlaintextPassword.Should().Be(inputPlaintextPassword, "Password returned was different");
        }
Beispiel #3
0
        public void ConnectionInformationDialog_CreateConnectionInformation_WithExistingConnection()
        {
            // Arrange
            var connectionInformation = new ConnectionInformation(new Uri("http://blablabla"), "admin", "P@ssword1".ToSecureString());

            // Act
            ConnectionInfoDialogViewModel viewModel = ConnectionInformationDialog.CreateViewModel(connectionInformation);

            // Assert
            viewModel.ServerUrl.Should().Be(connectionInformation.ServerUri, "Unexpected ServerUrl");
            viewModel.Username.Should().Be(null, "Not expecting the user name to be populated");
        }
        public void ConnectionInformationDialog_CreateConnectionInformation_WithExistingConnection()
        {
            // Setup
            var connectionInformation = new ConnectionInformation(new Uri("http://blablabla"), "admin", "P@ssword1".ConvertToSecureString());

            // Act
            ConnectionInfoDialogViewModel viewModel = ConnectionInformationDialog.CreateViewModel(connectionInformation);

            // Verify
            Assert.AreEqual(connectionInformation.ServerUri, viewModel.ServerUrl, "Unexpected ServerUrl");
            Assert.AreEqual(connectionInformation.UserName, viewModel.Username, "Unexpected UserName");
        }
Beispiel #5
0
        public void ConnectionInformationDialog_CreateConnectionInformation_NullArgumentChecks()
        {
            // Arrange
            ConnectionInfoDialogViewModel viewModel = ConnectionInformationDialog.CreateViewModel(null);

            // Test 1: null viewModel
            Exceptions.Expect <ArgumentNullException>(() =>
            {
                ConnectionInformationDialog.CreateConnectionInformation(null, new SecureString());
            });

            // Test 2: null password
            Exceptions.Expect <ArgumentNullException>(() =>
            {
                ConnectionInformationDialog.CreateConnectionInformation(viewModel, null);
            });
        }
Beispiel #6
0
        public void ConnectionInformationDialog_CreateConnectionInformation_InvalidModel_ReturnsNull()
        {
            // Arrange
            ConnectionInfoDialogViewModel viewModel = ConnectionInformationDialog.CreateViewModel(null);

            viewModel.IsValid.Should().BeFalse("Empty view model should be invalid");
            var emptyPassword = new SecureString();

            // Act
            ConnectionInformation connInfo;

            using (var assertIgnoreScope = new AssertIgnoreScope())
            {
                connInfo = ConnectionInformationDialog.CreateConnectionInformation(viewModel, emptyPassword);
            }

            // Assert
            connInfo.Should().BeNull("No ConnectionInformation should be returned with an invalid model");
        }
        /// <summary>
        /// Handler which attempts to sign in to a SonarQube server.
        /// </summary>
        private async Task OnSignInAsync(object parameter)
        {
            var connectionInfo = ConnectionInformationDialog.ShowDialog(_lastAttemptedSignIn);

            if (connectionInfo is null)
            {
                return;
            }

            _lastAttemptedSignIn = connectionInfo;
            ISonarQubeClient client = null;

            IsSignedIn  = false;
            IsSigningIn = true;

            try
            {
                client = await _clientManager.LogInAsync(new Uri(connectionInfo.ServerUrl), connectionInfo.Login, connectionInfo.Password);

                IsSignedIn = (null != client);
            }
            catch
            {
                IsSignedIn = false;
            }

            IsSigningIn = false;

            if (IsSignedIn)
            {
                _teamExplorer.HideNotification(ConnectionNotificationId);
                NavigateToProjectPage(client);
            }
            else
            {
                _teamExplorer.ShowNotification($"Could not connect to \"{connectionInfo.ServerUrl}\".",
                                               NotificationType.Error, NotificationFlags.None, null, ConnectionNotificationId);
            }
        }