public static void SaveToFile(this TestProjectInfo project, string defaultRunsettingsFile, Encoding encoding) { if (!Directory.Exists(project.Location)) { Directory.CreateDirectory(project.Location); } string output = TestProjectInfo.Serialize(project); string srcFile = Path.Combine(project.Location, project.Name + Constants.TestProjectFileTypeExtension); File.WriteAllText(srcFile, output, encoding); string runsettingsFile = Path.Combine(project.Location, project.Name + Constants.TestRunSettingFileTypeExtesion); if (!File.Exists(runsettingsFile)) { File.Copy(defaultRunsettingsFile, runsettingsFile, true); } string xml = File.ReadAllText(runsettingsFile); Dictionary <string, object> dict = VsualStudioTP.XmlRunSettingsUtilities.GetTestRunParameters(xml); IEnumerable <string> testAssemblies = (from r in project.TestMethods select r.Source).Distinct(StringComparer.InvariantCultureIgnoreCase); foreach (string assembly in testAssemblies) { DirectoryInfo root = new DirectoryInfo(Path.GetDirectoryName(assembly)); if (!root.Exists) { continue; } foreach (FileInfo info in root.GetFiles(Constants.TestRunSettingFileTypePattern)) { xml = File.ReadAllText(info.FullName); Dictionary <string, object> tmp = VsualStudioTP.XmlRunSettingsUtilities.GetTestRunParameters(xml); foreach (KeyValuePair <string, object> keyValue in tmp) { if (dict.ContainsKey(keyValue.Key)) { continue; } dict.Add(keyValue.Key, keyValue.Value); } TestRunParameters.AddLegacyNodes(xml, runsettingsFile); } } TestRunParameters.SaveTestRunParameters(dict, runsettingsFile); }
public static void Rename(this TestProjectInfo project, string originalName, string defaultRunsettingsFile, Encoding encoding) { if (File.Exists(ProjectFile(project.Location, originalName))) { File.Delete(ProjectFile(project.Location, originalName)); } if (File.Exists(RunsettingsFile(project.Location, originalName))) { File.Copy( RunsettingsFile(project.Location, originalName), RunsettingsFile(project.Location, project.Name), true); File.Delete(RunsettingsFile(project.Location, originalName)); } string runsettingsFile = File.Exists(RunsettingsFile(project.Location, originalName)) ? RunsettingsFile(project.Location, originalName) : defaultRunsettingsFile; project.SaveToFile(runsettingsFile, encoding); }
internal static string RunsettingsFile(this TestProjectInfo project) => RunsettingsFile(project.Location, project.Name);
internal static string ProjectFile(this TestProjectInfo project) => ProjectFile(project.Location, project.Name);