コード例 #1
0
        /// <summary>
        /// Loads class definitions, converting them from a 
        /// string containing these definitions to an IList object.
        /// If the conversion fails, an error message will be sent to the 
        /// console.
        /// </summary>
        /// <param name="xmlClassDefs">The string containing all the
        /// class definitions. If you are loading these from 
        /// a file, you can use 
        /// <code>new StreamReader("filename.xml").ReadToEnd()</code>
        /// to create a continuous string.</param>
        /// <returns>Returns an IList object containing the definitions</returns>
        public ClassDefCol LoadClassDefs(string xmlClassDefs)
        {
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.LoadXml(xmlClassDefs);
            }
            catch (XmlException ex)
            {
                throw new XmlException
                    ("The class definitions XML file has no root "
                     + "element 'classes'.  The document needs a master 'classes' element "
                     + "and individual 'class' elements for each of the classes you are " + "defining.", ex);
            }
            var origionalExceptionNotifier = GlobalRegistry.UIExceptionNotifier;
            try
            {
                
                var recordingExceptionNotifier = new RecordingExceptionNotifier();
                GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier;

                var loadClassDefs = LoadClassDefs(doc.DocumentElement);
                recordingExceptionNotifier.RethrowRecordedException();
                return loadClassDefs;
            }
            finally
            {
                GlobalRegistry.UIExceptionNotifier = origionalExceptionNotifier;
            }

        }
コード例 #2
0
        public void Test_EditDataTable_WhenVirtualProp_ShouldEditRelatedVirtualProp()
        {
            //---------------Set up test pack-------------------
            RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier();
            GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier;
            AddressTestBO.LoadDefaultClassDef();
            var contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();
            OrganisationTestBO.LoadDefaultClassDef();
            BusinessObjectCollection<ContactPersonTestBO> contactPersonTestBOS = new BusinessObjectCollection<ContactPersonTestBO>();
            contactPersonTestBOS.Add(new ContactPersonTestBO(), new ContactPersonTestBO(), new ContactPersonTestBO());

            OrganisationTestBO organisation = new OrganisationTestBO();

            UIGrid uiGrid = new UIGrid();
            new UIDef("fdafdas", new UIForm(), uiGrid) { ClassDef = contactPersonClassDef };
            const string propertyName = "-Organisation-";
            uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable()));

            IDataSetProvider dataSetProvider = CreateDataSetProvider(contactPersonTestBOS);
            DataTable table = dataSetProvider.GetDataTable(uiGrid);

            //---------------Assert Precondition----------------
            Assert.IsTrue(dataSetProvider is EditableDataSetProvider);
            Assert.AreEqual(3, table.Rows.Count);
            Assert.AreEqual(DBNull.Value, table.Rows[0][propertyName]);
            Assert.AreEqual(null, contactPersonTestBOS[0].Organisation);
            //---------------Execute Test ----------------------
            table.Rows[0][propertyName] = organisation;
            //---------------Test Result -----------------------
            Assert.AreSame(organisation, table.Rows[0][propertyName]);
            Assert.AreSame(organisation, contactPersonTestBOS[0].Organisation);
            recordingExceptionNotifier.RethrowRecordedException();
        }
コード例 #3
0
 public void Test_RethrowRecordedException_WhenNoRecordedExceptionsExist_ShouldDoNothing()
 {
     //---------------Set up test pack-------------------
     RecordingExceptionNotifier exceptionNotifier = new RecordingExceptionNotifier();
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     bool exceptionThrown = false;
     try
     {
         exceptionNotifier.RethrowRecordedException();
     }
     //---------------Test Result -----------------------
     catch (Exception)
     {
         exceptionThrown = true;
     }
     Assert.IsFalse(exceptionThrown, "Expected not to throw an Exception");
 }
コード例 #4
0
        public void Test_AddRow_WhenMultipleLevelProp_ShouldAddBOWithRelatedPropSet()
        {
            //---------------Set up test pack-------------------
            RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier();
            GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier;
            ClassDef.ClassDefs.Clear();
            AddressTestBO.LoadDefaultClassDef();
            ContactPersonTestBO.LoadClassDefWithOrganisationAndAddressRelationships();
            OrganisationTestBO.LoadDefaultClassDef();
            ContactPersonTestBO contactPersonTestBO = ContactPersonTestBO.CreateSavedContactPerson();
            BusinessObjectCollection<AddressTestBO> addresses = contactPersonTestBO.Addresses;

            OrganisationTestBO organisation = new OrganisationTestBO();

            UIGrid uiGrid = new UIGrid();
            const string propertyName = "ContactPersonTestBO.OrganisationID";
            uiGrid.Add(new UIGridColumn("Contact Organisation", propertyName, typeof(DataGridViewTextBoxColumn), true, 100, PropAlignment.left, new Hashtable()));

            IDataSetProvider dataSetProvider = CreateDataSetProvider(addresses);
            DataTable table = dataSetProvider.GetDataTable(uiGrid);

            //---------------Assert Precondition----------------
            Assert.IsTrue(dataSetProvider is EditableDataSetProvider);
            Assert.AreEqual(0, table.Rows.Count);
            Assert.AreEqual(0, addresses.Count);
            //---------------Execute Test ----------------------
            table.Rows.Add(new object[] { null, organisation.OrganisationID });
            //---------------Test Result -----------------------
            Assert.AreEqual(1, table.Rows.Count);
            Assert.AreEqual(1, addresses.Count);
            Assert.AreEqual(organisation.OrganisationID.ToString(), table.Rows[0][propertyName].ToString());
            Assert.AreEqual(organisation.OrganisationID, contactPersonTestBO.OrganisationID);
            recordingExceptionNotifier.RethrowRecordedException();
        }
コード例 #5
0
 public void Test_RethrowRecordedException_WhenRecordedExceptionExists_ShouldRethrowException()
 {
     //---------------Set up test pack-------------------
     RecordingExceptionNotifier exceptionNotifier = new RecordingExceptionNotifier();
     Exception exception = new Exception(GetRandomString());
     string furtherMessage = TestUtil.GetRandomString();
     string title = TestUtil.GetRandomString();
     exceptionNotifier.Notify(exception, furtherMessage, title);
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     bool exceptionThrown = false;
     try
     {
         exceptionNotifier.RethrowRecordedException();
     }
     //---------------Test Result -----------------------
     catch (Exception ex)
     {
         exceptionThrown = true;
         StringAssert.Contains(string.Format(
             "An Exception that was recorded by the RecordingExceptionNotifier and has been rethrown." +
             "{0}Title: {1}{0}Further Message: {2}", Environment.NewLine, title, exceptionNotifier.ExceptionMessage), ex.Message);
         Assert.AreSame(exception, ex.InnerException);
     }
     Assert.IsTrue(exceptionThrown, "Expected to throw an Exception");
 }