/** * Fabricate a result by multiplying the input by 2 * * @param note the note carrying the ControllerTestVO */ override public void Execute(INotification note) { ControllerTestVO vo = (ControllerTestVO)note.Body; // Fabricate a result vo.result = 2 * vo.input; }
public void ReregisterAndExecuteCommand() { // Fetch the controller, register the ControllerTestCommand2 to handle 'ControllerTest2' notes IController controller = Controller.Instance; string name = "ControllerTest2" + Thread.CurrentThread.Name; controller.RegisterCommand(name, typeof(ControllerTestCommand2)); // Remove the Command from the Controller controller.RemoveCommand(name); // Re-register the Command with the Controller controller.RegisterCommand(name, typeof(ControllerTestCommand2)); // Create a 'ControllerTest2' note ControllerTestVO vo = new ControllerTestVO(12); Notification note = new Notification(name, vo); // retrieve a reference to the View. IView view = View.Instance; // send the Notification view.NotifyObservers(note); // test assertions // if the command is executed once the value will be 24 Assert.IsTrue(vo.result == 24, "Expecting vo.result == 24"); // Prove that accumulation works in the VO by sending the notification again view.NotifyObservers(note); // if the command is executed twice the value will be 48 Assert.IsTrue(vo.result == 48, "Expecting vo.result == 48"); }
public void RegisterAndRemoveCommand() { // Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes IController controller = Controller.Instance; string name = "ControllerRemoveTest" + Thread.CurrentThread.Name; controller.RegisterCommand(name, typeof(ControllerTestCommand)); // Create a 'ControllerTest' note ControllerTestVO vo = new ControllerTestVO(12); INotification note = new Notification(name, vo); // Tell the controller to execute the Command associated with the note // the ControllerTestCommand invoked will multiply the vo.input value // by 2 and set the result on vo.result controller.ExecuteCommand(note); // test assertions Assert.IsTrue(vo.result == 24, "Expecting vo.result == 24"); // Reset result vo.result = 0; // Remove the Command from the Controller controller.RemoveCommand(name); // Tell the controller to execute the Command associated with the // note. This time, it should not be registered, and our vo result // will not change controller.ExecuteCommand(note); // test assertions Assert.IsTrue(vo.result == 0, "Expecting vo.result == 0"); }
public void RegisterAndExecuteCommand() { // Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes IController controller = Controller.Instance; string name = "ControllerTest" + Thread.CurrentThread.Name; controller.RegisterCommand(name, typeof(ControllerTestCommand)); // Create a 'ControllerTest' notification var vo = new ControllerTestVO(12); INotification note = new Notification(name, vo); // Tell the controller to execute the Command associated with the notification // the ControllerTestCommand invoked will multiply the vo.input value // by 2 and set the result on vo.result controller.ExecuteCommand(note); // test assertions Assert.IsTrue(vo.result == 24, "Expecting vo.result == 24"); }
public void RegisterAndExecuteCommand() { // Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes IController controller = Controller.Instance; string name = "ControllerTest" + Thread.CurrentThread.Name; controller.RegisterCommand(name, typeof(ControllerTestCommand)); // Create a 'ControllerTest' note ControllerTestVO vo = new ControllerTestVO(12); INotification note = new Notification(name, vo); // Tell the controller to execute the Command associated with the note // the ControllerTestCommand invoked will multiply the vo.input value // by 2 and set the result on vo.result controller.ExecuteCommand(note); // test assertions Assert.IsTrue(vo.result == 24, "Expecting vo.result == 24"); }
/** * Tests Command registration and removal. * * <P> * Tests that once a Command is registered and verified * working, it can be removed from the Controller.</P> */ public void TestRegisterAndRemoveCommand() { // Create the controller, register the ControllerTestCommand to handle 'ControllerTest' notes IController controller = Controller.Instance; string name = "ControllerRemoveTest" + Thread.CurrentThread.Name; controller.RegisterCommand(name, typeof(ControllerTestCommand)); // Create a 'ControllerTest' note ControllerTestVO vo = new ControllerTestVO(12); INotification note = new Notification(name, vo); // Tell the controller to execute the Command associated with the note // the ControllerTestCommand invoked will multiply the vo.input value // by 2 and set the result on vo.result controller.ExecuteCommand(note); // test assertions Assert.True(vo.result == 24, "Expecting vo.result == 24"); // Reset result vo.result = 0; // Remove the Command from the Controller controller.RemoveCommand(name); // Tell the controller to execute the Command associated with the // note. This time, it should not be registered, and our vo result // will not change controller.ExecuteCommand(note); // test assertions Assert.True(vo.result == 0, "Expecting vo.result == 0"); }