示例#1
0
        public void Given_SearchWord_getsFilesWithAWordOnlyInOne_returnsAListWithOnlyOneMatch()
        {
            var word = "gol";

            A.CallTo(() => _fakeFileProcessor.GetLowerCaseWord(word)).Returns(word);

            var response = _fileManager.SearchWord(_filesProcessed, word);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Count == 2);
            Assert.IsTrue(response.Any(r => r.FileName == "fileName.txt" && r.NumberOfTimesFound == 1));
            Assert.IsTrue(response.Any(r => r.FileName == "fileName2.txt" && r.NumberOfTimesFound == 0));
        }
示例#2
0
        public List <SearchResult> SearchWord(List <FileProcessed> files, string word)
        {
            var results = new List <SearchResult>();

            if (files == null || !files.Any())
            {
                return(results);
            }

            if (string.IsNullOrEmpty(word))
            {
                throw new ArgumentException("It is required to introduce a word to search.");
            }

            var lowerCaseWord = _fileProcessor.GetLowerCaseWord(word);

            foreach (var file in files)
            {
                var result = new SearchResult {
                    FileName = file.FileName, NumberOfTimesFound = 0
                };

                if (file.Dictionary.ContainsKey(lowerCaseWord))
                {
                    result.NumberOfTimesFound = file.Dictionary[lowerCaseWord];
                }

                results.Add(result);
            }

            return(results);
        }
 public void Given_GetLowerCaseWord_getsNullWord_returnsNullWord()
 {
     Assert.IsNull(_fileProcessor.GetLowerCaseWord(null));
 }