예제 #1
0
        public void NonCaseSensitiveMultipleStringRecognitionTest(string name, string search, bool containsSpecifiedString)
        {
            var sut = new MultiStringAnalyzer(search, false);

            var spcifiedStringRecognized = sut.IsMatch(name);

            Assert.Equal(containsSpecifiedString, spcifiedStringRecognized);
        }
예제 #2
0
        public void MultipleStringReplacementIndeciesTest(string name, string search, IReadOnlyList <StringIntervalIndecies> expectedIndecies)
        {
            var sut = new MultiStringAnalyzer(search, false);

            var indexList = sut.ReplacementIndecies(name).ToList();

            Assert.Equal(indexList.Count, expectedIndecies.Count);

            foreach (var replacementIndex in expectedIndecies)
            {
                Assert.True(indexList.Contains(replacementIndex));
            }
        }
예제 #3
0
        public static RenameProcessor Build(SearchType searchType, string searchString, bool searchCaseSensitive,
                                            ReplaceType replaceType, string replaceString)
        {
            INameAnalyzer nameAnalyzer = null;

            switch (searchType)
            {
            case SearchType.WhiteSpace: { nameAnalyzer = new WhiteSpaceAnalyzer();    break; }

            case SearchType.Special:    { nameAnalyzer = new SpecialEndingAnalyzer(); break; }

            case SearchType.Characters:
            {
                var splitParts = searchString.Split(',')
                                 .Select(split => split.Trim());

                var isMultiSearch = false;

                if (splitParts.Count() > 1)
                {
                    if (splitParts.All(split => split.StartsWith("\"") && split.EndsWith("\"")))
                    {
                        isMultiSearch = true;
                    }
                }

                if (isMultiSearch)
                {
                    nameAnalyzer = new MultiStringAnalyzer(searchString, searchCaseSensitive);
                }
                else
                {
                    nameAnalyzer = new SingleStringAnalyzer(searchString, searchCaseSensitive);
                }
                break;
            }
            }

            INameRefactorer nameRefactorer = null;

            switch (replaceType)
            {
            case ReplaceType.Delete:     { nameRefactorer = new StringRefactorer("");            break; }

            case ReplaceType.WhiteSpace: { nameRefactorer = new StringRefactorer(" ");           break; }

            case ReplaceType.Characters: { nameRefactorer = new StringRefactorer(replaceString); break; }
            }

            return(new RenameProcessor(nameAnalyzer, nameRefactorer));
        }