public void When_SchedulePeriodic_Then_CancelSubscription() { _scheduler.AdvanceTo(new DateTimeOffset(1983, 9, 9, 15, 15, 0, TimeSpan.FromHours(-4)).Ticks); var ran = 0; var host = new TestAutomationHost(_scheduler); var automation = new TestAutomation(host); IDisposable subscription; using (new AsyncContext(_scheduler)) { subscription = automation.At(new TimeSpan(22, 0, 0), Action); } _scheduler.AdvanceBy(TimeSpan.FromDays(3).Ticks); subscription.Dispose(); _scheduler.AdvanceBy(TimeSpan.FromDays(5).Ticks); Assert.AreEqual(3, ran); async Task Action(DateTimeOffset arg) { Interlocked.Increment(ref ran); } }