public void TestClassNameRefactoring() { CataloguePatcher p = new CataloguePatcher(); var patch = p.GetAllPatchesInAssembly(null).Single(kvp => kvp.Key == "068_FixNamespaces.sql").Value; Regex findSubsRegex = new Regex(@"REPLACE\(.*,'(.*)','(.*)'\)"); Dictionary <string, string> substitutions = new Dictionary <string, string>(); foreach (Match match in findSubsRegex.Matches(patch.EntireScript)) { if (substitutions.ContainsKey(match.Groups[1].Value)) { continue; } substitutions.Add(match.Groups[1].Value, match.Groups[2].Value); } SetupMEF(); MEF.SafeDirectoryCatalog.AddType(typeof(FAnsi.DatabaseType)); foreach (var oldClass in ExpectedClasses) { string newClass = oldClass; foreach (KeyValuePair <string, string> kvp in substitutions) { newClass = newClass.Replace(kvp.Key, kvp.Value); } Type foundNow = MEF.GetType(newClass); Assert.IsNotNull(foundNow, "Patch did not work correctly for Type '" + oldClass + "' which after renaming became '" + newClass + "'"); } }
public void FindProblems(MEF mef, List <string> csFilesFound) { Dictionary <string, string> suggestedNewFileContents = new Dictionary <string, string>(StringComparer.CurrentCultureIgnoreCase); foreach (var f in csFilesFound) { if (f.Contains(".Designer.cs")) { continue; } bool changes = false; StringBuilder sbSuggestedText = new StringBuilder(); var text = File.ReadAllLines(f); bool areInSummary = false; bool paraOpened = false; for (int i = 0; i < text.Length; i++) { //////////////////////////////////No Mapping Properties//////////////////////////////////////////////////// if (text[i].Trim().Equals("[NoMappingToDatabase]")) { var currentClassName = GetUniqueTypeName(Path.GetFileNameWithoutExtension(f)); Type t = mef.GetType(currentClassName); //if the previous line isn't a summary comment if (!text[i - 1].Trim().StartsWith("///")) { string next = text[i + 1]; var m = Regex.Match(next, @"(.*)public\b(.*)\s+(.*)\b"); if (m.Success) { var whitespace = m.Groups[1].Value; var type = m.Groups[2].Value; var member = m.Groups[3].Value; Assert.IsTrue(string.IsNullOrWhiteSpace(whitespace)); Assert.IsNotNull(t); if (t.GetProperty(member + "_ID") != null) { changes = true; sbSuggestedText.AppendLine(whitespace + string.Format("/// <inheritdoc cref=\"{0}\"/>", member + "_ID")); } else { sbSuggestedText.AppendLine(text[i]); continue; } } } } if (text[i].Trim().Equals("/// <summary>")) { areInSummary = true; paraOpened = false; } if (text[i].Trim().Equals("/// </summary>")) { if (paraOpened) { // sbSuggestedText.Insert(sbSuggestedText.Length - 2, "</para>"); paraOpened = false; } areInSummary = false; } //if we have a paragraph break in the summary comments and the next line isn't an end summary if (areInSummary && text[i].Trim().Equals("///") && !text[i + 1].Trim().Equals("/// </summary>")) { if (paraOpened) { sbSuggestedText.Insert(sbSuggestedText.Length - 2, "</para>"); paraOpened = false; } //there should be a para tag if (!text[i + 1].Contains("<para>") && text[i + 1].Contains("///")) { changes = true; //add current line sbSuggestedText.AppendLine(text[i]); //add the para tag string nextLine = text[i + 1].Insert(text[i + 1].IndexOf("///") + 4, "<para>"); sbSuggestedText.AppendLine(nextLine); i++; paraOpened = true; continue; } } sbSuggestedText.AppendLine(text[i]); } if (changes) { suggestedNewFileContents.Add(f, sbSuggestedText.ToString()); } } Assert.IsEmpty(suggestedNewFileContents); //drag your debugger stack pointer to here to mess up all your files to match the suggestedNewFileContents :) foreach (KeyValuePair <string, string> suggestedNewFileContent in suggestedNewFileContents) { File.WriteAllText(suggestedNewFileContent.Key, suggestedNewFileContent.Value); } }