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); }
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); }
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); }
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); }
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); }
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(); }