public void Can_remove_a_DbConnectionDefinition_object() { DbConnectionDefinitionList definitionList = new DbConnectionDefinitionList(); definitionList.DefaultName = "def"; var conn1 = new DbConnectionDefinition { ConnectionString = "cs1", Name = "nm1", ProviderName = "p1" }; var conn2 = new DbConnectionDefinition { ConnectionString = "cs2", Name = "nm2", ProviderName = "p2" }; var conn3unused = new DbConnectionDefinition { ConnectionString = "cs3", Name = "nm3", ProviderName = "p3" }; definitionList.Definitions = new[] { conn1, conn2 }; Assert.That(definitionList.Definitions.Length, Is.EqualTo(2)); bool remove1 = definitionList.RemoveDefinition(conn2); Assert.That(remove1, Is.EqualTo(true)); Assert.That(definitionList.Definitions.Length, Is.EqualTo(1)); Assert.That(definitionList.Definitions[0].Name, Is.EqualTo("nm1")); bool remove2 = definitionList.RemoveDefinition(conn3unused); Assert.That(remove2, Is.EqualTo(false)); Assert.That(definitionList.Definitions.Length, Is.EqualTo(1)); }
/// <summary>The tool strip button delete_ click.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void toolStripButtonDelete_Click(object sender, EventArgs e) { DbConnectionDefinition definition = lstConnections.SelectedItem as DbConnectionDefinition; if (definition != null) { int newIndex = Math.Max(lstConnections.SelectedIndex - 1, 0); _definitionList.RemoveDefinition(definition); RemoveFromList(definition); if (lstConnections.Items.Count > 0) { lstConnections.SelectedIndex = newIndex; } } }