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();
        }
        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();
        }
        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();
        }
        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();
        }