コード例 #1
0
        public static void Throw()
        {
            // Test that exceptions get passed all the way through PostOperationCompleted(callback, AsyncCompletedEventArgs)
            Task.Run(() =>
            {
                var operation = new TestAsyncOperation(op =>
                {
                    throw new TestException("Test throw");
                });

                Assert.Throws <TestException>(() => operation.Wait());
            }).GetAwaiter().GetResult();
        }
コード例 #2
0
        public static void ThrowAfterAsyncComplete()
        {
            Task.Run(() =>
            {
                var operation = new TestAsyncOperation(op => { });
                operation.Wait();

                SendOrPostCallback noopCallback = state => { };
                Assert.Throws <InvalidOperationException>(() => operation.AsyncOperation.Post(noopCallback, null));
                Assert.Throws <InvalidOperationException>(() => operation.AsyncOperation.PostOperationCompleted(noopCallback, null));
                Assert.Throws <InvalidOperationException>(() => operation.AsyncOperation.OperationCompleted());
            }).GetAwaiter().GetResult();
        }
コード例 #3
0
        public static void Noop()
        {
            // Test that a simple AsyncOperation can be dispatched and completed via AsyncOperationManager
            Task.Run(() =>
            {
                var operation = new TestAsyncOperation(op => { });
                operation.Wait();

                Assert.True(operation.Completed);
                Assert.False(operation.Cancelled);
                Assert.Null(operation.Exception);
            }).GetAwaiter().GetResult();
        }
コード例 #4
0
        public static void ThrowAfterAsyncComplete()
        {
            Task.Run(() =>
                {
                    var operation = new TestAsyncOperation(op => { });
                    operation.Wait();

                    SendOrPostCallback noopCallback = state => { };
                    Assert.Throws<InvalidOperationException>(() => operation.AsyncOperation.Post(noopCallback, null));
                    Assert.Throws<InvalidOperationException>(() => operation.AsyncOperation.PostOperationCompleted(noopCallback, null));
                    Assert.Throws<InvalidOperationException>(() => operation.AsyncOperation.OperationCompleted());
                }).Wait();
        }
コード例 #5
0
        public static void Noop()
        {
            // Test that a simple AsyncOperation can be dispatched and completed via AsyncOperationManager
            Task.Run(() =>
                {
                    var operation = new TestAsyncOperation(op => { });
                    operation.Wait();

                    Assert.True(operation.Completed);
                    Assert.False(operation.Cancelled);
                    Assert.Null(operation.Exception);

                }).Wait();
        }
コード例 #6
0
        public static void Cancel()
        {
            // Test that cancellation gets passed all the way through PostOperationCompleted(callback, AsyncCompletedEventArgs)
            Task.Run(() =>
            {
                var cancelEvent = new ManualResetEventSlim();
                var operation   = new TestAsyncOperation(op =>
                {
                    Assert.True(cancelEvent.Wait(TimeSpan.FromSeconds(SpinTimeoutSeconds)));
                }, cancelEvent: cancelEvent);

                operation.Cancel();
                operation.Wait();
                Assert.True(operation.Completed);
                Assert.True(operation.Cancelled);
                Assert.Null(operation.Exception);
            }).GetAwaiter().GetResult();
        }
コード例 #7
0
        public static void Cancel()
        {
            // Test that cancellation gets passed all the way through PostOperationCompleted(callback, AsyncCompletedEventArgs)
            Task.Run(() =>
             {
                 var cancelEvent = new ManualResetEventSlim();
                 var operation = new TestAsyncOperation(op =>
                 {
                     Assert.True(cancelEvent.Wait(TimeSpan.FromSeconds(SpinTimeoutSeconds)));
                 }, cancelEvent: cancelEvent);

                 operation.Cancel();
                 operation.Wait();
                 Assert.True(operation.Completed);
                 Assert.True(operation.Cancelled);
                 Assert.Null(operation.Exception);
             }).GetAwaiter().GetResult();
        }
コード例 #8
0
        public static void Throw()
        {
            // Test that exceptions get passed all the way through PostOperationCompleted(callback, AsyncCompletedEventArgs)
            Task.Run(() =>
            {
                var operation = new TestAsyncOperation(op =>
                {
                    throw new TestException("Test throw");
                });

                Assert.Throws<TestException>(() => operation.Wait());
            }).Wait();
        }