public void Test_SetBusinessObj_WhenSpecificGuidPropUsed_ShouldSetTheSelectedItemToCorrectRelatedCar()
        {
            //---------------Set up test pack-------------------
            ClassDef.ClassDefs.Clear();
            Sample.CreateClassDefWithAGuidProp();
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string sampleBOProp = "GuidProp";
            const string owningBoPropertyName = "CarId";
            CollectionComboBoxMapper mapper = new CollectionComboBoxMapper(cmbox, sampleBOProp, false,
                                                                           GetControlFactory())
                                                  {OwningBoPropertyName = owningBoPropertyName};

            Car car1;
            Car car2;
            mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
            Sample sample = new Sample();
            sample.SetPropertyValue(sampleBOProp, car1.CarID);
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, mapper.BusinessObjectCollection.Count);
            Assert.AreEqual(3, cmbox.Items.Count);
            Assert.IsNull(cmbox.SelectedItem);
            Assert.AreEqual(owningBoPropertyName, mapper.OwningBoPropertyName);
            Assert.IsNotNull(sample.GetPropertyValue(sampleBOProp));
            //---------------Execute Test ----------------------
            mapper.BusinessObject = sample;
            //---------------Test Result -----------------------
            Assert.IsNotNull(cmbox.SelectedItem);
            Assert.AreEqual(car1, cmbox.SelectedItem, "Combo Box selected item is not set.");
        }
 public void Test_LookupList_AddItemToComboBox_SelectAdditionalItem_SetsBOPropValueToNull()
 {
     //---------------Set up test pack-------------------
     IComboBox cmbox = GetControlFactory().CreateComboBox();
     const string propName = "SampleLookup2ID";
     CollectionComboBoxMapper mapper = CreateCollectionComboBoxMapper(cmbox, propName);
     Car car1;
     Car car2;
     mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
     Sample sample = new Sample {SampleLookupID = car1.CarID};
     mapper.BusinessObject = sample;
     cmbox.Items.Add("SomeItem");
     //---------------Assert Preconditions---------------
     Assert.AreEqual(4, cmbox.Items.Count);
     Assert.AreEqual("SomeItem", LastComboBoxItem(cmbox).ToString());
     //---------------Execute Test ----------------------
     cmbox.SelectedIndex = cmbox.Items.Count - 1;
     mapper.ApplyChangesToBusinessObject();
     //---------------Test Result -----------------------
     object value = sample.GetPropertyValue(propName);
     Assert.IsNull(value);
 }
        public void TestCustomiseLookupList_Add_SelectAdded()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleLookup2ID";
            CustomAddLookupComboBoxMapperStub mapperStub = new CustomAddLookupComboBoxMapperStub(cmbox, propName, false, GetControlFactory());
            Sample sample = new Sample();
            mapperStub.BusinessObject = sample;
            //---------------Assert Preconditions---------------
            Assert.AreEqual(5, cmbox.Items.Count);
            Assert.AreEqual("ExtraLookupItem", LastComboBoxItem(cmbox).ToString());
            //---------------Execute Test ----------------------
            cmbox.SelectedIndex = cmbox.Items.Count - 1;
            mapperStub.ApplyChangesToBusinessObject();
            //---------------Test Result -----------------------
            object value = sample.GetPropertyValue(propName);
            Assert.IsNotNull(value);

            //---------------Tear Down -------------------------
            // This test changes the static class def, so force a reload
            ClassDef.ClassDefs.Remove(typeof(Sample));
        }