コード例 #1
0
        private void ExceptionAtEndTranslationHelper <TExceptionExpected>(Exception exToThrow)
        {
            NativeStub myNativeStub = null;
            Task       t            = Utility.WrapNativeAsyncInvoke((callback) =>
            {
                myNativeStub = new NativeStub(callback);
                return(myNativeStub);
            },
                                                                    (adapter) =>
            {
                throw exToThrow;
            },
                                                                    CancellationToken.None,
                                                                    "test");

            // complete the task
            myNativeStub.get_Callback().Invoke(myNativeStub);

            try
            {
                t.Wait(taskWaitTimeout);
                Assert.Fail("Expected ex");
            }
            catch (AggregateException ex)
            {
                Assert.AreEqual(typeof(TExceptionExpected), ex.InnerException.GetType());
            }
        }
コード例 #2
0
        public void Initialize()
        {
            this.initial = AsyncTaskCallInAdapter.ReleaseComObjectWrapperInstance;
            Assert.IsInstanceOfType(this.initial, typeof(AsyncTaskCallInAdapter.ReleaseComObjectWrapper), "Release Com Object Wrapper Instance on the call in adapter is not set");

            this.releaseComObjectStub = new ReleaseComObjectWrapperStub();
            AsyncTaskCallInAdapter.ReleaseComObjectWrapperInstance = this.releaseComObjectStub;

            this.stub       = new NativeStub();
            this.asyncEvent = new ManualResetEventSlim();
            this.asyncEvent.Reset();
            this.baseTask = Task.Factory.StartNew(() => this.asyncEvent.Wait());
        }
コード例 #3
0
        public void WrapNativeAsyncInvoke_TaskIsCompletedWhenOperationIsDone()
        {
            NativeStub myNativeStub = null;
            Task       t            = Utility.WrapNativeAsyncInvoke((callback) =>
            {
                myNativeStub = new NativeStub(callback);
                return(myNativeStub);
            },
                                                                    (adapter) =>
            {
            },
                                                                    CancellationToken.None,
                                                                    "test");

            // the task is still running
            Assert.IsFalse(t.IsCompleted);

            // complete the task
            myNativeStub.get_Callback().Invoke(myNativeStub);

            Assert.IsTrue(t.IsCompleted);
        }