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); }
public void BasicUsageSound() { //Arrange var functions = new Mock <Functions>(); var namespaceCtx = new IntPtr(37); var target = new AsyncManager(functions.Object); //Act var cts = target.GetCancellationTokenForCommand(99); bool cancellationCalled = false; cts.Token.Register(() => { cancellationCalled = true; }); target.ProcessCancelCommand(99); //Assert Assert.True(cancellationCalled); }