public void LoadTest(string testName)
        {
            long startTime = DateTime.Now.Ticks;

            try
            {
                events.FireTestLoading(TestFileName);

                testRunner = CreateRunner();

                bool loaded = testRunner.Load(MakeTestPackage(testName));

                loadedTest     = testRunner.Test;
                loadedTestName = testName;
                testResult     = null;
                reloadPending  = false;

                if (ReloadOnChange)
                {
                    InstallWatcher( );
                }

                if (loaded)
                {
                    events.FireTestLoaded(TestFileName, 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.Assemblies)
                {
                    if (Path.GetFileNameWithoutExtension(assembly) == exception.FileName &&
                        !PathUtils.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);
            }

            double loadTime = (double)(DateTime.Now.Ticks - startTime) / (double)TimeSpan.TicksPerSecond;

            System.Diagnostics.Trace.WriteLine(string.Format("TestLoader: Loaded in {0} seconds", loadTime));
        }
예제 #2
0
        public void LoadTest(string testName)
        {
            try
            {
                events.FireTestLoading(TestFileName);

                testRunner = CreateRunner();

                bool loaded = testRunner.Load(MakeTestPackage(testName));

                loadedTest     = testRunner.Test;
                loadedTestName = testName;
                testResult     = null;
                reloadPending  = false;

                if (ReloadOnChange)
                {
                    InstallWatcher( );
                }

                if (loaded)
                {
                    events.FireTestLoaded(TestFileName, 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.Assemblies)
                {
                    if (Path.GetFileNameWithoutExtension(assembly) == exception.FileName &&
                        !PathUtils.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);
            }
        }
예제 #3
0
        public static string GetCommonAppBase(IList assemblies)
        {
            string commonBase = null;

            foreach (string assembly in assemblies)
            {
                string dir = Path.GetFullPath(Path.GetDirectoryName(assembly));
                if (commonBase == null)
                {
                    commonBase = dir;
                }
                else
                {
                    while (!PathUtils.SamePathOrUnder(commonBase, dir) && commonBase != null)
                    {
                        commonBase = Path.GetDirectoryName(commonBase);
                    }
                }
            }

            return(commonBase);
        }
예제 #4
0
        public void Save()
        {
            projectPath = ProjectPathFromFile(projectPath);

            XmlTextWriter writer = new XmlTextWriter(projectPath, System.Text.Encoding.UTF8);

            writer.Formatting = Formatting.Indented;

            writer.WriteStartElement("NUnitProject");

            if (configs.Count > 0 || this.BasePath != this.DefaultBasePath)
            {
                writer.WriteStartElement("Settings");
                if (configs.Count > 0)
                {
                    writer.WriteAttributeString("activeconfig", ActiveConfigName);
                }
                if (this.BasePath != this.DefaultBasePath)
                {
                    writer.WriteAttributeString("appbase", this.BasePath);
                }
                writer.WriteEndElement();
            }

            foreach (ProjectConfig config in Configs)
            {
                writer.WriteStartElement("Config");
                writer.WriteAttributeString("name", config.Name);
                string appbase = config.BasePath;
                if (!PathUtils.SamePathOrUnder(this.BasePath, appbase))
                {
                    writer.WriteAttributeString("appbase", appbase);
                }
                else if (config.RelativeBasePath != null)
                {
                    writer.WriteAttributeString("appbase", config.RelativeBasePath);
                }

                string configFile = config.ConfigurationFile;
                if (configFile != null && configFile != this.ConfigurationFile)
                {
                    writer.WriteAttributeString("configfile", config.ConfigurationFile);
                }

                if (config.BinPathType == BinPathType.Manual)
                {
                    writer.WriteAttributeString("binpath", config.PrivateBinPath);
                }
                else
                {
                    writer.WriteAttributeString("binpathtype", config.BinPathType.ToString());
                }

                foreach (string assembly in config.Assemblies)
                {
                    writer.WriteStartElement("assembly");
                    writer.WriteAttributeString("path", PathUtils.RelativePath(config.BasePath, assembly));
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }

            writer.WriteEndElement();

            writer.Close();
            this.IsDirty = false;

            // Once we save a project, it's no longer
            // loaded as an assembly wrapper on reload.
            this.isAssemblyWrapper = false;
        }
예제 #5
0
        public void LoadTest(string testName)
        {
            log.Info("Loading tests for " + Path.GetFileName(TestFileName));

            long startTime = DateTime.Now.Ticks;

            try
            {
                events.FireTestLoading(TestFileName);

                TestPackage package = MakeTestPackage(testName);
                testRunner = factory.MakeTestRunner(package);

                bool loaded = testRunner.Load(package);

                loadedTest     = testRunner.Test;
                loadedTestName = testName;
                testResult     = null;
                reloadPending  = false;

                if (Services.UserSettings.GetSetting("Options.TestLoader.ReloadOnChange", true))
                {
                    InstallWatcher( );
                }

                if (loaded)
                {
                    this.currentFramework = package.Settings.Contains("RuntimeFramework")
                        ? package.Settings["RuntimeFramework"] as RuntimeFramework
                        : RuntimeFramework.CurrentFramework;

                    testProject.HasChangesRequiringReload = false;
                    events.FireTestLoaded(TestFileName, loadedTest);
                }
                else
                {
                    lastException = new ApplicationException(string.Format("Unable to find test {0} in assembly", testName));
                    events.FireTestLoadFailed(TestFileName, lastException);
                }
            }
            catch (FileNotFoundException exception)
            {
                log.Error("File not found", exception);
                lastException = exception;

                foreach (string assembly in TestProject.ActiveConfig.Assemblies)
                {
                    if (Path.GetFileNameWithoutExtension(assembly) == exception.FileName &&
                        !PathUtils.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);

                double loadTime = (double)(DateTime.Now.Ticks - startTime) / (double)TimeSpan.TicksPerSecond;
                log.Info("Load completed in {0} seconds", loadTime);
            }
            catch (Exception exception)
            {
                log.Error("Failed to load test", exception);

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