Example #1
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;
 }
        void FillTests(NunitTestInfo ti)
        {
            if (ti.Tests == null)
            {
                return;
            }

            foreach (NunitTestInfo test in ti.Tests)
            {
                var newTest = new NUnitTestSuite(this, test);
                newTest.FixtureTypeName      = test.FixtureTypeName;
                newTest.FixtureTypeNamespace = test.FixtureTypeNamespace;

                newTest.ChildStatus(test, out bool isNamespace, out bool hasClassAsChild);

                if (!isNamespace || hasClassAsChild)
                {
                    Tests.Add(newTest);
                }

                var forceLoad = newTest.Tests;
                foreach (NUnitTestSuite child in newTest.ChildNamespaces)
                {
                    child.Title = newTest.Title + "." + child.Title;
                    Tests.Add(child);
                }
            }
            oldList = new UnitTest [Tests.Count];
            Tests.CopyTo(oldList, 0);
        }
Example #3
0
 public NUnitTestCase(NUnitAssemblyTestSuite rootSuite, NunitTestInfo tinfo, string className) : base(tinfo.Name)
 {
     this.className = className;
     this.pathName  = tinfo.PathName;
     this.rootSuite = rootSuite;
     this.TestSourceCodeDocumentId = this.TestId = tinfo.TestId;
     this.IsExplicit = tinfo.IsExplicit;
 }
Example #4
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.TestSourceCodeDocumentId = this.TestId = tinfo.TestId;
     this.childNamespaces          = new UnitTestCollection();
 }
Example #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;
     this.canMergeWithParent = string.IsNullOrEmpty(tinfo.FixtureTypeName) &&
                               string.IsNullOrEmpty(tinfo.FixtureTypeNamespace);
 }
        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 {
                Runtime.RunInMainThread(delegate {
                    if (ld.Error != null)
                    {
                        this.ErrorMessage = ld.Error.Message;
                    }
                    else
                    {
                        ErrorMessage = string.Empty;
                    }
                    AsyncCreateTests(ld);
                });
            };
            ld.SupportAssemblies = GetSupportAssembliesAsync();
            ld.NUnitVersion      = NUnitVersion;

            AsyncLoadTest(ld);

            // Read the cache from disk only once
            cacheLoaded = true;
        }
 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;
     }
 }
Example #8
0
 public void ChildStatus(NunitTestInfo test, out bool isNamespace, out bool hasClassAsChild)
 {
     isNamespace     = false;
     hasClassAsChild = false;
     foreach (NunitTestInfo child in test.Tests)
     {
         if (child.Tests != null)
         {
             isNamespace = true;
             if (child.Tests [0].Tests == null)
             {
                 hasClassAsChild = true;
             }
         }
     }
 }
 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);
 }
        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 = new ExternalTestRunner(Path.GetDirectoryName(ld.Path));
                        runner.ProcessExecutionArchitecture = AssemblyUtilities.GetProcessExecutionArchitectureForAssembly(ld.Path);
                        runner.Connect(ld.NUnitVersion).Wait();
                        var supportAssemblies = new List <string> (ld.SupportAssemblies.Result);
                        ld.Info = runner.GetTestInfo(ld.Path, supportAssemblies).Result;
                    }
                } catch (AggregateException exception) {
                    var baseException = exception.GetBaseException();
                    Console.WriteLine(baseException);
                    ld.Error = baseException;
                } catch (Exception exception) {
                    Console.WriteLine(exception);
                    ld.Error = exception;
                }
                finally {
                    try {
                        if (runner != null)
                        {
                            runner.Dispose();
                        }
                    } catch {}
                }

                try {
                    ld.Callback(ld);
                } catch {
                }
            }
        }