public void SuppressesInvalidCast()
        {
            int      number  = 1;
            ICommand command = ExecutionAwareCommand.FromAction <int>(i => number = i)
                               .SetThrowOnInvalidCast(false);

            var ex = Record.Exception(() => command.Execute("Hello World"));

            Assert.Null(ex);
            Assert.Equal(0, number);
        }
        public void ThrowsOnInvalidCast()
        {
            int      number  = 0;
            ICommand command = ExecutionAwareCommand.FromAction <int>(i => number = i)
                               .SetThrowOnInvalidCast(true);

            var ex = Record.Exception(() => command.Execute("Hello World"));

            Assert.NotNull(ex);
            Assert.IsType <UnhandledCommandException>(ex);
            Assert.IsType <InvalidCastException>(ex.InnerException);
        }
        public void IsExecutingIsChanged()
        {
            bool     didExecute = false;
            bool     didCommandIsExecutingChange = false;
            ICommand command = ExecutionAwareCommand.FromAction(() => didExecute = true)
                               .OnIsExecutingChanged(_ => didCommandIsExecutingChange = true);

            command.Execute(null);

            Assert.True(didExecute);
            Assert.True(didCommandIsExecutingChange);
        }
        public void ProperlyCatchesThrownInvalidCast()
        {
            int       number          = 0;
            Exception caughtException = null;
            ICommand  command         = ExecutionAwareCommand.FromAction <int>(i => number = i)
                                        .SetThrowOnInvalidCast(true)
                                        .Catch(e => caughtException = e);

            var ex = Record.Exception(() => command.Execute("Hello World"));

            Assert.Null(ex);
            Assert.NotNull(caughtException);
            Assert.IsType <InvalidCastException>(caughtException);
        }