public void GetCommonDirectory_SeveralCharacterCommonString_CommonString() { Assert.AreEqual("C:\\abc\\", CommonDirectorySearcher.GetCommonDirectory(new[] { "C:\\abc\\1", "C:\\abc\\2", "C:\\abc\\3" })); }
/// <summary> /// Searches the given source element (e.g. property) and updates the report if element can be found in source code files. /// </summary> /// <param name="sourceElement">The source element.</param> /// <param name="filenameByFileIdDictionary">Dictionary containing all files used in the report by their corresponding id.</param> /// <param name="fileIdsOfClass">The file ids of class.</param> /// <param name="reportElement">The report element.</param> /// <param name="updateReportElement">Action that updates the report element.</param> /// <param name="filesContainer">The files container.</param> /// <returns><c>true</c> if source element has been found.</returns> protected bool SearchElement( SourceElement sourceElement, Dictionary <string, string> filenameByFileIdDictionary, IEnumerable <string> fileIdsOfClass, XContainer reportElement, Action <XContainer, SourceElementPosition, string> updateReportElement, XContainer filesContainer) { Func <bool> searchSourceElement = () => { foreach (var fileId in fileIdsOfClass) { var elementPosition = SourceCodeAnalyzer.FindSourceElement(filenameByFileIdDictionary[fileId], sourceElement); if (elementPosition != null) { updateReportElement(reportElement, elementPosition, fileId); return(true); } } return(false); }; // Search files from module first if (!searchSourceElement()) { // Property has not been found in classes of module, now search the common directory if (this.ClassSearcher == null) { this.ClassSearcher = this.classSearcherFactory.CreateClassSearcher(CommonDirectorySearcher.GetCommonDirectory(filenameByFileIdDictionary.Values)); } fileIdsOfClass = this.TryToFindFileIdsOfClass( this.ClassSearcher, sourceElement.Classname, filenameByFileIdDictionary, filesContainer); // Property has not been found in common directory, now search the global directory if (!searchSourceElement()) { fileIdsOfClass = this.TryToFindFileIdsOfClass( this.globalClassSearcher, sourceElement.Classname, filenameByFileIdDictionary, filesContainer); return(searchSourceElement()); } } return(true); }
public void GetCommonDirectory_SingleCharacterCommonString_CommonString() { Assert.AreEqual("C:\\", CommonDirectorySearcher.GetCommonDirectory(new[] { "C:\\a", "C:\\ab" })); }
public void GetCommonDirectory_NoCommonString_EmptyString() { Assert.AreEqual(string.Empty, CommonDirectorySearcher.GetCommonDirectory(new[] { "C:\\", "D:\\" })); }
public void GetCommonDirectory_EmptyArray_Null() { Assert.IsNull(CommonDirectorySearcher.GetCommonDirectory(new string[] { })); }
public void GetCommonDirectory_PassNull_ArgumentNullExceptionIsThrown() { CommonDirectorySearcher.GetCommonDirectory(null); }
public void GetCommonDirectory_DifferingCase_CommonStringCaseInsensitive() { Assert.AreEqual("C:\\abc\\", CommonDirectorySearcher.GetCommonDirectory(new[] { "C:\\Abc\\1", "C:\\abc\\2" }), true); }