public void Accepts_new_invocation_list()
            {
                var invocationList = new ICommand[] {};
                var commandInvoker = new CommandInvoker(null);

                Assert.DoesNotThrow(() =>
                                    commandInvoker.Assign(invocationList));
            }
        public void Not_Throw_Exception_When_Assigned_Commands()
        {
            var invocationList = new ICommand[] { };
            var commandInvoker = new CommandInvoker(null);

            Assert.DoesNotThrow(() =>
                                commandInvoker.Assign(invocationList));
        }
            public void Invokes_Execute_for_each_command()
            {
                var mockCommand = new Mock <ILandingSurfaceSizeCommand>();

                mockCommand.Setup(x => x.GetCommandType()).Returns(CommandType.LandingSurfaceSizeCommand);

                var commandInvoker = new CommandInvoker(null);

                commandInvoker.Assign(new[] { mockCommand.Object, mockCommand.Object, mockCommand.Object });

                commandInvoker.InvokeAll();

                mockCommand.Verify(x => x.Execute(), Times.Exactly(3));
            }
            public void When_executing_LandingSurfaceSizeCommand_sets_LandingSurface_as_command_receiver()
            {
                var expectedLandingSurface    = new Mock <ILandingSurface>();
                var landingSurfaceSizeCommand = new Mock <ILandingSurfaceSizeCommand>();

                landingSurfaceSizeCommand.Setup(x => x.GetCommandType()).Returns(CommandType.LandingSurfaceSizeCommand);

                var commandInvoker = new CommandInvoker(null);

                commandInvoker.Assign(new[] { landingSurfaceSizeCommand.Object });
                commandInvoker.SetLandingSurface(expectedLandingSurface.Object);

                commandInvoker.InvokeAll();

                landingSurfaceSizeCommand.Verify(
                    x => x.SetReceiver(expectedLandingSurface.Object), Times.Once());
            }
            public void When_executing_RoverExploreCommand_sets_most_recently_added_Rover_as_command_receiver()
            {
                var expectedRover = new Mock <IRover>();

                var mockRoverExploreCommand = new Mock <IRoverExploreCommand>();

                mockRoverExploreCommand.Setup(x => x.GetCommandType()).Returns(CommandType.RoverExploreCommand);

                var commandInvoker = new CommandInvoker(null);

                commandInvoker.Assign(new[] { mockRoverExploreCommand.Object });
                commandInvoker.SetRovers(new List <IRover> {
                    null, expectedRover.Object
                });

                commandInvoker.InvokeAll();

                mockRoverExploreCommand.Verify(
                    x => x.SetReceiver(expectedRover.Object), Times.Once());
            }
            public void When_executing_RoverDeployCommand_sets_LandingSurface_and_new_Rover_as_command_receivers()
            {
                var expectedRover          = new Mock <IRover>();
                var expectedLandingSurface = new Mock <ILandingSurface>();

                var mockRoverDeployCommand = new Mock <IRoverDeployCommand>();

                mockRoverDeployCommand.Setup(x => x.GetCommandType()).Returns(CommandType.RoverDeployCommand);

                Func <IRover> mockRoverFactory = () => expectedRover.Object;

                var commandInvoker = new CommandInvoker(mockRoverFactory);

                commandInvoker.Assign(new[] { mockRoverDeployCommand.Object });
                commandInvoker.SetLandingSurface(expectedLandingSurface.Object);
                commandInvoker.SetRovers(new List <IRover>());

                commandInvoker.InvokeAll();

                mockRoverDeployCommand.Verify(
                    x => x.SetReceivers(expectedRover.Object, expectedLandingSurface.Object), Times.Once());
            }
        public void Set_Rover_As_Receiver_Given_A_RoverMoveCommand()
        {
            var expectedRover          = new Mock <IRover>();
            var expectedLandingSurface = new Mock <ILandingSurface>();

            var mockRoverMoveCommand = new Mock <IRoverMoveCommand>();

            mockRoverMoveCommand.Setup(x => x.GetCommandType()).Returns(CommandType.RoverMoveCommand);

            var commandInvoker = new CommandInvoker(null);

            commandInvoker.Assign(new[] { mockRoverMoveCommand.Object });
            commandInvoker.SetLandingSurface(expectedLandingSurface.Object);
            commandInvoker.SetRovers(new List <IRover> {
                null, expectedRover.Object
            });

            commandInvoker.InvokeAll();

            mockRoverMoveCommand.Verify(
                x => x.SetReceiver(expectedRover.Object, expectedLandingSurface.Object), Times.Once());
        }