示例#1
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(@"Please type the full file path to the document. Eg. C:\Temp\LargeFile.txt");
                string fullFilePath = Console.ReadLine();
                if (string.IsNullOrEmpty(fullFilePath))
                {
                    fullFilePath = @"C:\Temp\LargeFile.txt";
                }

                Console.WriteLine();
                Console.WriteLine(@"Please type the full file path to the result document. Eg. C:\Temp\Result.txt");
                string resultFullFilePath = Console.ReadLine();
                if (string.IsNullOrEmpty(resultFullFilePath))
                {
                    resultFullFilePath = @"C:\Temp\Result.txt";
                }

                Console.WriteLine();

                var documentWordCounter = new DocumentWordCounter();
                documentWordCounter.ProcessDocument(fullFilePath, resultFullFilePath);

                Console.WriteLine(string.Format("@The file {0} has been processed at {1}. The Word Count results can be found in {2}",
                                                fullFilePath, DateTime.Now, resultFullFilePath));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.WriteLine("Press ENTER to exit.");
            Console.ReadLine();
        }
示例#2
0
        public void ProcessDocument_VerifyAllExpectations()
        {
            // Arrange
            var    fileReader             = MockRepository.GenerateStrictMock <IFileReader>();
            var    fileWriter             = MockRepository.GenerateStrictMock <IFileWriter>();
            var    wordCounterFactory     = MockRepository.GenerateStrictMock <IWordCounterFactory>();
            var    wordCounter            = MockRepository.GenerateStrictMock <IWordCounter>();
            string testFullFilePath       = @"D:\Test\Read.txt";
            string testResultFullFilePath = @"D:\Test\Result.txt";
            var    wordsToCount           = new BlockingCollection <string>()
            {
                "abc"
            };
            var wordCountDictionary = new ConcurrentDictionary <string, ulong>();

            fileReader.Expect(fr => fr.Read(testFullFilePath, ref wordsToCount)).IgnoreArguments();
            fileWriter.Expect(fw => fw.WriteToFile(testResultFullFilePath, ref wordCountDictionary));
            wordCounterFactory.Expect(wcf => wcf.CreateWordCounter()).Repeat.Any().Return(wordCounter);
            wordCounter.Expect(wc => wc.IncrementCount(ref wordsToCount, ref wordCountDictionary)).Repeat.Any();

            // Act
            var documentWordCounter = new DocumentWordCounter(fileReader, fileWriter, wordCounterFactory);

            documentWordCounter.ProcessDocument(testFullFilePath, testResultFullFilePath);

            // Assert
            fileReader.VerifyAllExpectations();
            fileWriter.VerifyAllExpectations();
            wordCounterFactory.VerifyAllExpectations();
            wordCounter.VerifyAllExpectations();
        }
示例#3
0
        public void ReadFileAndPopulateWords_CallFileReader()
        {
            // Arrange
            var    fileReader         = MockRepository.GenerateStrictMock <IFileReader>();
            var    fileWriter         = MockRepository.GenerateStrictMock <IFileWriter>();
            var    wordCounterFactory = MockRepository.GenerateStrictMock <IWordCounterFactory>();
            string testFullFilePath   = "D:\\Test\\Read.txt";
            var    wordsToCount       = new BlockingCollection <string>()
            {
                "abc"
            };

            fileReader.Expect(fr => fr.Read(testFullFilePath, ref wordsToCount)).IgnoreArguments();

            // Act
            var documentWordCounter = new DocumentWordCounter(fileReader, fileWriter, wordCounterFactory);

            documentWordCounter.ReadFileAndPopulateWords(testFullFilePath);

            fileReader.VerifyAllExpectations();
        }