void AsyncCreateTests(XUnitTestInfo testInfo)
 {
     Tests.Clear();
     FillTests(testInfo);
     cache.SetTestInfo(testInfo);
     OnTestChanged();
 }
		public void SetTestInfo (XUnitTestInfo testInfo)
		{
			if (testInfo != null && File.Exists (testSuite.AssemblyPath)) {
				cachedTestInfo.TestInfo = testInfo;
				cachedTestInfo.LastWriteTime = File.GetLastWriteTime (testSuite.AssemblyPath);
				modified = true;
			}
		}
 public void SetTestInfo(XUnitTestInfo testInfo)
 {
     if (testInfo != null && File.Exists(testSuite.AssemblyPath))
     {
         cachedTestInfo.TestInfo      = testInfo;
         cachedTestInfo.LastWriteTime = File.GetLastWriteTime(testSuite.AssemblyPath);
         modified = true;
     }
 }
        public void OnTestSuiteLoaded(XUnitTestInfo testInfo)
        {
            lock (locker) {
                Status = TestStatus.Ready;
                Monitor.PulseAll(locker);
            }

            DispatchService.GuiDispatch(delegate {
                AsyncCreateTests(testInfo);
            });
        }
        public override SourceCodeLocation GetSourceCodeLocation(UnitTest unitTest)
        {
            XUnitTestInfo info = null;

            if (unitTest is XUnitTestCase)
            {
                info = ((XUnitTestCase)unitTest).TestInfo;
            }
            if (unitTest is XUnitTestSuite)
            {
                info = ((XUnitTestSuite)unitTest).TestInfo;
            }

            if (info == null || info.Type == null)
            {
                return(null);
            }

            string namespaceName = "", className = "", methodName = info.Method;

            // extract namespace and class
            string[] nameParts = info.Type.Split('.');
            if (nameParts.Length == 1)
            {
                className = nameParts [0];
            }
            else
            {
                namespaceName = String.Join(".", nameParts, 0, nameParts.Length - 1);
                className     = nameParts [nameParts.Length - 1];
            }

            var compilation = TypeSystemService.GetCompilation(project);
            var type        = compilation.MainAssembly.GetTypeDefinition(namespaceName, className);

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

            // try to find the method's location
            var method = type.GetMethods().FirstOrDefault(m => m.Name == methodName);

            if (method != null)
            {
                return(new SourceCodeLocation(method.Region.FileName, method.Region.BeginLine, method.Region.BeginColumn));
            }

            // or at least return the location of the type
            return(new SourceCodeLocation(type.Region.FileName, type.Region.BeginLine, type.Region.BeginColumn));
        }
        /// <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.Name;
                    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);
            }
        }
        /// <summary>
        /// Builds the test info.
        /// </summary>
        /// <returns>The test info.</returns>
        /// <param name="assembly">Assembly.</param>
        /// <remarks>It uses xunit built-in function to load test case info from the test assembly.</remarks>
        XUnitTestInfo BuildTestInfo(string assembly)
        {
            var infos = new List <TestCaseInfo> ();

            if (assembly != null && File.Exists(assembly))
            {
                using (var controller = new XunitFrontController(AppDomainSupport.Denied, assembly, null, false, null, new NullSourceInformationProvider()))
                    using (var discoveryVisitor = new TestDiscoveryVisitor()) {
                        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,
                                DisplayName = testCase.DisplayName,
                                Args        = testCase.TestMethodArguments
                            });
                        }
                    }

                // sort by type, method
                infos.Sort((info1, info2) => {
                    int i = info1.Type.CompareTo(info2.Type);
                    if (i == 0)
                    {
                        i = info1.Method.CompareTo(info2.Method);
                    }
                    return(i);
                });
            }

            var testInfo = new XUnitTestInfo();

            BuildTestInfo(testInfo, infos, 0);
            return(testInfo);
        }
Esempio n. 9
0
 public XUnitTestCase(XUnitAssemblyTestSuite rootSuite, XUnitTestExecutor executor, XUnitTestInfo testInfo) : base(testInfo.Name)
 {
     this.rootSuite = rootSuite;
     TestInfo       = testInfo;
     this.executor  = executor;
 }
Esempio n. 10
0
		public XUnitTestCase (XUnitAssemblyTestSuite rootSuite, XUnitTestExecutor executor, XUnitTestInfo testInfo): base (testInfo.Name)
		{
			this.rootSuite = rootSuite;
			TestInfo = testInfo;
			this.executor = executor;
		}
		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);
			}
		}
		void AsyncCreateTests (XUnitTestInfo testInfo)
		{
			Tests.Clear ();
			FillTests (testInfo);
			cache.SetTestInfo (testInfo);
			OnTestChanged ();
		}
		public void OnTestSuiteLoaded (XUnitTestInfo testInfo)
		{
			lock (locker) {
				Status = TestStatus.Ready;
				Monitor.PulseAll (locker);
			}

			DispatchService.GuiDispatch (delegate {
				AsyncCreateTests (testInfo);
			});
		}