public void NotifierT_TaskFaulted_NotifiesProperties() { var tcs = new TaskCompletionSource <object>(); var notifier = NotifyTask.Create(() => tcs.Task); var exception = new NotImplementedException(Guid.NewGuid().ToString("N")); var taskNotification = TestUtils.PropertyNotified(notifier, n => n.Task); var statusNotification = TestUtils.PropertyNotified(notifier, n => n.Status); var isCompletedNotification = TestUtils.PropertyNotified(notifier, n => n.IsCompleted); var isSuccessfullyCompletedNotification = TestUtils.PropertyNotified(notifier, n => n.IsSuccessfullyCompleted); var isCanceledNotification = TestUtils.PropertyNotified(notifier, n => n.IsCanceled); var isFaultedNotification = TestUtils.PropertyNotified(notifier, n => n.IsFaulted); var exceptionNotification = TestUtils.PropertyNotified(notifier, n => n.Exception); var innerExceptionNotification = TestUtils.PropertyNotified(notifier, n => n.InnerException); var errorMessageNotification = TestUtils.PropertyNotified(notifier, n => n.ErrorMessage); var resultNotification = TestUtils.PropertyNotified(notifier, n => n.Result); Assert.Same(tcs.Task, notifier.Task); Assert.False(notifier.TaskCompleted.IsCompleted); Assert.Equal(tcs.Task.Status, notifier.Status); Assert.False(notifier.IsCompleted); Assert.True(notifier.IsNotCompleted); Assert.False(notifier.IsSuccessfullyCompleted); Assert.Null(notifier.Result); Assert.False(notifier.IsCanceled); Assert.False(notifier.IsFaulted); Assert.Null(notifier.Exception); Assert.Null(notifier.InnerException); Assert.Null(notifier.ErrorMessage); tcs.SetException(exception); Assert.Same(tcs.Task, notifier.Task); Assert.True(notifier.TaskCompleted.IsCompleted && !notifier.TaskCompleted.IsCanceled && !notifier.TaskCompleted.IsFaulted); Assert.Equal(tcs.Task.Status, notifier.Status); Assert.True(notifier.IsCompleted); Assert.False(notifier.IsNotCompleted); Assert.False(notifier.IsSuccessfullyCompleted); Assert.Null(notifier.Result); Assert.False(notifier.IsCanceled); Assert.True(notifier.IsFaulted); Assert.NotNull(notifier.Exception); Assert.Same(exception, notifier.InnerException); Assert.Equal(exception.Message, notifier.ErrorMessage); Assert.False(taskNotification()); Assert.True(statusNotification()); Assert.True(isCompletedNotification()); Assert.False(isSuccessfullyCompletedNotification()); Assert.False(isCanceledNotification()); Assert.True(isFaultedNotification()); Assert.True(exceptionNotification()); Assert.True(innerExceptionNotification()); Assert.True(errorMessageNotification()); Assert.False(resultNotification()); }
public void StartExecution_NotifiesPropertyChanges() { var signal = new TaskCompletionSource <object>(); var command = new CustomAsyncCommand(_ => signal.Task, _ => true); var isExecutingNotification = TestUtils.PropertyNotified(command, n => n.IsExecuting); var executionNotification = TestUtils.PropertyNotified(command, n => n.Execution); ((ICommand)command).Execute(null); Assert.True(isExecutingNotification()); Assert.True(executionNotification()); signal.SetResult(null); }
public void Notifier_TaskCanceled_NotifiesProperties() { var tcs = new TaskCompletionSource <object>(); var notifier = NotifyTask.Create(() => (Task)tcs.Task); var taskNotification = TestUtils.PropertyNotified(notifier, n => n.Task); var statusNotification = TestUtils.PropertyNotified(notifier, n => n.Status); var isCompletedNotification = TestUtils.PropertyNotified(notifier, n => n.IsCompleted); var isSuccessfullyCompletedNotification = TestUtils.PropertyNotified(notifier, n => n.IsSuccessfullyCompleted); var isCanceledNotification = TestUtils.PropertyNotified(notifier, n => n.IsCanceled); var isFaultedNotification = TestUtils.PropertyNotified(notifier, n => n.IsFaulted); var exceptionNotification = TestUtils.PropertyNotified(notifier, n => n.Exception); var innerExceptionNotification = TestUtils.PropertyNotified(notifier, n => n.InnerException); var errorMessageNotification = TestUtils.PropertyNotified(notifier, n => n.ErrorMessage); Assert.Same(tcs.Task, notifier.Task); Assert.False(notifier.TaskCompleted.IsCompleted); Assert.Equal(tcs.Task.Status, notifier.Status); Assert.False(notifier.IsCompleted); Assert.True(notifier.IsNotCompleted); Assert.False(notifier.IsSuccessfullyCompleted); Assert.False(notifier.IsCanceled); Assert.False(notifier.IsFaulted); Assert.Null(notifier.Exception); Assert.Null(notifier.InnerException); Assert.Null(notifier.ErrorMessage); tcs.SetCanceled(); Assert.Same(tcs.Task, notifier.Task); Assert.True(notifier.TaskCompleted.IsCompleted && !notifier.TaskCompleted.IsCanceled && !notifier.TaskCompleted.IsFaulted); Assert.Equal(tcs.Task.Status, notifier.Status); Assert.True(notifier.IsCompleted); Assert.False(notifier.IsNotCompleted); Assert.False(notifier.IsSuccessfullyCompleted); Assert.True(notifier.IsCanceled); Assert.False(notifier.IsFaulted); Assert.Null(notifier.Exception); Assert.Null(notifier.InnerException); Assert.Null(notifier.ErrorMessage); Assert.False(taskNotification()); Assert.True(statusNotification()); Assert.True(isCompletedNotification()); Assert.False(isSuccessfullyCompletedNotification()); Assert.True(isCanceledNotification()); Assert.False(isFaultedNotification()); Assert.False(exceptionNotification()); Assert.False(innerExceptionNotification()); Assert.False(errorMessageNotification()); }
public void NotifierT_NonDefaultResult_TaskCompletesSuccessfully_UpdatesResult() { var tcs = new TaskCompletionSource <object>(); var defaultResult = new object(); var notifier = NotifyTask.Create(() => tcs.Task, defaultResult); var result = new object(); var resultNotification = TestUtils.PropertyNotified(notifier, n => n.Result); Assert.Same(defaultResult, notifier.Result); tcs.SetResult(result); Assert.Same(result, notifier.Result); Assert.True(resultNotification()); }
public void StartExecution_NotifiesPropertyChanges() { var signal = new TaskCompletionSource <object>(); var command = new AsyncCommand(_ => signal.Task); var isExecutingNotification = TestUtils.PropertyNotified(command, n => n.IsExecuting); var executionNotification = TestUtils.PropertyNotified(command, n => n.Execution); var sawCanExecuteChanged = false; ((ICommand)command).CanExecuteChanged += (_, __) => { sawCanExecuteChanged = true; }; ((ICommand)command).Execute(null); Assert.True(isExecutingNotification()); Assert.True(executionNotification()); Assert.True(sawCanExecuteChanged); signal.SetResult(null); }