Execute() 공개 메소드

Defines the method to be called when the command is invoked.
public Execute ( object parameter ) : void
parameter object Data used by the command. If the command does not require data to be passed, this object can be set to null.
리턴 void
예제 #1
0
        public void CanExecuteDuringAsyncExecute2()
        {
            var tcs = new TaskCompletionSource<object>();
            var canExecute = false;
            var executeCalled = false;

            var command = new AsyncDelegateCommand(() =>
            {
                executeCalled = true;
                return tcs.Task;
            }, () => canExecute);

            Assert.IsFalse(command.CanExecute(null));
            command.Execute(null);
            Assert.IsFalse(executeCalled);

            canExecute = true;
            Assert.IsTrue(command.CanExecute(null));
            command.Execute(null);

            executeCalled = false;
            Assert.IsFalse(command.CanExecute(null));
            command.Execute(null);
            Assert.IsFalse(executeCalled);

            tcs.SetResult(null);
            Assert.IsTrue(command.CanExecute(null));
            command.Execute(null);
            Assert.IsTrue(executeCalled);
        }
예제 #2
0
        public void CanExecuteDuringAsyncExecute()
        {
            AssertHelper.ExpectedException<ArgumentNullException>(() => new AsyncDelegateCommand((Func<Task>)null));

            var tcs = new TaskCompletionSource<object>();
            var executeCalled = false;

            var command = new AsyncDelegateCommand(() =>
            {
                executeCalled = true;
                return tcs.Task;
            });

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

            executeCalled = false;
            Assert.IsFalse(command.CanExecute(null));
            command.Execute(null);
            Assert.IsFalse(executeCalled);

            tcs.SetResult(null);
            Assert.IsTrue(command.CanExecute(null));
            command.Execute(null);
            Assert.IsTrue(executeCalled);
        }
예제 #3
0
        public void CanExecuteDuringAsyncExecuteWithParameter()
        {
            var tcs = new TaskCompletionSource<object>();
            string commandParameter = null;

            var command = new AsyncDelegateCommand(p =>
            {
                commandParameter = (string)p;
                return tcs.Task;
            });
            Assert.IsTrue(command.CanExecute(null));
            command.Execute("test");
            Assert.IsFalse(command.CanExecute(null));
            tcs.SetResult(null);
            Assert.IsTrue(command.CanExecute(null));

            Assert.AreEqual("test", commandParameter);
        }
예제 #4
0
        public void RaiseCanExecuteChangedTest()
        {
            var executed = false;
            var canExecute = false;
            var command = new AsyncDelegateCommand(() => { executed = true; return Task.FromResult((object)null); }, () => canExecute);

            Assert.IsFalse(command.CanExecute(null));
            canExecute = true;
            Assert.IsTrue(command.CanExecute(null));

            AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged());

            AssertHelper.CanExecuteChangedEvent(command, () => command.Execute(null), 2, ExpectedChangedCountMode.Exact);  // Because during execution CanExecute returns false
            Assert.IsTrue(executed);
        }