ContextSettingsCommand applies specified changes to the TestExecutionContext prior to running a test. No special action is needed after the test runs, since the prior context will be restored automatically.
Inheritance: NUnit.Framework.Internal.Commands.DelegatingTestCommand
Example #1
0
        /// <summary>
        /// Creates a test command for use in running this test.
        /// </summary>
        /// <returns></returns>
        public virtual TestCommand MakeTestCommand()
        {
            if (RunState != RunState.Runnable && RunState != RunState.Explicit)
                return new SkipCommand(this);

            TestCommand command = new TestMethodCommand(this);

            command = ApplyDecoratorsToCommand(command);

            IApplyToContext[] changes = (IApplyToContext[])this.Method.GetCustomAttributes(typeof(IApplyToContext), true);
            if (changes.Length > 0)
                command = new ApplyChangesToContextCommand(command, changes);

            return command;
        }
        /// <summary>
        /// Gets the command to be executed before any of
        /// the child tests are run.
        /// </summary>
        /// <returns>A TestCommand</returns>
        private static TestCommand MakeSetUpCommand(TestSuite suite, SetUpTearDownList setUpTearDown)
        {
            if (suite.RunState != RunState.Runnable && suite.RunState != RunState.Explicit)
                return new SkipCommand(suite);

            TestCommand command = new OneTimeSetUpCommand(suite, setUpTearDown);

            if (suite.FixtureType != null)
            {
                IApplyToContext[] changes = (IApplyToContext[])suite.FixtureType.GetCustomAttributes(typeof(IApplyToContext), true);
                if (changes.Length > 0)
                    command = new ApplyChangesToContextCommand(command, changes);
            }

            return command;
        }
Example #3
0
        /// <summary>
        /// Gets the command to be executed before any of
        /// the child tests are run.
        /// </summary>
        /// <returns>A TestCommand</returns>
        public virtual TestCommand GetOneTimeSetUpCommand()
        {
            if (RunState != RunState.Runnable && RunState != RunState.Explicit)
                return new SkipCommand(this);

            TestCommand command = new OneTimeSetUpCommand(this);

            if (this.FixtureType != null)
            {
                IApplyToContext[] changes = (IApplyToContext[])this.FixtureType.GetCustomAttributes(typeof(IApplyToContext), true);
                if (changes.Length > 0)
                    command = new ApplyChangesToContextCommand(command, changes);
            }

            return command;
        }