예제 #1
0
        public void TestApplyChangesToBusinessObject_DoesNothingAsChangesAreAlreadyAppliedForWin()
        {
            //---------------Set up test pack-------------------
            Sample.CreateClassDefWithTwoPropsOneInteger();
            Sample sampleBO = new Sample();
            const string startText = "startText";
            const string endText = "endText";
            sampleBO.SampleText = startText;
            sampleBO.SampleInt = 1;

            IPanelInfo panelInfo = new PanelInfo();
            PanelInfo.FieldInfo sampleTextFieldInfo = CreateFieldInfo("SampleText");
            PanelInfo.FieldInfo sampleIntFieldInfo = CreateFieldInfo("SampleInt");
            panelInfo.FieldInfos.Add(sampleTextFieldInfo);
            panelInfo.FieldInfos.Add(sampleIntFieldInfo);
            panelInfo.BusinessObject = sampleBO;

            sampleTextFieldInfo.InputControl.Text = endText;
            //---------------Assert Precondition----------------
            Assert.AreEqual(endText, sampleBO.SampleText);
            //---------------Execute Test ----------------------
            panelInfo.ApplyChangesToBusinessObject();
            //---------------Test Result -----------------------
            Assert.AreEqual(endText, sampleBO.SampleText);
            Assert.AreEqual(1, sampleBO.SampleInt);
        }
        public void TestChangePropValueUpdatesBusObj()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleLookupID";
            LookupComboBoxMapper mapper = new LookupComboBoxMapper(cmbox, propName, false, GetControlFactory());
            Sample s = new Sample();
            mapper.LookupList = Sample.LookupCollection;
            Guid guidResult;
            StringUtilities.GuidTryParse(Sample.LookupCollection[LOOKUP_ITEM_1], out guidResult);
            s.SampleLookupID = guidResult;
            mapper.BusinessObject = s;
            //---------------Test Preconditions-------------------
            Assert.AreEqual(3, Sample.LookupCollection.Count);
            Assert.IsNotNull(mapper.LookupList);
            Assert.IsNotNull(cmbox.SelectedItem, "There should be a selected item to start with");
            //---------------Execute Test ----------------------

            s.SampleLookupID = (Guid)GetGuidValue(Sample.LookupCollection, LOOKUP_ITEM_2);
            mapper.UpdateControlValueFromBusinessObject();

            //---------------Test Result -----------------------
            Assert.IsNotNull(cmbox.SelectedItem);
            Assert.AreEqual(LOOKUP_ITEM_2, cmbox.SelectedItem, "Value is not set after changing bo prop Value");
        }
        public void TestSetBusinessObject()
        {
            //---------------Set up test pack-------------------
            INumericUpDown numUpDown = GetControlFactory().CreateNumericUpDownInteger();
            NumericUpDownIntegerMapper mapper = new NumericUpDownIntegerMapper(numUpDown, INT_PROP_NAME, false, GetControlFactory());
            Sample s = new Sample();
            s.SampleInt = 100;
            //---------------Execute Test ----------------------
            mapper.BusinessObject = s;
            //---------------Test Result -----------------------
            Assert.AreEqual(100, numUpDown.Value, "Value is not set.");

            //---------------Tear Down -------------------------
        }
 public void Test_BusinessObjectChanged_UpdatesControl()
 {
     //---------------Set up test pack-------------------
     INumericUpDown numUpDown = GetControlFactory().CreateNumericUpDownInteger();
     NumericUpDownIntegerMapper mapper = new NumericUpDownIntegerMapper(numUpDown, INT_PROP_NAME, false, GetControlFactory());
     Sample s = new Sample();
     s.SampleInt = 100;
     mapper.BusinessObject = s;
     //---------------Execute Test ----------------------
     int newValue = 555;
     s.SampleInt = newValue;
     //---------------Test Result -----------------------
     Assert.AreEqual(newValue, numUpDown.Value);
     //---------------Tear down -------------------------
 }
        public void TestChangeBusinessObjectUpdatesComboBox_WithoutCallingUpdateControlValue()
        {
            //---------------Set up test pack-------------------
            IComboBox cbx = GetControlFactory().CreateComboBox();
            const string propName = "SampleText";
            ListComboBoxMapper mapper = new ListComboBoxMapper(cbx, propName, false, GetControlFactory());
            mapper.SetList("One|Two|Three|Four");
            Sample s = new Sample {SampleText = "Three"};
            mapper.BusinessObject = s;
            //---------------Execute Test ----------------------
            s.SampleText = "Four";

            //---------------Test Result -----------------------
            Assert.AreEqual("Four", cbx.SelectedItem, "Value is not set.");
        }
        public void TestSetBusinessObject()
        {
            //---------------Set up test pack-------------------
            INumericUpDown numUpDown = GetControlFactory().CreateNumericUpDownCurrency();
            NumericUpDownCurrencyMapper mapper =
                new NumericUpDownCurrencyMapper(numUpDown, CURRENCY_PROP_NAME, false, GetControlFactory());
            Sample s = new Sample();
            decimal val = 100.5m;
            s.SampleMoney = val;
            //---------------Execute Test ----------------------
            mapper.BusinessObject = s;
            //---------------Test Result -----------------------
            Assert.AreEqual(val, numUpDown.Value, "Value is not set.");

            //---------------Tear Down -------------------------
        }
 public void Test_ValueChangedEvent_UpdatesBusinessObject()
 {
     //---------------Set up test pack-------------------
     INumericUpDown numUpDown = GetControlFactory().CreateNumericUpDownInteger();
     NumericUpDownIntegerMapper mapper = new NumericUpDownIntegerMapper(numUpDown, INT_PROP_NAME, false, GetControlFactory());
     Sample s = new Sample();
     s.SampleInt = 100;
     mapper.BusinessObject = s;
     //---------------Execute Test ----------------------
     int newValue = 555;
     numUpDown.Value = newValue;
     //---------------Test Result -----------------------
     Assert.IsInstanceOf(typeof(NumericUpDownMapperStrategyWin), mapper.MapperStrategy);
     Assert.AreEqual(newValue, s.SampleInt);
     //---------------Tear down -------------------------
 }
 public void Test_BusinessObjectChanged_UpdatesControl()
 {
     //---------------Set up test pack-------------------
     INumericUpDown numUpDown = GetControlFactory().CreateNumericUpDownInteger();
     NumericUpDownCurrencyMapper mapper =
         new NumericUpDownCurrencyMapper(numUpDown, CURRENCY_PROP_NAME, false, GetControlFactory());
     Sample s = new Sample();
     s.SampleMoney = 100.10m;
     mapper.BusinessObject = s;
     //---------------Execute Test ----------------------
     decimal newValue = 555.45m;
     s.SampleMoney = newValue;
     //---------------Test Result -----------------------
     Assert.AreEqual(newValue, numUpDown.Value);
     //---------------Tear down -------------------------
 }
        public void TestSetComboBoxUpdatesBO_WithoutCallingApplyChanges()
        {
            //---------------Set up test pack-------------------
            IComboBox cbx = GetControlFactory().CreateComboBox();
            const string propName = "SampleText";
            ListComboBoxMapper mapper = new ListComboBoxMapper(cbx, propName, false, GetControlFactory());
            mapper.SetList("One|Two|Three|Four");
            Sample s = new Sample();
            s.SampleText = "Three";
            mapper.BusinessObject = s;
            //---------------Execute Test ----------------------
            cbx.SelectedIndex = 0;
            //---------------Test Result -----------------------
            Assert.AreEqual(cbx.SelectedItem, s.SampleText,
                            "BO property value isn't changed when control value is changed.");

        }
        public void TestSetBusinessObjectForDateTimePickerMapper()
        {
            //---------------Set up test pack-------------------
            Sample sampleBusinessObject = new Sample();
            DateTime origionalDate = new DateTime(2000, 1, 1);
            sampleBusinessObject.SampleDate = origionalDate;
            DateTimePickerMapper dtpMapper;
            IDateTimePicker dateTimePicker = GetDateTimePicker(out dtpMapper);
            //---------------Verify test pack-------------------
            Assert.AreEqual(DateTime.Today, dateTimePicker.Value.Date);
            //---------------Execute Test ----------------------

            dtpMapper.BusinessObject = sampleBusinessObject;
            //---------------Test Result -----------------------
            Assert.AreEqual(origionalDate, dateTimePicker.Value);
            //---------------Tear Down -------------------------          
        }
 public void Test_ValueChangedEvent_UpdatesBusinessObject()
 {
     //---------------Set up test pack-------------------
     INumericUpDown numUpDown = GetControlFactory().CreateNumericUpDownCurrency();
     NumericUpDownCurrencyMapper mapper =
         new NumericUpDownCurrencyMapper(numUpDown, CURRENCY_PROP_NAME, false, GetControlFactory());
     Sample s = new Sample();
     s.SampleMoney = 100.10m;
     mapper.BusinessObject = s;
     //---------------Execute Test ----------------------
     decimal newValue = 555.45m;
     numUpDown.Value = newValue;
     //---------------Test Result -----------------------
     Assert.IsInstanceOf(typeof(NumericUpDownMapperStrategyWin), mapper.MapperStrategy);
     Assert.AreEqual(newValue, s.SampleMoney);
     //---------------Tear down -------------------------
 }
 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 TestSetBOCollection()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleLookupID";
            CollectionComboBoxMapper mapper = CreateCollectionComboBoxMapper(cmbox, propName);

            Sample bo = new Sample();
            IBusinessObjectCollection col = new BusinessObjectCollection<Sample> {bo};
            //---------------Assert Precondition ---------------
            Assert.AreEqual(0, cmbox.Items.Count);
            //---------------Execute Test ----------------------
            mapper.BusinessObjectCollection = col;
            //---------------Test Result -----------------------
            Assert.AreEqual(2, cmbox.Items.Count, "The Sample item and the blank");
            Assert.AreSame(typeof (string), cmbox.Items[0].GetType(), "First Item should be blank");
            Assert.IsTrue(cmbox.Items.Contains(bo), "Second Item should be the Business Object");
        }
 public void TestUpdateValueInPicker_DoesNotChangeValueInBO_ForVWG()
 {
     //---------------Set up test pack-------------------
     Sample sampleBusinessObject = new Sample();
     DateTime origionalDate = new DateTime(2000, 1, 1);
     sampleBusinessObject.SampleDate = origionalDate;
     DateTimePickerMapper dtpMapper;
     IDateTimePicker dateTimePicker = GetDateTimePicker(out dtpMapper);
     dtpMapper.BusinessObject = sampleBusinessObject;
     //---------------Verify Preconditions -------------------
     Assert.AreEqual(origionalDate, dateTimePicker.Value.Date);
     //---------------Execute Test ----------------------
     DateTime newDate = DateTime.Today.AddDays(+3);
     dateTimePicker.Value = newDate;
     //---------------Test Result -----------------------
     Assert.AreEqual(origionalDate, sampleBusinessObject.SampleDate);
     //---------------Tear Down -------------------------          
 }
        public void TestSetBusinessObjectValue_ChangesDateTimePickerImmediately_InWin()
        {
            //---------------Set up test pack-------------------
            Sample sampleBusinessObject = new Sample();
            sampleBusinessObject.SampleDate = DateTime.Today;
            DateTimePickerMapper dtpMapper;
            IDateTimePicker dateTimePicker = GetDateTimePicker(out dtpMapper);
            dtpMapper.BusinessObject = sampleBusinessObject;

            //---------------Verify test pack-------------------
            Assert.AreEqual(DateTime.Today, dateTimePicker.Value.Date);
            //---------------Execute Test ----------------------
            DateTime testDateChangedValue = new DateTime(2000, 1, 1);
            sampleBusinessObject.SampleDate = testDateChangedValue;

            //---------------Test Result -----------------------
            Assert.AreEqual(sampleBusinessObject.SampleDate, dateTimePicker.Value);
            //---------------Tear Down -------------------------          
        }
        public virtual void TestChangeComboBoxDoesntUpdateBusinessObject()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleLookupID";
            LookupComboBoxMapper mapper = new LookupComboBoxMapper(cmbox, propName, false, GetControlFactory());
            Sample s = new Sample();
            mapper.LookupList = Sample.LookupCollection;
            Guid guidResult;
            StringUtilities.GuidTryParse(Sample.LookupCollection[LOOKUP_ITEM_1], out guidResult);
            s.SampleLookupID = guidResult;
            mapper.BusinessObject = s;
            //---------------Execute Test ----------------------
            cmbox.SelectedItem = LOOKUP_ITEM_2;

            //---------------Test Result -----------------------
            Assert.AreEqual(Sample.LookupCollection[LOOKUP_ITEM_1], s.SampleLookupID.ToString());
            //---------------Tear Down -------------------------
        }
        public override void TestChangeComboBoxDoesntUpdateBusinessObject()
        {
            //For Windows the value should be changed.
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleLookupID";
            LookupComboBoxMapper mapper = new LookupComboBoxMapper(cmbox, propName, false, GetControlFactory());
            Sample s = new Sample();
            Dictionary<string, string> collection = mapper.LookupList = GetLookupList();
            Guid guidResult;
            StringUtilities.GuidTryParse(collection[LOOKUP_ITEM_1], out guidResult);
            s.SampleLookupID = guidResult;
            mapper.BusinessObject = s;
            //---------------Execute Test ----------------------
            cmbox.SelectedItem = LOOKUP_ITEM_2;

            //---------------Test Result -----------------------
            Assert.AreEqual(collection[LOOKUP_ITEM_2], 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";
            LookupComboBoxMapper mapper = new LookupComboBoxMapper(cmbox, propName, false, GetControlFactory());
            Sample s = new Sample();
            mapper.LookupList = Sample.LookupCollection;
            s.SampleLookupID = (Guid)GetGuidValue(Sample.LookupCollection, LOOKUP_ITEM_1);
            mapper.BusinessObject = s;
            //---------------Execute Test ----------------------

            s.SampleLookupID = (Guid)GetGuidValue(Sample.LookupCollection, LOOKUP_ITEM_2);

            //---------------Test Result -----------------------
            Assert.AreEqual(LOOKUP_ITEM_2, cmbox.SelectedItem, "Value is not set after changing bo prop");

            //---------------Tear Down -------------------------
        }
        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 TestSetBusinessObjectForDateTimePickerMapper_DoesntFirePropertyUpdate()
 {
     //---------------Set up test pack-------------------
     Sample sampleBusinessObject = new Sample();
     DateTime origionalDate = DateTime.Now;
     sampleBusinessObject.SampleDate = origionalDate;
     DateTimePickerMapper dtpMapper;
     IDateTimePicker dateTimePicker = GetDateTimePicker(out dtpMapper);
     bool updatedEventFired = false;
     sampleBusinessObject.Props["SampleDate"].Updated += delegate {
         updatedEventFired = true;
     };
     //---------------Verify test pack-------------------
     Assert.AreEqual(DateTime.Today, dateTimePicker.Value.Date);
     Assert.IsFalse(updatedEventFired);
     //---------------Execute Test ----------------------
     dtpMapper.BusinessObject = sampleBusinessObject;
     //---------------Test Result -----------------------
     Assert.AreEqual(origionalDate, dateTimePicker.Value);
     Assert.IsFalse(updatedEventFired);
 }
        public void Test_SetBusinessObj_ShouldSetTheSelectedItemToCorrectRelatedCar()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleLookupID";
            CollectionComboBoxMapper mapper = CreateCollectionComboBoxMapper(cmbox, propName);

            Car car1;
            Car car2;
            mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
            Sample s = new Sample {SampleLookupID = car1.CarID};
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, mapper.BusinessObjectCollection.Count);
            Assert.AreEqual(3, cmbox.Items.Count);
            Assert.IsNull(cmbox.SelectedItem);
            Assert.IsNull(mapper.OwningBoPropertyName);
            //---------------Execute Test ----------------------
            mapper.BusinessObject = s;
            //---------------Test Result -----------------------
            Assert.IsNotNull(cmbox.SelectedItem);
            Assert.AreEqual(car1, cmbox.SelectedItem, "Combo Box selected item is not set.");
            Assert.AreEqual(s.SampleLookupID.ToString(), cmbox.SelectedValue.ToString(), "Combo Box Value is not set");
        }
        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");
        }
예제 #23
0
        public void Test_BuildPanelForTab_PopulatesFieldInfoCollection()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = Sample.CreateClassDefWithTwoPropsOneInteger();
            UIFormTab twoFieldTabOneCompulsory = (UIFormTab) classDef.UIDefCol["default"].UIForm[0];
            PanelBuilder panelBuilder = CreatePanelBuilder();
            Sample sample = new Sample();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IPanelInfo panelInfo = panelBuilder.BuildPanelForTab(twoFieldTabOneCompulsory);
            panelInfo.BusinessObject = sample;
            //---------------Test Result -----------------------

            IControlHabanero sampleTextLabel = panelInfo.Panel.Controls[PanelBuilder.LABEL_CONTROL_COLUMN_NO];
            IControlHabanero sampleTextInputControl = panelInfo.Panel.Controls[PanelBuilder.INPUT_CONTROL_COLUMN_NO];
            const string propertyName = "SampleText";
            IControlMapper sampleTextControlMapper = panelInfo.FieldInfos[propertyName].ControlMapper;

            Assert.AreEqual(2, panelInfo.FieldInfos.Count);

            PanelInfo.FieldInfo fieldInfo = panelInfo.FieldInfos[propertyName];
            Assert.AreSame(sampleTextLabel, fieldInfo.LabelControl);
            Assert.AreSame(sampleTextInputControl, fieldInfo.InputControl);

            Assert.AreSame(sampleTextInputControl, sampleTextControlMapper.Control);
            Assert.AreSame(sample, sampleTextControlMapper.BusinessObject);
            Assert.AreEqual(propertyName, sampleTextControlMapper.PropertyName);
        }
        public void Test_SetBusinessObj_WhenSpecificPropUsed_ShouldSetTheSelectedItemToCorrectRelatedCar()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleText";
            CollectionComboBoxMapper 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};
            //---------------Assert Precondition----------------
            Assert.AreEqual(2, mapper.BusinessObjectCollection.Count);
            Assert.AreEqual(3, cmbox.Items.Count);
            Assert.IsNull(cmbox.SelectedItem);
            Assert.AreEqual("CarRegNo", mapper.OwningBoPropertyName);
            //---------------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_AddItemToCollection_ShouldAddItemToComboBox()
 {
     //---------------Set up test pack-------------------
     var cmbox = GetControlFactory().CreateComboBox();
     const string propName = "SampleLookup2ID";
     CollectionComboBoxMapper mapper = CreateCollectionComboBoxMapper(cmbox, propName);
     Car car1;
     Car car2;
     IBusinessObjectCollection collection =
         mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
     Sample sample = new Sample {SampleLookupID = car1.CarID};
     mapper.BusinessObject = sample;
     //---------------Assert Preconditions---------------
     Assert.AreEqual(3, cmbox.Items.Count);
     //---------------Execute Test ----------------------
     collection.Add(new Car());
     //---------------Test Result -----------------------
     Assert.AreEqual(4, cmbox.Items.Count);
 }
 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 TestApplyChangesToBusObj()
 {
     //---------------Set up test pack-------------------
     IComboBox cmbox = GetControlFactory().CreateComboBox();
     const string propName = "SampleLookupID";
     CollectionComboBoxMapper mapper = CreateCollectionComboBoxMapper(cmbox, propName);
     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;
     mapper.ApplyChangesToBusinessObject();
     //---------------Test Result -----------------------
     //            Assert.AreEqual((Guid) Sample.LookupCollection[LOOKUP_ITEM_2], s.SampleLookupID);
     Assert.AreEqual(car2.CarID, s.SampleLookupID);
 }
        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);
            }
        }
            Test_ResetBusinessObj_WhenHasNullValueForProperty_WhenPreviousBOHadAValue_ShouldSetSelectedItemNull_BUGFIX()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleLookupID";
            CollectionComboBoxMapper mapper = CreateCollectionComboBoxMapper(cmbox, propName);

            Car car1;
            Car car2;
            mapper.BusinessObjectCollection = GetCollectionWithTwoCars(out car1, out car2);
            Sample s = new Sample {SampleLookupID = car1.CarID};

            mapper.BusinessObject = s;
            Sample sWithNullPropValue = new Sample();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(cmbox.SelectedItem);
            Assert.AreEqual(car1, cmbox.SelectedItem, "Combo Box selected item is not set.");
            Assert.AreEqual(s.SampleLookupID.ToString(), cmbox.SelectedValue.ToString(), "Combo Box Value is not set");

            Assert.IsNull(sWithNullPropValue.SampleLookupID);
            //---------------Execute Test ----------------------
            mapper.BusinessObject = sWithNullPropValue;
            //---------------Test Result -----------------------
//            Assert.IsNull(cmbox.SelectedItem);
            TestUtil.AssertStringEmpty(Convert.ToString(cmbox.SelectedItem), "cmbox.SelectedItem",
                                       "there should be no item selected");
        }
        public virtual void Test_ChangeComboBoxDoesntUpdateBusinessObject()
        {
            //---------------Set up test pack-------------------
            IComboBox cmbox = GetControlFactory().CreateComboBox();
            const string propName = "SampleLookupID";
            CollectionComboBoxMapper mapper = CreateCollectionComboBoxMapper(cmbox, propName);

            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(car1.CarID.ToString(), s.SampleLookupID.ToString());
        }