public void Validate_WordCount_InSentence_NegativeTesting()
        {
            //Step1: arrange
            //test input
            var line = "This is a statement, and so is this.";
            IWordProcessor wordProcessor = new WordProcessor();

            //expected output
            var expectedDictionary = new System.Collections.Generic.Dictionary<string, int>
            {
                {"this",2},
                {"is", 2},
                {"a", 1},
                {"statement", 2},  //changed for negative testing from 1 to 2
                {"and", 1},
                {"so",  1 }
            };

            //Step2: act
            //Calculate the word count and store in dictionary
            var outputDictionary = wordProcessor.CalculateWordCount(line);

            // Step3: assert
            //compare expected dictionary and actual dictionary derived from sentence
            Assert.IsFalse(expectedDictionary.SequenceEqual(outputDictionary));
        }
Пример #2
0
        static void Main()
        {
            ILogger logger;

            //Relocate this dependency to some factory or get it's instance from repository/MEF/UNITY
            logger = new Author.Logger();

            try
            {

                Console.WriteLine  ("Enter a sentence and press enter to count occurences of word");
                Console.WriteLine("Input:\n--------------------");
                //Enter the sentence
                var line = Console.ReadLine();

                //Check if the sentence is blank
                if (line.Trim().Length <= 0)
                {
                    Console.WriteLine("You have entered blank sentence. Please try again..!");
                    Console.WriteLine("Input:\n--------------------");
                    line = Console.ReadLine();
                }

                //Relocate this dependency to some factory or get it's instance from repository/MEF/UNITY
                IWordProcessor wordProcessor = new WordProcessor();

                //Calculate wordcount
                var dictionary = wordProcessor.CalculateWordCount(line);

                //Display wordcount
                wordProcessor.DisplayWordCount(dictionary);

                Console.WriteLine("\nPress enter to exit..");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                logger.WriteLog("Error occured :" + ex.Message);
            }
        }