Esempio n. 1
0
 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);
        }
Esempio n. 3
0
 public void GetCommonDirectory_SingleCharacterCommonString_CommonString()
 {
     Assert.AreEqual("C:\\", CommonDirectorySearcher.GetCommonDirectory(new[] { "C:\\a", "C:\\ab" }));
 }
Esempio n. 4
0
 public void GetCommonDirectory_NoCommonString_EmptyString()
 {
     Assert.AreEqual(string.Empty, CommonDirectorySearcher.GetCommonDirectory(new[] { "C:\\", "D:\\" }));
 }
Esempio n. 5
0
 public void GetCommonDirectory_EmptyArray_Null()
 {
     Assert.IsNull(CommonDirectorySearcher.GetCommonDirectory(new string[] { }));
 }
Esempio n. 6
0
 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);
 }