public void Ctor_NotYetCompleted(int completionMode, TaskCompletionSource <int> tcs, ValueAwaiter <int> va) { Assert.False(tcs.Task.IsCompleted); Assert.False(va.IsCompleted); var are = new AutoResetEvent(false); Action action = () => are.Set(); switch (completionMode) { case 0: va.OnCompleted(action); break; case 1: va.UnsafeOnCompleted(action); break; } tcs.SetResult(42); are.WaitOne(); Assert.True(va.IsCompleted); Assert.Equal(42, va.GetResult()); }
public void Ctor_AlreadyCompletedInput(ValueAwaiter <string> va) { Assert.True(va.IsCompleted); Assert.Equal("hello", va.GetResult()); int threadId = Environment.CurrentManagedThreadId; var are = new AutoResetEvent(false); va.OnCompleted(() => { Assert.NotEqual(threadId, Environment.CurrentManagedThreadId); are.Set(); }); are.WaitOne(); va.UnsafeOnCompleted(() => { Assert.NotEqual(threadId, Environment.CurrentManagedThreadId); are.Set(); }); are.WaitOne(); }