public void DisposeShouldClearAllLists() { var sut = new StubFiber(); var channel = new Channel<int>(); channel.Subscribe(sut, x => { }); sut.Schedule(() => { }, 1000); channel.Publish(2); Assert.AreEqual(1, sut.Subscriptions.Count); Assert.AreEqual(1, sut.Scheduled.Count); Assert.AreEqual(1, sut.Pending.Count); sut.Dispose(); Assert.AreEqual(0, sut.Subscriptions.Count); Assert.AreEqual(0, sut.Scheduled.Count); Assert.AreEqual(0, sut.Pending.Count); }
public void ScheduledTasksShouldBeExecutedOnceScheduleIntervalShouldBeExecutedEveryTimeExecuteScheduleAllIsCalled() { var sut = new StubFiber(); var scheduleFired = 0; var scheduleOnIntervalFired = 0; sut.Schedule(() => scheduleFired++, 100); var intervalSub = sut.ScheduleOnInterval(() => scheduleOnIntervalFired++, 100, 100); sut.ExecuteAllScheduled(); Assert.AreEqual(1, scheduleFired); Assert.AreEqual(1, scheduleOnIntervalFired); sut.ExecuteAllScheduled(); Assert.AreEqual(1, scheduleFired); Assert.AreEqual(2, scheduleOnIntervalFired); intervalSub.Dispose(); sut.ExecuteAllScheduled(); Assert.AreEqual(1, scheduleFired); Assert.AreEqual(2, scheduleOnIntervalFired); }