コード例 #1
0
        public void InvokeWithCallback()
        {
            // Arrange
            ObjectAsyncResult <int> oar = new ObjectAsyncResult <int>(42);

            SignalContainer <IAsyncResult> callbackContainer = new SignalContainer <IAsyncResult>();
            AsyncCallback callback = ar => {
                callbackContainer.Signal(ar);
            };

            // Act
            IAsyncResult asyncResult      = oar.BeginInvoke(callback, "some state");
            IAsyncResult passedToCallback = callbackContainer.Wait();
            int          returned         = oar.EndInvoke(asyncResult);

            // Assert
            Assert.AreEqual(asyncResult, passedToCallback);
            Assert.AreEqual("some state", asyncResult.AsyncState);
            Assert.AreEqual(42, returned);
        }