예제 #1
0
        public void CanCreateCommandAndReplaceItemText()
        {
            var i = new TestReplacable();

            i.Text = "test";
            string str = "sth";
            var    c   = new ReplaceTextCommand(i, str);

            c.Execute();
            Assert.AreEqual(i.Text, str);
        }
예제 #2
0
        public void Execute_ReplaceTextCommand_WithNewText_ShouldReplacePrevTextFromParagraph()
        {
            var paragraph = new Text()
            {
                Value = "Old text"
            };
            var newText = "New text";
            var command = new ReplaceTextCommand(paragraph, newText);

            command.Execute();
            Assert.AreEqual(newText, paragraph.Value);
        }
예제 #3
0
        public void CanReturnTextBackToPreviousState()
        {
            var    i       = new TestReplacable();
            string oldText = "test";

            i.Text = oldText;
            string str = "sth";
            var    c   = new ReplaceTextCommand(i, str);

            c.Execute();
            Assert.AreEqual(i.Text, str);
            c.Unexecute();
            Assert.AreEqual(i.Text, oldText);
        }
예제 #4
0
        public void Execute_GetItemAndReplaceText()
        {
            // Arrange
            var paragrpahDocumentItem = new DocumentItem(new Paragraph.Paragraph(""));

            _documentMock.Setup(d => d.GetItem(It.IsAny <int>())).Returns(paragrpahDocumentItem);
            ICommand command = new ReplaceTextCommand(1, "Hey", _documentMock.Object);

            // Act
            command.Execute();

            // Assert
            Assert.Equal("Hey", paragrpahDocumentItem.Paragraph.Text);
        }
예제 #5
0
        public void Unexecute_ReplaceTextCommand_ShouldReturnPrevTextToParagraph()
        {
            var prevText  = "Old text";
            var paragraph = new Text()
            {
                Value = prevText
            };
            var newText = "New text";
            var command = new ReplaceTextCommand(paragraph, newText);

            command.Execute();
            Assert.AreEqual(newText, paragraph.Value);

            command.Unexecute();
            Assert.AreEqual(prevText, paragraph.Value);
        }
예제 #6
0
        private void ReplaceTextCommandExecutor(string commandParams)
        {
            var argumentsParser = new ArgumentsParser(commandParams);

            if (argumentsParser.NextArgumentsCount < 2)
            {
                throw new MenuException();
            }

            int?position = argumentsParser.GetNextAsInt();

            if (position == null)
            {
                throw new MenuException();
            }
            string text = argumentsParser.GetNextsAsString(' ');

            ICommand command = new ReplaceTextCommand(position.Value, text, _document);

            command.Execute();
        }