/// <summary> /// True if the two paths are the same. However, two paths /// to the same file or directory using different network /// shares or drive letters are not treated as equal. /// </summary> public static bool SamePath(string path1, string path2) { return(string.Compare(Canonicalize(path1), Canonicalize(path2), PathUtils.IsWindows()) == 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); } if (this.AutoConfig) { writer.WriteAttributeString("autoconfig", "true"); } if (this.ProcessModel != ProcessModel.Default) { writer.WriteAttributeString("processModel", this.ProcessModel.ToString()); } if (this.DomainUsage != DomainUsage.Default) { writer.WriteAttributeString("domainUsage", this.DomainUsage.ToString()); } 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()); } if (config.RuntimeFramework != null) { writer.WriteAttributeString("runtimeFramework", config.RuntimeFramework.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; }
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); if (testRunner != null) { testRunner.Dispose(); } testRunner = factory.MakeTestRunner(package); bool loaded = testRunner.Load(package); 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); } }