コード例 #1
0
 public void Test_GetMapperType_WhenComboBox_WhenPropTypeIsLookupList_ShouldReturnLookupComboBoxMapper()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Add(FakeBoWithLookupListProp.GetClassDef());
     var registry = CreateWinFormsControlMapperRegistry();
     var comboBox = new ComboBox { Name = "cmbLookupListProp" };
     var classDef = ClassDef.Get<FakeBoWithLookupListProp>();
     var propDef = classDef.GetPropDef("LookupListProp", false);
     //---------------Assert Precondition----------------
     Assert.IsNotNull(comboBox);
     Assert.IsTrue(propDef.HasLookupList());
     //---------------Execute Test ----------------------
     var mapperType = registry.GetMapperType<FakeBoWithLookupListProp>(comboBox);
     //---------------Test Result -----------------------
     Assert.AreEqual(typeof(LookupComboBoxMapper), mapperType, "Should be LookupComboBoxMapper");
 }
コード例 #2
0
 public void Test_AddMappersByConventions_WhenComboBox_WhenUsesConvention_ShouldAddLookupComboBoxMapper_WithCorrectControlAndProperty()
 {
     //---------------Set up test pack-------------------
     ClassDef.ClassDefs.Add(FakeBoWithLookupListProp.GetClassDef());
     var haberoControlBinder = new HabaneroControlBinder<FakeBoWithLookupListProp>();
     var comboBox = new ComboBox { Name = "cmbLookupListProp" };
     Control.ControlCollection controls = GetControlsCollection(comboBox);
     //---------------Assert Precondition----------------
     Assert.AreEqual(1, controls.Count, "Should have ComboBox");
     Assert.Contains(comboBox, controls, "Should have ComboBox");
     Assert.AreEqual(0, haberoControlBinder.ControlMappers.Count);
     //---------------Execute Test ----------------------
     haberoControlBinder.AddMappersByConvention(controls.Cast<Control>());
     //---------------Test Result -----------------------
     Assert.AreEqual(1, haberoControlBinder.ControlMappers.Count);
     var comboBoxMapper = haberoControlBinder.ControlMappers[0];
     var comboBoxAdapter = comboBoxMapper.Control as IWinFormsComboBoxAdapter;
     Assert.IsNotNull(comboBoxAdapter, "Should adapt the winforms control");
     Assert.AreSame(comboBox, comboBoxAdapter.WrappedControl);
     Assert.AreEqual("LookupListProp", comboBoxMapper.PropertyName, "The prop name should be derived from the control.Name");
 }