public void TestCancelButton_BOAndControlsAreSynchronised() { //---------------Set up test pack------------------- BusinessObjectCollection <MyBO> myBOs = CreateSavedMyBoCollection(); IGridWithPanelControl <MyBO> gridWithPanelControl = CreateGridAndBOEditorControl_WithStrategy(); gridWithPanelControl.SetBusinessObjectCollection(myBOs); IButton cancelButton = gridWithPanelControl.Buttons["Cancel"]; MyBO firstBO = myBOs[0]; string originalValue = firstBO.TestProp; string newValue = BOTestUtils.RandomString; PanelInfo.FieldInfo testPropFieldInfo = ((IBusinessObjectPanel)gridWithPanelControl.BusinessObjectControl).PanelInfo.FieldInfos["TestProp"]; testPropFieldInfo.ControlMapper.Control.Text = newValue; //---------------Assert Precondition---------------- Assert.IsFalse(firstBO.Status.IsNew); Assert.IsFalse(firstBO.Status.IsDirty); Assert.AreNotEqual(originalValue, newValue); Assert.AreNotEqual(newValue, firstBO.TestProp); //vwg doesn't synchronise by default //---------------Execute Test ---------------------- cancelButton.PerformClick(); //---------------Test Result ----------------------- Assert.IsFalse(firstBO.Status.IsNew); Assert.IsFalse(firstBO.Status.IsDirty); Assert.AreEqual(originalValue, firstBO.TestProp); Assert.AreEqual(originalValue, testPropFieldInfo.ControlMapper.Control.Text); }
public void TestApplyChangesToBusinessObject() { //---------------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(startText, sampleBO.SampleText); //---------------Execute Test ---------------------- panelInfo.ApplyChangesToBusinessObject(); //---------------Test Result ----------------------- Assert.AreEqual(endText, sampleBO.SampleText); Assert.AreEqual(1, sampleBO.SampleInt); }
public void TestSaveButton_UpdatesGridText() { //---------------Set up test pack------------------- BusinessObjectCollection <MyBO> myBOs = CreateSavedMyBoCollection(); IGridWithPanelControl <MyBO> gridWithPanelControl = CreateGridAndBOEditorControl_WithStrategy(); gridWithPanelControl.SetBusinessObjectCollection(myBOs); IButton saveButton = gridWithPanelControl.Buttons["Save"]; MyBO currentBO = gridWithPanelControl.CurrentBusinessObject; string originalValue = currentBO.TestProp; string newValue = BOTestUtils.RandomString; PanelInfo.FieldInfo testPropFieldInfo = ((IBusinessObjectPanel)gridWithPanelControl.BusinessObjectControl).PanelInfo.FieldInfos["TestProp"]; testPropFieldInfo.ControlMapper.Control.Text = newValue; //---------------Assert Precondition---------------- Assert.AreNotEqual(originalValue, newValue); Assert.AreEqual(originalValue, currentBO.TestProp); Assert.AreEqual(originalValue, gridWithPanelControl.ReadOnlyGridControl.Grid.Rows[0].Cells["TestProp"].Value); //---------------Execute Test ---------------------- saveButton.PerformClick(); //---------------Test Result ----------------------- Assert.AreEqual(newValue, currentBO.TestProp); Assert.AreEqual(newValue, gridWithPanelControl.ReadOnlyGridControl.Grid.Rows[0].Cells["TestProp"].Value); Assert.AreSame(currentBO, gridWithPanelControl.CurrentBusinessObject); }
private static void AssertErrorProviderHasErrors(IBusinessObjectPanel controlWin, string propertyName) { IPanelInfo panelInfo = controlWin.PanelInfo; PanelInfo.FieldInfo fieldInfo = panelInfo.FieldInfos[propertyName]; string error = fieldInfo.ControlMapper.ErrorProvider.GetError(fieldInfo.InputControl); Assert.IsFalse(string.IsNullOrEmpty(error), "string '" + error + "' should not be null"); }
public void TestFieldInfos_WrongPropertyNameGivesUsefulError() { //---------------Set up test pack------------------- IPanelInfo panelInfo = new PanelInfo(); //---------------Execute Test ---------------------- try { PanelInfo.FieldInfo fieldInfo = panelInfo.FieldInfos["invalidPropName"]; Assert.Fail("Expected to throw an InvalidPropertyNameException"); } //---------------Test Result ----------------------- catch (InvalidPropertyNameException ex) { StringAssert.Contains("A label for the property invalidPropName was not found", ex.Message); } }
public void TestFieldInfo_Constructor() { //---------------Set up test pack------------------- ILabel label = GetControlFactory().CreateLabel(); string propertyName = TestUtil.GetRandomString(); ITextBox tb = GetControlFactory().CreateTextBox(); IControlMapper controlMapper = new TextBoxMapper(tb, propertyName, false, GetControlFactory()); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- PanelInfo.FieldInfo fieldInfo = new PanelInfo.FieldInfo(propertyName, label, controlMapper); //---------------Test Result ----------------------- Assert.AreEqual(propertyName, fieldInfo.PropertyName); Assert.AreSame(label, fieldInfo.LabelControl); Assert.AreSame(controlMapper, fieldInfo.ControlMapper); Assert.AreSame(tb, fieldInfo.InputControl); }
public void TestClearErrorProviders() { //---------------Set up test pack------------------- IClassDef classDef = Sample.CreateClassDefWithTwoPropsOneCompulsory(); PanelBuilder panelBuilder = new PanelBuilder(GetControlFactory()); IPanelInfo panelInfo = panelBuilder.BuildPanelForTab((UIFormTab)classDef.UIDefCol["default"].UIForm[0]); Sample businessObject = new Sample(); panelInfo.BusinessObject = businessObject; //businessObject.SetPropertyValue("SampleText2", "sdlkfj"); PanelInfo.FieldInfo fieldInfo = panelInfo.FieldInfos["SampleText2"]; panelInfo.ApplyChangesToBusinessObject(); IErrorProvider errorProvider = fieldInfo.ControlMapper.ErrorProvider; //---------------Assert Precondition---------------- Assert.IsTrue(errorProvider.GetError(fieldInfo.InputControl).Length > 0); //---------------Execute Test ---------------------- panelInfo.ClearErrorProviders(); //---------------Test Result ----------------------- Assert.IsFalse(errorProvider.GetError(fieldInfo.InputControl).Length > 0); }
private PanelInfo.FieldInfo AddControlsForField(UIFormField formField, IPanelInfo panelInfo) { IControlHabanero labelControl; IControlMapper controlMapper; if (formField.Layout == LayoutStyle.Label) { labelControl = CreateAndAddLabel(panelInfo, formField); controlMapper = CreateAndAddInputControl(panelInfo, formField); } else { labelControl = CreateAndAddGroupBox(panelInfo, formField); controlMapper = CreateAndAddInputControlToContainerControl(formField, labelControl); } CreateAndAddErrorProviderPanel(panelInfo, formField); PanelInfo.FieldInfo fieldInfo = new PanelInfo.FieldInfo(formField.PropertyName, labelControl, controlMapper); panelInfo.FieldInfos.Add(fieldInfo); return fieldInfo; }