Beispiel #1
0
        /// <summary>
        /// Load a new project, optionally selecting the config and fire events
        /// </summary>
        public void LoadProject(string filePath, string configName)
        {
            try
            {
                events.FireProjectLoading(filePath);

                NUnitProject newProject = NUnitProject.LoadProject(filePath);
                if (configName != null)
                {
                    newProject.SetActiveConfig(configName);
                    newProject.IsDirty = false;
                }

                OnProjectLoad(newProject);

//				return true;
            }
            catch (Exception exception)
            {
                lastException = exception;
                events.FireProjectLoadFailed(filePath, exception);

//				return false;
            }
        }
		public RenameConfigurationDialog( NUnitProject project, string configurationName )
		{
			InitializeComponent();
			this.project = project;
			this.configurationName = configurationName;
			this.originalName = configurationName;
		}
Beispiel #3
0
        /// <summary>
        /// Unload the current project and fire events
        /// </summary>
        public void UnloadProject()
        {
            string testFileName = TestFileName;

            try
            {
                events.FireProjectUnloading(testFileName);

//				if ( testFileName != null && File.Exists( testFileName ) )
//					UserSettings.RecentProjects.RecentFile = testFileName;

                if (IsTestLoaded)
                {
                    UnloadTest();
                }

                testProject.Changed -= new ProjectEventHandler(OnProjectChanged);
                testProject          = null;

                events.FireProjectUnloaded(testFileName);
            }
            catch (Exception exception)
            {
                lastException = exception;
                events.FireProjectUnloadFailed(testFileName, exception);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Unload the current project and fire events
        /// </summary>
        public void UnloadProject()
        {
            string testFileName = TestFileName;

            log.Info("Unloading project " + testFileName);
            try
            {
                events.FireProjectUnloading(testFileName);

                if (IsTestLoaded)
                {
                    UnloadTest();
                }

                testProject = null;

                events.FireProjectUnloaded(testFileName);
            }
            catch (Exception exception)
            {
                log.Error("Project unload failed", exception);
                lastException = exception;
                events.FireProjectUnloadFailed(testFileName, exception);
            }
        }
        public static NUnitProject FromVSSolution(string solutionPath)
        {
            NUnitProject project = new NUnitProject(Path.GetFullPath(solutionPath));

            string solutionDirectory = Path.GetDirectoryName(solutionPath);

            using (StreamReader reader = new StreamReader(solutionPath))
            {
                char[] delims    = { '=', ',' };
                char[] trimchars = { ' ', '"' };

                string line = reader.ReadLine();
                while (line != null)
                {
                    if (line.StartsWith("Project"))
                    {
                        string[] parts         = line.Split(delims);
                        string   vsProjectPath = parts[2].Trim(trimchars);

                        if (VSProject.IsProjectFile(vsProjectPath))
                        {
                            project.Add(new VSProject(Path.Combine(solutionDirectory, vsProjectPath)));
                        }
                    }

                    line = reader.ReadLine();
                }
            }

            project.isDirty = false;

            return(project);
        }
		public void SetUp()
		{
			project = new NUnitProject( "path" );
			project.Configs.Add( "Debug" );
			project.Configs.Add( "Release" );
			dlg = new AddConfigurationDialog( project );
			this.Form = dlg;
		}
Beispiel #7
0
        public void CreateFixtureObjects()
        {
            project = new NUnitProject( "temp.nunit" );
            project.Configs.Add( "Debug" );
            project.Configs.Add( "Release" );

            editor = new ProjectEditor( project );

            this.Form = editor;
        }
Beispiel #8
0
        public NUnitProject NewProject()
        {
            NUnitProject project = EmptyProject();

            project.Configs.Add("Debug");
            project.Configs.Add("Release");
            project.IsDirty = false;

            return(project);
        }
Beispiel #9
0
        /// <summary>
        /// Common operations done each time a project is loaded
        /// </summary>
        /// <param name="testProject">The newly loaded project</param>
        private void OnProjectLoad(NUnitProject testProject)
        {
            if (IsProjectLoaded)
            {
                UnloadProject();
            }

            this.testProject = testProject;

            events.FireProjectLoaded(TestFileName);
        }
Beispiel #10
0
        public NUnitProject LoadProject(string path)
        {
            if (NUnitProject.IsNUnitProjectFile(path))
            {
                NUnitProject project = new NUnitProject(path);
                project.Load();
                return(project);
            }

            return(ConvertFrom(path));
        }
		public NUnitProject LoadProject(string path)
		{
			if ( NUnitProject.IsNUnitProjectFile(path) )
			{
				NUnitProject project = new NUnitProject( path );
				project.Load();
				return project;
			}

			return ConvertFrom(path);
		}
Beispiel #12
0
        /// <summary>
        /// Common operations done each time a project is loaded
        /// </summary>
        /// <param name="testProject">The newly loaded project</param>
        private void OnProjectLoad(NUnitProject testProject)
        {
            if (IsProjectLoaded)
            {
                UnloadProject();
            }

            this.testProject     = testProject;
            testProject.Changed += new ProjectEventHandler(OnProjectChanged);

            events.FireProjectLoaded(TestFileName);
        }
Beispiel #13
0
        public ProjectEditor( NUnitProject project )
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            this.project = project;
        }
        public static NUnitProject FromVSProject(string vsProjectPath)
        {
            NUnitProject project = new NUnitProject(Path.GetFullPath(vsProjectPath));

            VSProject vsProject = new VSProject(vsProjectPath);

            project.Add(vsProject);

            project.isDirty = false;

            return(project);
        }
Beispiel #15
0
        public Test Load(NUnitProject project, string testFixture)
        {
            ProjectConfig cfg = project.ActiveConfig;

            if (project.IsAssemblyWrapper)
            {
                return(Load(cfg.Assemblies[0].FullPath, testFixture));
            }
            else
            {
                return(Load(project.ProjectPath, cfg.BasePath, cfg.ConfigurationFile, cfg.PrivateBinPath, cfg.TestAssemblies, testFixture));
            }
        }
Beispiel #16
0
        /// <summary>
        /// Create a new project with default naming
        /// </summary>
        public void NewProject()
        {
            try
            {
                events.FireProjectLoading("New Project");

                OnProjectLoad(NUnitProject.NewProject());
            }
            catch (Exception exception)
            {
                lastException = exception;
                events.FireProjectLoadFailed("New Project", exception);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Load a project from a list of assemblies and fire events
        /// </summary>
        public void LoadProject(string[] assemblies)
        {
            try
            {
                events.FireProjectLoading("New Project");

                NUnitProject newProject = NUnitProject.FromAssemblies(assemblies);

                OnProjectLoad(newProject);
            }
            catch (Exception exception)
            {
                lastException = exception;
                events.FireProjectLoadFailed("New Project", exception);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Load a project from a list of assemblies and fire events
        /// </summary>
        public void LoadProject(string[] assemblies)
        {
            try
            {
                log.Info("Loading multiple assemblies as new project");
                events.FireProjectLoading("New Project");

                NUnitProject newProject = Services.ProjectService.WrapAssemblies(assemblies);

                OnProjectLoad(newProject);
            }
            catch (Exception exception)
            {
                log.Error("Project load failed", exception);
                lastException = exception;
                events.FireProjectLoadFailed("New Project", exception);
            }
        }
Beispiel #19
0
        /// <summary>
        /// Create a new project using a given path
        /// </summary>
        public void NewProject(string filePath)
        {
            try
            {
                events.FireProjectLoading(filePath);

                NUnitProject project = new NUnitProject(filePath);

                project.Configs.Add("Debug");
                project.Configs.Add("Release");
                project.IsDirty = false;

                OnProjectLoad(project);
            }
            catch (Exception exception)
            {
                lastException = exception;
                events.FireProjectLoadFailed(filePath, exception);
            }
        }
Beispiel #20
0
        /// <summary>
        /// Creates a project to wrap a list of assemblies
        /// </summary>
        public NUnitProject WrapAssemblies(string[] assemblies)
        {
            // if only one assembly is passed in then the configuration file
            // should follow the name of the assembly. This will only happen
            // if the LoadAssembly method is called. Currently the console ui
            // does not differentiate between having one or multiple assemblies
            // passed in.
            if (assemblies.Length == 1)
            {
                return(WrapAssembly(assemblies[0]));
            }


            NUnitProject  project = Services.ProjectService.EmptyProject();
            ProjectConfig config  = new ProjectConfig("Default");

            foreach (string assembly in assemblies)
            {
                string fullPath = Path.GetFullPath(assembly);

                if (!File.Exists(fullPath))
                {
                    throw new FileNotFoundException(string.Format("Assembly not found: {0}", fullPath));
                }

                config.Assemblies.Add(fullPath);
            }

            project.Configs.Add(config);

            // TODO: Deduce application base, and provide a
            // better value for loadpath and project path
            // analagous to how new projects are handled
            string basePath = Path.GetDirectoryName(Path.GetFullPath(assemblies[0]));

            project.ProjectPath = Path.Combine(basePath, project.Name + ".nunit");

            project.IsDirty = true;

            return(project);
        }
 /// <summary>
 /// Return a test project by either loading it from
 /// the supplied path, creating one from a VS file
 /// or wrapping an assembly.
 /// </summary>
 public static NUnitProject LoadProject(string path)
 {
     if (NUnitProject.IsProjectFile(path))
     {
         NUnitProject project = new NUnitProject(path);
         project.Load();
         return(project);
     }
     else if (VSProject.IsProjectFile(path))
     {
         return(NUnitProject.FromVSProject(path));
     }
     else if (VSProject.IsSolutionFile(path))
     {
         return(NUnitProject.FromVSSolution(path));
     }
     else
     {
         return(NUnitProject.FromAssembly(path));
     }
 }
Beispiel #22
0
        /// <summary>
        /// Creates a project to wrap an assembly
        /// </summary>
        public NUnitProject WrapAssembly(string assemblyPath)
        {
            if (!File.Exists(assemblyPath))
            {
                throw new FileNotFoundException(string.Format("Assembly not found: {0}", assemblyPath));
            }

            string fullPath = Path.GetFullPath(assemblyPath);

            NUnitProject project = new NUnitProject(fullPath);

            ProjectConfig config = new ProjectConfig("Default");

            config.Assemblies.Add(fullPath);
            project.Configs.Add(config);

            project.IsAssemblyWrapper = true;
            project.IsDirty           = false;

            return(project);
        }
Beispiel #23
0
        /// <summary>
        /// Create a new project using a given path
        /// </summary>
        public void NewProject(string filePath)
        {
            log.Info("Creating project " + filePath);
            try
            {
                events.FireProjectLoading(filePath);

                NUnitProject project = new NUnitProject(filePath);

                project.Configs.Add("Debug");
                project.Configs.Add("Release");
                project.IsDirty = false;

                OnProjectLoad(project);
            }
            catch (Exception exception)
            {
                log.Error("Project creation failed", exception);
                lastException = exception;
                events.FireProjectLoadFailed(filePath, exception);
            }
        }
Beispiel #24
0
        /// <summary>
        /// Load a new project, optionally selecting the config and fire events
        /// </summary>
        public void LoadProject(string filePath, string configName)
        {
            try
            {
                log.Info("Loading project {0}, {1} config", filePath, configName == null ? "default" : configName);
                events.FireProjectLoading(filePath);

                NUnitProject newProject = Services.ProjectService.LoadProject(filePath);
                if (configName != null)
                {
                    newProject.SetActiveConfig(configName);
                    newProject.IsDirty = false;
                }

                OnProjectLoad(newProject);
            }
            catch (Exception exception)
            {
                log.Error("Project load failed", exception);
                lastException = exception;
                events.FireProjectLoadFailed(filePath, exception);
            }
        }
Beispiel #25
0
        /// <summary>
        /// Unload the current project and fire events
        /// </summary>
        public void UnloadProject()
        {
            string testFileName = TestFileName;

            try
            {
                events.FireProjectUnloading(testFileName);

                if (IsTestLoaded)
                {
                    UnloadTest();
                }

                testProject.Changed -= new ProjectEventHandler(OnProjectChanged);
                testProject          = null;

                events.FireProjectUnloaded(testFileName);
            }
            catch (Exception exception)
            {
                lastException = exception;
                events.FireProjectUnloadFailed(testFileName, exception);
            }
        }
Beispiel #26
0
        public static NUnitProject FromVSSolution( string solutionPath )
        {
            NUnitProject project = new NUnitProject( Path.GetFullPath( solutionPath ) );

            string solutionDirectory = Path.GetDirectoryName( solutionPath );
            using(StreamReader reader = new StreamReader( solutionPath ))
            {
                char[] delims = { '=', ',' };
                char[] trimchars = { ' ', '"' };

                string line = reader.ReadLine();
                while ( line != null )
                {
                    if ( line.StartsWith( "Project" ) )
                    {
                        string[] parts = line.Split( delims );
                        string vsProjectPath = parts[2].Trim(trimchars);

                        if ( VSProject.IsProjectFile( vsProjectPath ) )
                            project.Add( new VSProject( Path.Combine( solutionDirectory, vsProjectPath ) ) );
                    }

                    line = reader.ReadLine();
                }
            }

            project.isDirty = false;

            return project;
        }
Beispiel #27
0
        /// <summary>
        /// Creates a project to wrap an assembly
        /// </summary>
        public static NUnitProject FromAssembly( string assemblyPath )
        {
            if ( !File.Exists( assemblyPath ) )
                throw new FileNotFoundException( string.Format( "Assembly not found: {0}", assemblyPath ) );

            string fullPath = Path.GetFullPath( assemblyPath );

            NUnitProject project = new NUnitProject( fullPath );

            ProjectConfig config = new ProjectConfig( "Default" );
            config.Assemblies.Add( fullPath );
            project.Configs.Add( config );

            project.isAssemblyWrapper = true;
            project.IsDirty = false;

            return project;
        }
Beispiel #28
0
        public static NUnitProject FromVSProject( string vsProjectPath )
        {
            NUnitProject project = new NUnitProject( Path.GetFullPath( vsProjectPath ) );

            VSProject vsProject = new VSProject( vsProjectPath );
            project.Add( vsProject );

            project.isDirty = false;

            return project;
        }
Beispiel #29
0
 public Test Load(NUnitProject project)
 {
     return(Load(project, null));
 }
        private IEnumerable<string> GetDistributedConfigurationFileNames(TestProject project, NUnitParameters nUnitParameters)
        {
            if (nUnitParameters.AssembliesToTest.Count == 1)
            {
                var localName = Path.Combine(project.Path, Path.GetFileName(nUnitParameters.AssembliesToTest[0]));
                if (NUnitProject.IsNUnitProjectFile(localName) &&
                    File.Exists(localName))
                {
                    var nUnitProject = new NUnitProject(localName);
                    nUnitProject.Load();
                    var matchingConfig = nUnitProject.Configs.Cast<ProjectConfig>().Where(c => c.Name.Equals(nUnitParameters.Configuration)).FirstOrDefault();

                    if (matchingConfig == null)
                    {
                        var configFileNamedAsProject = Path.ChangeExtension(localName, ".config");
                        if (File.Exists(configFileNamedAsProject))
                            yield return configFileNamedAsProject;
                        yield break;
                    }

                    yield return matchingConfig.ConfigurationFilePath;
                    yield break;
                }
            }

            foreach (var assembly in nUnitParameters.AssembliesToTest)
            {
                var localName = Path.Combine(project.Path, Path.GetFileName(assembly));
                string possibleConfigName = null;
                if (File.Exists(possibleConfigName = localName + ".config"))
                    yield return possibleConfigName;
                else if (File.Exists(possibleConfigName = Path.ChangeExtension(localName, ".config")))
                    yield return possibleConfigName;
            }
        }
        /// <summary>
        /// Create a new project using a given path
        /// </summary>
        ////调用重写方法: private void OnProjectLoad(NUnitProject testProject)
        public new void NewProject(string filePath)
        {
            log.Info("Creating project " + filePath);

            object value;
            TestEventDispatcher events;
            Exception lastException;
            try
            {
                //private TestEventDispatcher events;
                //events.FireProjectLoading(filePath);
                events = null;
                value = GetBaseNoPublicField("events");
                if (value != null)  events = (TestEventDispatcher)value;
                if (events != null) events.FireProjectLoading(filePath);

                NUnitProject project = new NUnitProject(filePath);

                project.Configs.Add("Debug");
                project.Configs.Add("Release");
                project.IsDirty = false;

                OnProjectLoad(project);
            }
            catch (Exception exception)
            {
                log.Error("Project creation failed", exception);

                //private Exception lastException = null;
                //lastException = exception;
                lastException = exception;
                SetBaseNoPublicField("lastException", lastException);

                //private TestEventDispatcher events;
                //events.FireProjectLoadFailed(filePath, exception);
                events = null;
                value = GetBaseNoPublicField("events");
                if (value != null)  events = (TestEventDispatcher)value;
                if (events != null) events.FireProjectLoadFailed(filePath, exception);
            }
        }
Beispiel #32
0
 public void SaveProject(NUnitProject project)
 {
     project.Save();
 }
        /// <summary>
        /// Construct an application domain for running a test package
        /// </summary>
        /// <param name="package">The TestPackage to be run</param>
        public AppDomain CreateDomain(TestPackage package)
        {
            FileInfo testFile = new FileInfo(package.FullName);

            AppDomainSetup setup = new AppDomainSetup();

            //For paralell tests, we need to use distinct application name
            setup.ApplicationName = "Tests" + "_" + Environment.TickCount;
            //setup.ApplicationName = package.Name;

            string appBase = package.BasePath;

            if (appBase == null || appBase == string.Empty)
            {
                appBase = testFile.DirectoryName;
            }
            setup.ApplicationBase = appBase;

            string configFile = package.ConfigurationFile;

            if (configFile == null || configFile == string.Empty)
            {
                configFile = NUnitProject.IsProjectFile(testFile.Name)
                                        ? Path.GetFileNameWithoutExtension(testFile.Name) + ".config"
                                        : testFile.Name + ".config";
            }
            // Note: Mono needs full path to config file...
            setup.ConfigurationFile = Path.Combine(appBase, configFile);

            string binPath = package.PrivateBinPath;

            if (package.AutoBinPath)
            {
                binPath = GetPrivateBinPath(appBase, package.Assemblies);
            }

            setup.PrivateBinPath = binPath;

            if (package.GetSetting("ShadowCopyFiles", true))
            {
                setup.ShadowCopyFiles       = "true";
                setup.ShadowCopyDirectories = appBase;
                setup.CachePath             = GetCachePath();
            }
            else
            {
                setup.ShadowCopyFiles = "false";
            }

            string domainName = "test-domain-" + package.Name;
            // Setup the Evidence
            Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);

            if (evidence.Count == 0)
            {
                Zone zone = new Zone(SecurityZone.MyComputer);
                evidence.AddHost(zone);
                Assembly assembly = Assembly.GetExecutingAssembly();
                Url      url      = new Url(assembly.CodeBase);
                evidence.AddHost(url);
                Hash hash = new Hash(assembly);
                evidence.AddHost(hash);
            }

            log.Info("Creating AppDomain " + domainName);

            AppDomain runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);

            // HACK: Only pass down our AddinRegistry one level so that tests of NUnit
            // itself start without any addins defined.
            if (!IsTestDomain(AppDomain.CurrentDomain))
            {
                runnerDomain.SetData("AddinRegistry", Services.AddinRegistry);
            }

            // Inject DomainInitializer into the remote domain - there are other
            // approaches, but this works for all CLR versions.
            DomainInitializer initializer = DomainInitializer.CreateInstance(runnerDomain);

            initializer.InitializeDomain(IsTestDomain(AppDomain.CurrentDomain)
                ? TraceLevel.Off : InternalTrace.Level);

            return(runnerDomain);
        }
        /// <summary>
        /// Gets the NUnit test result.
        /// </summary>
        /// <param name="test">The test.</param>
        /// <param name="project">The project.</param>
        /// <param name="configurationSubstitutions">The configuration substitutions.</param>
        /// <param name="isChild">if set to <c>true</c> [is child].</param>
        /// <returns></returns>
        public TestResult GetNUnitTestResult(TestUnit test, TestProject project, DistributedConfigurationSubstitutions configurationSubstitutions, bool isChild = false)
        {
            var nativeRunner = runnerCache.GetOrLoad(test.Run, configurationSubstitutions,
                                                     () =>
                                                         {
                                                             initializer.Initialize();

                                                             string configurationFileName =
                                                                 configurationOperator.GetSubstitutedConfigurationFile(project,
                                                                                                            test.Run.
                                                                                                                NUnitParameters,
                                                                                                            configurationSubstitutions);

                                                             var mappedAssemblyFile = Path.Combine(project.Path,
                                                                                                   Path.GetFileName(
                                                                                                       test.Run.NUnitParameters.
                                                                                                           AssembliesToTest[0]));

                                                             TestPackage package;
                                                             if (!NUnitProject.IsNUnitProjectFile(mappedAssemblyFile))
                                                                 package = new TestPackage(mappedAssemblyFile);
                                                             else
                                                             {
                                                                 var nunitProject = new NUnitProject(mappedAssemblyFile);
                                                                 nunitProject.Load();
                                                                 if (!string.IsNullOrEmpty(test.Run.NUnitParameters.Configuration))
                                                                     nunitProject.SetActiveConfig(test.Run.NUnitParameters.Configuration);

                                                                 package = nunitProject.ActiveConfig.MakeTestPackage();
                                                             }

                                                             package.Settings["ShadowCopyFiles"] = true;
                                                             package.AutoBinPath = true;
                                                             if (!string.IsNullOrEmpty(configurationFileName))
                                                             {
                                                                 package.ConfigurationFile = configurationFileName;
                                                             }

                                                             var nativeTestRunner = new NDistribUnitProcessRunner(log);
                                                             nativeTestRunner.Load(package);
                                                             return nativeTestRunner;
                                                         });

            var testOptions = test.Run.NUnitParameters;
            TestResult testResult = null;

            try
            {
                Action runTest = ()=>
                                     {
                                         try
                                         {
                                             testResult = nativeRunner.Run(new NullListener(),
                                                                           new NUnitTestsFilter(
                                                                               testOptions.IncludeCategories,
                                                                               testOptions.ExcludeCategories,
                                                                               test.UniqueTestId).NativeFilter);
                                             nativeRunner.CleanupAfterRun();
                                         }
                                         //TODO: remove this. This is for tracking purposes only
                                         catch(AppDomainUnloadedException ex)
                                         {
                                             log.Warning("AppDomainUnloadedException is still being thrown", ex);
                                             if (!isChild)
                                             {
                                                 runnerCache.Remove(test.Run, configurationSubstitutions);
                                                 testResult = GetNUnitTestResult(test, project,
                                                                                 configurationSubstitutions,
                                                                                 isChild: true);
                                             }
                                             else
                                                 throw;
                                         }
                                     };

                if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA
                    && !Thread.CurrentThread.TrySetApartmentState(ApartmentState.STA))
                {
                    var thread = new Thread(()=> exceptionCatcher.Run(runTest));
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                }
                else
                {
                    runTest();
                }
            }
            catch (Exception ex)
            {
                log.Error("Error while running test on agent", ex);
                throw;
            }
            return testResult;
        }
Beispiel #35
0
		public Test Load( NUnitProject project )
		{
			return Load( project, null );
		}
Beispiel #36
0
        private TestPackage GetTestPackage(string projectFileName, NUnitParameters nUnitParameters)
        {
            if (!NUnitProject.IsNUnitProjectFile(projectFileName))
                return new TestPackage(projectFileName);

            var nunitProject = new NUnitProject(projectFileName);
            nunitProject.Load();
            if (!string.IsNullOrEmpty(nUnitParameters.Configuration))
                nunitProject.SetActiveConfig(nUnitParameters.Configuration);

            return nunitProject.ActiveConfig.MakeTestPackage();
        }
Beispiel #37
0
		public Test Load( NUnitProject project, string testFixture )
		{
			ProjectConfig cfg = project.ActiveConfig;

			if ( project.IsAssemblyWrapper )
				return Load( cfg.Assemblies[0].FullPath, testFixture );
			else
				return Load( project.ProjectPath, cfg.BasePath, cfg.ConfigurationFile, cfg.PrivateBinPath, cfg.TestAssemblies, testFixture );
		}
Beispiel #38
0
		public ProjectConfigCollection( NUnitProject project ) 
		{ 
			this.project = project;
		}
Beispiel #39
0
 public ProjectConfigCollection(NUnitProject project)
 {
     this.project = project;
 }
Beispiel #40
0
 /// <summary>
 /// Return a test project by either loading it from
 /// the supplied path, creating one from a VS file
 /// or wrapping an assembly.
 /// </summary>
 public static NUnitProject LoadProject( string path )
 {
     if ( NUnitProject.IsProjectFile( path ) )
     {
         NUnitProject project = new NUnitProject( path );
         project.Load();
         return project;
     }
     else if ( VSProject.IsProjectFile( path ) )
         return NUnitProject.FromVSProject( path );
     else if ( VSProject.IsSolutionFile( path ) )
         return NUnitProject.FromVSSolution( path );
     else
         return NUnitProject.FromAssembly( path );
 }
Beispiel #41
0
		/// <summary>
		/// Common operations done each time a project is loaded
		/// </summary>
		/// <param name="testProject">The newly loaded project</param>
		private void OnProjectLoad( NUnitProject testProject )
		{
			if ( IsProjectLoaded )
				UnloadProject();

			this.testProject = testProject;
			testProject.Changed += new ProjectEventHandler( OnProjectChanged );

			events.FireProjectLoaded( TestFileName );
		}
        /// <summary>
        /// Common operations done each time a project is loaded
        /// </summary>
        /// <param name="testProject">The newly loaded project</param>
        //调用new public void UnloadProject()
        private new void OnProjectLoad(NUnitProject testProject)
        {
            if (IsProjectLoaded)
                UnloadProject();

            object value;
            TestEventDispatcher events;
            //private NUnitProject testProject = null;
            //this.testProject = testProject;
            SetBaseNoPublicField("testProject", testProject);

            //private TestEventDispatcher events;
            //events.FireProjectLoaded(TestFileName);
            events = null;
            value = GetBaseNoPublicField("events");
            if (value != null)  events = (TestEventDispatcher)value;
            if (events != null) events.FireProjectLoaded(TestFileName);
        }
Beispiel #43
0
		/// <summary>
		/// Unload the current project and fire events
		/// </summary>
		public void UnloadProject()
		{
			string testFileName = TestFileName;

			try
			{
				events.FireProjectUnloading( testFileName );

				if ( IsTestLoaded )
					UnloadTest();

				testProject.Changed -= new ProjectEventHandler( OnProjectChanged );
				testProject = null;

				events.FireProjectUnloaded( testFileName );
			}
			catch (Exception exception )
			{
				lastException = exception;
				events.FireProjectUnloadFailed( testFileName, exception );
			}

		}
        /// <summary>
        /// Construct an application domain for running a test package
        /// </summary>
        /// <param name="package">The TestPackage to be run</param>
        public AppDomain CreateDomain(TestPackage package)
        {
            FileInfo testFile = new FileInfo(package.FullName);

            AppDomainSetup setup = new AppDomainSetup();

            // We always use the same application name
            setup.ApplicationName = "Tests";

            string appBase = package.BasePath;

            if (appBase == null || appBase == string.Empty)
            {
                appBase = testFile.DirectoryName;
            }
            setup.ApplicationBase = appBase;

            string configFile = package.ConfigurationFile;

            if (configFile == null || configFile == string.Empty)
            {
                configFile = NUnitProject.IsProjectFile(testFile.Name)
                         ? Path.GetFileNameWithoutExtension(testFile.Name) + ".config"
                         : testFile.Name + ".config";
            }
            // Note: Mono needs full path to config file...
            setup.ConfigurationFile = Path.Combine(appBase, configFile);

            string binPath = package.PrivateBinPath;

            if (package.AutoBinPath)
            {
                binPath = GetPrivateBinPath(appBase, package.Assemblies);
            }
            setup.PrivateBinPath = binPath;

            if (package.GetSetting("ShadowCopyFiles", true))
            {
                setup.ShadowCopyFiles       = "true";
                setup.ShadowCopyDirectories = appBase;
                setup.CachePath             = GetCachePath();
            }

            string    domainName   = "domain-" + package.Name;
            Evidence  baseEvidence = AppDomain.CurrentDomain.Evidence;
            Evidence  evidence     = new Evidence(baseEvidence);
            AppDomain runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);

            // Inject assembly resolver into remote domain to help locate our assemblies
            AssemblyResolver assemblyResolver = (AssemblyResolver)runnerDomain.CreateInstanceFromAndUnwrap(
                typeof(AssemblyResolver).Assembly.CodeBase,
                typeof(AssemblyResolver).FullName);

            // Tell resolver to use our core assemblies in the test domain
            assemblyResolver.AddFile(typeof(NUnit.Core.RemoteTestRunner).Assembly.Location);
            assemblyResolver.AddFile(typeof(NUnit.Core.ITest).Assembly.Location);

// No reference to extensions, so we do it a different way
            string moduleName   = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            string nunitDirPath = Path.GetDirectoryName(moduleName);
//            string coreExtensions = Path.Combine(nunitDirPath, "nunit.core.extensions.dll");
//			assemblyResolver.AddFile( coreExtensions );
            //assemblyResolver.AddFiles( nunitDirPath, "*.dll" );

            string addinsDirPath = Path.Combine(nunitDirPath, "addins");

            assemblyResolver.AddDirectory(addinsDirPath);

            // HACK: Only pass down our AddinRegistry one level so that tests of NUnit
            // itself start without any addins defined.
            if (!IsTestDomain(AppDomain.CurrentDomain))
            {
                runnerDomain.SetData("AddinRegistry", Services.AddinRegistry);
            }

            return(runnerDomain);
        }
		public void SaveProject( NUnitProject project )
		{
			project.Save();
		}
Beispiel #46
0
 public bool CanLoadProject(string path)
 {
     return(NUnitProject.IsNUnitProjectFile(path) || CanConvertFrom(path));
 }
Beispiel #47
0
		/// <summary>
		/// Create a new project using a given path
		/// </summary>
		public void NewProject( string filePath )
		{
			try
			{
				events.FireProjectLoading( filePath );

				NUnitProject project = new NUnitProject( filePath );

				project.Configs.Add( "Debug" );
				project.Configs.Add( "Release" );			
				project.IsDirty = false;

				OnProjectLoad( project );
			}
			catch( Exception exception )
			{
				lastException = exception;
				events.FireProjectLoadFailed( filePath, exception );
			}
		}
		public ConfigurationEditor( NUnitProject project )
		{
			InitializeComponent();
			this.project = project;
		}
Beispiel #49
0
		/// <summary>
		/// Unload the current project and fire events
		/// </summary>
		public void UnloadProject()
		{
			string testFileName = TestFileName;

            log.Info("Unloading project " + testFileName);
			try
			{
				events.FireProjectUnloading( testFileName );

				if ( IsTestLoaded )
					UnloadTest();

				testProject = null;

				events.FireProjectUnloaded( testFileName );
			}
			catch (Exception exception )
			{
                log.Error("Project unload failed", exception);
                lastException = exception;
				events.FireProjectUnloadFailed( testFileName, exception );
			}

		}
Beispiel #50
0
		/// <summary>
		/// Create a new project using a given path
		/// </summary>
		public void NewProject( string filePath )
		{
            log.Info("Creating project " + filePath);
            try
			{
				events.FireProjectLoading( filePath );

				NUnitProject project = new NUnitProject( filePath );

				project.Configs.Add( "Debug" );
				project.Configs.Add( "Release" );			
				project.IsDirty = false;

				OnProjectLoad( project );
			}
			catch( Exception exception )
			{
                log.Error("Project creation failed", exception);
                lastException = exception;
				events.FireProjectLoadFailed( filePath, exception );
			}
		}
		public AddConfigurationDialog( NUnitProject project )
		{ 
			InitializeComponent();
			this.project = project;
		}
Beispiel #52
0
		/// <summary>
		/// Common operations done each time a project is loaded
		/// </summary>
		/// <param name="testProject">The newly loaded project</param>
		private void OnProjectLoad( NUnitProject testProject )
		{
			if ( IsProjectLoaded )
				UnloadProject();

			this.testProject = testProject;

			events.FireProjectLoaded( TestFileName );
		}
Beispiel #53
0
		/// <summary>
		/// Unload the current project and fire events
		/// </summary>
		public void UnloadProject()
		{
			string testFileName = TestFileName;

			try
			{
				events.FireProjectUnloading( testFileName );

//				if ( testFileName != null && File.Exists( testFileName ) )
//					UserSettings.RecentProjects.RecentFile = testFileName;

				if ( IsTestLoaded )
					UnloadTest();

				testProject.Changed -= new ProjectEventHandler( OnProjectChanged );
				testProject = null;

				events.FireProjectUnloaded( testFileName );
			}
			catch (Exception exception )
			{
				lastException = exception;
				events.FireProjectUnloadFailed( testFileName, exception );
			}

		}