public void Test_Construct() { //---------------Set up test pack------------------- //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- RecordingExceptionNotifier exceptionNotifier = new RecordingExceptionNotifier(); //---------------Test Result ----------------------- Assert.AreEqual(0, exceptionNotifier.Exceptions.Count); Assert.IsInstanceOf(typeof(IExceptionNotifier), exceptionNotifier); }
public void Test_HasException_WhenHas_ShouldRetTrue() { //---------------Set up test pack------------------- RecordingExceptionNotifier exceptionNotifier = new RecordingExceptionNotifier(); exceptionNotifier.Notify(new Exception(), TestUtil.GetRandomString(), TestUtil.GetRandomString()); //---------------Assert Precondition---------------- Assert.AreEqual(1, exceptionNotifier.Exceptions.Count); //---------------Execute Test ---------------------- var hasExceptions = exceptionNotifier.HasExceptions; //---------------Test Result ----------------------- Assert.IsTrue(hasExceptions); }
public void Test_Notify_ShouldIncludeDetailsInExceptions() { //---------------Set up test pack------------------- Exception exception = new Exception(); string furtherMessage = TestUtil.GetRandomString(); string title = TestUtil.GetRandomString(); RecordingExceptionNotifier exceptionNotifier = new RecordingExceptionNotifier(); //---------------Assert Precondition---------------- Assert.AreEqual(0, exceptionNotifier.Exceptions.Count); //---------------Execute Test ---------------------- exceptionNotifier.Notify(exception, furtherMessage, title); //---------------Test Result ----------------------- Assert.AreEqual(1, exceptionNotifier.Exceptions.Count); RecordingExceptionNotifier.ExceptionDetail exceptionDetail = exceptionNotifier.Exceptions[0]; Assert.AreSame(exception, exceptionDetail.Exception); Assert.AreSame(furtherMessage, exceptionDetail.FurtherMessage); Assert.AreSame(title, exceptionDetail.Title); }
/// <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; } }
public void Test_AddRow_WhenVirtualProp_ShouldAddBOWithRelatedVirtualPropSet() { //---------------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>(); 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(0, table.Rows.Count); Assert.AreEqual(0, contactPersonTestBOS.Count); //---------------Execute Test ---------------------- table.Rows.Add(new object[] { null, organisation }); //---------------Test Result ----------------------- Assert.AreEqual(1, table.Rows.Count); Assert.AreEqual(1, contactPersonTestBOS.Count); Assert.AreSame(organisation, table.Rows[0][propertyName]); Assert.AreSame(organisation, contactPersonTestBOS[0].Organisation); }
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(); }
public void Test_HasException_WhenNotHas_ShouldRetFalse() { //---------------Set up test pack------------------- RecordingExceptionNotifier exceptionNotifier = new RecordingExceptionNotifier(); //---------------Assert Precondition---------------- Assert.AreEqual(0, exceptionNotifier.Exceptions.Count); //---------------Execute Test ---------------------- var hasExceptions = exceptionNotifier.HasExceptions; //---------------Test Result ----------------------- Assert.IsFalse(hasExceptions); }
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"); }
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"); }
public void Test_Message_WhenTwoItem_ShouldReturnMessage() { //---------------Set up test pack------------------- string title = TestUtil.GetRandomString(); RecordingExceptionNotifier exceptionNotifier = new RecordingExceptionNotifier(); Exception exception = new Exception(GetRandomString()); string furtherMessage = TestUtil.GetRandomString(); exceptionNotifier.Notify(exception, furtherMessage, title); Exception exception2 = new Exception(GetRandomString()); string furtherMessage2 = TestUtil.GetRandomString(); exceptionNotifier.Notify(exception2, furtherMessage2, title); //---------------Assert Precondition---------------- Assert.AreEqual(2, exceptionNotifier.Exceptions.Count); //---------------Execute Test ---------------------- var exceptionMessage = exceptionNotifier.ExceptionMessage; //---------------Test Result ----------------------- var expectedErrorMessage = exception.Message + " - " + furtherMessage + Environment.NewLine + exception2.Message + " - " + furtherMessage2; Assert.AreEqual(expectedErrorMessage, exceptionMessage); }
public void Test_Message_WhenOneItem_ShouldReturnMessage() { //---------------Set up test pack------------------- Exception exception = new Exception(GetRandomString()); string furtherMessage = TestUtil.GetRandomString(); string title = TestUtil.GetRandomString(); RecordingExceptionNotifier exceptionNotifier = new RecordingExceptionNotifier(); exceptionNotifier.Notify(exception, furtherMessage, title); //---------------Assert Precondition---------------- Assert.AreEqual(1, exceptionNotifier.Exceptions.Count); //---------------Execute Test ---------------------- var exceptionMessage = exceptionNotifier.ExceptionMessage; //---------------Test Result ----------------------- Assert.AreEqual(exception.Message + " - " + furtherMessage, exceptionMessage); }
public void Test_Message_When_NoItems_ShouldBeEmptyString() { //---------------Set up test pack------------------- // Exception exception = new Exception(); // string furtherMessage = TestUtil.GetRandomString(); // string title = TestUtil.GetRandomString(); IExceptionNotifier exceptionNotifier = new RecordingExceptionNotifier(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var exceptionMessage = exceptionNotifier.ExceptionMessage; //---------------Test Result ----------------------- Assert.IsNullOrEmpty(exceptionMessage); }
public void Test_CustomButtonEventHandler_WhenExceptionThrown_ShouldBeCaughtByUIExceptionNotifier() { //---------------Set up test pack------------------- IButtonGroupControl buttons = CreateButtonGroupControl(); RecordingExceptionNotifier recordingExceptionNotifier = new RecordingExceptionNotifier(); GlobalRegistry.UIExceptionNotifier = recordingExceptionNotifier; bool clickEventFired = false; Exception exception = new Exception(); IButton btn = buttons.AddButton("Test", delegate { clickEventFired = true; throw exception; }); //---------------Execute Test ---------------------- btn.PerformClick(); //---------------Test Result ----------------------- Assert.IsTrue(clickEventFired, "The click event should have fired"); Assert.AreEqual(1, recordingExceptionNotifier.Exceptions.Count); Assert.AreSame(exception, recordingExceptionNotifier.Exceptions[0].Exception); Assert.AreSame("Error performing action", recordingExceptionNotifier.Exceptions[0].FurtherMessage); Assert.AreSame("Error", recordingExceptionNotifier.Exceptions[0].Title); }