public void ShouldCorrectlyExecuteTheCommands() { //arrange var obj = new ValueObject() { Number = 1 }; var context = new CommandExecutionContext(handler); //act context.Execute(new AddOneCommand(obj)); //assert Assert.AreEqual(2, obj.Number); }
public void ShouldCorrectlyUndoAndRedoActions() { var obj = new ValueObject() { Number = 1 }; handler.Execute(new AddOneCommand(obj)); Assert.AreEqual(2, obj.Number); handler.Undo(); Assert.AreEqual(1, obj.Number); handler.Redo(); Assert.AreEqual(2, obj.Number); }
public void ShouldFailSilentlyWhenUndoingMultipleTimes() { //arrange var hasFailed = false; var valueObj = new ValueObject(); handler.Execute(new AddOneCommand(valueObj)); //act //execute a couple of times handler.Undo(); try { handler.Undo(); //this should fail as there is nothing to be undone } catch (ApplicationException) { hasFailed = true; } //assert Assert.AreEqual(0, valueObj.Number); Assert.IsTrue(hasFailed, "The 2nd undo operation should have failed"); }
public void ShouldUndoAndRedoMultipleLevels() { //arrange var valueObj = new ValueObject(); for (int i = 0; i < 5; i++) { handler.Execute(new AddOneCommand(valueObj)); } Assert.AreEqual(5, valueObj.Number); //exec handler.Undo(3); //assert Assert.AreEqual(2, valueObj.Number); //redo handler.Redo(2); Assert.AreEqual(4, valueObj.Number); }
public AddTwoCommand(ValueObject valObj) { this.valObj = valObj; }