Example #1
0
        public void OnSnoozeCompletion_SleepCalled_EventIsRaizedProperly()
        {
            SnoozeManager target = new SnoozeManager(new StubSleep());

            Assert.IsFalse(target.IsSnoozed, "target just launched and shouldn't be snoozed");

            bool calledback = false;

            target.OnSnoozeCompletion += () => { calledback = true; };

            var sleepDuration = new TimeSpan(0, 0, 0, 0, 200);

            target.Sleep(sleepDuration);

            Assert.IsTrue(target.IsSnoozed, "Target should be snoozed now");

            Thread.Sleep(TimeSpan.FromTicks(sleepDuration.Ticks * 2));

            Assert.IsFalse(target.IsSnoozed, "target should be awake now");
            Assert.IsTrue(calledback, "Should call callback delegate");

            calledback = false;

            Thread.Sleep(sleepDuration);
            Assert.IsFalse(calledback, "Should not call callback delegate after called once");
        }
Example #2
0
        public void Wakeup_Sleep_NoCallbackAndIsNotSnoozed()
        {
            SnoozeManager target        = new SnoozeManager(new StubSleep());
            var           sleepDuration = new TimeSpan(0, 0, 0, 0, 200);

            bool calledback = false;

            target.OnSnoozeCompletion += () => { calledback = true; };

            target.Sleep(sleepDuration);
            Assert.IsTrue(target.IsSnoozed, "Target should be snoozed now");

            target.Wakeup();

            Assert.IsFalse(target.IsSnoozed, "should be able to abort snooze");

            // Lets wait and see if callback isn't called
            Thread.Sleep(TimeSpan.FromTicks(sleepDuration.Ticks * 2));
            Assert.IsFalse(calledback, "Shouldn't call callback delegate because snooze was aborted");
        }