Ejemplo n.º 1
0
 public RunTestCommandsAction(SimpleTestDriver driver, ITestCommand rootTestCommand, TestExecutionOptions options, TestHarness testHarness, ITestContextManager testContextManager, IProgressMonitor progressMonitor)
 {
     this.driver             = driver;
     this.rootTestCommand    = rootTestCommand;
     this.options            = options;
     this.testHarness        = testHarness;
     this.testContextManager = testContextManager;
     this.progressMonitor    = progressMonitor;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a test command.
        /// </summary>
        /// <param name="contextManager">The test context manager.</param>
        /// <param name="test">The test.</param>
        /// <param name="isExplicit">True if the test is being executed explicitly.</param>
        public ManagedTestCommand(ITestContextManager contextManager, Test test, bool isExplicit)
        {
            if (contextManager == null)
                throw new ArgumentNullException("contextManager");
            if (test == null)
                throw new ArgumentNullException("test");

            this.contextManager = contextManager;
            this.test = test;
            this.isExplicit = isExplicit;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a test command.
        /// </summary>
        /// <param name="contextManager">The test context manager.</param>
        /// <param name="test">The test.</param>
        /// <param name="isExplicit">True if the test is being executed explicitly.</param>
        public ManagedTestCommand(ITestContextManager contextManager, Test test, bool isExplicit)
        {
            if (contextManager == null)
            {
                throw new ArgumentNullException("contextManager");
            }
            if (test == null)
            {
                throw new ArgumentNullException("test");
            }

            this.contextManager = contextManager;
            this.test           = test;
            this.isExplicit     = isExplicit;
        }
        /// <inheritdoc />
        public ITestCommand BuildCommands(TestModel testModel, FilterSet<ITestDescriptor> filterSet, bool exactFilter, ITestContextManager contextManager)
        {
            if (testModel == null)
                throw new ArgumentNullException("testModel");
            if (filterSet == null)
                throw new ArgumentNullException("filterSet");
            if (contextManager == null)
                throw new ArgumentNullException("contextManager");

            var commands = new Dictionary<Test, ManagedTestCommand>();
            bool hasExplicitAncestor = ! filterSet.HasInclusionRules;
            ManagedTestCommand rootCommand = CreateFilteredClosure(commands, testModel.RootTest, filterSet, exactFilter,
                hasExplicitAncestor, contextManager);
            if (rootCommand == null)
                return null;

            var siblingDependencies = new MultiMap<ManagedTestCommand, ManagedTestCommand>();
            PopulateCommandDependencies(commands, siblingDependencies);

            SortChildren(rootCommand, siblingDependencies);
            return rootCommand;
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        sealed protected override void RunAssembly(Assembly assembly, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor)
        {
            using (progressMonitor.BeginTask(string.Format("Running {0} tests.", FrameworkName), 100))
            {
                using (TestHarness testHarness = CreateTestHarness())
                {
                    IDisposable appDomainState = null;
                    try
                    {
                        progressMonitor.SetStatus("Setting up the test harness.");
                        appDomainState = testHarness.SetUpAppDomain();
                        progressMonitor.Worked(1);

                        progressMonitor.SetStatus("Building the test model.");
                        TestModel testModel = GenerateTestModel(assembly, messageSink);
                        progressMonitor.Worked(3);

                        progressMonitor.SetStatus("Building the test commands.");
                        ITestContextManager testContextManager = CreateTestContextManager(messageSink);
                        ITestCommand        rootTestCommand    = GenerateCommandTree(testModel, testExecutionOptions, testContextManager);
                        progressMonitor.Worked(2);

                        progressMonitor.SetStatus("Running the tests.");
                        if (rootTestCommand != null)
                        {
                            RunTestCommandsAction action = new RunTestCommandsAction(this, rootTestCommand, testExecutionOptions,
                                                                                     testHarness, testContextManager, progressMonitor.CreateSubProgressMonitor(93));

                            if (testExecutionOptions.SingleThreaded)
                            {
                                // The execution options require the use of a single thread.
                                action.Run();
                            }
                            else
                            {
                                // Create a new thread so that we can consistently set the default apartment
                                // state to STA and so as to reduce the effective stack depth during the
                                // test run.  We use Thread instead of ThreadTask because we do not
                                // require the ability to abort the Thread so we do not need to take the
                                // extra overhead.
                                Thread thread = new Thread(action.Run);
                                thread.Name = "Simple Test Driver";
                                thread.SetApartmentState(ApartmentState.STA);
                                thread.Start();
                                thread.Join();
                            }

                            if (action.Exception != null)
                            {
                                throw new ModelException("A fatal exception occurred while running test commands.", action.Exception);
                            }
                        }
                        else
                        {
                            progressMonitor.Worked(93);
                        }
                    }
                    finally
                    {
                        progressMonitor.SetStatus("Tearing down the test harness.");
                        if (appDomainState != null)
                        {
                            appDomainState.Dispose();
                        }
                        progressMonitor.Worked(1);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private ITestCommand GenerateCommandTree(TestModel testModel, TestExecutionOptions testExecutionOptions, ITestContextManager testContextManager)
        {
            ITestCommandFactory testCommandFactory = CreateTestCommandFactory();

            ITestCommand rootCommand = testCommandFactory.BuildCommands(testModel, testExecutionOptions.FilterSet,
                                                                        testExecutionOptions.ExactFilter, testContextManager);

            return(rootCommand);
        }
Ejemplo n.º 7
0
 public RunTestCommandsAction(SimpleTestDriver driver, ITestCommand rootTestCommand, TestExecutionOptions options, TestHarness testHarness, ITestContextManager testContextManager, IProgressMonitor progressMonitor)
 {
     this.driver = driver;
     this.rootTestCommand = rootTestCommand;
     this.options = options;
     this.testHarness = testHarness;
     this.testContextManager = testContextManager;
     this.progressMonitor = progressMonitor;
 }
Ejemplo n.º 8
0
        private ITestCommand GenerateCommandTree(TestModel testModel, TestExecutionOptions testExecutionOptions, ITestContextManager testContextManager)
        {
            ITestCommandFactory testCommandFactory = CreateTestCommandFactory();

            ITestCommand rootCommand = testCommandFactory.BuildCommands(testModel, testExecutionOptions.FilterSet,
                testExecutionOptions.ExactFilter, testContextManager);
            return rootCommand;
        }
        private ManagedTestCommand CreateFilteredClosure(Dictionary<Test, ManagedTestCommand> commands,
            Test test, FilterSet<ITestDescriptor> filterSet, bool exactFilter, bool hasExplicitAncestor, ITestContextManager contextManager)
        {
            FilterSetResult filterSetResult = filterSet.Evaluate(test);

            if (filterSetResult == FilterSetResult.Exclude)
                return null;

            bool isMatch = filterSetResult == FilterSetResult.Include;
            bool isExplicit = isMatch && ! hasExplicitAncestor;
            bool hasExplicitChild = false;

            var children = new List<ManagedTestCommand>(test.Children.Count);
            foreach (Test child in test.Children)
            {
                ManagedTestCommand childMonitor = CreateFilteredClosure(commands, child, filterSet, exactFilter,
                    hasExplicitAncestor || isExplicit, contextManager);
                if (childMonitor != null)
                {
                    children.Add(childMonitor);

                    if (childMonitor.IsExplicit)
                        hasExplicitChild = true;
                }
            }

            if (isMatch || children.Count != 0 || (! exactFilter && hasExplicitAncestor))
                return CreateCommand(commands, test, children, isExplicit || hasExplicitChild, contextManager);

            return null;
        }
        private ManagedTestCommand CreateCommand(Dictionary<Test, ManagedTestCommand> commands,
            Test test, IEnumerable<ManagedTestCommand> children, bool isExplicit, ITestContextManager contextManager)
        {
            var testMonitor = new ManagedTestCommand(contextManager, test, isExplicit);
            foreach (ManagedTestCommand child in children)
                testMonitor.AddChild(child);

            commands.Add(test, testMonitor);
            return testMonitor;
        }
Ejemplo n.º 11
0
        private ManagedTestCommand CreateFilteredClosure(Dictionary <Test, ManagedTestCommand> commands,
                                                         Test test, FilterSet <ITestDescriptor> filterSet, bool exactFilter, bool hasExplicitAncestor, ITestContextManager contextManager)
        {
            FilterSetResult filterSetResult = filterSet.Evaluate(test);

            if (filterSetResult == FilterSetResult.Exclude)
            {
                return(null);
            }

            bool isMatch          = filterSetResult == FilterSetResult.Include;
            bool isExplicit       = isMatch && !hasExplicitAncestor;
            bool hasExplicitChild = false;

            var children = new List <ManagedTestCommand>(test.Children.Count);

            foreach (Test child in test.Children)
            {
                ManagedTestCommand childMonitor = CreateFilteredClosure(commands, child, filterSet, exactFilter,
                                                                        hasExplicitAncestor || isExplicit, contextManager);
                if (childMonitor != null)
                {
                    children.Add(childMonitor);

                    if (childMonitor.IsExplicit)
                    {
                        hasExplicitChild = true;
                    }
                }
            }

            if (isMatch || children.Count != 0 || (!exactFilter && hasExplicitAncestor))
            {
                return(CreateCommand(commands, test, children, isExplicit || hasExplicitChild, contextManager));
            }

            return(null);
        }
Ejemplo n.º 12
0
        /// <inheritdoc />
        public ITestCommand BuildCommands(TestModel testModel, FilterSet <ITestDescriptor> filterSet, bool exactFilter, ITestContextManager contextManager)
        {
            if (testModel == null)
            {
                throw new ArgumentNullException("testModel");
            }
            if (filterSet == null)
            {
                throw new ArgumentNullException("filterSet");
            }
            if (contextManager == null)
            {
                throw new ArgumentNullException("contextManager");
            }

            var  commands                  = new Dictionary <Test, ManagedTestCommand>();
            bool hasExplicitAncestor       = !filterSet.HasInclusionRules;
            ManagedTestCommand rootCommand = CreateFilteredClosure(commands, testModel.RootTest, filterSet, exactFilter,
                                                                   hasExplicitAncestor, contextManager);

            if (rootCommand == null)
            {
                return(null);
            }

            var siblingDependencies = new MultiMap <ManagedTestCommand, ManagedTestCommand>();

            PopulateCommandDependencies(commands, siblingDependencies);

            SortChildren(rootCommand, siblingDependencies);
            return(rootCommand);
        }
Ejemplo n.º 13
0
        private ManagedTestCommand CreateCommand(Dictionary <Test, ManagedTestCommand> commands,
                                                 Test test, IEnumerable <ManagedTestCommand> children, bool isExplicit, ITestContextManager contextManager)
        {
            var testMonitor = new ManagedTestCommand(contextManager, test, isExplicit);

            foreach (ManagedTestCommand child in children)
            {
                testMonitor.AddChild(child);
            }

            commands.Add(test, testMonitor);
            return(testMonitor);
        }