TestAutomationEssentials.MSTest.ExecutionContext.TestExecutionScopesManager.AddCleanupAction C# (CSharp) Method

AddCleanupAction() public method

Adds a delegate to an action that will be executed on cleanup
public AddCleanupAction ( System.Action action ) : void
action System.Action A delegate to the action to perform
return void
        public void AddCleanupAction(Action action)
        {
            if (_currentState == State.Cleanup)
                throw new InvalidOperationException("Adding cleanup actions from within cleanup is not supported");

            _currentIsolationLevel.AddCleanupAction(action);
        }

Usage Example

        public void CleaupActionIsCalledAfterInitialize()
        {
            bool cleanupWasCalled = false;
            var context = new TestExecutionScopesManager("dummy", ctx => { });
            context.AddCleanupAction(() => cleanupWasCalled = true);

            context.EndIsolationScope();
            Assert.IsTrue(cleanupWasCalled);
        }
All Usage Examples Of TestAutomationEssentials.MSTest.ExecutionContext.TestExecutionScopesManager::AddCleanupAction