-
Notifications
You must be signed in to change notification settings - Fork 292
Expand file tree
/
Copy pathClassCleanupManagerTests.cs
More file actions
67 lines (54 loc) · 2.68 KB
/
ClassCleanupManagerTests.cs
File metadata and controls
67 lines (54 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using AwesomeAssertions;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Moq;
using TestFramework.ForTestingMSTest;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution;
public class ClassCleanupManagerTests : TestContainer
{
public void AssemblyCleanupRunsAfterAllTestsFinishEvenIfWeScheduleTheSameTestMultipleTime()
{
ReflectHelper reflectHelper = Mock.Of<ReflectHelper>();
MethodInfo classCleanupMethodInfo = typeof(FakeTestClass).GetMethod(nameof(FakeTestClass.FakeClassCleanupMethod), BindingFlags.Instance | BindingFlags.NonPublic)!;
// Full class name must agree between unitTestElement.TestMethod.FullClassName and testMethod.FullClassName;
string fullClassName = typeof(FakeTestClass).FullName!;
TestMethod testMethod = new(nameof(FakeTestClass.FakeTestMethod), fullClassName, typeof(FakeTestClass).Assembly.FullName!, displayName: null);
// Setting 2 of the same test to run, we should run assembly cleanup after both these tests
// finish, not after the first one finishes.
List<UnitTestElement> testsToRun =
[
new(testMethod),
new(testMethod)
];
var classCleanupManager = new ClassCleanupManager(testsToRun);
TestClassInfo testClassInfo = new(typeof(FakeTestClass), null!, true, new TestClassAttribute(), null!)
{
// This needs to be set, to allow running class cleanup.
ClassCleanupMethod = classCleanupMethodInfo,
};
classCleanupManager.MarkTestComplete(testMethod, out bool shouldRunEndOfClassCleanup);
// The cleanup should not run here yet, we have 1 remaining test to run.
shouldRunEndOfClassCleanup.Should().BeFalse();
classCleanupManager.ShouldRunEndOfAssemblyCleanup.Should().BeFalse();
classCleanupManager.MarkTestComplete(testMethod, out shouldRunEndOfClassCleanup);
classCleanupManager.MarkClassComplete(fullClassName);
// The cleanup should run here.
shouldRunEndOfClassCleanup.Should().BeTrue();
classCleanupManager.ShouldRunEndOfAssemblyCleanup.Should().BeTrue();
}
[TestClass]
private class FakeTestClass
{
[TestMethod]
internal void FakeTestMethod()
{
}
[ClassCleanup]
internal void FakeClassCleanupMethod()
{
}
}
}