public override bool Load(TestPackage package)
        {
            this.projectName       = package.FullName;
            this.testName.FullName = this.testName.Name = projectName;
            runners = new ArrayList();

            int nfound = 0;
            int index  = 0;

            string targetAssemblyName = null;

            if (package.TestName != null && package.Assemblies.Contains(package.TestName))
            {
                targetAssemblyName = package.TestName;
                package.TestName   = null;
            }

            foreach (string assembly in package.Assemblies)
            {
                if (targetAssemblyName == null || targetAssemblyName == assembly)
                {
                    TestDomain runner = new TestDomain(this.runnerID * 100 + index + 1);

                    TestPackage p = new TestPackage(assembly);
                    p.AutoBinPath       = package.AutoBinPath;
                    p.ConfigurationFile = package.ConfigurationFile;
                    p.BasePath          = package.BasePath;
                    p.PrivateBinPath    = package.PrivateBinPath;
                    p.TestName          = package.TestName;
                    foreach (object key in package.Settings.Keys)
                    {
                        p.Settings[key] = package.Settings[key];
                    }

                    if (package.TestName == null)
                    {
                        runners.Add(runner);
                        if (runner.Load(p))
                        {
                            nfound++;
                        }
                    }
                    else if (runner.Load(p))
                    {
                        runners.Add(runner);
                        nfound++;
                    }
                }
            }

            if (package.TestName == null && targetAssemblyName == null)
            {
                return(nfound == package.Assemblies.Count);
            }
            else
            {
                return(nfound > 0);
            }
        }
		public override bool Load(TestPackage package)
		{
			this.projectName = package.FullName;
			this.testName.FullName = this.testName.Name = projectName;
			runners = new ArrayList();

			int nfound = 0;
			int index = 0;

			string targetAssemblyName = null;
			if( package.TestName != null && package.Assemblies.Contains( package.TestName ) )
			{
				targetAssemblyName = package.TestName;
				package.TestName = null;
			}
			
			foreach( string assembly in package.Assemblies )
			{
				if ( targetAssemblyName == null || targetAssemblyName == assembly )
				{
					TestDomain runner = new TestDomain( this.runnerID * 100 + index + 1 );

					TestPackage p = new TestPackage( assembly );
					p.AutoBinPath = package.AutoBinPath;
					p.ConfigurationFile = package.ConfigurationFile;
					p.BasePath = package.BasePath;
					p.PrivateBinPath = package.PrivateBinPath;
					p.TestName = package.TestName;
					foreach( object key in package.Settings.Keys )
						p.Settings[key] = package.Settings[key];

					if ( package.TestName == null )
					{
						runners.Add( runner );
						if ( runner.Load( p ) )
							nfound++;
					}
					else if ( runner.Load( p ) )
					{
						runners.Add( runner );
						nfound++;
					}
				}
			}

			if ( package.TestName == null && targetAssemblyName == null )
				return nfound == package.Assemblies.Count;
			else
				return nfound > 0;
		}
Exemple #3
0
        public void LoadTest(string testName)
        {
            try
            {
                events.FireTestLoading(TestFileName);

                testDomain = new TestDomain(stdOutWriter, stdErrWriter);
                Test test = testDomain.Load(TestProject, testName);

                TestSuite suite = test as TestSuite;
                if (suite != null)
                {
                    suite.Sort();
                }

                loadedTest     = test;
                loadedTestName = testName;
                results        = null;
                reloadPending  = false;

                if (ReloadOnChange)
                {
                    InstallWatcher( );
                }

                if (suite != null)
                {
                    events.FireTestLoaded(TestFileName, this.loadedTest);
                }
                else
                {
                    lastException = new ApplicationException(string.Format("Unable to find test {0} in assembly", testName));
                    events.FireTestLoadFailed(TestFileName, lastException);
                }
            }
            catch (FileNotFoundException exception)
            {
                lastException = exception;

                foreach (string assembly in TestProject.ActiveConfig.AbsolutePaths)
                {
                    if (Path.GetFileNameWithoutExtension(assembly) == exception.FileName &&
                        !ProjectPath.SamePathOrUnder(testProject.ActiveConfig.BasePath, assembly))
                    {
                        lastException = new ApplicationException(string.Format("Unable to load {0} because it is not located under the AppBase", exception.FileName), exception);
                        break;
                    }
                }

                events.FireTestLoadFailed(TestFileName, lastException);
            }
            catch (Exception exception)
            {
                lastException = exception;
                events.FireTestLoadFailed(TestFileName, exception);
            }
        }
        public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink)
        {
            testLog.Initialize(messageLogger);
            Info("discovering tests", "started");

            // Ensure any channels registered by other adapters are unregistered
            CleanUpRegisteredChannels();

            foreach (string sourceAssembly in sources)
            {
                testLog.SendDebugMessage("Processing " + sourceAssembly);

                TestRunner runner = new TestDomain();
                TestPackage package = new TestPackage(sourceAssembly);
                TestConverter testConverter = null;
                try
                {
                    if (runner.Load(package))
                    {
                        testConverter  = new TestConverter(testLog, sourceAssembly);
                        int cases = ProcessTestCases(runner.Test, discoverySink, testConverter);
                        testLog.SendDebugMessage(string.Format("Discovered {0} test cases", cases));
                        }
                    else
                    {
                        testLog.NUnitLoadError(sourceAssembly);
                    }
                }
                catch (System.BadImageFormatException)
                {
                    // we skip the native c++ binaries that we don't support.
                    testLog.AssemblyNotSupportedWarning(sourceAssembly);
                }

                catch (System.IO.FileNotFoundException ex)
                {
                    // Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
                    testLog.DependentAssemblyNotFoundWarning(ex.FileName, sourceAssembly);
                }
                catch (System.Exception ex)
                {
                    testLog.SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
                }
                finally
                {
                    if (testConverter != null)
                        testConverter.Dispose();
                    testConverter = null;
                    runner.Unload();
                }
            }

            Info("discovering test", "finished");
        }
Exemple #5
0
        /// <summary>
        /// Handle watcher event that signals when the loaded assembly
        /// file has changed. Make sure it's a real change before
        /// firing the SuiteChangedEvent. Since this all happens
        /// asynchronously, we use an event to let ui components
        /// know that the failure happened.
        /// </summary>
        /// <param name="assemblyFileName">Assembly file that changed</param>
        public void OnTestChanged(string testFileName)
        {
            if (IsTestRunning)
            {
                reloadPending = true;
            }
            else
            {
                try
                {
                    events.FireTestReloading(testFileName, this.loadedTest);

                    // Don't unload the old domain till after the event
                    // handlers get a chance to compare the trees.
                    TestDomain newDomain = new TestDomain(stdOutWriter, stdErrWriter);
                    Test       newTest   = newDomain.Load(testProject, loadedTestName);
                    TestSuite  suite     = newTest as TestSuite;
                    if (suite != null)
                    {
                        suite.Sort();
                    }

                    testDomain.Unload();

                    testDomain    = newDomain;
                    loadedTest    = newTest;
                    reloadPending = false;

                    events.FireTestReloaded(testFileName, newTest);
                }
                catch (Exception exception)
                {
                    lastException = exception;
                    events.FireTestReloadFailed(testFileName, exception);
                }
            }
        }
Exemple #6
0
        private Test MakeTest(TestDomain testDomain, string assemblyName)
		{
			NUnitProject project;
                
			project = NUnitProject.FromAssembly(assemblyName);
                                 
			return testDomain.Load(project);
        }
Exemple #7
0
        private ITest MakeTest(TestDomain testDomain, string assemblyName)
        {
            TestPackage package = new TestPackage(assemblyName);
            package.Settings["ShadowCopyFiles"] = false;

            return testDomain.Load(package) ? testDomain.Test : null;
        }
Exemple #8
0
        public void LoadTestsFromCompiledAssembly()
        {
            CompilerResults results = compiler.CompileCode( goodCode );
            Assert.AreEqual( 0, results.NativeCompilerReturnValue );

            TestRunner runner = new TestDomain();

            try
            {
                Assert.IsTrue( runner.Load( new TestPackage( outputName ) ) );
                Assert.AreEqual( 2, runner.Test.TestCount );
            }
            finally
            {
                runner.Unload();
            }
        }
Exemple #9
0
        private static bool MakeTestFromCommandLine(TestDomain testDomain,
						string testDll)
        {
            ServiceManager.Services.AddService(new DomainManager());
              var package = new TestPackage(testDll);
              return testDomain.Load(package);
        }
		private static Test MakeTestFromCommandLine(TestDomain testDomain, ConsoleOptions parser)
		{
			NUnitProject project;

			if ( parser.IsTestProject )
			{
				project = NUnitProject.LoadProject( (string)parser.Parameters[0] );
				string configName = (string) parser.config;
				if ( configName != null )
					project.SetActiveConfig( configName );
			}
			else
				project = NUnitProject.FromAssemblies( (string[])parser.Parameters.ToArray( typeof( string ) ) );

			return testDomain.Load( project, parser.fixture );
		}
        public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink)
        {
            TestLog.Initialize(messageLogger);
            if (RegistryFailure)
            {
                TestLog.SendErrorMessage(ErrorMsg);
            }
            Info("discovering tests", "started");

            // Ensure any channels registered by other adapters are unregistered
            CleanUpRegisteredChannels();

            foreach (string sourceAssembly in sources)
            {
                TestLog.SendDebugMessage("Processing " + sourceAssembly);

                TestRunner runner = new TestDomain();
                var package = CreateTestPackage(sourceAssembly);
                TestConverter testConverter = null;
                try
                {
                    if (runner.Load(package))
                    {
                        testConverter = new TestConverter(TestLog, sourceAssembly);
                        int cases = ProcessTestCases(runner.Test, discoverySink, testConverter);
                        TestLog.SendDebugMessage(string.Format("Discovered {0} test cases", cases));
                    }
                    else
                    {
                        TestLog.NoNUnit2TestsFoundIn(sourceAssembly);
                    }
                }
                catch (BadImageFormatException)
                {
                    // we skip the native c++ binaries that we don't support.
                    TestLog.AssemblyNotSupportedWarning(sourceAssembly);
                }

                catch (FileNotFoundException ex)
                {
                    // Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
                    TestLog.DependentAssemblyNotFoundWarning(ex.FileName, sourceAssembly);
                }
                catch (FileLoadException ex)
                {
                    // Attempts to load an invalid assembly, or an assembly with missing dependencies
                    TestLog.LoadingAssemblyFailedWarning(ex.FileName, sourceAssembly);
                }
                catch (UnsupportedFrameworkException)
                {
                    TestLog.UnsupportedFrameworkWarning(sourceAssembly);
                }
                catch (Exception ex)
                {

                    TestLog.SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
                }
                finally
                {
                    runner.Unload();
                }
            }

            Info("discovering test", "finished");
        }
        public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink)
        {
            TestLog.Initialize(messageLogger);
            if (RegistryFailure)
            {
                TestLog.SendErrorMessage(ErrorMsg);
            }
            Info("discovering tests", "started");

            // Ensure any channels registered by other adapters are unregistered
            CleanUpRegisteredChannels();

            // var initPath = Path.Combine(Environment.CurrentDirectory, "init.tml");

            var initPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NUnitTestAdapter");
            initPath = Path.Combine(initPath, "init.tml");

            var blackList = new List<string>();
            if (File.Exists(initPath))
            {
                var config = Toml.ReadFile<Configuration>(initPath);
                blackList = config.Blacklist.Select(b => b.ToLowerInvariant()).ToList();
            }
           

            foreach (string sourceAssembly in sources)
            {
                if (blackList.Contains(Path.GetFileName(sourceAssembly.ToLowerInvariant())))
                {
                    TestLog.SendDebugMessage("Ignore " + sourceAssembly);
                    continue;
                }

                TestLog.SendDebugMessage("Processing " + sourceAssembly);

                //config.Blacklist.Add(sourceAssembly);

                TestRunner runner = new TestDomain();
                var package = CreateTestPackage(sourceAssembly);
                TestConverter testConverter = null;
                try
                {
                    if (runner.Load(package))
                    {
                        testConverter = new TestConverter(TestLog, sourceAssembly);
                        int cases = ProcessTestCases(runner.Test, discoverySink, testConverter);
                        TestLog.SendDebugMessage(string.Format("Discovered {0} test cases", cases));
                    }
                    else
                    {
                        TestLog.NUnitLoadError(sourceAssembly);
                    }
                }
                catch (BadImageFormatException)
                {
                    // we skip the native c++ binaries that we don't support.
                    TestLog.AssemblyNotSupportedWarning(sourceAssembly);
                }

                catch (FileNotFoundException ex)
                {
                    // Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
                    TestLog.DependentAssemblyNotFoundWarning(ex.FileName, sourceAssembly);
                }
                catch (FileLoadException ex)
                {
                    // Attempts to load an invalid assembly, or an assembly with missing dependencies
                    TestLog.LoadingAssemblyFailedWarning(ex.FileName, sourceAssembly);
                }
                catch (UnsupportedFrameworkException ex)
                {
                    TestLog.UnsupportedFrameworkWarning(sourceAssembly);
                }
                catch (Exception ex)
                {

                    TestLog.SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
                }
                finally
                {
                    if (testConverter != null)
                        testConverter.Dispose();
                    runner.Unload();
                }
            }

            //Toml.WriteFile(config, @"test.tml");

            Info("discovering test", "finished");
        }
Exemple #13
0
		/// <summary>
		/// Handle watcher event that signals when the loaded assembly
		/// file has changed. Make sure it's a real change before
		/// firing the SuiteChangedEvent. Since this all happens
		/// asynchronously, we use an event to let ui components
		/// know that the failure happened.
		/// </summary>
		/// <param name="assemblyFileName">Assembly file that changed</param>
		public void OnTestChanged( string testFileName )
		{
			if ( IsTestRunning )
				reloadPending = true;
			else 
				try
				{
					events.FireTestReloading( testFileName, this.loadedTest );

					// Don't unload the old domain till after the event
					// handlers get a chance to compare the trees.
					TestDomain newDomain = new TestDomain( stdOutWriter, stdErrWriter );
					Test newTest = newDomain.Load( testProject, loadedTestName );
					TestSuite suite = newTest as TestSuite;
					if ( suite != null )
						suite.Sort();

					testDomain.Unload();

					testDomain = newDomain;
					loadedTest = newTest;
					reloadPending = false;

					events.FireTestReloaded( testFileName, newTest );				
				}
				catch( Exception exception )
				{
					lastException = exception;
					events.FireTestReloadFailed( testFileName, exception );
				}
		}
Exemple #14
0
		public void LoadTest( string testName )
		{
			try
			{
				events.FireTestLoading( TestFileName );

				testDomain = new TestDomain( stdOutWriter, stdErrWriter );		
				Test test = testDomain.Load( TestProject, testName );

				TestSuite suite = test as TestSuite;
				if ( suite != null )
					suite.Sort();
			
				loadedTest = test;
				loadedTestName = testName;
				results = null;
				reloadPending = false;
			
				if ( ReloadOnChange )
					InstallWatcher( );

				if ( suite != null )
					events.FireTestLoaded( TestFileName, this.loadedTest );
				else
				{
					lastException = new ApplicationException( string.Format ( "Unable to find test {0} in assembly", testName ) );
					events.FireTestLoadFailed( TestFileName, lastException );
				}
			}
			catch( FileNotFoundException exception )
			{
				lastException = exception;

				foreach( string assembly in TestProject.ActiveConfig.AbsolutePaths )
				{
					if ( Path.GetFileNameWithoutExtension( assembly ) == exception.FileName &&
						!ProjectPath.SamePathOrUnder( testProject.ActiveConfig.BasePath, assembly ) )
					{
						lastException = new ApplicationException( string.Format( "Unable to load {0} because it is not located under the AppBase", exception.FileName ), exception );
						break;
					}
				}

				events.FireTestLoadFailed( TestFileName, lastException );
			}
			catch( Exception exception )
			{
				lastException = exception;
				events.FireTestLoadFailed( TestFileName, exception );
			}
		}