public void ExecuteDoesNotRunIfValueTypeAndSetToNull()
        {
            var executions = 0;
            var command    = new DarkCommand <int>(context => executions += 1);

            Assert.True(executions == 0, "the command should not have executed");
        }
        public void ExecuteDoesNotRunIfParameterIsWrongValueType()
        {
            var executions = 0;
            var command    = new DarkCommand <int>(context => executions += 1);

            Assert.True(executions == 0, "the command should not have executed");
        }
        public void ExecuteWithCanExecute()
        {
            var executed = false;
            var cmd      = new DarkCommand(() => executed = true, () => true);

            cmd.Execute(null);
            Assert.True(executed);
        }
        public void ExecuteRunsIfNullableAndSetToNull()
        {
            var executions = 0;
            var command    = new DarkCommand <int?>(context => executions += 1);

            command.Execute(null);
            Assert.True(executions == 1, "the command should have executed");
        }
        public void ExecuteRunsIfReferenceTypeAndSetToNull()
        {
            var executions = 0;
            var command    = new DarkCommand <FakeChildContext>(context => executions += 1);

            command.Execute(null);
            Assert.True(executions == 1, "the command should have executed");
        }
        public void GenericExecuteWithCanExecute()
        {
            string result = null;
            var    cmd    = new DarkCommand <string>(s => result = s, s => true);

            cmd.Execute("Foo");
            Assert.Equal("Foo", result);
        }
        public void ChangeCanExecute()
        {
            var signaled = false;
            var cmd      = new DarkCommand(() => { });

            cmd.CanExecuteChanged += (sender, args) => signaled = true;

            cmd.RaiseCanExecuteChanged();
            Assert.True(signaled);
        }
        public void ExecuteParameterized()
        {
            object executed = null;
            var    cmd      = new DarkCommand(o => executed = o);

            var expected = new object();

            cmd.Execute(expected);

            Assert.Equal(expected, executed);
        }
        public void CanExecute()
        {
            var canExecuteRan = false;
            var cmd           = new DarkCommand(() => { }, () =>
            {
                canExecuteRan = true;
                return(true);
            });

            Assert.True(cmd.CanExecute(null));
            Assert.True(canExecuteRan);
        }
        public void GenericCanExecute()
        {
            string result = null;
            var    cmd    = new DarkCommand <string>(s => { }, s =>
            {
                result = s;
                return(true);
            });

            Assert.True(cmd.CanExecute("Foo"));
            Assert.Equal("Foo", result);
        }
        public void CanExecuteIgnoresParameterIfValueTypeAndSetToNull()
        {
            var command = new DarkCommand <int>(context => { }, context => true);

            Assert.Throws <InvalidCommandParameterException>(() => command.CanExecute(null));
        }
        public void CanExecuteUsesParameterIfNullableAndSetToNull()
        {
            var command = new DarkCommand <int?>(context => { }, context => true);

            Assert.True(command.CanExecute(null), "null is a valid value for a Nullable<int> type");
        }
        public void CanExecuteUsesParameterIfReferenceTypeAndSetToNull()
        {
            var command = new DarkCommand <FakeChildContext>(context => { }, context => true);

            Assert.True(command.CanExecute(null), "null is a valid value for a reference type");
        }
        public void CanExecuteReturnsFalseIfParameterIsWrongValueType()
        {
            var command = new DarkCommand <int>(context => { }, context => true);

            Assert.Throws <InvalidCommandParameterException>(() => command.CanExecute(10.5));
        }
        public void CanExecuteReturnsFalseIfParameterIsWrongReferenceType()
        {
            var command = new DarkCommand <FakeChildContext>(context => { }, context => true);

            Assert.Throws <InvalidCommandParameterException>(() => command.CanExecute(new FakeParentContext()));
        }
        public void Constructor()
        {
            var cmd = new DarkCommand(() => { });

            Assert.True(cmd.CanExecute(null));
        }