public void OnTraversing_AcceptProcessor_TraversesAllWordsInLinearFashoin()
        {
            IEnumerable<string> words = new List<string>() { "Our", "time", "in", "the", "world", "is", "a", "loan", "we", "must", "pay", "it", "with", "interest" };
            IWordProcessor processor = Rhino.Mocks.MockRepository.GenerateMock<IWordProcessor>();

            StandardWordTraverser traverser = new StandardWordTraverser(words);
            traverser.AcceptProcessor(processor);

            processor.AssertWasCalled(p => p.ProcessEach(Arg<string>.Is.Anything), options => options.Repeat.Times(words.Count()));
        }
Beispiel #2
0
        static void ProcessFile(string file)
        {
            Console.WriteLine(string.Format("Processing File: {0}", file));

            try
            {
                string fileContent = File.ReadAllText(file);

                WordsParser parser = new WordsParser();

                IEnumerable<string> words = parser.GetWords(fileContent);

                StandardWordTraverser traverser = new StandardWordTraverser(words);

                // Part 1
                WordsCounter counter = new WordsCounter();
                traverser.AcceptProcessor(counter);
                counter.ReportTo(Console.WriteLine);

                // Part 2
                CompositionMatcher compositonMatcher = new CompositionMatcher(words, 6);
                traverser.AcceptProcessor(compositonMatcher);
                compositonMatcher.ReportTo(Console.WriteLine);
            }
            catch (IOException ex)
            {
                Console.WriteLine("Unable to read the file.");
                Console.WriteLine(string.Format("Message: {0}", ex.Message));
                Console.WriteLine(string.Format("Details: {0}", ex.StackTrace));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Oops... Unexpected error occurred.");
                Console.WriteLine(string.Format("Message: {0}", ex.Message));
                Console.WriteLine(string.Format("Details: {0}", ex.StackTrace));
            }
        }