public void TestCommandLineProcessorFewGoodCommands()
        {
            var commandLineTextBox = new TextBox();
            commandLineTextBox.Text = "I0001, , ,, I0000,  F0102, ";

            var mock = new Mock<ICommunicationHelper>();

            mock.Setup(x => x.SendMessageToRobot(It.IsAny<string>()))
                .Returns(true);

            // LastSentMessage должен возвращать разные значения ("переданные" роботу команды) при каждом вызове.
            string[] sentMessages = { "I0001", "I0000", "F0102" };
            int sentMessageIndex = 0;
            mock.Setup(x => x.LastSentMessage)
                .Returns(() => sentMessages[sentMessageIndex++]);

            var outputTextBox = new RichTextBox();
            var historyBox = new HistoryBox(outputTextBox);
            var commandProcessor = new CommandProcessor(commandLineTextBox, historyBox, mock.Object, new CommandHistory());
            commandProcessor.ProcessCommand();

            Assert.AreEqual(string.Empty, commandLineTextBox.Text);
            Assert.AreEqual(4, outputTextBox.Lines.Length);
            Assert.AreEqual("I0001", outputTextBox.Lines[0]);
            Assert.AreEqual("I0000", outputTextBox.Lines[1]);
            Assert.AreEqual("F0102", outputTextBox.Lines[2]);
            Assert.AreEqual(string.Empty, outputTextBox.Lines[3]);
        }
 /// <summary>
 /// Initializes a new instance of the CommandProcessor class.
 /// </summary>
 /// <param name="commandLineTextBox">
 /// Control to input commands.
 /// </param>
 /// <param name="historyBox">
 /// Control for commands and responses history.
 /// </param>
 /// <param name="communicationHelper">
 /// Class that communicates with robot.
 /// </param>
 /// <param name="commandHistory">
 /// Class that containts command history.
 /// </param>
 public CommandProcessor(
     TextBox commandLineTextBox, 
     HistoryBox historyBox, 
     ICommunicationHelper communicationHelper, 
     CommandHistory commandHistory)
 {
     this.commandLineTextBox = commandLineTextBox;
     this.historyBox = historyBox;
     this.communicationHelper = communicationHelper;
     this.commandHistory = commandHistory;
 }
        public void TestCommandLineProcessorOneBadCommand()
        {
            var commandLineTextBox = new TextBox();
            commandLineTextBox.Text = "I0001";

            var mock = new Mock<ICommunicationHelper>();
            mock.Setup(x => x.SendMessageToRobot(It.IsAny<string>())).Returns(false);

            var outputTextBox = new RichTextBox();
            var historyBox = new HistoryBox(outputTextBox);
            var commandProcessor = new CommandProcessor(commandLineTextBox, historyBox, mock.Object, new CommandHistory());
            commandProcessor.ProcessCommand();

            Assert.AreEqual("I0001", commandLineTextBox.Text);
            Assert.AreEqual(2, outputTextBox.Lines.Length);
            Assert.IsTrue(outputTextBox.Lines[0].StartsWith("Ошибка"));
        }
        public void TestCommandLineProcessorOneGoodCommand()
        {
            var commandLineTextBox = new TextBox();
            commandLineTextBox.Text = "I0001";

            var mock = new Mock<ICommunicationHelper>();
            mock.Setup(x => x.SendMessageToRobot(It.IsAny<string>())).Returns(true);
            mock.Setup(x => x.LastSentMessage).Returns("I0001");

            var outputTextBox = new RichTextBox();
            var historyBox = new HistoryBox(outputTextBox);
            var commandProcessor = new CommandProcessor(commandLineTextBox, historyBox, mock.Object, new CommandHistory());
            commandProcessor.ProcessCommand();

            Assert.AreEqual(string.Empty, commandLineTextBox.Text);
            Assert.AreEqual(2, outputTextBox.Lines.Length);
            Assert.AreEqual("I0001", outputTextBox.Lines[0]);
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the FormMain class.
 /// </summary>
 public FormMain()
 {
     this.InitializeComponent();
     this.historyBox = new HistoryBox(this.textBoxHistory);
 }
        public void TestCommandLineProcessorOneBadInFewGoodCommands()
        {
            var commandLineTextBox = new TextBox();
            commandLineTextBox.Text = "I0001, , ,, I0000,  F0102, ";

            var mock = new Mock<ICommunicationHelper>();
            mock.Setup(x => x.SendMessageToRobot(It.IsAny<string>()))
                .Returns((string command) => !command.Equals("I0000"));
            mock.Setup(x => x.LastSentMessage)
                .Returns("I0001");

            var outputTextBox = new RichTextBox();
            var historyBox = new HistoryBox(outputTextBox);
            var commandProcessor = new CommandProcessor(commandLineTextBox, historyBox, mock.Object, new CommandHistory());
            commandProcessor.ProcessCommand();

            Assert.AreEqual("I0000, F0102", commandLineTextBox.Text);
            Assert.AreEqual(3, outputTextBox.Lines.Length);
            Assert.AreEqual("I0001", outputTextBox.Lines[0]);
            Assert.IsTrue(outputTextBox.Lines[1].StartsWith("Ошибка"));
            Assert.AreEqual(string.Empty, outputTextBox.Lines[2]);
        }
        public void TestCommandLineProcessorStrangeCommands2()
        {
            var commandLineTextBox = new TextBox();
            commandLineTextBox.Text = ",,,";

            var mock = new Mock<ICommunicationHelper>();
            mock.Setup(x => x.SendMessageToRobot(It.IsAny<string>()))
                .Returns(false);

            var outputTextBox = new RichTextBox();
            var historyBox = new HistoryBox(outputTextBox);
            var commandProcessor = new CommandProcessor(commandLineTextBox, historyBox, mock.Object, new CommandHistory());
            commandProcessor.ProcessCommand();

            Assert.AreEqual(string.Empty, commandLineTextBox.Text);
            Assert.AreEqual(string.Empty, outputTextBox.Text);
        }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the FormMain class.
 /// </summary>
 public FormMain()
 {
     this.InitializeComponent();
     this.historyBox = new HistoryBox(this.textBoxHistory);
 }