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); }
public void Test_SetBusinessObject_WhenHasNullCollection_ShouldRaiseError() { //---------------Set up test pack------------------- IComboBox cmbox = GetControlFactory().CreateComboBox(); const string propName = "SampleLookupID"; CollectionComboBoxMapper mapper = CreateCollectionComboBoxMapper(cmbox, propName); mapper.BusinessObjectCollection = null; Car car1 = new Car(); Sample s = new Sample {SampleLookupID = car1.CarID}; //---------------Assert Precondition---------------- Assert.IsNull(cmbox.SelectedItem); Assert.IsNull(mapper.BusinessObjectCollection); //---------------Execute Test ---------------------- try { mapper.BusinessObject = s; Assert.Fail("expected developer exception"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains( "The BusinessObjectCollection is null in the CollectionComboBoxMapper when the BusinessObject is set ", ex.Message); StringAssert.Contains( "The BusinessObjectCollection is null in the CollectionComboBoxMapper when the BusinessObject is set ", ex.DeveloperMessage); } }
protected static BusinessObjectCollection<Car> GetCollectionWithTwoCars(out Car car1, out Car car2) { car1 = new Car(); car2 = new Car(); return new BusinessObjectCollection<Car> {car1, car2}; }
Test_BusinessObjectCollection_WhenSet_WithNewCollection_WhenItemAlreadySelected_AndDifferentMatchInNewList_ShouldSelectNewMatch () { //---------------Set up test pack------------------- IComboBox cmbox = GetControlFactory().CreateComboBox(); const string propName = "SampleText"; var mapper = CreateCollectionComboBoxMapper(cmbox, propName); mapper.OwningBoPropertyName = "CarRegNo"; Car car1; Car car2; mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2); string carRegNo = "MySelectedRegNo " + TestUtil.GetRandomString().Substring(0, 4); car1.CarRegNo = carRegNo; car2.CarRegNo = TestUtil.GetRandomString(); Sample sample = new Sample {SampleText = carRegNo}; BusinessObjectCollection<Car> newCol = new BusinessObjectCollection<Car>(); Car car3 = new Car {CarRegNo = carRegNo}; newCol.Add(car2, car3); mapper.BusinessObject = sample; //---------------Assert Precondition---------------- Assert.AreEqual(2, mapper.BusinessObjectCollection.Count); Assert.AreEqual(3, cmbox.Items.Count); Assert.AreEqual(car1, cmbox.SelectedItem, "Combo Box selected item should be set."); Assert.AreEqual("CarRegNo", mapper.OwningBoPropertyName); //---------------Execute Test ---------------------- mapper.BusinessObjectCollection = newCol; //---------------Test Result ----------------------- Assert.IsNotNull(cmbox.SelectedItem); Assert.AreEqual(car3, cmbox.SelectedItem, "Combo Box selected item should now be the new match."); Assert.AreSame(carRegNo, sample.SampleText); }
private static Car CreateUnsavedCar(string regno, ContactPerson owner) { Car car = new Car(); if (owner != null) car.OwnerID = owner.ContactPersonID; car.CarRegNo = regno; return car; }
public static Engine CreateSavedEngine(Car car, string engineNo) { Engine engine = new Engine(); engine.CarID = car.CarID; engine.EngineNo = engineNo; engine.Save(); return engine; }
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_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); }