public void ReplayCommandRunTest(List <string> command) { _moveRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "m", "10" })); _robot.AssertWasCalled(x => x.Move(Arg <double> .Matches(dist => dist.Equals(10)))); _turnRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "t", "100" })); _robot.AssertWasCalled(x => x.Turn(Arg <double> .Matches(ang => ang.Equals(100)))); _beepRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "b" })); _robot.AssertWasCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 3); var robotB = MockRepository.GenerateStub <IRobot>(); var robotCommandEventArgs = new RobotCommandEventArgs(robotB, command); _replayRobotCommand.Execute(robotCommandEventArgs); robotB.AssertWasCalled(x => x.Move(Arg <double> .Matches(dist => dist.Equals(10)))); robotB.AssertWasCalled(x => x.Turn(Arg <double> .Matches(ang => ang.Equals(100)))); robotB.AssertWasCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 3); }
public void ReplayCommandRunNegativeCommandTest(List <string> command) { _moveRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "m", "10" })); _robot.AssertWasCalled(x => x.Move(Arg <double> .Matches(dist => dist.Equals(10)))); _turnRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "t", "100" })); _robot.AssertWasCalled(x => x.Turn(Arg <double> .Matches(ang => ang.Equals(100)))); _beepRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "b" })); _robot.AssertWasCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 3); var robotB = MockRepository.GenerateStub <IRobot>(); var robotCommandEventArgs = new RobotCommandEventArgs(robotB, command); var ex = Assert.Throws(typeof(ArgumentException), () => _replayRobotCommand.Execute(robotCommandEventArgs)); Assert.AreEqual(ex.Message, String.Format("Replay command syntax not matched.{0}Syntax: R{0}Eg: R", Environment.NewLine)); robotB.AssertWasNotCalled(x => x.Move(Arg <double> .Is.Anything)); robotB.AssertWasNotCalled(x => x.Turn(Arg <double> .Is.Anything)); robotB.AssertWasNotCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 3); }
public void RunResetCommandWithNullRobotTest() { _moveRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "m", "10" })); _robot.AssertWasCalled(x => x.Move(Arg <double> .Matches(dist => dist.Equals(10)))); _turnRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "t", "100" })); _robot.AssertWasCalled(x => x.Turn(Arg <double> .Matches(ang => ang.Equals(100)))); _beepRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "b" })); _robot.AssertWasCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 3); var robotB = MockRepository.GenerateStub <IRobot>(); var robotCommandEventArgs = new RobotCommandEventArgs(null, new List <string> { "S" }); Assert.DoesNotThrow(() => _resetRobotCommand.Execute(robotCommandEventArgs)); robotB.AssertWasNotCalled(x => x.Move(Arg <double> .Is.Anything)); robotB.AssertWasNotCalled(x => x.Turn(Arg <double> .Is.Anything)); robotB.AssertWasNotCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 0); }
public void RunReplayCommandWithNullRobotTest() { _moveRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "m", "10" })); _robot.AssertWasCalled(x => x.Move(Arg <double> .Matches(dist => dist.Equals(10)))); _turnRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "t", "100" })); _robot.AssertWasCalled(x => x.Turn(Arg <double> .Matches(ang => ang.Equals(100)))); _beepRobotCommand.Execute(new RobotCommandEventArgs(_robot, new List <string> { "b" })); _robot.AssertWasCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 3); var robotB = MockRepository.GenerateStub <IRobot>(); var robotCommandEventArgs = new RobotCommandEventArgs(null, new List <string> { "R" }); var ex = Assert.Throws(typeof(ArgumentException), () => _replayRobotCommand.Execute(robotCommandEventArgs)); Assert.AreEqual(ex.Message, "Robot has not been initialized. Cannot send command to it."); robotB.AssertWasNotCalled(x => x.Move(Arg <double> .Is.Anything)); robotB.AssertWasNotCalled(x => x.Turn(Arg <double> .Is.Anything)); robotB.AssertWasNotCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 3); }
public void BeepCommandRunTest(List <string> command) { var robotCommandEventArgs = new RobotCommandEventArgs(_robot, command); _beepRobotCommand.Execute(robotCommandEventArgs); _robot.AssertWasCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 1); }
public void TurnCommandRunTest(List <string> command, double distance) { var robotCommandEventArgs = new RobotCommandEventArgs(_robot, command); _turnRobotCommand.Execute(robotCommandEventArgs); _robot.AssertWasCalled(x => x.Turn(Arg <double> .Matches(dist => dist.Equals(distance)))); Assert.AreEqual(_commandRecorder.Replay().Count, 1); }
public void BeepCommandRunNegativeCommandTest(List <string> command) { var robotCommandEventArgs = new RobotCommandEventArgs(_robot, command); var ex = Assert.Throws(typeof(ArgumentException), () => _beepRobotCommand.Execute(robotCommandEventArgs)); Assert.AreEqual(ex.Message, String.Format("Beep command syntax not matched.{0}Syntax: B{0}Eg: B", Environment.NewLine)); _robot.AssertWasNotCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 0); }
public void TurnCommandRunNegativeCommandTest(List <string> command) { var robotCommandEventArgs = new RobotCommandEventArgs(_robot, command); var ex = Assert.Throws(typeof(ArgumentException), () => _turnRobotCommand.Execute(robotCommandEventArgs)); Assert.AreEqual(ex.Message, String.Format("Turn command syntax not matched.{0}Syntax: T <Angle in Decimal number>{0}Eg: T 45.8", Environment.NewLine)); _robot.AssertWasNotCalled(x => x.Turn(Arg <double> .Is.Anything)); Assert.AreEqual(_commandRecorder.Replay().Count, 0); }
public void RunBeepCommandWithNullRobotTest() { var robotCommandEventArgs = new RobotCommandEventArgs(null, new List <string> { "B" }); var ex = Assert.Throws(typeof(ArgumentException), () => _beepRobotCommand.Execute(robotCommandEventArgs)); Assert.AreEqual(ex.Message, "Robot has not been initialized. Cannot send command to it."); _robot.AssertWasNotCalled(x => x.Beep()); Assert.AreEqual(_commandRecorder.Replay().Count, 0); }