Exemple #1
0
        public void EditTest1()
        {
            // Arrange
            _clientConfiguration.Add("test", new LegacyClient {
                Settings = new ClientSettings(ClientType.Legacy)
                {
                    Name = "test", Path = "/home/harlam357/"
                }
            });
            Assert.AreEqual(1, _clientConfiguration.Count);
            ConfigurationChangedEventArgs eventArgs = null;

            _clientConfiguration.DictionaryChanged += (sender, e) => { eventArgs = e; };
            ClientEditedEventArgs editedEventArgs = null;

            _clientConfiguration.ClientEdited += (sender, e) => editedEventArgs = e;
            // Act
            _clientConfiguration.Edit("test", new ClientSettings(ClientType.Legacy)
            {
                Name = "test2", Path = "/home/harlam357/FAH/"
            });
            // Assert
            Assert.AreEqual(1, _clientConfiguration.Count);
            Assert.IsTrue(_clientConfiguration.ContainsKey("test2"));
            Assert.AreEqual(ConfigurationChangedType.Edit, eventArgs.ChangedType);
            Assert.AreEqual("test2", eventArgs.Client.Settings.Name);
            Assert.AreEqual("/home/harlam357/FAH/", eventArgs.Client.Settings.Path);
            Assert.AreEqual("test", editedEventArgs.PreviousName);
            Assert.AreEqual("/home/harlam357/", editedEventArgs.PreviousPath);
            Assert.AreEqual("test2", editedEventArgs.NewName);
            Assert.AreEqual("/home/harlam357/FAH/", editedEventArgs.NewPath);
        }
        public void ClientsEditClick(FahClientSettingsPresenterFactory presenterFactory)
        {
            var selectedSlot = GridModel.SelectedSlot;

            if (selectedSlot == null)
            {
                return;
            }

            var client           = ClientConfiguration.Get(selectedSlot.Settings.Name);
            var originalSettings = client.Settings;

            Debug.Assert(originalSettings.ClientType == ClientType.FahClient);

            var model = new FahClientSettingsModel(originalSettings);

            using (var dialog = presenterFactory.Create(model))
            {
                while (dialog.ShowDialog(Form) == DialogResult.OK)
                {
                    var newSettings = dialog.Model.ClientSettings;
                    // perform the edit
                    try
                    {
                        ClientConfiguration.Edit(originalSettings.Name, newSettings);
                        break;
                    }
                    catch (ArgumentException ex)
                    {
                        Logger.Error(ex.Message, ex);
                        MessageBox.ShowError(Form, ex.Message, Core.Application.NameAndVersion);
                    }
                }
            }
        }