public void Test_PreserveSelectedItem_AsFalse_WhenSetBusinessObjectCollection_AndSelectedItemInNewCol_ShouldNotPreserveSelection() { //---------------Set up test pack------------------- IBOComboBoxSelector selector = (IBOComboBoxSelector)CreateSelector(); selector.AutoSelectFirstItem = false; selector.PreserveSelectedItem = false; Car car = new Car(); Car car2 = new Car(); Car car3 = new Car(); Car car4 = new Car(); BusinessObjectCollection <Car> collection = new BusinessObjectCollection <Car> { car, car2, car3 }; selector.BusinessObjectCollection = collection; selector.SelectedBusinessObject = car2; BusinessObjectCollection <Car> newCollection = new BusinessObjectCollection <Car> { car, car4, car2, car3 }; //---------------Assert Precondition---------------- Assert.AreSame(car2, selector.SelectedBusinessObject); //---------------Execute Test ---------------------- selector.BusinessObjectCollection = newCollection; //---------------Test Result ----------------------- AssertIsNullSelection(selector); }
public void Test_BOPropUpdated_WhenBONotInComboBox_ShouldNotRaiseError_FixBug() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); IBusinessObjectCollection col; IBOColSelectorControl boColSelector = GetSelectorWith_4_Rows(out col); const string propName = "TestProp"; const int rowIndex = 1; MyBO bo = (MyBO)col[rowIndex]; boColSelector.BusinessObjectCollection = col; IBOComboBoxSelector selector = ((IBOComboBoxSelector)boColSelector); string origStringValue = selector.GetItemText(bo); selector.ComboBox.Items.Remove(bo); //---------------Assert Precondition---------------- Assert.AreEqual(bo.ToString(), origStringValue); Assert.AreEqual(4, selector.ComboBox.Items.Count); //---------------Execute Test ---------------------- const string newPropValue = "NewValue"; bo.SetPropertyValue(propName, newPropValue); bo.Save(); //---------------Test Result ----------------------- string newBoItemText = selector.GetItemText(bo); Assert.AreNotEqual(origStringValue, newBoItemText); Assert.AreEqual(newPropValue + " - " + bo.MyBoID, newBoItemText); }
public void Test_WhenParentSelectedBOIsNull_ShouldDisableChildSelector() { //---------------Set up test pack------------------- var contactPersonNoAddress = CreateFakeContactPersonWithNoFakeAddress(); var address = CreateFakeAddressWithFakeContactPerson(); IBOComboBoxSelector parentSelector = CreateComboBoxControl(); IBOComboBoxSelector childSelector = CreateComboBoxControl(); const string relationshipName = "Addresses"; new BOColSelectorLinker <FakeContactPerson, FakeAddress>(parentSelector, childSelector, relationshipName); parentSelector.BusinessObjectCollection = GetFakeContactPeople(); parentSelector.SelectedBusinessObject = address.ContactPerson; //---------------Assert Precondition---------------- Assert.AreEqual(3, parentSelector.NoOfItems, "Two departments and Blank Field"); Assert.AreSame(address.ContactPerson, parentSelector.SelectedBusinessObject); Assert.AreEqual(2, childSelector.NoOfItems, "The Blank Item and the address"); Assert.AreSame(address, childSelector.SelectedBusinessObject); Assert.IsTrue(childSelector.ComboBox.Enabled, "Should be enabled"); //---------------Execute Test ---------------------- parentSelector.SelectedBusinessObject = null; //---------------Test Result ----------------------- Assert.IsFalse(childSelector.ComboBox.Enabled, "Should be disabled"); Assert.AreEqual(3, parentSelector.NoOfItems, "Two departments and Blank Field"); Assert.IsNull(parentSelector.SelectedBusinessObject, "Should not have a selected parent"); Assert.AreEqual(1, childSelector.NoOfItems, "The Blank Item as there is no selected parent"); Assert.IsNull(childSelector.SelectedBusinessObject, "Should not have a selected child"); }
public void Test_ChangeParentSelectedIndex_WithNonEmpty_ShouldLoadChildren() { //---------------Set up test pack------------------- var contactPersonNoAddress = CreateFakeContactPersonWithNoFakeAddress(); CreateFakeAddressWithFakeContactPerson(); IBOComboBoxSelector parentSelector = CreateComboBoxControl(); IBOComboBoxSelector childSelector = CreateComboBoxControl(); const string relationshipName = "Addresses"; new BOColSelectorLinker <FakeContactPerson, FakeAddress>(parentSelector, childSelector, relationshipName); parentSelector.BusinessObjectCollection = GetFakeContactPeople(); parentSelector.SelectedBusinessObject = contactPersonNoAddress; //---------------Assert Precondition---------------- Assert.AreEqual(3, parentSelector.NoOfItems, "Two departments and Blank Field"); Assert.AreSame(contactPersonNoAddress, parentSelector.SelectedBusinessObject); Assert.AreEqual(1, childSelector.NoOfItems, "The Blank Item"); //---------------Execute Test ---------------------- parentSelector.SelectedIndex = 1; //---------------Test Result ----------------------- Assert.IsNotNull(parentSelector.SelectedBusinessObject); FakeContactPerson contactPerson = parentSelector.SelectedBusinessObject as FakeContactPerson; Assert.AreEqual(contactPerson.Addresses.Count + 1, childSelector.NoOfItems); }
public void Test_ChangeParentSelectedIndex_WithEmptyEntry_ShouldClearChildSelector() { //---------------Set up test pack------------------- CreateFakeContactPersonWithNoFakeAddress(); var address = CreateFakeAddressWithFakeContactPerson(); IBOComboBoxSelector parentSelector = CreateComboBoxControl(); IBOComboBoxSelector childSelector = CreateComboBoxControl(); const string relationshipName = "Addresses"; new BOColSelectorLinker <FakeContactPerson, FakeAddress>(parentSelector, childSelector, relationshipName); parentSelector.BusinessObjectCollection = GetFakeContactPeople(); parentSelector.SelectedBusinessObject = address.ContactPerson; //---------------Assert Precondition---------------- Assert.AreEqual(3, parentSelector.NoOfItems, "Two departments and Blank Field"); Assert.AreSame(address.ContactPerson, parentSelector.SelectedBusinessObject); Assert.AreEqual(2, childSelector.NoOfItems, "The Blank Item and child"); Assert.IsNotNull(childSelector.SelectedBusinessObject); Assert.IsNotNull(childSelector.SelectedItem); Assert.IsNotNull(childSelector.SelectedValue); //---------------Execute Test ---------------------- parentSelector.SelectedIndex = 0; //---------------Test Result ----------------------- Assert.IsNull(parentSelector.SelectedBusinessObject); Assert.AreEqual(1, childSelector.NoOfItems); Assert.IsNull(childSelector.SelectedBusinessObject); Assert.IsNull(childSelector.SelectedValue); }
private static void AssertIsNullSelection(IBOComboBoxSelector selector) { Assert.IsNull(selector.SelectedBusinessObject); Assert.IsNull(selector.SelectedValue); Assert.IsNull(selector.SelectedItem); Assert.IsTrue(String.IsNullOrEmpty(selector.Text)); Assert.AreEqual(-1, selector.SelectedIndex); }
public void Test_Constructor_ShouldSetPreserveSelectedItemToFalse() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IBOComboBoxSelector selector = (IBOComboBoxSelector)CreateSelector(); //---------------Test Result ----------------------- Assert.IsFalse(selector.PreserveSelectedItem); }
public void Test_Constructor_ComboBoxSet() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- IBOComboBoxSelector selector = (IBOComboBoxSelector)CreateSelector(); //---------------Test Result ----------------------- Assert.IsNotNull(selector.ComboBox); Assert.IsInstanceOf(typeof(IComboBox), selector.ComboBox); }
public void Test_SelectedBusinessObject_SetToNull_ShouldHaveNothingSelectedInCombo() { //---------------Set up test pack------------------- IBOComboBoxSelector selector = (IBOComboBoxSelector)CreateSelector(); Car car = new Car(); BusinessObjectCollection <Car> collection = new BusinessObjectCollection <Car> { car }; selector.BusinessObjectCollection = collection; selector.SelectedBusinessObject = car; //---------------Assert Precondition---------------- Assert.AreSame(car, selector.SelectedBusinessObject); //---------------Execute Test ---------------------- selector.SelectedBusinessObject = null; //---------------Test Result ----------------------- AssertIsNullSelection(selector); }
public void Test_SelectedBusinessObject_BlankItemSelected_ReturnsNull() { //---------------Set up test pack------------------- IBOComboBoxSelector selector = (IBOComboBoxSelector)CreateSelector(); Car car = new Car(); BusinessObjectCollection <Car> collection = new BusinessObjectCollection <Car> { car }; selector.BusinessObjectCollection = collection; SetSelectedIndex(selector, -1); //---------------Assert Precondition---------------- Assert.AreEqual(2, selector.NoOfItems, "The blank item and one other"); Assert.AreEqual(-1, SelectedIndex(selector)); Assert.AreEqual(null, selector.SelectedValue); //---------------Execute Test ---------------------- SetSelectedIndex(selector, 0); //---------------Test Result ----------------------- Assert.AreEqual(0, SelectedIndex(selector)); Assert.AreEqual("", selector.SelectedValue); Assert.IsNull(selector.SelectedBusinessObject); }