コード例 #1
0
        public void TestInitGrid_GlobalDateFormat_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);
            const string dateTimeNoFormatPropertyName = "TestDateTimeNoFormat";

            const string expectedFormat = "dd.MMM.yyyy";

            GlobalUIRegistry.DateDisplaySettings = new DateDisplaySettings();
            GlobalUIRegistry.DateDisplaySettings.GridDateFormat = expectedFormat;
            //--------------Assert PreConditions----------------
            IUIGridColumn dateTimeNoFormatGridColumn = uiGridDef[dateTimeNoFormatPropertyName];

            Assert.IsNotNull(dateTimeNoFormatGridColumn);
            Assert.IsNull(dateTimeNoFormatGridColumn.GetParameterValue("dateFormat"));
            Assert.IsNotNull(GlobalUIRegistry.DateDisplaySettings);
            Assert.AreEqual(expectedFormat, GlobalUIRegistry.DateDisplaySettings.GridDateFormat);

            MyBO     myBo            = new MyBO();
            DateTime currentDateTime = DateTime.Now;

            myBo.SetPropertyValue(dateTimeNoFormatPropertyName, 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[dateTimeNoFormatPropertyName];

            //((DataGridViewCellVWG) dataGridViewCell).DataGridViewCell.HasStyle = false;
            Assert.AreSame(typeof(DateTime), dataGridViewCell.ValueType);
            Assert.AreEqual(currentDateTime.ToString(expectedFormat), dataGridViewCell.FormattedValue);

            //---------------Tear Down -------------------------
        }
コード例 #2
0
        public void TestInitGrid_UIDef_CurrencyFormat_ShouldFormatColumn()
        {
            //---------------Set up test pack-------------------
            IClassDef            classDef    = MyBO.LoadClassDefWithCurrencyParameterFormat_VirtualProp();
            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 = "-MyVirtualDoubleProp-";

            Assert.IsNotNull(uiGridDef[formattedPropertyName]);

            object currencyFormat = uiGridDef[formattedPropertyName].GetParameterValue("currencyFormat");

            Assert.IsNotNull(currencyFormat);

            string       currencyFormatParameter = currencyFormat.ToString();
            const string expectedFormat          = "### ###.##";

            Assert.AreEqual(expectedFormat, currencyFormatParameter);

            MyBO   myBo          = new MyBO();
            double currencyValue = myBo.MyVirtualDoubleProp;
            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);
        }
コード例 #3
0
        public void TestSetupComboBoxFromClassDef_SetsItemsInComboBox()
        {
            //---------------Set up test pack-------------------
            IClassDef classDef = ContactPersonTestBO.LoadClassDefOrganisationTestBORelationship_MultipleReverse();

            OrganisationTestBO.LoadDefaultClassDef();
            ContactPerson.DeleteAllContactPeople();
            OrganisationTestBO.ClearAllFromDB();
            OrganisationTestBO.CreateSavedOrganisation();
            OrganisationTestBO.CreateSavedOrganisation();
            ContactPersonTestBO.CreateSavedContactPersonNoAddresses();
            TestUtil.WaitForGC();
            BusinessObjectCollection <ContactPersonTestBO> col = new BusinessObjectCollection <ContactPersonTestBO>();

            col.LoadAll();

            IEditableGridControl gridControl     = GetControlFactory().CreateEditableGridControl();
            GridInitialiser      gridInitialiser = new GridInitialiser(gridControl, GetControlFactory());

            //--------------Assert PreConditions----------------
            Assert.AreEqual(0, gridControl.Grid.Columns.Count);
            Assert.AreEqual(1, classDef.UIDefCol.Count);
            const string uiDefName = "default";
            IUIGrid      uiGridDef = classDef.UIDefCol[uiDefName].UIGrid;

            Assert.IsNotNull(uiGridDef);
            Assert.AreEqual(1, uiGridDef.Count);
            Assert.AreEqual(1, col.Count);
            Assert.AreEqual(2,
                            BORegistry.DataAccessor.BusinessObjectLoader.GetBusinessObjectCollection <OrganisationTestBO>
                                ("").Count);

            //---------------Execute Test ----------------------
            gridInitialiser.InitialiseGrid(classDef, uiDefName);

            //---------------Test Result -----------------------
            Assert.AreEqual(2, gridControl.Grid.Columns.Count, "Should have ID column and should have comboBoxColumn");
            IDataGridViewColumn dataGridViewColumn = gridControl.Grid.Columns[1];

            AssertIsComboBoxColumnType(dataGridViewColumn);
            AssertComboBoxItemCount(dataGridViewColumn, 3);
        }
コード例 #4
0
        public void TestInitGrid_WithInvalidUIDef()
        {
            //---------------Set up test pack-------------------
            IClassDef            classDef    = LoadMyBoDefaultClassDef();
            IReadOnlyGridControl grid        = CreateReadOnlyGridControl();
            IGridInitialiser     initialiser = new GridInitialiser(grid, GetControlFactory());

            //---------------Execute Test ----------------------
            try
            {
                initialiser.InitialiseGrid(classDef, "NonExistantUIDef");
                Assert.Fail("Should raise an error if the class def does not have the UIDef");
                //---------------Test Result -----------------------
            }
            catch (ArgumentException ex)
            {
                StringAssert.Contains(" does not contain a definition for UIDef ", ex.Message);
            }
            //---------------Tear Down -------------------------
        }
コード例 #5
0
        public void TestInitGrid_WithNonDefaultUIDef()
        {
            //---------------Set up test pack-------------------
            IClassDef            classDef           = LoadMyBoDefaultClassDef();
            const string         alternateUIDefName = "Alternate";
            IReadOnlyGridControl grid        = CreateReadOnlyGridControl();
            IGridInitialiser     initialiser = new GridInitialiser(grid, GetControlFactory());
            IUIDef  uiDef     = classDef.UIDefCol[alternateUIDefName];
            IUIGrid uiGridDef = uiDef.UIGrid;

            //---------------Assert Preconditions---------------
            Assert.AreEqual(1, uiGridDef.Count, "1 defined column in the alternateUIDef");
            //---------------Execute Test ----------------------
            initialiser.InitialiseGrid(classDef, alternateUIDefName);

            //---------------Test Result -----------------------
            Assert.AreEqual(alternateUIDefName, grid.UiDefName);
            Assert.AreEqual(classDef, grid.ClassDef);
            Assert.AreEqual
                (uiGridDef.Count + 1, grid.Grid.Columns.Count,
                "There should be 1 ID column and 1 defined column in the alternateUIDef");
            //---------------Tear Down -------------------------
        }
コード例 #6
0
        public void TestInitGrid_DefaultUIDef_VerifyColumnsSetupCorrectly()
        {
            //---------------Set up test pack-------------------
            IClassDef            classDef    = LoadMyBoDefaultClassDef();
            IReadOnlyGridControl grid        = CreateReadOnlyGridControl();
            IGridInitialiser     initialiser = new GridInitialiser(grid, GetControlFactory());
            IUIDef  uiDef     = classDef.UIDefCol["default"];
            IUIGrid uiGridDef = uiDef.UIGrid;

            GlobalUIRegistry.DateDisplaySettings = new DateDisplaySettings();
            GlobalUIRegistry.DateDisplaySettings.GridDateFormat = "dd MMM yyyy";
            //---------------Assert Preconditions---------------
            Assert.AreEqual(2, uiGridDef.Count, "2 defined columns in the defaultDef");
            IUIGridColumn columnDef1 = uiGridDef[0];

            Assert.AreEqual("TestProp", columnDef1.PropertyName);
            IUIGridColumn columnDef2 = uiGridDef[1];

            Assert.AreEqual("TestProp2", columnDef2.PropertyName);
            Assert.IsNotNull(GlobalUIRegistry.DateDisplaySettings);
            //---------------Execute Test ----------------------
            initialiser.InitialiseGrid(classDef);

            //---------------Test Result -----------------------
            IDataGridViewColumn idColumn = grid.Grid.Columns[0];

            AssertVerifyIDFieldSetUpCorrectly(idColumn);

            IDataGridViewColumn dataColumn1 = grid.Grid.Columns[1];

            AssertThatDataColumnSetupCorrectly(classDef, columnDef1, dataColumn1);
            Assert.AreEqual("", dataColumn1.DefaultCellStyle.Format);
            IDataGridViewColumn dataColumn2 = grid.Grid.Columns[2];

            AssertThatDataColumnSetupCorrectly(classDef, columnDef2, dataColumn2);
            //---------------Tear Down -------------------------
        }
コード例 #7
0
 /// <summary>
 /// Initialises the grid without a ClassDef. This is used where the columns are set up manually.
 /// A typical case of when you would want to set the columns manually would be when the grid
 /// requires alternate columns, such as images to indicate the state of the object or buttons/links.
 /// The grid must already have at least one column added with the name "HABANERO_OBJECTID". This column is used
 /// to synchronise the grid with the business objects.
 /// </summary>
 /// <exception cref="GridBaseInitialiseException">Occurs where the columns have not
 /// already been defined for the grid</exception>
 public void Initialise()
 {
     GridInitialiser.InitialiseGrid();
 }
コード例 #8
0
 /// <summary>
 /// Initialises the grid structure with a given UI definition
 ///  </summary>
 /// <param name="classDef">The Classdef used to initialise the grid</param>
 /// <param name="gridDef">The <see cref="IUIGrid"/> that specifies the grid </param>
 /// <param name="uiDefName">The name of the <see cref="IUIGrid"/></param>
 public void Initialise(IClassDef classDef, IUIGrid gridDef, string uiDefName)
 {
     GridInitialiser.InitialiseGrid(classDef, gridDef, uiDefName);
 }
コード例 #9
0
 /// <summary>
 /// Initiliases the grid structure using the default UI class definition (implicitly named "default")
 /// </summary>
 /// <param name="classDef">The class definition of the business objects shown in the grid</param>
 public void Initialise(IClassDef classDef)
 {
     GridInitialiser.InitialiseGrid(classDef);
 }