Exemplo n.º 1
0
        /// <summary>
        /// Gets the command to be executed before any of
        /// the child tests are run.
        /// </summary>
        /// <returns>A TestCommand</returns>
        public static TestCommand MakeOneTimeSetUpCommand(TestSuite suite, List<SetUpTearDownItem> setUpTearDown, List<TestActionItem> actions)
        {
            // Handle skipped tests
            if (suite.RunState != RunState.Runnable && suite.RunState != RunState.Explicit)
                return MakeSkipCommand(suite);

            // Build the OneTimeSetUpCommand itself
            TestCommand command = new OneTimeSetUpCommand(suite, setUpTearDown, actions);

            // Prefix with any IApplyToContext items from attributes
            if (suite.TypeInfo != null)
            {
                IApplyToContext[] changes = suite.TypeInfo.GetCustomAttributes<IApplyToContext>(true);
                if (changes.Length > 0)
                    command = new ApplyChangesToContextCommand(command, changes);
            }
            if (suite.Method!=null)
            {
                IApplyToContext[] changes = suite.Method.GetCustomAttributes<IApplyToContext>(true);
                if (changes.Length > 0)
                    command = new ApplyChangesToContextCommand(command, changes);
            }

            return command;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the command to be executed before any of
        /// the child tests are run.
        /// </summary>
        /// <returns>A TestCommand</returns>
        public static TestCommand MakeOneTimeSetUpCommand(TestSuite suite, List <SetUpTearDownItem> setUpTearDown, List <TestActionItem> actions)
        {
            // Handle skipped tests
            if (suite.RunState != RunState.Runnable && suite.RunState != RunState.Explicit)
            {
                return(MakeSkipCommand(suite));
            }

            // Build the OneTimeSetUpCommand itself
            TestCommand command = new OneTimeSetUpCommand(suite, setUpTearDown, actions);

            // Prefix with any IApplyToContext items from attributes
            if (suite.TypeInfo != null)
            {
                IApplyToContext[] changes = suite.TypeInfo.GetCustomAttributes <IApplyToContext>(true);
                if (changes.Length > 0)
                {
                    command = new ApplyChangesToContextCommand(command, changes);
                }
            }
            if (suite.Method != null)
            {
                IApplyToContext[] changes = suite.Method.GetCustomAttributes <IApplyToContext>(true);
                if (changes.Length > 0)
                {
                    command = new ApplyChangesToContextCommand(command, changes);
                }
            }

            return(command);
        }
        private TestCommand MakeOneTimeSetUpCommand(List <SetUpTearDownItem> setUpTearDown, List <TestActionItem> actions)
        {
            TestCommand command = new EmptyTestCommand(Test);

            // Add Action Commands
            int index = actions.Count;

            while (--index >= 0)
            {
                command = new BeforeTestActionCommand(command, actions[index]);
            }

            if (Test.TypeInfo != null)
            {
                // Build the OneTimeSetUpCommands
                foreach (SetUpTearDownItem item in setUpTearDown)
                {
                    command = new OneTimeSetUpCommand(command, item);
                }

                // Construct the fixture if necessary
                if (!Test.TypeInfo.IsStaticClass)
                {
                    command = new ConstructFixtureCommand(command);
                }
            }

            // Prefix with any IApplyToContext items from attributes
            foreach (var attr in Test.GetCustomAttributes <IApplyToContext>(true))
            {
                command = new ApplyChangesToContextCommand(command, attr);
            }

            return(command);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the command to be executed before any of
        /// the child tests are run.
        /// </summary>
        /// <returns>A TestCommand</returns>
        public static TestCommand MakeOneTimeSetUpCommand(TestSuite suite, List<SetUpTearDownItem> setUpTearDown, List<TestActionItem> actions)
        {
            // Handle skipped tests
            if (suite.RunState != RunState.Runnable && suite.RunState != RunState.Explicit)
                return MakeSkipCommand(suite);

            // Build the OneTimeSetUpCommand itself
            TestCommand command = new OneTimeSetUpCommand(suite, setUpTearDown, actions);

            // Prefix with any IApplyToContext items from attributes
            IList<IApplyToContext> changes = null;

            if (suite.TypeInfo != null)
                changes = suite.TypeInfo.GetCustomAttributes<IApplyToContext>(true);
            else if (suite.Method != null)
                changes = suite.Method.GetCustomAttributes<IApplyToContext>(true);
            else
            {
                var testAssembly = suite as TestAssembly;
                if (testAssembly != null)
#if PORTABLE
                    changes = new List<IApplyToContext>(testAssembly.Assembly.GetAttributes<IApplyToContext>());
#else
                    changes = (IApplyToContext[])testAssembly.Assembly.GetCustomAttributes(typeof(IApplyToContext), true);
#endif
            }

            if (changes != null && changes.Count > 0)
                command = new ApplyChangesToContextCommand(command, changes);

            return command;
        }
Exemplo n.º 5
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()
        {
            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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the command to be executed before any of
        /// the child tests are run.
        /// </summary>
        /// <returns>A TestCommand</returns>
        public static TestCommand MakeOneTimeSetUpCommand(TestSuite suite, List <SetUpTearDownItem> setUpTearDown, List <TestActionItem> actions)
        {
            // Handle skipped tests
            if (suite.RunState != RunState.Runnable && suite.RunState != RunState.Explicit)
            {
                return(MakeSkipCommand(suite));
            }

            // Build the OneTimeSetUpCommand itself
            TestCommand command = new OneTimeSetUpCommand(suite, setUpTearDown, actions);

            // Prefix with any IApplyToContext items from attributes
            IList <IApplyToContext> changes = null;

            if (suite.TypeInfo != null)
            {
                changes = (IApplyToContext[])suite.TypeInfo.GetCustomAttributes <IApplyToContext>(true);
            }
            else if (suite.Method != null)
            {
                changes = (IApplyToContext[])suite.Method.GetCustomAttributes <IApplyToContext>(true);
            }
            else
            {
                var testAssembly = suite as TestAssembly;
                if (testAssembly != null)
#if PORTABLE
                {   //changes = new List<IApplyToContext>(testAssembly.Assembly.GetAttributes<IApplyToContext>());
                    changes = new List <IApplyToContext>();
                }
#else
                { changes = (IApplyToContext[])testAssembly.Assembly.GetCustomAttributes(typeof(IApplyToContext), true); }
#endif
            }

            if (changes != null && changes.Count > 0)
            {
                command = new ApplyChangesToContextCommand(command, changes);
            }

            return(command);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        /// <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);
        }