Exemple #1
0
        public void When_EnabledTwiceByHost_Then_SubscriptionCreatedOnlyOnce()
        {
            int totalActivations = 0, pendingActivations = 0;
            var host       = new TestAutomationHost(_scheduler);
            var automation = new TestAutomation(host, OnEnabled);

            _scheduler.AdvanceBy(100);
            Assert.AreEqual(0, totalActivations);
            Assert.AreEqual(0, pendingActivations);

            host.SetIsEnabled(automation, true);

            _scheduler.AdvanceBy(100);
            Assert.AreEqual(1, totalActivations);
            Assert.AreEqual(1, pendingActivations);

            host.SetIsEnabled(automation, true);

            _scheduler.AdvanceBy(100);
            Assert.AreEqual(1, totalActivations);
            Assert.AreEqual(1, pendingActivations);

            IDisposable OnEnabled()
            {
                Interlocked.Increment(ref totalActivations);
                Interlocked.Increment(ref pendingActivations);

                return(Disposable.Create(() => Interlocked.Decrement(ref pendingActivations)));
            }
        }
Exemple #2
0
        public void When_Enable_Then_AsyncContextIsSet()
        {
            var ctx          = default(AsyncContext);
            var ctxScheduler = default(IScheduler);
            var host         = new TestAutomationHost(_scheduler);
            var automation   = new TestAutomation(host, OnEnabled);

            _scheduler.AdvanceBy(100);
            host.SetIsEnabled(automation, true);
            _scheduler.AdvanceBy(100);

            Assert.IsNotNull(ctx);
            Assert.IsNotNull(ctxScheduler);
            Assert.AreEqual(_scheduler, ctxScheduler);

            IDisposable OnEnabled()
            {
                ctx          = AsyncContext.Current;
                ctxScheduler = AsyncContext.Current?.Scheduler;

                return(Disposable.Empty);
            }
        }