This is used to map a collection of Business objects to a particular property of the Business object. This is typically used when you are wanting to load a collection of business objects via some custom collection loading code that does not allow you to use either the LookupComboBoxMapper or the RelationshipComboBoxMapper.
Inheritance: ControlMapper, IComboBoxMapper
 public void TestChangeComboBox_UpdatesBusinessObject()
 {
     //For Windows the value should be changed.
     //---------------Set up test pack-------------------
     IComboBox cmbox = GetControlFactory().CreateComboBox();
     const string propName = "SampleLookupID";
     CollectionComboBoxMapper mapper = new CollectionComboBoxMapper(cmbox, propName, false, GetControlFactory());
     Car car1;
     Car car2;
     mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
     Sample s = new Sample { SampleLookupID = car1.CarID };
     mapper.BusinessObject = s;
     //---------------Execute Test ----------------------
     cmbox.SelectedItem = car2;
     //---------------Test Result -----------------------
     Assert.AreEqual(car2.CarID.ToString(), s.SampleLookupID.ToString(),
                     "For Windows the value should be changed");
 }
        public void TestChangePropValueUpdatesBusObj_WithoutCallingUpdateControlValue()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleLookupID";
            CollectionComboBoxMapper mapper = new CollectionComboBoxMapper(cmbox, propName, false, GetControlFactory());
            Car car1;
            Car car2;
            mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
            Sample s = new Sample { SampleLookupID = car1.CarID };
            mapper.BusinessObject = s;
            //---------------Execute Test ----------------------

            s.SampleLookupID = car2.CarID;

            //---------------Test Result -----------------------
            Assert.IsNotNull(cmbox.SelectedItem);
            Assert.AreEqual(s.SampleLookupID.ToString(), cmbox.SelectedItem.ToString(),
                            "Value is not set after changing bo prop Value");
        }
        public void TestChangePropValueUpdatesBusObj()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleLookupID";
            CollectionComboBoxMapper mapper = new CollectionComboBoxMapper(cmbox, propName, true, GetControlFactory());
            Car car1;
            Car car2;
            mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
            Sample s = new Sample { SampleLookupID = car1.CarID };
            mapper.BusinessObject = s;
            //---------------Test Preconditions-------------------
            Assert.AreEqual(3, Sample.LookupCollection.Count);
            Assert.IsNotNull(mapper.BusinessObjectCollection);
            Assert.IsNotNull(cmbox.SelectedItem, "There should be a selected item to start with");
            //---------------Execute Test ----------------------
            s.SampleLookupID = car2.CarID;
            mapper.UpdateControlValueFromBusinessObject();

            //---------------Test Result -----------------------
            Assert.IsNotNull(cmbox.SelectedItem);
            Assert.AreEqual(s.SampleLookupID.ToString(), cmbox.SelectedItem.ToString(),
                            "Value is not set after changing bo prop Value");
        }
        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 TestKeyPressEventUpdatesBusinessObject_WithoutCallingApplyChanges()
 {
     //---------------Set up test pack-------------------
     ComboBoxWinStub cmbox = new ComboBoxWinStub();
     const string propName = "SampleLookupID";
     CollectionComboBoxMapper mapper = new CollectionComboBoxMapper(cmbox, propName, false, GetControlFactory());
     Car car1;
     Car car2;
     mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
     Sample s = new Sample { SampleLookupID = car1.CarID };
     mapper.BusinessObject = s;
     //---------------Execute Test ----------------------
     cmbox.Text = car2.ToString();
     //---------------Test Result -----------------------
     Assert.IsInstanceOf(typeof(ComboBoxDefaultMapperStrategyWin), mapper.MapperStrategy);
     Assert.AreEqual(car2.CarID, s.SampleLookupID);
 }
 public void Test_WhenUseToStringSet_ShouldUseBoToString()
 {
     //---------------Set up test pack-------------------
     IComboBox cmbox = GetControlFactory().CreateComboBox();
     const string propName = "SampleText";
     CollectionComboBoxMapper mapper = new CollectionComboBoxMapper(cmbox, propName, false, GetControlFactory());
     Car car1; Car car2;
     IBusinessObjectCollection collection =
         mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
     car1.CarRegNo = "MyCarRegNo";
     Sample sample = new Sample { SampleLookupID = car1.CarID };
     mapper.BusinessObjectCollection = collection;
     mapper.BusinessObject = sample;
     //---------------Assert Precondition----------------
     Assert.AreEqual(3, cmbox.Items.Count);
     //---------------Execute Test ----------------------
     mapper.OwningBoPropertyName = "CarRegNo";
     cmbox.SelectedItem = car1;
     //---------------Test Result -----------------------
     Assert.AreEqual(car1.CarRegNo, sample.SampleText);
 }
        public void Test_KeyPressStrategy_DoesNotUpdateBusinessObject_When_SelectedIndexChanged()
        {
            //---------------Set up test pack-------------------
            ComboBoxWinStub cmbox = new ComboBoxWinStub();
            const string propName = "SampleLookupID";
            CollectionComboBoxMapper mapper = new CollectionComboBoxMapper(cmbox, propName, false, GetControlFactory());
            mapper.MapperStrategy = GetControlFactory().CreateLookupKeyPressMapperStrategy();
            Car car1;
            Car car2;
            mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
            Sample s = new Sample { SampleLookupID = car1.CarID };
            mapper.BusinessObject = s;
            //---------------Execute Test ----------------------
            cmbox.SelectedItem = car2;

            //---------------Test Result -----------------------
            Assert.IsInstanceOf(typeof(ComboBoxKeyPressMapperStrategyWin), mapper.MapperStrategy);
            Assert.AreEqual(car1.CarID, s.SampleLookupID);
        }