Example #1
0
        public void Invokes_callback_on_async_completion()
        {
            OneAsyncStepOperation op     = new OneAsyncStepOperation();
            object        state          = new object();
            IAsyncResult  returnedResult = null;
            IAsyncResult  callbackResult = null;
            AsyncCallback callback       = delegate(IAsyncResult r)
            {
                callbackResult = r;
                Assert.NotNull(returnedResult);
                Assert.Same(state, r.AsyncState);
                Assert.Equal(1234, OneAsyncStepOperation.End(r));
            };

            returnedResult = op.Start(callback, state);

            Assert.Null(callbackResult);
            Assert.False(returnedResult.IsCompleted);

            op.Complete(1234);

            Assert.True(returnedResult.IsCompleted);
            Assert.False(returnedResult.CompletedSynchronously);
            Assert.Same(callbackResult, returnedResult);
        }
Example #2
0
        public void Completes_async_after_one_async_step()
        {
            OneAsyncStepOperation op     = new OneAsyncStepOperation();
            IAsyncResult          result = op.Start(null, null);

            Assert.False(result.IsCompleted);

            op.Complete(1234);

            Assert.True(result.IsCompleted);
            Assert.False(result.CompletedSynchronously);
            Assert.Equal(1234, OneAsyncStepOperation.End(result));
        }
Example #3
0
        public void Completes_with_async_exception_after_one_async_step_with_async_exception()
        {
            InvalidTimeZoneException expected = new InvalidTimeZoneException("Expected.");
            OneAsyncStepOperation    op       = new OneAsyncStepOperation();
            IAsyncResult             result   = op.Start(null, null);

            Assert.False(result.IsCompleted);

            op.Complete(expected);

            Assert.True(result.IsCompleted);
            Assert.False(result.CompletedSynchronously);
            InvalidTimeZoneException actual = Assert.Throws <InvalidTimeZoneException>(() => OneAsyncStepOperation.End(result));

            Assert.Same(expected, actual);
        }