Exemplo n.º 1
0
        NunitTestInfo NamespaceWithDot()
        {
            NunitTestInfo namespaceInfo = new NunitTestInfo {
                FixtureTypeName      = "",
                FixtureTypeNamespace = "",
                Name = "A"
            };
            NunitTestInfo namespaceInfo2 = new NunitTestInfo {
                FixtureTypeName      = "",
                FixtureTypeNamespace = "",
                Name = "B"
            };

            namespaceInfo.Tests [0] = namespaceInfo2;

            NunitTestInfo classInfo = new NunitTestInfo {
                FixtureTypeName      = "TestClassAB",
                FixtureTypeNamespace = "A.B",
                Name = "TestClassAB"
            };

            namespaceInfo2.Tests [0] = classInfo;

            NunitTestInfo methodInfo = new NunitTestInfo {
                FixtureTypeName      = "TestClassAB",
                FixtureTypeNamespace = "A.B",
                Name = "TestMethodAB"
            };

            classInfo.Tests [0] = methodInfo;

            return(namespaceInfo);
        }
Exemplo n.º 2
0
        NunitTestInfo NamespaceNoDot()
        {
            NunitTestInfo namespaceInfo = new NunitTestInfo {
                FixtureTypeName      = "",
                FixtureTypeNamespace = "",
                Name = "A"
            };

            NunitTestInfo classInfo = new NunitTestInfo {
                FixtureTypeName      = "TestClassA",
                FixtureTypeNamespace = "A",
                Name = "TestClassA"
            };

            namespaceInfo.Tests [0] = classInfo;

            NunitTestInfo methodInfo = new NunitTestInfo {
                FixtureTypeName      = "TestClassA",
                FixtureTypeNamespace = "A",
                Name = "TestMethodA"
            };

            classInfo.Tests [0] = methodInfo;

            return(namespaceInfo);
        }
Exemplo n.º 3
0
 public NUnitTestSuite(NUnitAssemblyTestSuite rootSuite, NunitTestInfo tinfo) : base(tinfo.Name)
 {
     fullName       = !string.IsNullOrEmpty(tinfo.PathName) ? tinfo.PathName + "." + tinfo.Name : tinfo.Name;
     this.testInfo  = tinfo;
     this.rootSuite = rootSuite;
     this.TestId    = tinfo.TestId;
 }
 public NUnitTestCase(NUnitAssemblyTestSuite rootSuite, NunitTestInfo tinfo, string className) : base(tinfo.Name)
 {
     this.className = className;
     this.pathName  = tinfo.PathName;
     this.rootSuite = rootSuite;
     this.TestId    = tinfo.TestId;
 }
Exemplo n.º 5
0
		public NUnitTestSuite (NUnitAssemblyTestSuite rootSuite, NunitTestInfo tinfo): base (tinfo.Name)
		{
			fullName = !string.IsNullOrEmpty (tinfo.PathName) ? tinfo.PathName + "." + tinfo.Name : tinfo.Name;
			this.testInfo = tinfo;
			this.rootSuite = rootSuite;
			this.TestId = tinfo.TestId;
		}
Exemplo n.º 6
0
        internal NunitTestInfo BuildTestInfo(Test test)
        {
            NunitTestInfo ti = new NunitTestInfo();
            // The name of inherited tests include the base class name as prefix.
            // That prefix has to be removed
            string tname = test.TestName.Name;

            // Find the last index of the dot character that is not a part of the test parameters
            // Parameterized methods can contain '.' as class name & they don't seem to prefix base class name, so it's safe to skip them
            if (!(test.Parent is ParameterizedMethodSuite))
            {
                int j = tname.IndexOf('(');
                int i = tname.LastIndexOf('.', (j == -1) ? (tname.Length - 1) : j);
                if (i != -1)
                {
                    tname = tname.Substring(i + 1);
                }
            }

            if (test.FixtureType != null)
            {
                ti.FixtureTypeName      = test.FixtureType.Name;
                ti.FixtureTypeNamespace = test.FixtureType.Namespace;
            }
            else if (test.TestType == "ParameterizedTest")
            {
                ti.FixtureTypeName      = test.Parent.FixtureType.Name;
                ti.FixtureTypeNamespace = test.Parent.FixtureType.Namespace;
            }
            ti.Name   = tname;
            ti.TestId = test.TestName.FullName;

            // Trim short name from end of full name to get the path
            string testNameWithDelimiter = "." + tname;

            if (test.TestName.FullName.EndsWith(testNameWithDelimiter))
            {
                int pathLength = test.TestName.FullName.Length - testNameWithDelimiter.Length;
                ti.PathName = test.TestName.FullName.Substring(0, pathLength);
            }
            else
            {
                ti.PathName = null;
            }

            if (test.Tests != null && test.Tests.Count > 0)
            {
                ti.Tests = new NunitTestInfo [test.Tests.Count];
                for (int n = 0; n < test.Tests.Count; n++)
                {
                    ti.Tests [n] = BuildTestInfo((Test)test.Tests [n]);
                }
            }
            ti.IsExplicit = test.RunState == RunState.Explicit;
            return(ti);
        }
Exemplo n.º 7
0
 public void SetInfo(string path, NunitTestInfo info)
 {
     if (File.Exists(path))
     {
         CachedTestInfo cti = new CachedTestInfo();
         cti.LastWriteTime = File.GetLastWriteTime(path);
         cti.Info          = info;
         table [path]      = cti;
         modified          = true;
     }
 }
Exemplo n.º 8
0
        internal NunitTestInfo BuildTestInfo(XmlElement test)
        {
            NunitTestInfo ti = new NunitTestInfo();
            // The name of inherited tests include the base class name as prefix.
            // That prefix has to be removed
            string tname    = test.GetAttribute("name");
            string fullName = test.GetAttribute("fullname");

            var tn = test.GetAttribute("classname");

            if (tn != null)
            {
                var i = tn.LastIndexOf('.');
                if (i != -1)
                {
                    ti.FixtureTypeName      = tn.Substring(i + 1);
                    ti.FixtureTypeNamespace = tn.Substring(0, i);
                }
                else
                {
                    ti.FixtureTypeName      = tn;
                    ti.FixtureTypeNamespace = "";
                }
            }
            ti.Name   = tname;
            ti.TestId = fullName;
            // Trim short name from end of full name to get the path
            string testNameWithDelimiter = "." + tname;

            if (fullName.EndsWith(testNameWithDelimiter))
            {
                int pathLength = fullName.Length - testNameWithDelimiter.Length;
                ti.PathName = fullName.Substring(0, pathLength);
            }
            else
            {
                ti.PathName = null;
            }

            ti.IsExplicit = test.GetAttribute("classname") == "Explicit";

            var children = test.ChildNodes.OfType <XmlElement> ().Where(e => e.LocalName == "test-suite" || e.LocalName == "test-case").ToArray();

            if (children.Length > 0)
            {
                ti.Tests = new NunitTestInfo [children.Length];
                for (int n = 0; n < children.Length; n++)
                {
                    ti.Tests [n] = BuildTestInfo(children [n]);
                }
            }
            return(ti);
        }
Exemplo n.º 9
0
        protected override void OnCreateTests()
        {
            lock (locker)
            {
                if (Status == TestStatus.Loading)
                {
                    return;
                }

                NunitTestInfo ti = testInfoCache.GetInfo(AssemblyPath);
                if (ti != null)
                {
                    FillTests(ti);
                    return;
                }

                Status = TestStatus.Loading;
            }

            lastAssemblyTime = GetAssemblyTime();

            if (oldList != null)
            {
                foreach (UnitTest t in oldList)
                {
                    Tests.Add(t);
                }
            }

            OnTestStatusChanged();

            LoadData ld = new LoadData();

            ld.Path = AssemblyPath;
            ld.TestInfoCachePath = cacheLoaded ? null : TestInfoCachePath;
            ld.Callback          = delegate
            {
                DispatchService.GuiDispatch(delegate
                {
                    AsyncCreateTests(ld);
                });
            };
            ld.SupportAssemblies = new List <string> (SupportAssemblies);

            AsyncLoadTest(ld);

            // Read the cache from disk only once
            cacheLoaded = true;
        }
Exemplo n.º 10
0
        NunitTestInfo DirectClassCase()
        {
            NunitTestInfo classInfo = new NunitTestInfo {
                FixtureTypeName      = "TestClass",
                FixtureTypeNamespace = "",
                Name = "TestClass"
            };

            NunitTestInfo methodInfo = new NunitTestInfo {
                FixtureTypeName      = "TestClass",
                FixtureTypeNamespace = "",
                Name = "TestMethod"
            };

            classInfo.Tests [0] = methodInfo;

            return(classInfo);
        }
 void FillTests(NunitTestInfo ti)
 {
     if (ti.Tests == null)
     {
         return;
     }
     foreach (NunitTestInfo test in ti.Tests)
     {
         if (test.Tests != null)
         {
             Tests.Add(new NUnitTestSuite(this, test));
         }
         else
         {
             Tests.Add(new NUnitTestCase(this, test));
         }
     }
     oldList = new UnitTest [Tests.Count];
     Tests.CopyTo(oldList, 0);
 }
Exemplo n.º 12
0
        NunitTestInfo NestedNamespace()
        {
            NunitTestInfo namespaceInfo = new NunitTestInfo {
                FixtureTypeName      = "",
                FixtureTypeNamespace = "",
                Name = "A"
            };
            NunitTestInfo namespaceInfo2 = new NunitTestInfo {
                FixtureTypeName      = "",
                FixtureTypeNamespace = "",
                Name = "B"
            };

            namespaceInfo.Tests [0] = namespaceInfo2;
            NunitTestInfo namespaceInfo3 = new NunitTestInfo {
                FixtureTypeName      = "",
                FixtureTypeNamespace = "",
                Name = "C"
            };

            namespaceInfo2.Tests [0] = namespaceInfo3;

            NunitTestInfo classInfo = new NunitTestInfo {
                FixtureTypeName      = "TestClassABC",
                FixtureTypeNamespace = "A.B.C",
                Name = "TestClassABC"
            };

            namespaceInfo3.Tests [0] = classInfo;

            NunitTestInfo methodInfo = new NunitTestInfo {
                FixtureTypeName      = "TestClassABC",
                FixtureTypeNamespace = "A.B.C",
                Name = "TestMethodABC"
            };

            classInfo.Tests [0] = methodInfo;

            return(namespaceInfo);
        }
Exemplo n.º 13
0
 void FillTests(NunitTestInfo ti)
 {
     if (ti.Tests == null)
     {
         return;
     }
     foreach (NunitTestInfo test in ti.Tests)
     {
         UnitTest newTest;
         if (test.Tests != null)
         {
             newTest = new NUnitTestSuite(this, test);
         }
         else
         {
             newTest = new NUnitTestCase(this, test, test.PathName);
         }
         newTest.FixtureTypeName      = test.FixtureTypeName;
         newTest.FixtureTypeNamespace = test.FixtureTypeNamespace;
         Tests.Add(newTest);
     }
     oldList = new UnitTest [Tests.Count];
     Tests.CopyTo(oldList, 0);
 }
Exemplo n.º 14
0
 public NUnitTestCase(NUnitAssemblyTestSuite rootSuite, NunitTestInfo tinfo) : base(tinfo.Name)
 {
     className      = tinfo.PathName;
     this.rootSuite = rootSuite;
 }
			public void SetInfo (string path, NunitTestInfo info)
			{
				if (File.Exists (path)) {
					CachedTestInfo cti = new CachedTestInfo ();
					cti.LastWriteTime = File.GetLastWriteTime (path);
					cti.Info = info;
					table [path] = cti;
					modified = true;
				}
			}
Exemplo n.º 16
0
        static void RunAsyncLoadTest()
        {
            while (true)
            {
                LoadData ld;
                lock (loadQueue) {
                    if (loadQueue.Count == 0)
                    {
                        if (!Monitor.Wait(loadQueue, 5000, true))
                        {
                            loaderRunning = false;
                            return;
                        }
                    }
                    ld = (LoadData)loadQueue.Dequeue();
                }

                try {
                    // If the information is cached in a file and it is up to date information,
                    // there is no need to parse again the assembly.

                    if (ld.TestInfoCachePath != null && File.Exists(ld.TestInfoCachePath))
                    {
                        ld.InfoCache = TestInfoCache.Read(ld.TestInfoCachePath);
                        NunitTestInfo info = ld.InfoCache.GetInfo(ld.Path);
                        if (info != null)
                        {
                            ld.Info = info;
                            ld.Callback(ld);
                            continue;
                        }
                    }
                } catch (Exception ex) {
                    LoggingService.LogError(ex.ToString());
                }

                ExternalTestRunner runner = null;

                try {
                    if (File.Exists(ld.Path))
                    {
                        runner  = (ExternalTestRunner)Runtime.ProcessService.CreateExternalProcessObject(typeof(ExternalTestRunner), false);
                        ld.Info = runner.GetTestInfo(ld.Path, ld.SupportAssemblies);
                    }
                } catch (Exception ex) {
                    Console.WriteLine(ex);
                    ld.Error = ex;
                }
                finally {
                    try {
                        if (runner != null)
                        {
                            runner.Dispose();
                        }
                    } catch {}
                }

                try {
                    ld.Callback(ld);
                } catch {
                }
            }
        }
Exemplo n.º 17
0
		internal NunitTestInfo BuildTestInfo (Test test)
		{
			NunitTestInfo ti = new NunitTestInfo ();
			// The name of inherited tests include the base class name as prefix.
			// That prefix has to be removed
			string tname = test.TestName.Name;
			// Find the last index of the dot character that is not a part of the test parameters
			// Parameterized methods can contain '.' as class name & they don't seem to prefix base class name, so it's safe to skip them
			if (!(test.Parent is ParameterizedMethodSuite)) {
				int j = tname.IndexOf ('(');
				int i = tname.LastIndexOf ('.', (j == -1) ? (tname.Length - 1) : j);
				if (i != -1)
					tname = tname.Substring (i + 1);
			}

			if (test.FixtureType != null) {
				ti.FixtureTypeName = test.FixtureType.Name;
				ti.FixtureTypeNamespace = test.FixtureType.Namespace;
			} else if (test.TestType == "ParameterizedTest") {
				ti.FixtureTypeName = test.Parent.FixtureType.Name;
				ti.FixtureTypeNamespace = test.Parent.FixtureType.Namespace;
			}
			ti.Name = tname;
			ti.TestId = test.TestName.FullName;

			// Trim short name from end of full name to get the path
			string testNameWithDelimiter = "." + tname;
			if (test.TestName.FullName.EndsWith (testNameWithDelimiter)) {
				int pathLength = test.TestName.FullName.Length - testNameWithDelimiter.Length;
				ti.PathName = test.TestName.FullName.Substring(0, pathLength );
			}
			else
				ti.PathName = null;
			
			if (test.Tests != null && test.Tests.Count > 0) {
				ti.Tests = new NunitTestInfo [test.Tests.Count];
				for (int n=0; n<test.Tests.Count; n++)
					ti.Tests [n] = BuildTestInfo ((Test)test.Tests [n]);
			}
			ti.IsExplicit = test.RunState == RunState.Explicit;
			return ti;
		}
Exemplo n.º 18
0
		internal NunitTestInfo BuildTestInfo (XmlElement test)
		{
			NunitTestInfo ti = new NunitTestInfo ();
			// The name of inherited tests include the base class name as prefix.
			// That prefix has to be removed
			string tname = test.GetAttribute ("name");
			string fullName = test.GetAttribute ("fullname");

			var tn = test.GetAttribute ("classname");
			if (tn != null) {
				var i = tn.LastIndexOf ('.');
				if (i != -1) {
					ti.FixtureTypeName = tn.Substring (i + 1);
					ti.FixtureTypeNamespace = tn.Substring (0, i);
				} else {
					ti.FixtureTypeName = tn;
					ti.FixtureTypeNamespace = "";
				}
			}
			ti.Name = tname;
			ti.TestId = fullName;
			// Trim short name from end of full name to get the path
			string testNameWithDelimiter = "." + tname;
			if (fullName.EndsWith (testNameWithDelimiter)) {
				int pathLength = fullName.Length - testNameWithDelimiter.Length;
				ti.PathName = fullName.Substring (0, pathLength);
			}
			else
				ti.PathName = null;

			ti.IsExplicit = test.GetAttribute ("classname") == "Explicit";

			var children = test.ChildNodes.OfType<XmlElement> ().Where (e => e.LocalName == "test-suite" || e.LocalName == "test-case").ToArray ();
			if (children.Length > 0) {
				ti.Tests = new NunitTestInfo [children.Length];
				for (int n=0; n<children.Length; n++)
					ti.Tests [n] = BuildTestInfo (children [n]);
			}
			return ti;
		}
Exemplo n.º 19
0
 public NUnitTestSuite(NUnitAssemblyTestSuite rootSuite, NunitTestInfo tinfo) : base(tinfo.Name)
 {
     fullName       = tinfo.PathName != null && tinfo.PathName.Length > 0 ? tinfo.PathName + "." + tinfo.Name : tinfo.Name;
     this.testInfo  = tinfo;
     this.rootSuite = rootSuite;
 }
		void FillTests (NunitTestInfo ti)
		{
			if (ti.Tests == null)
				return;
			foreach (NunitTestInfo test in ti.Tests) {
				UnitTest newTest;
				if (test.Tests != null)
					newTest = new NUnitTestSuite (this, test);
				else
					newTest = new NUnitTestCase (this, test, test.PathName);
				newTest.FixtureTypeName = test.FixtureTypeName;
				newTest.FixtureTypeNamespace = test.FixtureTypeNamespace;
				Tests.Add (newTest);

			}
			oldList = new UnitTest [Tests.Count];
			Tests.CopyTo (oldList, 0);
		}