Ejemplo n.º 1
0
 public XUnitTestCase(XUnitAssemblyTestSuite rootSuite, XUnitTestExecutor executor, XUnitTestInfo testInfo) : base(testInfo.Name)
 {
     this.rootSuite  = rootSuite;
     TestInfo        = testInfo;
     this.executor   = executor;
     FixtureTypeName = testInfo.Type;
 }
 void AsyncCreateTests(XUnitTestInfo testInfo)
 {
     Tests.Clear();
     FillTests(testInfo);
     cache.SetTestInfo(testInfo);
     OnTestChanged();
 }
Ejemplo n.º 3
0
 public XUnitTestSuite(XUnitAssemblyTestSuite rootSuite, XUnitTestExecutor executor, XUnitTestInfo testInfo) : base(testInfo.Name)
 {
     this.rootSuite = rootSuite;
     TestInfo       = testInfo;
     this.executor  = executor;
     this.TestId    = testInfo.Id;
 }
Ejemplo n.º 4
0
        public XUnitTestInfo GetTestInfo(string path, string[] supportAssemblies)
        {
            var infos = new List <TestCaseInfo>();

            if (null != path && File.Exists(path))
            {
                using (var controller = new XunitFrontController(AppDomainSupport.Denied, path))
                    using (var discoveryVisitor = new DefaultDiscoveryVisitor()) {
                        controller.Find(false, discoveryVisitor, TestFrameworkOptions.ForDiscovery());
                        discoveryVisitor.Finished.WaitOne();
                        foreach (var testCase in discoveryVisitor.TestCases)
                        {
                            infos.Add(new TestCaseInfo {
                                Id     = testCase.UniqueID,
                                Type   = testCase.TestMethod.TestClass.Class.Name,
                                Method = testCase.TestMethod.Method.Name,
                                Args   = testCase.TestMethodArguments
                            });
                        }
                    }
                // sort by type, method
                infos.Sort((info1, info2) => {
                    int i = string.Compare(info1.Type, info2.Type, StringComparison.Ordinal);
                    if (i == 0)
                    {
                        i = string.Compare(info1.Method, info2.Method, StringComparison.Ordinal);
                    }
                    return(i);
                });
            }
            var testInfo = new XUnitTestInfo();

            BuildTestInfo(testInfo, infos, 0);
            return(testInfo);
        }
        public void OnTestSuiteLoaded(XUnitTestInfo testInfo)
        {
            lock (locker)
            {
                Status = TestStatus.Ready;
                Monitor.PulseAll(locker);
            }

            Runtime.RunInMainThread(delegate
            {
                AsyncCreateTests(testInfo);
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Organizes test case info as a hierarchy.
        /// </summary>
        /// <returns>The test info.</returns>
        /// <param name="testInfo">Test info.</param>
        /// <param name="infos">Infos.</param>
        /// <param name="step">Step.</param>
        void BuildTestInfo(XUnitTestInfo testInfo, IEnumerable <TestCaseInfo> infos, int step)
        {
            int count = infos.Count();

            if (count == 0)
            {
                return;
            }

            var firstItem = infos.First();

            // if the test is the last element in the group
            // then it's going to be a leaf node in the structure
            if (count == 1)
            {
                if (step == firstItem.NameParts.Length)
                {
                    testInfo.Id     = firstItem.Id;
                    testInfo.Type   = firstItem.Type;
                    testInfo.Method = firstItem.Method;
                    testInfo.Name   = firstItem.DisplayName;
                    testInfo.Args   = firstItem.Args;
                    return;
                }
            }

            // build the tree structure based on the parts of the name, so
            // [a.b.c, a.b.d, a.e] would become
            //  (a)
            //   |-(b)
            //      |-(c)
            //      |-(d)
            //   |-(e)
            var groups   = infos.GroupBy(info => info.NameParts[step]);
            var children = new List <XUnitTestInfo>();

            foreach (var group in groups)
            {
                var child = new XUnitTestInfo {
                    Name = group.Key
                };

                BuildTestInfo(child, group, step + 1);
                children.Add(child);
            }
            testInfo.Tests = children.ToArray();
        }
        void FillTests(XUnitTestInfo testInfo)
        {
            if (testInfo == null || testInfo.Tests == null)
            {
                return;
            }

            foreach (var child in testInfo.Tests)
            {
                UnitTest test;
                if (child.Tests == null)
                {
                    test = new XUnitTestCase(this, executor, child);
                }
                else
                {
                    test = new XUnitTestSuite(this, executor, child);
                }
                Tests.Add(test);
            }
        }