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(); }
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)); }
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); }
public void CancelAndWaitTest2() { asyncTestCommand = new AsyncCommand <int>(CancelInsideCommandAndWaitMethod); executingAsyncMethod = true; asyncTestCommand.Execute(100); asyncTestCommand.Wait(); Assert.AreEqual(false, executingAsyncMethod); EnqueueTestComplete(); }
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); }
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); }
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); }
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); }
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)); }