Beispiel #1
0
 public void WaitTest()
 {
     asyncTestCommand     = new AsyncCommand <int>((a) => AsyncExecuteMethod(a));
     executingAsyncMethod = true;
     asyncTestCommand.Execute(100);
     asyncTestCommand.Wait();
     Assert.AreEqual(false, executingAsyncMethod);
     asyncTestCommand.Wait();
     Assert.AreEqual(false, executingAsyncMethod);
     EnqueueTestComplete();
 }
Beispiel #2
0
        void AllowMultipleExecutionTestCore(Func <int, Task> a)
        {
            asyncTestCommand = new AsyncCommand <int>(a, o => true)
            {
                AllowMultipleExecution = true
            };

            asyncTestCommand.Execute(100);
            Assert.IsTrue(asyncTestCommand.IsExecuting);
            Assert.IsTrue(asyncTestCommand.CanExecute(100));
            asyncTestCommand.Cancel();
            Assert.IsTrue(asyncTestCommand.IsExecuting);
            Assert.IsTrue(asyncTestCommand.CanExecute(100));

            asyncTestCommand.Wait(latencyTime);
            Assert.IsFalse(asyncTestCommand.IsExecuting);
            Assert.IsTrue(asyncTestCommand.CanExecute(100));
            asyncTestCommand = new AsyncCommand <int>(a, o => false)
            {
                AllowMultipleExecution = true
            };
            asyncTestCommand.Execute(100);
            Assert.IsFalse(asyncTestCommand.IsExecuting);
            Assert.IsFalse(asyncTestCommand.CanExecute(100));
        }
Beispiel #3
0
        public void WaitTest()
        {
            asyncTestCommand = new AsyncCommand <int>((a) => AsyncExecuteMethod(a));
            int isExecutingChangedCount = 0;

            ((INotifyPropertyChanged)asyncTestCommand).PropertyChanged += (s, e) =>
                                                                          e.If(x => x.PropertyName == "IsExecuting").Do(x => isExecutingChangedCount++);
            asyncTestCommand.Execute(100);
            Assert.AreEqual(1, isExecutingChangedCount);
            Assert.AreEqual(true, asyncTestCommand.IsExecuting);
            asyncTestCommand.Wait();
            Assert.AreEqual(2, isExecutingChangedCount);
            Assert.AreEqual(false, asyncTestCommand.IsExecuting);
            asyncTestCommand.Wait();
            Assert.AreEqual(2, isExecutingChangedCount);
            Assert.AreEqual(false, asyncTestCommand.IsExecuting);
        }
Beispiel #4
0
 public void CancelAndWaitTest2()
 {
     asyncTestCommand     = new AsyncCommand <int>(CancelInsideCommandAndWaitMethod);
     executingAsyncMethod = true;
     asyncTestCommand.Execute(100);
     asyncTestCommand.Wait();
     Assert.AreEqual(false, executingAsyncMethod);
     EnqueueTestComplete();
 }
Beispiel #5
0
        public void CancelAndWaitTest()
        {
            asyncTestCommand = new AsyncCommand <int>(CancelInsideCommandAndWaitMethod);
            int isExecutingChangedCount = 0;

            ((INotifyPropertyChanged)asyncTestCommand).PropertyChanged += (s, e) =>
                                                                          e.If(x => x.PropertyName == "IsExecuting").Do(x => isExecutingChangedCount++);
            asyncTestCommand.Execute(100);
            Assert.AreEqual(1, isExecutingChangedCount);
            Assert.AreEqual(true, asyncTestCommand.IsExecuting);
            asyncTestCommand.CancellationTokenSource.Cancel();
            Assert.AreEqual(true, asyncTestCommand.IsExecuting);
            asyncTestCommand.Wait();
            Assert.AreEqual(2, isExecutingChangedCount);
            Assert.AreEqual(false, asyncTestCommand.IsExecuting);
        }
Beispiel #6
0
        public void AsyncIsExecuting()
        {
            asyncTestCommand = new AsyncCommand <int>(a => AsyncExecuteMethod(a));
            Assert.IsFalse(asyncTestCommand.IsExecuting);
            Assert.IsTrue(asyncTestCommand.CanExecute(100));
            executingAsyncMethod = true;

            asyncTestCommand.Execute(100);
            Assert.IsTrue(asyncTestCommand.IsExecuting);
            Assert.IsFalse(asyncTestCommand.CanExecute(100));

            asyncTestCommand.Wait(latencyTime);
            Assert.IsFalse(asyncTestCommand.IsExecuting);
            Assert.IsTrue(asyncTestCommand.CanExecute(100));
            Assert.IsFalse(executingAsyncMethod);
        }
Beispiel #7
0
        void AsyncCancelTestCore(Func <int, Task> a)
        {
            asyncTestCommand = new AsyncCommand <int>(a);
            Assert.IsNull(asyncTestCommand.CancellationTokenSource);

            asyncTestCommand.Execute(100);
            Assert.IsNotNull(asyncTestCommand.CancellationTokenSource);
            Assert.IsTrue(asyncTestCommand.IsExecuting);
            asyncTestCommand.Cancel();
            Assert.IsTrue(asyncTestCommand.ShouldCancel);
            Assert.IsTrue(asyncTestCommand.IsCancellationRequested);
            Assert.IsTrue(asyncTestCommand.IsExecuting);

            asyncTestCommand.Wait(latencyTime);
            Assert.IsTrue(asyncTestCommand.executeTask.IsCompleted);
            Assert.IsFalse(asyncTestCommand.IsExecuting);
            Assert.IsFalse(asyncTestCommand.ShouldCancel);
            Assert.IsTrue(asyncTestCommand.IsCancellationRequested);
        }
        public void ExecuteAsyncTest()
        {
            asyncTestCommand = new AsyncCommand <int>((a) => AsyncExecuteMethod3(a));
            int isExecutingChangedCount = 0;

            ((INotifyPropertyChanged)asyncTestCommand).PropertyChanged += (s, e) =>
                                                                          e.If(x => x.PropertyName == "IsExecuting").Do(x => isExecutingChangedCount++);
            bool completed = false;

            asyncTestCommand.ExecuteAsync(100).ContinueWith(x => {
                Assert.AreEqual(2, isExecutingChangedCount);
                Assert.AreEqual(false, asyncTestCommand.IsExecuting);
                completed = true;
            });
            Assert.Throws <NotSupportedException>(() => asyncTestCommand.Wait(),
                                                  "The Wait method is not supported when you use the ExecuteAsync method. Use async/await syntax instead.");
            WaitCondition(() => completed);
            Assert.AreEqual(true, completed);
        }
Beispiel #9
0
        public void IsExecutingPropertyChangedTest()
        {
            asyncTestCommand = new AsyncCommand <int>((a) => AsyncExecuteMethod(a));
            bool isExecutingChanged = false;

            ((INotifyPropertyChanged)asyncTestCommand).PropertyChanged += (s, e) => {
                if (e.PropertyName == "IsExecuting")
                {
                    isExecutingChanged = true;
                }
            };

            asyncTestCommand.Execute(100);
            Assert.IsTrue(isExecutingChanged);
            isExecutingChanged = false;

            asyncTestCommand.Wait(latencyTime);
            Assert.IsFalse(asyncTestCommand.IsExecuting);
            Assert.IsTrue(isExecutingChanged);
        }
Beispiel #10
0
        void AsyncCanExecuteTestCore(Func <int, Task> a)
        {
            asyncTestCommand = new AsyncCommand <int>(a, o => true);

            asyncTestCommand.Execute(100);
            Assert.IsTrue(asyncTestCommand.IsExecuting);
            Assert.IsFalse(asyncTestCommand.CanExecute(100));
            asyncTestCommand.Cancel();
            Assert.IsTrue(asyncTestCommand.IsExecuting);
            Assert.IsTrue(asyncTestCommand.ShouldCancel);
            Assert.IsTrue(asyncTestCommand.IsCancellationRequested);

            asyncTestCommand.Wait(latencyTime);
            Assert.IsTrue(asyncTestCommand.executeTask.IsCompleted);
            Assert.IsFalse(asyncTestCommand.IsExecuting);
            Assert.IsTrue(asyncTestCommand.CanExecute(100));
            asyncTestCommand = new AsyncCommand <int>(a, o => false);
            asyncTestCommand.Execute(100);
            Assert.IsFalse(asyncTestCommand.IsExecuting);
            Assert.IsFalse(asyncTestCommand.CanExecute(100));
        }