public void NewCancelationRegistrationIsNotRegistered()
            {
                CancelationRegistration cancelationRegistration = new CancelationRegistration();

                Assert.IsFalse(cancelationRegistration.IsRegistered);

                TestHelper.Cleanup();
            }
            public void RegistrationFromCancelationTokenIsNotRegisteredAfterSourceIsDisposed1()
            {
                CancelationSource       cancelationSource       = CancelationSource.New();
                CancelationToken        cancelationToken        = cancelationSource.Token;
                CancelationRegistration cancelationRegistration = cancelationToken.Register(0, (i, _) => { });

                cancelationSource.Dispose();
                Assert.IsFalse(cancelationRegistration.IsRegistered);

                TestHelper.Cleanup();
            }
            public void RegistrationFromCancelationTokenIsRegistered0()
            {
                CancelationSource       cancelationSource       = CancelationSource.New();
                CancelationToken        cancelationToken        = cancelationSource.Token;
                CancelationRegistration cancelationRegistration = cancelationToken.Register(_ => { });

                Assert.IsTrue(cancelationRegistration.IsRegistered);
                cancelationSource.Dispose();

                TestHelper.Cleanup();
            }
            public void RegistrationFromCancelationTokenIsNotRegisteredAfterInvoked3()
            {
                CancelationSource       cancelationSource       = CancelationSource.New();
                CancelationToken        cancelationToken        = cancelationSource.Token;
                CancelationRegistration cancelationRegistration = new CancelationRegistration();

                cancelationRegistration = cancelationToken.Register(0, (i, _) => Assert.IsFalse(cancelationRegistration.IsRegistered));
                cancelationSource.Cancel();
                cancelationSource.Dispose();

                TestHelper.Cleanup();
            }
            public void CancelationRegistrationUnregisterCallbackIsNotInvoked0()
            {
                CancelationSource cancelationSource = CancelationSource.New();
                CancelationToken  cancelationToken  = cancelationSource.Token;
                bool invoked = false;
                CancelationRegistration cancelationRegistration = cancelationToken.Register(_ => invoked = true);

                cancelationRegistration.Unregister();
                cancelationSource.Cancel();
                Assert.IsFalse(invoked);
                cancelationSource.Dispose();

                TestHelper.Cleanup();
            }
            public void RegisteredCallbackIsRegisteredAfterSourceIsDisposedDuringInvocation()
            {
                CancelationSource cancelationSource = CancelationSource.New();
                CancelationToken  cancelationToken  = cancelationSource.Token;
                // This should never be done in practice!
                CancelationRegistration cancelationRegistration = new CancelationRegistration();

                cancelationToken.Register(_ =>
                {
                    cancelationSource.Dispose();
                    Assert.IsTrue(cancelationRegistration.IsRegistered);
                });
                cancelationRegistration = cancelationToken.Register(_ => { });
                cancelationSource.Cancel();

                TestHelper.Cleanup();
            }