예제 #1
0
            public void AllCancelledOnDispose()
            {
                //Arrange
                var functions    = new Mock <Functions>();
                var namespaceCtx = new IntPtr(37);
                var target       = new AsyncManager(functions.Object);

                //Act
                int cancellationsCalled = 0;
                var cts1 = target.GetCancellationTokenForCommand(99);

                cts1.Token.Register(() =>
                {
                    Interlocked.Increment(ref cancellationsCalled);
                });
                var cts2 = target.GetCancellationTokenForCommand(99);

                cts2.Token.Register(() =>
                {
                    Interlocked.Increment(ref cancellationsCalled);
                });
                var cts3 = target.GetCancellationTokenForCommand(99);

                cts3.Token.Register(() =>
                {
                    Interlocked.Increment(ref cancellationsCalled);
                });
                target.Dispose();

                //Assert
                Assert.Equal(3, cancellationsCalled);
            }