Пример #1
0
        public void AsyncCommand_CanExecuteChanged_Test()
        {
            //Arrange
            bool canCommandExecute       = false;
            bool didCanExecuteChangeFire = false;

            SafeCommand command = new SafeCommand(NoParameterTask, canExecute: commandCanExecute);

            command.CanExecuteChanged += handleCanExecuteChanged;

            void handleCanExecuteChanged(object sender, EventArgs e) => didCanExecuteChangeFire = true;
            bool commandCanExecute() => canCommandExecute;

            Assert.False(command.CanExecute(null));

            //Act
            canCommandExecute = true;

            //Assert
            Assert.True(command.CanExecute(null));
            Assert.False(didCanExecuteChangeFire);

            //Act
            command.RaiseCanExecuteChanged();

            //Assert
            Assert.True(didCanExecuteChangeFire);
            Assert.True(command.CanExecute(null));
        }
Пример #2
0
        public void AsyncCommand_Parameter_CanExecuteFalse_Test()
        {
            //Arrange
            SafeCommand <int> command = new SafeCommand <int>(IntParameterTask, canExecute: o => CanExecuteFalse(o));

            //Act

            //Assert
            Assert.False(command.CanExecute(null));
        }
Пример #3
0
        public void AsyncCommand_NoParameter_CanExecuteFalse_Test()
        {
            //Arrange
            SafeCommand command = new SafeCommand(NoParameterTask, canExecute: CanExecuteFalse);

            //Act

            //Assert
            Assert.False(command.CanExecute(null));
        }
Пример #4
0
        public void CanExecuteT_NullParameterWithNonNullableValueType_False()
        {
            //Arrange
            SafeCommand <int> command = new SafeCommand <int>(IntParameterTask, canExecute: o => CanExecuteTrue(o));

            //Act

            //Assert

            Assert.False(command.CanExecute(null));
        }
        public void CanExecute(bool expected)
        {
            bool canExecuteRan = false;
            var  cmd           = new SafeCommand(() => { }, canExecute: () => {
                canExecuteRan = true;
                return(expected);
            });

            Assert.Equal(expected, cmd.CanExecute(null));
            Assert.True(canExecuteRan);
        }
        public void GenericCanExecute(bool expected)
        {
            string result = null;
            var    cmd    = new SafeCommand <string>(s => { }, canExecute: s => {
                result = s;
                return(expected);
            });

            Assert.Equal(expected, cmd.CanExecute("Foo"));
            Assert.Equal("Foo", result);
        }
        public void CanExecute_ValueTypeAndSetToNull_IgnoresParameter()
        {
            var command = new SafeCommand <int>(executeAction: context => { }, canExecute: context => true);

            Assert.False(command.CanExecute(null));
        }
        public void CanExecuteUsesParameterIfNullableAndSetToNull()
        {
            var command = new SafeCommand <int?>(context => { }, canExecute: context => true);

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

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

            Assert.False(command.CanExecute(10.5), "the parameter is of the wrong type");
        }
        public void CanExecuteReturnsFalseIfParameterIsWrongReferenceType()
        {
            var command = new SafeCommand <FakeChildContext>(executeAction: context => { }, canExecute: context => true);

            Assert.False(command.CanExecute(new FakeParentContext()), "the parameter is of the wrong type");
        }
        public void Constructor()
        {
            var cmd = new SafeCommand(() => { });

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