private TestCaseData CreateRootFolderData(string path, string rootFolder, bool isMatched, string name)
 {
     FileSystemItem item = new FileSystemItem(path);
     List<string> rootFolders = new List<string> { rootFolder };
     TestCaseData testCaseData = new TestCaseData(item, rootFolders, null, isMatched).SetName(name);
     return testCaseData;
 }
 private TestCaseData CreateExcludeTemplateData(string path, string excludeFolderTemplate, bool isMatched, string name)
 {
     FileSystemItem item = new FileSystemItem(path);
     List<string> excludeFolderTemplates = excludeFolderTemplate == null ? null : new List<string> { excludeFolderTemplate };
     TestCaseData testCaseData = new TestCaseData(item, null, excludeFolderTemplates, isMatched).SetName(name);
     return testCaseData;
 }
        public void TestCorrectness(FileSystemItem item, List<string> rootFolders, List<string> excludeFolderTemplates, bool isCorrect)
        {
            _fileSystemFilter.FoldersToParse = rootFolders;
            _fileSystemFilter.ExcludeFolderTemplates = excludeFolderTemplates;

            List<FileSystemItem> filteredItems = _fileSystemFilter.FilterItems(new List<FileSystemItem> { item });

            int expectedFilteredItemsCount = isCorrect ? 1 : 0;
            Assert.That(filteredItems.Count, Is.EqualTo(expectedFilteredItemsCount));
        }
        private MatchedFileSystemItem GetMatchedItem(FileSystemItem item, Regex searchRegex)
        {
            List<MatchSubstring> substrings = GetMatchSubstrings(item.Name, searchRegex);
            if (substrings == null)
            {
                return null;
            }

            MatchedFileSystemItem matchedItem = new MatchedFileSystemItem(item, new MatchString(substrings));

            return matchedItem;
        }
 private static string GetCacheItemLine(FileSystemItem item)
 {
     return string.Format(CultureInfo.InvariantCulture, "{1}{0}{2}", Separator, item.FullPath ?? string.Empty, item.Name);
 }
        public IEnumerable<TestCaseData> GetMatchCases()
        {
            const string rootPath = @"C:\";

            FileSystemItem item;
            string searchText;
            MatchString matchString;
            MatchedFileSystemItem expectedMatch;
            TestCaseData testCaseData;

            yield return CreateTestCaseData("my doc", "y d", null, "Match just from word start (first word violation)");

            yield return CreateTestCaseData("my doc", "m d", "my d", "Simple match of two words");

            yield return CreateTestCaseData("my own doc", "m d", null, "Match just neighboring words");

            yield return CreateTestCaseData("my doc", "m o", null, "Match just from word start (second word violation)");

            item = new FileSystemItem(rootPath + "my own doc");
            searchText = "ow Do";
            matchString = new MatchString
                              {
                                  new MatchSubstring("my ", false),
                                  new MatchSubstring("own do", true),
                                  new MatchSubstring("c", false),
                              };
            expectedMatch = new MatchedFileSystemItem(item, matchString);
            testCaseData = new TestCaseData(item, searchText, expectedMatch).SetName("Simple match from the second word");
            yield return testCaseData;

            item = new FileSystemItem(rootPath + "my oWn dOc");
            searchText = "Ow Do";
            matchString = new MatchString
                              {
                                  new MatchSubstring("my ", false),
                                  new MatchSubstring("oWn dO", true),
                                  new MatchSubstring("c", false),
                              };
            expectedMatch = new MatchedFileSystemItem(item, matchString);
            testCaseData = new TestCaseData(item, searchText, expectedMatch).SetName("Simple match from the second word (ignored case)");
            yield return testCaseData;

            yield return CreateTestCaseData("myDoc", "m dO", "myDo", "Match camel/pascal casing");

            yield return CreateTestCaseData("my    Doc", "m do", "my    Do", "Ignore multiple spaces in item name");

            yield return CreateTestCaseData("my Doc", "m   do", "my Do", "Ignore multiple spaces in search text");

            item = new FileSystemItem(rootPath + "myOwnDoc");
            searchText = "o do";
            matchString = new MatchString
                              {
                                  new MatchSubstring("my", false),
                                  new MatchSubstring("OwnDo", true),
                                  new MatchSubstring("c", false)
                              };
            expectedMatch = new MatchedFileSystemItem(item, matchString);
            testCaseData = new TestCaseData(item, searchText, expectedMatch).SetName("Match camel/pascal casing in the middle");
            yield return testCaseData;

            yield return CreateTestCaseData("mydoc", "m do", null, "Do not match words not separated with space or camel case");
        }
        private void MatchesCorrect(FileSystemItem item, string searchText, MatchedFileSystemItem expectedMatch)
        {
            List<FileSystemItem> items = new List<FileSystemItem> {item};

            List<MatchedFileSystemItem> actualMatches = _matchSearcher.GetMatches(items, searchText);

            bool matchExistenceCorrect = ((expectedMatch == null) && (ListUtility.IsNullOrEmpty(actualMatches))) ||
                                         ((expectedMatch != null) && (!ListUtility.IsNullOrEmpty(actualMatches)));

            Assert.That(matchExistenceCorrect, Is.True);

            if (expectedMatch == null)
            {
                return;
            }

            Assert.That(MatchesEqual(actualMatches[0], expectedMatch));
        }
        private TestCaseData CreateTestCaseData(string folderName, string searchText, string matchedSubstring, string testName)
        {
            FileSystemItem item = new FileSystemItem("C:\\" + folderName);
            MatchedFileSystemItem expectedMatch;
            if (string.IsNullOrEmpty(matchedSubstring))
            {
                expectedMatch = null;
            }
            else
            {
                MatchString matchString = new MatchString
                                  {
                                      new MatchSubstring(matchedSubstring, true),
                                      new MatchSubstring(folderName.Substring(matchedSubstring.Length), false),
                                  };
                expectedMatch = new MatchedFileSystemItem(item, matchString);
            }

            TestCaseData testCaseData = new TestCaseData(item, searchText, expectedMatch).SetName(testName);
            return testCaseData;
        }
 public void GetMatches_WithSpecialSymbols_MatchesCorrect(FileSystemItem item, string searchText, MatchedFileSystemItem expectedMatch)
 {
     MatchesCorrect(item, searchText, expectedMatch);
 }