public override void Test_SetDateToGridCustomFormat_LoadViaCollection() { //---------------Set up test pack------------------- MyBO.LoadClassDefWithDateTime(); IDataGridViewColumn column; const string requiredFormat = "dd.MMM.yyyy"; IGridBase gridBase = CreateGridBaseWithDateCustomFormatCol(out column, requiredFormat); BusinessObjectCollection <MyBO> col = new BusinessObjectCollection <MyBO>(); MyBO bo = new MyBO(); const string dateTimeProp = "TestDateTime"; DateTime expectedDate = DateTime.Now; bo.SetPropertyValue(dateTimeProp, expectedDate); col.Add(bo); //--------------Assert PreConditions---------------- Assert.AreEqual(expectedDate, bo.GetPropertyValue(dateTimeProp)); Assert.AreEqual(1, gridBase.ColumnCount); Assert.AreEqual(dateTimeProp, gridBase.Columns[0].Name); Assert.AreEqual(dateTimeProp, gridBase.Columns[0].DataPropertyName); //---------------Execute Test ---------------------- gridBase.BusinessObjectCollection = col; //---------------Test Result ----------------------- IDataGridViewCell dataGridViewCell = gridBase.Rows[0].Cells[0]; Assert.AreEqual(expectedDate.ToString(requiredFormat), dataGridViewCell.FormattedValue); }
public void TestInitGrid_UIDef_DateFormat_FormatsDateColumn() { //---------------Set up test pack------------------- IClassDef classDef = MyBO.LoadClassDefWithDateTimeParameterFormat(); IReadOnlyGridControl grid = CreateReadOnlyGridControl(); IGridInitialiser initialiser = new GridInitialiser(grid, GetControlFactory()); IUIDef uiDef = classDef.UIDefCol["default"]; IUIGrid uiGridDef = uiDef.UIGrid; AddControlToForm(grid); GlobalUIRegistry.DateDisplaySettings = new DateDisplaySettings(); GlobalUIRegistry.DateDisplaySettings.GridDateFormat = "dd MMM yyyy"; //--------------Assert PreConditions---------------- const string formattedPropertyName = "TestDateTimeFormat"; Assert.IsNotNull(uiGridDef[formattedPropertyName]); Assert.IsNotNull(uiGridDef["TestDateTimeNoFormat"]); Assert.IsNotNull(uiGridDef["TestDateTime"]); Assert.IsNull(uiGridDef["TestDateTimeNoFormat"].GetParameterValue("dateFormat")); Assert.IsNull(uiGridDef["TestDateTime"].GetParameterValue("dateFormat")); object dateFormatObject = uiGridDef[formattedPropertyName].GetParameterValue("dateFormat"); string dateFormatParameter = dateFormatObject.ToString(); const string expectedFormat = "dd.MMM.yyyy"; Assert.AreEqual(expectedFormat, dateFormatParameter); MyBO myBo = new MyBO(); DateTime currentDateTime = DateTime.Now; myBo.SetPropertyValue(formattedPropertyName, currentDateTime); BusinessObjectCollection <MyBO> col = new BusinessObjectCollection <MyBO>(); col.Add(myBo); //---------------Execute Test ---------------------- initialiser.InitialiseGrid(classDef); grid.BusinessObjectCollection = col; //---------------Test Result ----------------------- Assert.AreEqual(1, col.Count); Assert.AreEqual(1, grid.Grid.Rows.Count); IDataGridViewCell dataGridViewCell = grid.Grid.Rows[0].Cells[formattedPropertyName]; //((DataGridViewCellVWG) dataGridViewCell).DataGridViewCell.HasStyle = false; Assert.AreSame(typeof(DateTime), dataGridViewCell.ValueType); Assert.AreEqual(currentDateTime.ToString(expectedFormat), dataGridViewCell.FormattedValue); //---------------Tear Down ------------------------- }
public void TestInitGrid_UIDef_CurrencyFormat_WhenVirtualProp_ShouldFormatColumn() { //---------------Set up test pack------------------- IClassDef classDef = MyBO.LoadClassDefWithCurrencyParameterFormat(); IReadOnlyGridControl grid = CreateReadOnlyGridControl(); IGridInitialiser initialiser = new GridInitialiser(grid, GetControlFactory()); IUIDef uiDef = classDef.UIDefCol["default"]; IUIGrid uiGridDef = uiDef.UIGrid; AddControlToForm(grid); //--------------Assert PreConditions---------------- const string formattedPropertyName = "TestCurrencyFormat"; Assert.IsNotNull(uiGridDef[formattedPropertyName]); Assert.IsNotNull(uiGridDef[formattedPropertyName].GetParameterValue("currencyFormat")); const string unformattedPropName = "TestCurrencyNoFormat"; Assert.IsNotNull(uiGridDef[unformattedPropName]); Assert.IsNull(uiGridDef[unformattedPropName].GetParameterValue("currencyFormat")); object currencyFormat = uiGridDef[formattedPropertyName].GetParameterValue("currencyFormat"); string currencyFormatParameter = currencyFormat.ToString(); const string expectedFormat = "### ###.##"; Assert.AreEqual(expectedFormat, currencyFormatParameter); MyBO myBo = new MyBO(); const double currencyValue = 222222.55555d; myBo.SetPropertyValue(formattedPropertyName, currencyValue); BusinessObjectCollection <MyBO> col = new BusinessObjectCollection <MyBO>(); col.Add(myBo); //---------------Execute Test ---------------------- initialiser.InitialiseGrid(classDef); grid.BusinessObjectCollection = col; //---------------Test Result ----------------------- Assert.AreEqual(1, col.Count); Assert.AreEqual(1, grid.Grid.Rows.Count); IDataGridViewCell dataGridViewCell = grid.Grid.Rows[0].Cells[formattedPropertyName]; //((DataGridViewCellVWG) dataGridViewCell).DataGridViewCell.HasStyle = false; Assert.AreSame(typeof(Double), dataGridViewCell.ValueType); Assert.AreEqual(currencyValue.ToString(expectedFormat), dataGridViewCell.FormattedValue); }
public void TestVWG_Set_BusinessObjectCollection() { //---------------Set up test pack------------------- MyBO.LoadDefaultClassDef(); BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects(); IGridBase gridBase = CreateGridBaseStub(); SetupGridColumnsForMyBo(gridBase); const string propName = "TestProp"; const int rowIndex = 1; //---------------Execute Test ---------------------- gridBase.BusinessObjectCollection = col; //---------------Test Result ----------------------- MyBO selectedBo = (MyBO)gridBase.GetBusinessObjectAtRow(rowIndex); IDataGridViewRow row = gridBase.Rows[rowIndex]; IDataGridViewCell cell = row.Cells[propName]; Assert.AreEqual(selectedBo.TestProp, cell.Value); }
public override void Test_SetDateToGridCustomFormat_LoadViaDataTable() { //---------------Set up test pack------------------- MyBO.LoadClassDefWithDateTime(); IDataGridViewColumn column; const string requiredFormat = "dd.MMM.yyyy"; IGridBase gridBase = CreateGridBaseWithDateCustomFormatCol(out column, requiredFormat); DataTable dataTable = new DataTable(); const string dateTimeProp = "TestDateTime"; dataTable.Columns.Add(dateTimeProp, typeof(DateTime)); DateTime expectedDate = DateTime.Now; dataTable.Rows.Add(expectedDate); //--------------Assert PreConditions---------------- //---------------Execute Test ---------------------- gridBase.DataSource = dataTable.DefaultView; //---------------Test Result ----------------------- IDataGridViewCell dataGridViewCell = gridBase.Rows[0].Cells[0]; Assert.AreEqual(expectedDate.ToString(requiredFormat), dataGridViewCell.FormattedValue); }
public void TestVWG_RowShowingBusinessObjectsValues() { //---------------Set up test pack------------------- MyBO.LoadDefaultClassDef(); BusinessObjectCollection <MyBO> col = CreateCollectionWith_4_Objects(); IGridBase gridBase = CreateGridBaseStub(); SetupGridColumnsForMyBo(gridBase); const string propName = "TestProp"; const int rowIndex = 1; //---------------Execute Test ---------------------- #pragma warning disable 618,612 //Maintained for backward compatibility testing gridBase.SetBusinessObjectCollection(col); #pragma warning restore 618,612 //---------------Test Result ----------------------- MyBO selectedBo = (MyBO)gridBase.GetBusinessObjectAtRow(rowIndex); IDataGridViewRow row = gridBase.Rows[rowIndex]; IDataGridViewCell cell = row.Cells[propName]; Assert.AreEqual(selectedBo.TestProp, cell.Value); }
///// <summary>Copies the entire collection of cells into an array at a specified location within the array.</summary> ///// <param name="array">The destination array to which the contents will be copied.</param> ///// <param name="index">The index of the element in array at which to start copying.</param> ///// <filterpriority>1</filterpriority> //public void CopyTo(IDataGridViewCell[] array, int index) //{ // throw new NotImplementedException(); //} /// <summary>Returns the index of the specified cell.</summary> /// <returns>The zero-based index of the value of dataGridViewCell parameter, if it is found in the collection; otherwise, -1.</returns> /// <param name="dataGridViewCell">The cell to locate in the collection.</param> /// <filterpriority>1</filterpriority> public int IndexOf(IDataGridViewCell dataGridViewCell) { return(_cells.IndexOf((DataGridViewCell)dataGridViewCell)); }
/// <summary>Determines whether the specified cell is contained in the collection.</summary> /// <returns>true if dataGridViewCell is in the collection; otherwise, false.</returns> /// <param name="dataGridViewCell">A <see cref="IDataGridViewCell"></see> to locate in the collection.</param> /// <filterpriority>1</filterpriority> public bool Contains(IDataGridViewCell dataGridViewCell) { return(_cells.Contains((DataGridViewCell)dataGridViewCell)); }
//public int Count //{ // get { return _cells.Count; } //} /// <summary>Adds a cell to the collection.</summary> /// <returns>The position in which to insert the new element.</returns> /// <param name="dataGridViewCell">A <see cref="IDataGridViewCell"></see> to add to the collection.</param> /// <exception cref="T:System.InvalidOperationException">The row that owns this /// <see cref="IDataGridViewCellCollection"></see> already belongs to a DataGridView control.-or- /// dataGridViewCell already belongs to a DataGridViewRow>.</exception> /// <filterpriority>1</filterpriority> public int Add(IDataGridViewCell dataGridViewCell) { return(_cells.Add((DataGridViewCell)dataGridViewCell)); }