예제 #1
0
        public async Task RemoteProxyBase_WithCancellation_Cancelled()
        {
            var mre   = new ManualResetEvent(false);
            var svc   = new TestService(mre);
            var proxy = new TestProxy(svc);

            var val = 42;
            var cts = new CancellationTokenSource();
            var t   = proxy.IncrementAsync(val, cts.Token);

            Assert.IsFalse(t.IsCompleted);
            Assert.IsFalse(t.IsFaulted);
            cts.Cancel();

            try
            {
                await t;
            }
            catch (TaskCanceledException)
            {
                mre.Set();
                return;
            }

            mre.Set();
            Assert.Fail();
        }
예제 #2
0
        public void RemoteProxyBase_NoCancellation()
        {
            var mre   = new ManualResetEvent(false);
            var svc   = new TestService(mre);
            var proxy = new TestProxy(svc);

            var val = 42;
            var t   = proxy.IncrementAsync(val);

            Assert.IsFalse(t.IsCompleted);
            mre.Set();
            Assert.AreEqual(val + 1, t.Result);

            mre.Reset();

            var t2 = proxy.IncrementAsync(val, CancellationToken.None);

            Assert.IsFalse(t2.IsCompleted);
            mre.Set();
            Assert.AreEqual(val + 1, t2.Result);
        }