public void Test_Notify_Again_ShouldIncludeDetailsInExceptions() { //---------------Set up test pack------------------- Exception exception = new Exception(); string furtherMessage = TestUtil.GetRandomString(); string title = TestUtil.GetRandomString(); RecordingExceptionNotifier exceptionNotifier = new RecordingExceptionNotifier(); exceptionNotifier.Notify(new Exception(), TestUtil.GetRandomString(), TestUtil.GetRandomString()); //---------------Assert Precondition---------------- Assert.AreEqual(1, exceptionNotifier.Exceptions.Count); //---------------Execute Test ---------------------- exceptionNotifier.Notify(exception, furtherMessage, title); //---------------Test Result ----------------------- Assert.AreEqual(2, exceptionNotifier.Exceptions.Count); RecordingExceptionNotifier.ExceptionDetail exceptionDetail = exceptionNotifier.Exceptions[1]; Assert.AreSame(exception, exceptionDetail.Exception); Assert.AreSame(furtherMessage, exceptionDetail.FurtherMessage); Assert.AreSame(title, exceptionDetail.Title); }
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_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_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_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); }