public void TestGetUserInputToReturnCorrectValue()
        {
            var mockedReader = new Mock <HelperReader>();

            Console.SetIn(mockedReader.Object);

            IList <string> input = new List <string>()
            {
                "DOWNARROW", "UPARROW", "LEFTARROW", "RIGHTARROW"
            };

            int indexOfCommand = 0;

            mockedReader.Setup(r => r.ReadLine()).Returns(() => input[indexOfCommand]);

            IUserInterface userInterface = new ConsoleInterface();
            string         result;

            for (; indexOfCommand < input.Count; indexOfCommand++)
            {
                result = userInterface.GetUserInput();
                Assert.AreEqual(input[indexOfCommand], result);
            }

            mockedReader.Verify(r => r.ReadLine(), Times.Exactly(input.Count));
        }
示例#2
0
        public void TestHelpRequestEvent()
        {
            bool isTriggered = false;
            IUserInterface consoleInterface = new ConsoleInterface();
            consoleInterface.HelpRequest += (sender, eventInfo) =>
            {
                isTriggered = true;
            };

            Word currentWord = new Word("test");
            WordData currentWordDate = new WordData(currentWord);

            string inputString = string.Format("help{0}", Environment.NewLine);
            using (StringReader sr = new StringReader(inputString))
            {
                Console.SetIn(sr);

                consoleInterface.GetUserInput(currentWordDate);
            }

            Assert.IsTrue(isTriggered);
        }
示例#3
0
        public void TestGameRestartEvent()
        {
            bool           isTriggered      = false;
            IUserInterface consoleInterface = new ConsoleInterface();

            consoleInterface.GameRestart += (sender, eventInfo) =>
            {
                isTriggered = true;
            };

            Word     currentWord     = new Word("test");
            WordData currentWordDate = new WordData(currentWord);

            string inputString = string.Format("restart{0}", Environment.NewLine);

            using (StringReader sr = new StringReader(inputString))
            {
                Console.SetIn(sr);

                consoleInterface.GetUserInput(currentWordDate);
            }

            Assert.IsTrue(isTriggered);
        }