public void TestAddRowP_RowValueDBNull_BOProp_DateTime_NUll_ShouldNotRaiseException_FIXBUG() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); SetupTestData(); BusinessObjectCollection <MyBO> boCollection = new BusinessObjectCollection <MyBO>(); _dataSetProvider = new EditableDataSetProvider(boCollection); BOMapper mapper = new BOMapper(boCollection.ClassDef.CreateNewBusinessObject()); itsTable = _dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); //--------------Assert PreConditions---------------- Assert.AreEqual(0, boCollection.Count); Assert.AreEqual(0, boCollection.PersistedBusinessObjects.Count, "Should be no created items to start"); // Assert.AreEqual(0, boCollection.CreatedBusinessObjects.Count, "Should be no created items to start"); //---------------Execute Test ---------------------- itsTable.Rows.Add(new object[] { DBNull.Value, DBNull.Value, DBNull.Value }); //---------------Test Result ----------------------- Assert.AreEqual (1, boCollection.PersistedBusinessObjects.Count, "Adding a row to the table should use the collection to create the object"); // Assert.AreEqual // (1, boCollection.CreatedBusinessObjects.Count, // "Adding a row to the table should use the collection to create the object"); Assert.AreEqual(1, boCollection.Count, "Adding a row to the table should add a bo to the main collection"); }
public void TestAddRowP_RowValueDBNull_VirtualProp_NUll_ShouldNotRaiseException_FIXBUG() { //---------------Set up test pack------------------- BORegistry.DataAccessor = new DataAccessorInMemory(); ClassDef.ClassDefs.Clear(); IClassDef classDef = MyBO.LoadClassDefWithUIAllDataTypes(); classDef.UIDefCol["default"].UIGrid.Add(new UIGridColumn("VirtualProp", "-TestProp-", typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable())); BusinessObjectCollection <MyBO> boCollection = new BusinessObjectCollection <MyBO>(); _dataSetProvider = new EditableDataSetProvider(boCollection); BOMapper mapper = new BOMapper(boCollection.ClassDef.CreateNewBusinessObject()); itsTable = _dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); //--------------Assert PreConditions---------------- Assert.AreEqual(0, boCollection.Count); Assert.AreEqual(0, boCollection.PersistedBusinessObjects.Count, "Should be no created items to start"); // Assert.AreEqual(0, boCollection.CreatedBusinessObjects.Count, "Should be no created items to start"); //---------------Execute Test ---------------------- itsTable.Rows.Add(new object[] { DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value }); //---------------Test Result ----------------------- Assert.IsFalse(itsTable.Rows[0].HasErrors); //Behaviour has been changed to persist the business object Assert.AreEqual (1, boCollection.PersistedBusinessObjects.Count, "Adding a row to the table should use the collection to create the object"); // Assert.AreEqual // (1, boCollection.CreatedBusinessObjects.Count, // "Adding a row to the table should use the collection to create the object"); Assert.AreEqual(1, boCollection.Count, "Adding a row to the table should add a bo to the main collection"); }
/// <summary> /// A constructor as before, but with a UIDefName specified /// </summary> public PanelFactory(BusinessObject bo, string uiDefName, IControlFactory controlFactory) { _uiDefName = uiDefName; _controlFactory = controlFactory; BOMapper mapper = new BOMapper(bo); IUIDef uiDef = mapper.GetUIDef(uiDefName); if (uiDef == null) { string errMessage = "Cannot create a panel factory for '" + bo.ClassDef.ClassName + "' since the classdefs do not contain a uiDef '" + uiDefName + "'"; throw new HabaneroDeveloperException ("There is a serious application error please contact your system administrator" + Environment.NewLine + errMessage, errMessage); } _uiForm = uiDef.GetUIFormProperties(); if (_uiForm == null) { string errMsg = "Cannot create a panel factory for '" + bo.ClassDef.ClassName + "' since the classdefs do not contain a form def for uidef '" + uiDefName + "'"; throw new HabaneroDeveloperException ("There is a serious application error please contact your system administrator" + Environment.NewLine + errMsg, errMsg); } InitialiseFactory(bo); }
public void TestDuplicateColumnNames() { //---------------Set up test pack------------------- SetupTestData(); BOMapper mapper = new BOMapper(_collection.ClassDef.CreateNewBusinessObject()); //---------------Execute Test ---------------------- try { itsTable = _dataSetProvider.GetDataTable(mapper.GetUIDef("duplicateColumns").UIGrid); Assert.Fail("Expected to throw an DuplicateNameException"); } //---------------Test Result ----------------------- catch (DuplicateNameException ex) { StringAssert.Contains("Only one column per property can be specified", ex.Message); } }
public void TestAddRow_UpdatesCollection() { BusinessObjectCollection <MyBO> col = null; IDataSetProvider dataSetProvider = GetDataSetProviderWithCollection(ref col); BOMapper mapper = new BOMapper(col.ClassDef.CreateNewBusinessObject()); DataTable table = dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); MyBO boNew = new MyBO(); boNew.SetPropertyValue("TestProp", "bo3prop1"); boNew.SetPropertyValue("TestProp2", "s2"); //---------------Assert Precondition---------------- Assert.AreEqual(4, table.Rows.Count); Assert.AreEqual(4, col.Count); Assert.AreEqual(4, col.CreatedBusinessObjects.Count); //---------------Execute Test ---------------------- table.Rows.Add(new object[] { null, "bo3prop1", "bo3prop2" }); //---------------Test Result ----------------------- Assert.AreEqual(5, col.Count); Assert.AreEqual(5, col.CreatedBusinessObjects.Count); Assert.AreEqual(5, table.Rows.Count); }
public void TestAddRowCreatesBusinessObjectThroughCollection() { SetupTestData(); //---------------Set up test pack------------------- BusinessObjectCollection <MyBO> boCollection = new BusinessObjectCollection <MyBO>(); MyBO bo = new MyBO(); bo.SetPropertyValue("TestProp", "bo1prop1"); bo.SetPropertyValue("TestProp2", "s1"); bo.Save(); boCollection.Add(bo); MyBO bo2 = new MyBO(); bo2.SetPropertyValue("TestProp", "bo2prop1"); bo2.SetPropertyValue("TestProp2", "s2"); bo2.Save(); boCollection.Add(bo2); _dataSetProvider = new EditableDataSetProvider(boCollection); BOMapper mapper = new BOMapper(boCollection.ClassDef.CreateNewBusinessObject()); itsTable = _dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); //--------------Assert PreConditions---------------- Assert.AreEqual(2, boCollection.Count); Assert.AreEqual(0, boCollection.CreatedBusinessObjects.Count, "Should be no created items to start"); //---------------Execute Test ---------------------- itsTable.Rows.Add(new object[] { null, "bo3prop1", "bo3prop2" }); //---------------Test Result ----------------------- Assert.AreEqual (1, boCollection.CreatedBusinessObjects.Count, "Adding a row to the table should use the collection to create the object"); //Assert.AreEqual(2, boCollection.Count, "Adding a row to the table should not add a bo to the main collection"); Assert.AreEqual(3, boCollection.Count, "Adding a row to the table should add a bo to the main collection"); }
public void Test_EditDataTable_ToDBNull_EditsBo() { //---------------Set up test pack------------------- BusinessObjectCollection <MyBO> col = null; IDataSetProvider dataSetProvider = GetDataSetProviderWithCollection(ref col); BOMapper mapper = new BOMapper(col.ClassDef.CreateNewBusinessObject()); DataTable table = dataSetProvider.GetDataTable(mapper.GetUIDef().UIGrid); MyBO bo1 = col[0]; // const string updatedvalue = "UpdatedValue"; const string columnName = "TestProp"; object origionalPropValue = bo1.GetPropertyValue(columnName); //---------------Assert Precondition---------------- Assert.IsTrue(dataSetProvider is EditableDataSetProvider); Assert.AreEqual(4, table.Rows.Count); Assert.AreEqual(bo1.ID.AsString_CurrentValue(), table.Rows[0][_dataTableIdColumnName]); Assert.AreEqual(origionalPropValue, table.Rows[0][columnName]); //---------------Execute Test ---------------------- table.Rows[0][columnName] = DBNull.Value; //---------------Test Result ----------------------- Assert.AreEqual(bo1.ID.AsString_CurrentValue(), table.Rows[0][_dataTableIdColumnName]); Assert.AreEqual(DBNull.Value, table.Rows[0][columnName]); Assert.AreEqual(null, bo1.GetPropertyValue(columnName)); }
/// <summary> /// Constructs the <see cref="DefaultBOEditorFormVWG"/> class with /// the specified <see cref="BusinessObject"/>, uiDefName and <see cref="IControlFactory"/>. /// </summary> /// <param name="bo">The business object to represent</param> /// <param name="uiDefName">The name of the ui def to use.</param> /// <param name="controlFactory">The <see cref="IControlFactory"/> to use for creating the Editor form controls</param> public DefaultBOEditorFormVWG(BusinessObject bo, string uiDefName, IControlFactory controlFactory) { _bo = bo; _controlFactory = controlFactory; _uiDefName = uiDefName; GroupControlCreator = _controlFactory.CreateTabControl; BOMapper mapper = new BOMapper(bo); IUIForm def; if (_uiDefName.Length > 0) { IUIDef uiMapper = mapper.GetUIDef(_uiDefName); if (uiMapper == null) { throw new NullReferenceException("An error occurred while " + "attempting to load an object editing form. A possible " + "cause is that the class definitions do not have a " + "'form' section for the class, under the 'ui' " + "with the name '" + _uiDefName + "'."); } def = uiMapper.UIForm; } else { IUIDef uiMapper = mapper.GetUIDef(); if (uiMapper == null) { throw new NullReferenceException("An error occurred while " + "attempting to load an object editing form. A possible " + "cause is that the class definitions do not have a " + "'form' section for the class."); } def = uiMapper.UIForm; } if (def == null) { throw new NullReferenceException("An error occurred while " + "attempting to load an object editing form. A possible " + "cause is that the class definitions do not have a " + "'form' section for the class."); } PanelBuilder panelBuilder = new PanelBuilder(_controlFactory); //_panelInfo = panelBuilder.BuildPanelForForm(_bo.ClassDef.UIDefCol["default"].UIForm); //_panelInfo = panelBuilder.BuildPanelForForm(_bo.ClassDef.UIDefCol[uiDefName].UIForm); _panelInfo = panelBuilder.BuildPanelForForm(def); _panelInfo.BusinessObject = _bo; _boPanel = _panelInfo.Panel; _buttons = _controlFactory.CreateButtonGroupControl(); // These buttons used to be "&Cancel" and "&OK", but they are missing the "&" in win, so I took them out for VWG // Soriya had originally removed them from Win in revision 2854, but I'm not sure of the reason other than // externally, when fetching the button from the button control, it would be fetched using the text only. // I would prefer to have the "&" in the control, but it may break existing code that uses the buttons on this form. // Also, it seems that VWG does not do anything with the "&" _buttons.AddButton("Cancel", CancelButtonHandler); IButton okbutton = _buttons.AddButton("OK", OKButtonHandler); okbutton.TabStop = false; //okbutton.TabIndex = 3; //okbutton.TabStop = true; //cancelButton.TabIndex = 4; //cancelButton.TabStop = true; okbutton.NotifyDefault(true); this.AcceptButton = (ButtonVWG)okbutton; this.Load += delegate { FocusOnFirstControl(); }; this.Closing += OnClosing; this.Text = def.Title; SetupFormSize(def); MinimizeBox = false; MaximizeBox = false; //this.ControlBox = false; this.StartPosition = FormStartPosition.CenterScreen; CreateLayout(); OnResize(new EventArgs()); }
/// <summary> /// Constructs the <see cref="DefaultBOEditorFormWin"/> class with /// the specified businessObject, uiDefName and post edit action. /// </summary> /// <param name="bo">The business object to represent</param> /// <param name="uiDefName">The name of the ui def to use.</param> /// <param name="controlFactory">The <see cref="IControlFactory"/> to use for creating the Editor form controls</param> /// <param name="creator">The Creator used to Create the Group Control.</param> public DefaultBOEditorFormWin(BusinessObject bo, string uiDefName, IControlFactory controlFactory, GroupControlCreator creator) { _bo = bo; _controlFactory = controlFactory; GroupControlCreator = creator; _uiDefName = uiDefName; BOMapper mapper = new BOMapper(bo); IUIForm def; if (_uiDefName.Length > 0) { IUIDef uiMapper = mapper.GetUIDef(_uiDefName); if (uiMapper == null) { throw new NullReferenceException("An error occurred while " + "attempting to load an object editing form. A possible " + "cause is that the class definitions do not have a " + "'form' section for the class, under the 'ui' " + "with the name '" + _uiDefName + "'."); } def = uiMapper.UIForm; } else { IUIDef uiMapper = mapper.GetUIDef(); if (uiMapper == null) { throw new NullReferenceException("An error occurred while " + "attempting to load an object editing form. A possible " + "cause is that the class definitions do not have a " + "'form' section for the class."); } def = uiMapper.UIForm; } if (def == null) { throw new NullReferenceException("An error occurred while " + "attempting to load an object editing form. A possible " + "cause is that the class definitions do not have a " + "'form' section for the class."); } PanelBuilder panelBuilder = new PanelBuilder(_controlFactory); //_panelInfo = panelBuilder.BuildPanelForForm(_bo.ClassDef.UIDefCol["default"].UIForm); //_panelInfo = panelBuilder.BuildPanelForForm(_bo.ClassDef.UIDefCol[uiDefName].UIForm, this.GroupControlCreator); _panelInfo = panelBuilder.BuildPanelForForm(def, this.GroupControlCreator); _panelInfo.BusinessObject = _bo; _boPanel = _panelInfo.Panel; _buttons = _controlFactory.CreateButtonGroupControl(); _buttons.AddButton("Cancel", CancelButtonHandler); IButton okbutton = _buttons.AddButton("OK", OkButtonHandler); okbutton.NotifyDefault(true); this.AcceptButton = (ButtonWin)okbutton; this.Load += delegate { FocusOnFirstControl(); }; this.FormClosing += OnFormClosing; this.Text = def.Title; SetupFormSize(def); MinimizeBox = false; MaximizeBox = false; //this.ControlBox = false; this.StartPosition = FormStartPosition.CenterScreen; CreateLayout(); OnResize(new EventArgs()); }