示例#1
0
 public void TestAddNull()
 {
     using (MultiWaiter <Task> waiter = new MultiWaiter <Task>())
     {
         waiter.Add(null);
     }
 }
示例#2
0
 public void TestRemoveNull()
 {
     using (MultiWaiter <Task> waiter = new MultiWaiter <Task>())
     {
         waiter.Remove(null);
     }
 }
示例#3
0
 public void TestMultiMoveNext()
 {
     using (MultiWaiter <Task> waiter = new MultiWaiter <Task>())
     {
         waiter.WaitNextAsync();
         waiter.WaitNextAsync().AwaitSynchronously();
     }
 }
示例#4
0
        public void TestCompleteRemoved()
        {
            using (MultiWaiter <Task> waiter = new MultiWaiter <Task>())
            {
                TaskCompletionSource <int> tcs1 = new TaskCompletionSource <int>();

                waiter.Add(tcs1.Task);
                waiter.Remove(tcs1.Task);

                tcs1.SetResult(1);
                tcs1.Task.AwaitSynchronously();

                Assert.IsFalse(waiter.WaitNextAsync().IsCompleted);
            }
        }
示例#5
0
        public void TestAddTwice()
        {
            using (MultiWaiter <Task> waiter = new MultiWaiter <Task>())
            {
                Task t = new Task(() => { });
                t.RunSynchronously();

                Assert.IsTrue(waiter.Add(t));
                Assert.IsFalse(waiter.Add(t));

                Assert.AreEqual(t, waiter.WaitNextAsync().AwaitSynchronously());

                Assert.IsTrue(waiter.Add(t));
                Assert.IsFalse(waiter.Add(t));
            }
        }
示例#6
0
        public void TestDispose()
        {
            MultiWaiter <Task> waiter = new MultiWaiter <Task>();
            var waitForNextTask       = waiter.WaitNextAsync();

            Assert.IsFalse(waitForNextTask.IsCompleted);

            waiter.Dispose();

            // Calling Dispose twice is allowed
            waiter.Dispose();

            waitForNextTask.Wait();
            Assert.IsTrue(waitForNextTask.IsCompleted);

            try
            {
                waiter.Add(new Task(() => { }));
                Assert.Fail();
            }
            catch (ObjectDisposedException)
            { }

            try
            {
                waiter.Remove(new Task(() => { }));
                Assert.Fail();
            }
            catch (ObjectDisposedException)
            { }

            try
            {
                waiter.WaitNextAsync().AwaitSynchronously();
                Assert.Fail();
            }
            catch (ObjectDisposedException)
            { }
        }
示例#7
0
        public void TestSimple()
        {
            using (MultiWaiter <Task> waiter = new MultiWaiter <Task>())
            {
                var waitForNextTask             = waiter.WaitNextAsync();
                TaskCompletionSource <int> tcs1 = new TaskCompletionSource <int>();
                TaskCompletionSource <int> tcs2 = new TaskCompletionSource <int>();
                TaskCompletionSource <int> tcs3 = new TaskCompletionSource <int>();

                waiter.Add(tcs1.Task);
                waiter.Add(tcs2.Task);
                waiter.Add(tcs3.Task);

                Assert.IsFalse(waitForNextTask.IsCompleted);

                tcs1.SetResult(1);
                var completedTask = waitForNextTask.AwaitSynchronously();
                Assert.AreSame(tcs1.Task, completedTask);

                waitForNextTask = waiter.WaitNextAsync();
                Assert.IsFalse(waitForNextTask.IsCompleted);
            }
        }