Ejemplo n.º 1
0
        public void OrderByCompletion_PropagatesFaultOnSecondCompletion()
        {
            Test.Async(async () =>
            {
                var tcs = new TaskCompletionSource<int>[] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() };
                var results = tcs.Select(x => x.Task).OrderByCompletion();

                tcs[0].SetResult(13);
                tcs[1].SetException(new InvalidOperationException("test message"));
                await results[0];
                try
                {
                    await results[1];
                }
                catch (InvalidOperationException ex)
                {
                    Assert.AreEqual("test message", ex.Message);
                    return;
                }

                Assert.Fail();
            });
        }
Ejemplo n.º 2
0
        public void OrderByCompletion_PropagatesCancelOnSecondCompletion()
        {
            Test.Async(async () =>
            {
                var tcs = new TaskCompletionSource<int>[] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() };
                var results = tcs.Select(x => x.Task).OrderByCompletion();

                tcs[0].SetResult(13);
                tcs[1].SetCanceled();
                await results[0];
                try
                {
                    await results[1];
                }
                catch (OperationCanceledException)
                {
                    return;
                }

                Assert.Fail();
            });
        }
Ejemplo n.º 3
0
 public void OrderByCompletion_OrdersByCompletion()
 {
     Test.Async(async () =>
     {
         var tcs = new TaskCompletionSource<int>[] { new TaskCompletionSource<int>(), new TaskCompletionSource<int>() };
         var results = tcs.Select(x => x.Task).OrderByCompletion();
     
         Assert.IsFalse(results[0].IsCompleted);
         Assert.IsFalse(results[1].IsCompleted);
     
         tcs[1].SetResult(13);
         var result0 = await results[0];
         Assert.IsFalse(results[1].IsCompleted);
         Assert.AreEqual(13, result0);
     
         tcs[0].SetResult(17);
         var result1 = await results[1];
         Assert.AreEqual(13, result0);
         Assert.AreEqual(17, result1);
     });
 }