-
Notifications
You must be signed in to change notification settings - Fork 288
Today even if classInit wasnt called we used to call class cleanup. f… #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1ebe2ca
67c197e
23b237d
7819037
31cfe68
967eb99
ab84619
91ca2a9
4874cf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,10 +103,15 @@ internal set | |
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether is class initialize executed. | ||
| /// Gets a value indicating whether class initialize has executed. | ||
| /// </summary> | ||
| public bool IsClassInitializeExecuted { get; internal set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether class cleanup has executed. | ||
| /// </summary> | ||
| public bool IsClassCleanupExecuted { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the exception thrown during <see cref="ClassInitializeAttribute"/> method invocation. | ||
| /// </summary> | ||
|
|
@@ -306,40 +311,52 @@ public string RunClassCleanup() | |
| return null; | ||
| } | ||
|
|
||
| lock (this.testClassExecuteSyncObject) | ||
| if (this.IsClassInitializeExecuted) | ||
|
||
| { | ||
| try | ||
| { | ||
| this.ClassCleanupMethod.InvokeAsSynchronousTask(null); | ||
|
|
||
| return null; | ||
| } | ||
| catch (Exception exception) | ||
| lock (this.testClassExecuteSyncObject) | ||
|
||
| { | ||
| var realException = exception.InnerException ?? exception; | ||
|
|
||
| string errorMessage; | ||
|
|
||
| // special case AssertFailedException to trim off part of the stack trace | ||
| if (realException is AssertFailedException || | ||
| realException is AssertInconclusiveException) | ||
| { | ||
| errorMessage = realException.Message; | ||
| } | ||
| else | ||
| if (this.IsClassInitializeExecuted) | ||
|
||
| { | ||
| errorMessage = StackTraceHelper.GetExceptionMessage(realException); | ||
| } | ||
| try | ||
| { | ||
| this.ClassCleanupMethod.InvokeAsSynchronousTask(null); | ||
|
|
||
| return string.Format( | ||
| CultureInfo.CurrentCulture, | ||
| Resource.UTA_ClassCleanupMethodWasUnsuccesful, | ||
| this.ClassType.Name, | ||
| this.ClassCleanupMethod.Name, | ||
| errorMessage, | ||
| StackTraceHelper.GetStackTraceInformation(realException)?.ErrorStackTrace); | ||
| return null; | ||
| } | ||
| catch (Exception exception) | ||
| { | ||
| var realException = exception.InnerException ?? exception; | ||
|
|
||
| string errorMessage; | ||
|
|
||
| // special case AssertFailedException to trim off part of the stack trace | ||
| if (realException is AssertFailedException || | ||
| realException is AssertInconclusiveException) | ||
| { | ||
| errorMessage = realException.Message; | ||
| } | ||
| else | ||
| { | ||
| errorMessage = StackTraceHelper.GetExceptionMessage(realException); | ||
| } | ||
|
|
||
| return string.Format( | ||
| CultureInfo.CurrentCulture, | ||
| Resource.UTA_ClassCleanupMethodWasUnsuccesful, | ||
| this.ClassType.Name, | ||
| this.ClassCleanupMethod.Name, | ||
| errorMessage, | ||
| StackTraceHelper.GetStackTraceInformation(realException)?.ErrorStackTrace); | ||
| } | ||
| finally | ||
| { | ||
| this.IsClassCleanupExecuted = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,18 @@ public void TestClassInfoClassCleanupMethodSetShouldThrowForMultipleClassCleanup | |
| ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TypeInspectionException)); | ||
| } | ||
|
|
||
| [TestMethod] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a negative test case. Can we add a positive test case as well? |
||
| public void TestClassInfoClassCleanupMethodShouldNotInvokeWhenNoTestClassInitializedIsCalled() | ||
| { | ||
| this.testClassInfo.ClassCleanupMethod = this.testClassType.GetMethods().First(); | ||
| this.testClassInfo.ClassInitializeMethod = this.testClassType.GetMethods()[1]; | ||
|
|
||
| var ret = this.testClassInfo.RunClassCleanup(); // call cleanup without calling init | ||
|
|
||
| Assert.AreEqual(null, ret); | ||
| Assert.AreEqual(false, this.testClassInfo.IsClassCleanupExecuted); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void TestClassInfoHasExecutableCleanupMethodShouldReturnFalseIfClassDoesNotHaveCleanupMethod() | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required?