Example #1
0
        public void ShouldExecuteAllRegisteredCommands()
        {
            // Given
            var firstCommandInvokable = new Mock <IInvokable <bool> >();

            firstCommandInvokable.Setup(i => i.CanInvoke(It.IsAny <bool>())).Returns(true);
            var firstCommand = new TestCommand <bool>(firstCommandInvokable.Object);

            var secondCommandInvokable = new Mock <IInvokable <bool> >();

            secondCommandInvokable.Setup(i => i.CanInvoke(It.IsAny <bool>())).Returns(true);
            var secondCommand = new TestCommand <bool>(secondCommandInvokable.Object);

            var compositeCommand = new TestCompositeCommand <bool>();

            compositeCommand.RegisterCommand(firstCommand);
            compositeCommand.RegisterCommand(secondCommand);

            // When
            compositeCommand.Execute(true);

            // Then
            firstCommandInvokable.Verify(i => i.Invoke(It.IsAny <bool>()), Times.Once);
            secondCommandInvokable.Verify(i => i.Invoke(It.IsAny <bool>()), Times.Once);
        }
Example #2
0
        public void ShouldNotAllowToExecuteWhenNotAllRegisteredCommandsCanBeExecuted()
        {
            // Given
            var firstCommandInvokable = new Mock <IInvokable <bool> >();

            firstCommandInvokable.Setup(i => i.CanInvoke(It.IsAny <bool>())).Returns(false);
            var firstCommand = new TestCommand <bool>(firstCommandInvokable.Object);

            var secondCommandInvokable = new Mock <IInvokable <bool> >();

            secondCommandInvokable.Setup(i => i.CanInvoke(It.IsAny <bool>())).Returns(true);
            var secondCommand = new TestCommand <bool>(secondCommandInvokable.Object);

            var compositeCommand = new TestCompositeCommand <bool>();

            compositeCommand.RegisterCommand(firstCommand);
            compositeCommand.RegisterCommand(secondCommand);

            // When
            // Then
            Assert.Throws <CannotExecuteCommandException>(() => compositeCommand.Execute(true));
        }