RunTearDown() public method

Run TearDown for this level.
public RunTearDown ( TestExecutionContext context ) : void
context TestExecutionContext
return void
Exemplo n.º 1
0
        public void SuccessfulThenFailingTeardownShouldRecordFailureInTestContext()
        {
            var item = new SetUpTearDownItem(Empty, Success.Concat(Failure).ToList());

            item.RunSetUp(_context);
            item.RunTearDown(_context);

            Assert.That(_context.CurrentResult.ResultState, Is.EqualTo(ResultState.Error));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SetUpTearDownCommand"/> class.
        /// </summary>
        /// <param name="innerCommand">The inner command.</param>
        /// <param name="setUpTearDown">List of setup/teardown items</param>
        public SetUpTearDownCommand(TestCommand innerCommand, SetUpTearDownItem setUpTearDown)
            : base(innerCommand)
        {
            Guard.ArgumentValid(innerCommand.Test is TestMethod, "SetUpTearDownCommand may only apply to a TestMethod", "innerCommand");
            Guard.OperationValid(Test.TypeInfo != null, "TestMethod must have a non-null TypeInfo");
            Guard.ArgumentNotNull(setUpTearDown, nameof(setUpTearDown));

            BeforeTest = (context) =>
            {
                setUpTearDown.RunSetUp(context);
            };

            AfterTest = (context) =>
            {
                setUpTearDown.RunTearDown(context);
            };
        }
        /// <summary>
        /// Construct a OneTimeTearDownCommand
        /// </summary>
        /// <param name="innerCommand">The command wrapped by this command</param>
        /// <param name="setUpTearDownItem">A SetUpTearDownList for use by the command</param>
        public OneTimeTearDownCommand(TestCommand innerCommand, SetUpTearDownItem setUpTearDownItem)
            : base(innerCommand)
        {
            Guard.ArgumentValid(innerCommand.Test is TestSuite, "OneTimeTearDownCommand may only apply to a TestSuite", "innerCommand");
            Guard.ArgumentNotNull(setUpTearDownItem, nameof(setUpTearDownItem));

            AfterTest = (context) =>
            {
                TestResult suiteResult = context.CurrentResult;

                try
                {
                    setUpTearDownItem.RunTearDown(context);
                }
                catch (Exception ex)
                {
                    suiteResult.RecordTearDownException(ex);
                }
            };
        }