Пример #1
0
        public void TestInitGrid_UIDef_ZeroWidthColumn_HidesColumn()
        {
            //---------------Set up test pack-------------------
            IClassDef            classDef    = MyBO.LoadClassDefWith_Grid_2Columns_1stHasZeroWidth();
            IReadOnlyGridControl grid        = CreateReadOnlyGridControl();
            IGridInitialiser     initialiser = new GridInitialiser(grid, GetControlFactory());
            IUIDef  uiDef     = classDef.UIDefCol["default"];
            IUIGrid uiGridDef = uiDef.UIGrid;

            //---------------Assert Preconditions---------------
            Assert.AreEqual(2, uiGridDef.Count, "2 defined columns in the defaultDef");
            IUIGridColumn columnDef1 = uiGridDef[0];

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

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

            //---------------Test Result -----------------------
            IDataGridViewColumn dataColumn1 = grid.Grid.Columns[1];

            AssertThatDataColumnSetupCorrectly(classDef, columnDef1, dataColumn1);

            IDataGridViewColumn dataColumn2 = grid.Grid.Columns[2];

            AssertThatDataColumnSetupCorrectly(classDef, columnDef2, dataColumn2);
            //---------------Tear Down -------------------------
        }
Пример #2
0
        public void TestLoadWithBothGridAndForm()
        {
            IUIDef def =
                itsLoader.LoadUIDef(
                    @"
				<ui name=""defTestName1"">
					<grid>
						<column heading=""testheading1"" property=""testpropname1""  />
						<column heading=""testheading2"" property=""testpropname2""  />
						<column heading=""testheading3"" property=""testpropname3""  />
					</grid>
					<form>
						<tab name=""testtab"">
							<columnLayout>
								<field label=""testlabel1"" property=""testpropname1"" type=""Button"" mapperType=""testmappertypename1"" />
								<field label=""testlabel2"" property=""testpropname2"" type=""Button"" mapperType=""testmappertypename2"" />
							</columnLayout>
						</tab>
					</form>
				</ui> 
							"                            );

            Assert.IsNotNull(def.UIForm);
            Assert.AreEqual(1, def.UIForm.Count);
            Assert.IsNotNull(def.UIGrid);
            Assert.AreEqual(3, def.UIGrid.Count);
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        public virtual void TestClassWithUIDef()
        {
            ClassDef.ClassDefs.Remove(typeof(TestClass));
            ClassDef.ClassDefs.Remove(typeof(TestRelatedClass));
            IClassDef def =
                _loader.LoadClass(
                    @"
				<class name=""TestClass"" assembly=""Habanero.Test.BO.Loaders"">
					<property  name=""TestProp"" />
					<property  name=""TestProp2"" />
					<primaryKey>
						<prop name=""TestProp"" />
					</primaryKey>
					<ui>
						<form>
							<tab name=""testtab"">
								<columnLayout>
									<field label=""Test Prop"" property=""TestProp"" />
								</columnLayout>
							</tab>
						</form>
					</ui>
				</class>
			"            );
            IUIDef uiDef = def.UIDefCol["default"];

            Assert.IsNotNull(uiDef);
            Assert.IsNotNull(uiDef.UIForm);
            Assert.IsNull(uiDef.UIGrid);
        }
        public void Test_GetDefaultUIDef_WhenNotHasViewAndHasStringProp_ShouldCreateUIField()
        {
            //---------------Set up test pack-------------------
            var       viewCreator = new UIViewCreator(GetFactory());
            IClassDef classDef    = typeof(FakeBo).MapClass();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, classDef.UIDefCol.Count);
            //---------------Execute Test ----------------------
            IUIDef returnedUIDef = viewCreator.GetDefaultUIDef(classDef);
            //---------------Test Result -----------------------
            IUIForm uiForm = returnedUIDef.UIForm;

            Assert.IsNotNull(uiForm);
            // Assert.AreSame(returnedUIDef, uiForm.UIDef);
            Assert.AreEqual(1, uiForm.Count, "Should create tab");
            IUIFormTab uiFormTab = uiForm[0];

            Assert.AreSame(uiForm, uiFormTab.UIForm);
            Assert.AreEqual("default", uiFormTab.Name);
            Assert.AreEqual(1, uiFormTab.Count, "Should create col");
            IUIFormColumn uiFormColumn = uiFormTab[0];

            Assert.AreSame(uiFormTab, uiFormColumn.UIFormTab);
            Assert.AreEqual(1, uiFormColumn.Count, "Should create field");
            IUIFormField uiFormField = uiFormColumn[0];

            Assert.AreEqual("Fake Bo Name", uiFormField.Label);
            Assert.AreEqual("FakeBoName", uiFormField.PropertyName);
        }
        public void Test_GetDefaultUIDef_WhenNotHasViewAndHasStringProp_ShouldCreateUIGridColumn()
        {
            //---------------Set up test pack-------------------
            var       viewCreator = new UIViewCreator(GetFactory());
            IClassDef classDef    = typeof(FakeBoW2Props).MapClass();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, classDef.UIDefCol.Count);
            Assert.AreEqual(3, classDef.PropDefcol.Count, "2 Props and IDProp");
            //---------------Execute Test ----------------------
            IUIDef returnedUIDef = viewCreator.GetDefaultUIDef(classDef);

            //---------------Test Result -----------------------
            Assert.IsNotNull(returnedUIDef.UIGrid);
            var returnedUIGrid = returnedUIDef.UIGrid;

            Assert.AreEqual(2, returnedUIGrid.Count);
            IUIGridColumn uiFormField1 = returnedUIGrid[0];

            Assert.AreEqual("Fake Bo Name", uiFormField1.Heading);
            Assert.AreEqual("FakeBoName", uiFormField1.PropertyName);

            IUIGridColumn uiFormField2 = returnedUIGrid[1];

            Assert.AreEqual("Fake Bo Name 2", uiFormField2.Heading);
            Assert.AreEqual("FakeBoName2", uiFormField2.PropertyName);
        }
Пример #7
0
        public void TestInitGrid_LoadsCustomColumnType()
        {
            //---------------Set up test pack-------------------
            IClassDef            classDef    = MyBO.LoadClassDefWithDateTimeParameterFormat();
            IEditableGridControl grid        = GetControlFactory().CreateEditableGridControl();
            IGridInitialiser     initialiser = new GridInitialiser(grid, GetControlFactory());
            IUIDef  uiDef     = classDef.UIDefCol["default"];
            IUIGrid uiGridDef = uiDef.UIGrid;

            Type customColumnType = typeof(CustomDataGridViewColumnVWG);

            uiGridDef[2].GridControlTypeName     = customColumnType.Name; //"CustomDataGridViewColumn";
            uiGridDef[2].GridControlAssemblyName = "Habanero.Faces.Test.VWG";
            AddControlToForm(grid);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            initialiser.InitialiseGrid(classDef);
            //---------------Test Result -----------------------
            Assert.AreEqual(6, grid.Grid.Columns.Count);
            IDataGridViewColumn column3 = grid.Grid.Columns[3];

            Assert.AreEqual("TestDateTime", column3.Name);
            Assert.IsInstanceOf(typeof(IDataGridViewColumn), column3);
            AssertGridColumnTypeAfterCast(column3, customColumnType);
        }
Пример #8
0
        public virtual void TestInitGrid_LoadsDataGridViewComboBoxColumn_WhenPropDefMissing()
        {
            //---------------Set up test pack-------------------
            IClassDef            classDef = MyBO.LoadClassDefWith_Grid_1ComboBoxColumn();
            IEditableGridControl grid     = GetControlFactory().CreateEditableGridControl();

            DisposeOnTearDown(grid);
            IGridInitialiser initialiser   = new GridInitialiser(grid, GetControlFactory());
            IUIDef           uiDef         = classDef.UIDefCol["default"];
            IUIGrid          uiGridDef     = uiDef.UIGrid;
            IUIGridColumn    uiComboColDef = uiGridDef[0];

            uiComboColDef.GridControlTypeName = "DataGridViewComboBoxColumn";
            uiComboColDef.PropertyName        = "OtherProp";
            AddControlToForm(grid);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            initialiser.InitialiseGrid(classDef);
            //---------------Test Result -----------------------
            Assert.AreEqual(2, grid.Grid.Columns.Count);
            IDataGridViewColumn column1 = grid.Grid.Columns[1];

            Assert.AreEqual("OtherProp", column1.Name);
            Assert.AreEqual(uiComboColDef.Heading, column1.HeaderText);
            Assert.IsInstanceOf(typeof(IDataGridViewComboBoxColumn), column1);
            AssertGridColumnTypeAfterCast(column1, GetComboBoxGridColumnType());
        }
Пример #9
0
        public virtual IClassDef GetClassDef()
        {
            IUIFormColumn column = this.UIFormColumn;

            if (column == null)
            {
                return(null);
            }
            IUIFormTab tab = column.UIFormTab;

            if (tab == null)
            {
                return(null);
            }
            IUIForm form = tab.UIForm;

            if (form == null)
            {
                return(null);
            }
            IUIDef uiDef = form.UIDef;

            if (uiDef == null)
            {
                return(null);
            }
            if (uiDef.ClassDef != null)
            {
                return(uiDef.ClassDef);
            }
            return(uiDef.UIDefCol == null ? null : uiDef.UIDefCol.ClassDef);
        }
Пример #10
0
        public virtual void TestInitGrid_LoadsDataGridViewDateTimeColumn()
        {
            //---------------Set up test pack-------------------
            IClassDef            classDef = MyBO.LoadClassDefWithDateTimeParameterFormat();
            IEditableGridControl grid     = GetControlFactory().CreateEditableGridControl();

            DisposeOnTearDown(grid);
            IGridInitialiser initialiser = new GridInitialiser(grid, GetControlFactory());
            IUIDef           uiDef       = classDef.UIDefCol["default"];
            IUIGrid          uiGridDef   = uiDef.UIGrid;
            IUIGridColumn    uiDTColDef  = uiGridDef[2];

            uiDTColDef.GridControlTypeName = "DataGridViewDateTimeColumn";
            AddControlToForm(grid);

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            initialiser.InitialiseGrid(classDef);
            //---------------Test Result -----------------------
            Assert.AreEqual(6, grid.Grid.Columns.Count);
            IDataGridViewColumn column3 = grid.Grid.Columns[3];

            Assert.AreEqual("TestDateTime", column3.Name);
            Assert.AreEqual(uiDTColDef.Heading, column3.HeaderText);
            Assert.IsInstanceOf(typeof(IDataGridViewColumn), column3);
            AssertGridColumnTypeAfterCast(column3, GetDateTimeGridColumnType());
        }
Пример #11
0
        public void TestInitGrid_Twice_Fail()
        {
            //---------------Set up test pack-------------------
            IReadOnlyGridControl grid        = CreateReadOnlyGridControl();
            IGridInitialiser     initialiser = new GridInitialiser(grid, GetControlFactory());
            IClassDef            classDef    = LoadMyBoDefaultClassDef();
            //---------------Assert Preconditions---------------
            IUIDef  uiDef     = classDef.UIDefCol["default"];
            IUIGrid uiGridDef = uiDef.UIGrid;

            //---------------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);
            //---------------Execute Test ----------------------
            initialiser.InitialiseGrid(classDef);

            initialiser.InitialiseGrid(classDef);
            //---------------Test Result -----------------------
            IDataGridViewColumn idColumn = grid.Grid.Columns[0];

            AssertVerifyIDFieldSetUpCorrectly(idColumn);

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

            AssertThatDataColumnSetupCorrectly(classDef, columnDef1, dataColumn1);

            IDataGridViewColumn dataColumn2 = grid.Grid.Columns[2];

            AssertThatDataColumnSetupCorrectly(classDef, columnDef2, dataColumn2);
        }
Пример #12
0
        public void TestInitialiseGrid()
        {
            //---------------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;

            //---------------Assert Preconditions---------------
            Assert.AreEqual(2, uiGridDef.Count, "2 defined columns in the defaultDef");
//            Assert.AreEqual("", grid.UiDefName);
            Assert.IsNull(grid.ClassDef);
            //---------------Execute Test ----------------------
            initialiser.InitialiseGrid(classDef);

            //---------------Test Result -----------------------
            Assert.AreEqual("default", grid.UiDefName);
            Assert.AreEqual(classDef, grid.ClassDef);
            Assert.AreEqual
                (uiGridDef.Count + 1, grid.Grid.Columns.Count,
                "There should be 1 ID column and 2 defined columns in the defaultDef");
            Assert.IsTrue(initialiser.IsInitialised);
//            Assert.IsTrue(grid.IsInitialised);
        }
Пример #13
0
        private void AddFieldToClassDef(IClassDef classDef, IUIFormField uiFormField)
        {
            IUIDef        def    = classDef.UIDefCol["default"];
            IUIForm       form   = def.UIForm;
            IUIFormTab    tab    = form[0];
            IUIFormColumn column = tab[0];

            column.Add(uiFormField);
        }
        private IUIFormField GetFormField(IUIDef uiDef, int index)
        {
            IUIForm       uiForm       = uiDef.UIForm;
            IUIFormTab    uiFormTab    = uiForm[0];
            IUIFormColumn uiFormColumn = uiFormTab[0];
            IUIFormField  uiFormField  = uiFormColumn[index];

            return(uiFormField);
        }
Пример #15
0
        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 -------------------------
        }
Пример #16
0
        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);
        }
Пример #17
0
        public void TestName()
        {
            IUIDef def =
                itsLoader.LoadUIDef(
                    @"
				<ui name=""defTestName1"">
					<grid>
						<column heading=""testheading1"" property=""testpropname1""  />
						<column heading=""testheading2"" property=""testpropname2""  />
						<column heading=""testheading3"" property=""testpropname3""  />
					</grid>
				</ui> "                );

            Assert.AreEqual("defTestName1", def.Name);
        }
        public void Test_GetDefaultUIDef_WhenNotHas_ShouldSetTitle()
        {
            //---------------Set up test pack-------------------
            var       viewCreator = new UIViewCreator(GetFactory());
            IClassDef classDef    = typeof(FakeBo).MapClass();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, classDef.UIDefCol.Count);
            //---------------Execute Test ----------------------
            IUIDef returnedUIDef = viewCreator.GetDefaultUIDef(classDef);

            //---------------Test Result -----------------------
            Assert.IsNotNull(returnedUIDef.UIForm);
            Assert.AreEqual("Fake Bo Form", returnedUIDef.UIForm.Title);
        }
Пример #19
0
        public void TestOtherUIDefMissingException()
        {
            UIDefCol col = new UIDefCol();

            try
            {
                IUIDef uiDef = col["otherdef"];
                Assert.Fail("Expected to throw an HabaneroApplicationException");
            }
            //---------------Test Result -----------------------
            catch (HabaneroApplicationException ex)
            {
                StringAssert.Contains("The ui definition with the name 'otherdef' does not " +
                                      "exist in the collection of definitions for the", ex.Message);
            }
        }
Пример #20
0
        public void TestDefaultUIDefMissingException()
        {
            //---------------Set up test pack-------------------
            UIDefCol col = new UIDefCol();

            //---------------Execute Test ----------------------
            try
            {
                IUIDef uiDef = col["default"];
                Assert.Fail("Expected to throw an HabaneroApplicationException");
            }
            //---------------Test Result -----------------------
            catch (HabaneroApplicationException ex)
            {
                StringAssert.Contains("No default 'ui' definition exists (a definition with no name attribute)", ex.Message);
            }
        }
Пример #21
0
        public void TestLoadWithJustGrid()
        {
            IUIDef def =
                itsLoader.LoadUIDef(
                    @"
				<ui name=""defTestName1"">
					<grid>
						<column heading=""testheading1"" property=""testpropname1""  />
						<column heading=""testheading2"" property=""testpropname2""  />
						<column heading=""testheading3"" property=""testpropname3""  />
					</grid>
				</ui> 
							"                            );

            Assert.IsNotNull(def.UIGrid);
            Assert.AreEqual(3, def.UIGrid.Count);
        }
Пример #22
0
        public void TestCloneUIFormNull()
        {
            //---------------Set up test pack-------------------
            UIDef uiDef = new UIDef("Name", null, GetUiGrid());
            //--------------Assert PreConditions----------------

            //---------------Execute Test ----------------------
            IUIDef clonedDef = uiDef.Clone();

            //---------------Test Result -----------------------
            Assert.IsTrue(uiDef == (UIDef)clonedDef);
            Assert.IsTrue(uiDef.Equals(clonedDef));
            Assert.AreNotSame(uiDef, clonedDef);

            Assert.AreSame(null, clonedDef.UIForm);
            Assert.AreNotSame(uiDef.UIGrid, clonedDef.UIGrid);
            //---------------Tear Down -------------------------
        }
        public void Test_GetDefaultUIDef_WhenHasDefaultUIView_ShouldReturnUIDef()
        {
            //---------------Set up test pack-------------------
            var       viewCreator   = new UIViewCreator(GetFactory());
            IClassDef classDef      = typeof(FakeBo).MapClass();
            var       expectedUIDef = new UIDef("default", new UIForm(), new UIGrid());

            classDef.UIDefCol.Add(expectedUIDef);
            //---------------Assert Precondition----------------
            Assert.AreEqual(1, classDef.UIDefCol.Count);
            Assert.AreEqual("default", classDef.UIDefCol["default"].Name);
            //---------------Execute Test ----------------------
            IUIDef returnedUIDef = viewCreator.GetDefaultUIDef(classDef);

            //---------------Test Result -----------------------
            Assert.IsNotNull(returnedUIDef);
            Assert.AreEqual(expectedUIDef, returnedUIDef);
        }
Пример #24
0
        public void Test_GetClassDef_ReturnsUIDefsClassDef()
        {
            //---------------Set up test pack-------------------
            IClassDef expectedClassDef = MockRepository.GenerateStub <IClassDef>();
            IUIGrid   uiGrid           = new UIGrid();
            IUIDef    uiDef            = MockRepository.GenerateStub <IUIDef>();

            uiGrid.UIDef = uiDef;
            //---------------Assert Precondition----------------
            Assert.IsNull(uiGrid.ClassDef);
            Assert.IsNotNull(uiGrid.UIDef);
            //---------------Execute Test ----------------------
            uiDef.ClassDef = expectedClassDef;
            var actualClassDef = uiGrid.ClassDef;

            //---------------Test Result -----------------------
            Assert.AreSame(expectedClassDef, actualClassDef);
        }
Пример #25
0
        public void TestCloneUIDef()
        {
            //---------------Set up test pack-------------------
            UIForm uiForm = GetUiForm();

            UIGrid uiGrid = GetUiGrid();

            UIDef uiDef = new UIDef("Name", uiForm, uiGrid);
            //---------------Execute Test ----------------------
            IUIDef clonedDef = uiDef.Clone();

            //---------------Test Result -----------------------
            Assert.IsTrue(uiDef == (UIDef)clonedDef);
            Assert.IsTrue(uiDef.Equals(clonedDef));
            Assert.AreNotSame(uiDef, clonedDef);

            Assert.AreNotSame(uiDef.UIForm, clonedDef.UIForm);
            Assert.AreNotSame(uiDef.UIGrid, clonedDef.UIGrid);
        }
        public void Test_GetDefaultUIDef_With2Props_ShouldCreate2UIFields()
        {
            //---------------Set up test pack-------------------
            var       viewCreator = new UIViewCreator(GetFactory());
            IClassDef classDef    = typeof(FakeBoW2Props).MapClass();

            //---------------Assert Precondition----------------
            Assert.AreEqual(0, classDef.UIDefCol.Count);
            Assert.AreEqual(3, classDef.PropDefcol.Count, "2 Props and IDProp");
            //---------------Execute Test ----------------------
            IUIDef returnedUIDef = viewCreator.GetDefaultUIDef(classDef);
            //---------------Test Result -----------------------
            IUIFormField uiFormField1 = GetFormField(returnedUIDef, 0);

            Assert.AreEqual("Fake Bo Name", uiFormField1.Label);
            Assert.AreEqual("FakeBoName", uiFormField1.PropertyName);

            IUIFormField uiFormField2 = GetFormField(returnedUIDef, 1);

            Assert.AreEqual("Fake Bo Name 2", uiFormField2.Label);
            Assert.AreEqual("FakeBoName2", uiFormField2.PropertyName);
        }
Пример #27
0
        private IUIGrid GetGridDef(ClassDef classDef, string uiDefName)
        {
            IUIDef uiDef = classDef.GetUIDef(uiDefName);

            if (uiDef == null)
            {
                throw new ArgumentException
                          (String.Format
                              ("You cannot initialise {0} because it does not contain a definition for UIDef {1} for the class def {2}",
                              this.Grid.Grid.Name, uiDefName, classDef.ClassName));
            }
            IUIGrid gridDef = uiDef.UIGrid;

            if (gridDef == null)
            {
                throw new ArgumentException
                          (String.Format
                              ("You cannot initialise {0} does not contain a grid definition for UIDef {1} for the class def {2}",
                              this.Grid.Grid.Name, uiDefName, classDef.ClassName));
            }
            return(gridDef);
        }
Пример #28
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 -------------------------
        }
Пример #29
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 -------------------------
        }
        /// <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());
        }