public void SaveRemote_should_throw_if_remoteName_is_null_or_empty()
 {
     ((Action)(() => _controller.SaveRemote(null, null, "b", "c", "d"))).ShouldThrow <ArgumentNullException>()
     .WithMessage("Value cannot be null.\r\nParameter name: remoteName");
     ((Action)(() => _controller.SaveRemote(null, "", "b", "c", "d"))).ShouldThrow <ArgumentNullException>()
     .WithMessage("Value cannot be null.\r\nParameter name: remoteName");
     ((Action)(() => _controller.SaveRemote(null, "  ", "b", "c", "d"))).ShouldThrow <ArgumentNullException>()
     .WithMessage("Value cannot be null.\r\nParameter name: remoteName");
 }
Exemple #2
0
        private void SaveClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(RemoteName.Text))
            {
                return;
            }

            try
            {
                // disable the control while saving
                tabControl1.Enabled = false;

                if ((string.IsNullOrEmpty(comboBoxPushUrl.Text) && checkBoxSepPushUrl.Checked) ||
                    (comboBoxPushUrl.Text.Equals(Url.Text, StringComparison.OrdinalIgnoreCase)))
                {
                    checkBoxSepPushUrl.Checked = false;
                }

                // update all other remote properties
                var result = _gitRemoteController.SaveRemote(_selectedRemote,
                                                             RemoteName.Text,
                                                             Url.Text,
                                                             checkBoxSepPushUrl.Checked ? comboBoxPushUrl.Text : null,
                                                             PuttySshKey.Text);
                if (OnRemoteRenamedOrAdded != null)
                {
                    OnRemoteRenamedOrAdded(
                        _selectedRemote != null? _selectedRemote.Name : RemoteName.Text, RemoteName.Text);
                }

                if (!string.IsNullOrEmpty(result.UserMessage))
                {
                    MessageBox.Show(this, result.UserMessage, _gitMessage.Text);
                }

                // if the user has just created a fresh new remote
                // there may be a need to configure it
                if (result.ShouldUpdateRemote && !string.IsNullOrEmpty(Url.Text) &&
                    DialogResult.Yes == MessageBox.Show(this,
                                                        _questionAutoPullBehaviour.Text,
                                                        _questionAutoPullBehaviourCaption.Text,
                                                        MessageBoxButtons.YesNo))
                {
                    FormRemoteProcess.ShowDialog(this, "remote update");
                    _gitRemoteController.ConfigureRemotes(RemoteName.Text);
                    UICommands.RepoChangedNotifier.Notify();
                }
            }
            finally
            {
                // re-enable the control and re-initialize
                tabControl1.Enabled = true;
                Initialize(RemoteName.Text);
            }
        }