Exemple #1
0
        /// <summary>Run all tests.</summary>
        private void RunTests()
        {
            storage?.Writer.WaitForIdle();
            storage?.Reader.Refresh();

            List <object> services;

            if (relativeTo is Simulations)
            {
                services = (relativeTo as Simulations).GetServices();
            }
            else
            {
                Simulations sims = relativeTo.FindInScope <Simulations>();
                if (sims != null)
                {
                    services = sims.GetServices();
                }
                else if (relativeTo is Simulation)
                {
                    services = (relativeTo as Simulation).Services;
                }
                else
                {
                    services = new List <object>();
                    if (storage != null)
                    {
                        services.Add(storage);
                    }
                }
            }

            var links = new Links(services);

            foreach (ITest test in rootModel.FindAllDescendants <ITest>())
            {
                DateTime startTime = DateTime.Now;

                links.Resolve(test as IModel, true);

                // If we run into problems, we will want to include the name of the test in the
                // exception's message. However, tests may be manager scripts, which always have
                // a name of 'Script'. Therefore, if the test's parent is a Manager, we use the
                // manager's name instead.
                string    testName  = test.Parent is Manager ? test.Parent.Name : test.Name;
                Exception exception = null;
                try
                {
                    Status = "Running tests";
                    test.Run();
                }
                catch (Exception err)
                {
                    exception = err;
                    AddException(new Exception("Encountered an error while running test " + testName, err));
                }
            }
        }