Exemplo n.º 1
0
        public void CommandBase_T_FrameworkMethodsMustBeCalledWithData_ReferenceType()
        {
            ICommand command = new TestCommand <string>();

            bool canExecute = command.CanExecute("240");

            Assert.True(canExecute);
            Assert.Throws <ArgumentNullException>("parameter", () => command.CanExecute(null));

            command.Execute("240");
            Assert.Throws <ArgumentNullException>("parameter", () => command.Execute(null));
        }
Exemplo n.º 2
0
        public void CommandBase_T_FrameworkMethodsMustBeCalledWithData_ValueType()
        {
            ICommand command = new TestCommand <int>();

            bool canExecute = command.CanExecute(240);

            Assert.True(canExecute);
            Assert.Throws <NullReferenceException>(() => command.CanExecute(null));

            command.Execute(240);
            Assert.Throws <NullReferenceException>(() => command.Execute(null));
        }
Exemplo n.º 3
0
        public void CommandBase_FrameworkMethodsMustBeCalledWithoutData()
        {
            ICommand command = new TestCommand();

            bool canExecute = command.CanExecute(null);

            Assert.True(canExecute);
            Assert.Throws <ArgumentException>("parameter", () => command.CanExecute(240));

            command.Execute(null);
            Assert.Throws <ArgumentException>("parameter", () => command.Execute(240));
        }
Exemplo n.º 4
0
        public void CommandBase_T_NonGenericFrameworkMethodsMustBeCalledWithDataOfTypeCompatibleWithGenericTypeParameter()
        {
            ICommand command = new TestCommand <float>();

            Assert.Throws <InvalidCastException>(() => command.CanExecute(240.0));
            Assert.Throws <InvalidCastException>(() => command.Execute(240.0));
        }
Exemplo n.º 5
0
        public void CommandBase_T_FrameworkMethodsCallIntoStronglyTypedImplementations()
        {
            string?  text    = null;
            ICommand command = new TestCommand <string>(t => text = t, t => text = t);

            bool canExecute = command.CanExecute(nameof(ICommand.CanExecute));

            Assert.Equal("CanExecute", text);
            Assert.True(canExecute);

            command.Execute(nameof(ICommand.Execute));
            Assert.Equal("Execute", text);
        }
Exemplo n.º 6
0
        public void CommandBase_FrameworkMethodsCallIntoParameterlessImplementations()
        {
            string?  text    = null;
            ICommand command = new TestCommand(() => text = nameof(ICommand.CanExecute), () => text = nameof(ICommand.Execute));

            bool canExecute = command.CanExecute(null);

            Assert.Equal("CanExecute", text);
            Assert.True(canExecute);

            command.Execute(null);
            Assert.Equal("Execute", text);
        }
Exemplo n.º 7
0
        public void ShouldCallInheritedCommandWhenUsingCanExecuteObject()
        {
            // Given
            var invokable = new Mock <IInvokable <bool> >();
            var command   = new TestCommand <bool>(invokable.Object);
            var parameter = (object)true;

            // When
            command.CanExecute(parameter);

            // Then
            invokable.Verify(i => i.CanInvoke(It.IsAny <bool>()), Times.Once);
        }
Exemplo n.º 8
0
        public void CoverNonFunctions()
        {
            var   model   = new ApplicationModel();
            ITile command = new TestCommand(model);

            OnCanExecuteChanged(this, EventArgs.Empty);
            command.CanExecuteChanged += OnCanExecuteChanged;
            command.CanExecuteChanged -= OnCanExecuteChanged;

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

            Assert.IsFalse(((TestCommand)command)._called);
            command.Execute(null);
            Assert.IsTrue(((TestCommand)command)._called);

            Assert.AreEqual("Wibble", command.Content);
        }