Beispiel #1
0
        public void Triggered_Updates_NextAndPreviousFireTime()
        {
            // Arrange.
            var startTime = new DateTime(2013, 1, 16, 0, 0, 0, DateTimeKind.Local);
            var nextTime1 = new DateTime(2013, 1, 16, 1, 0, 0, DateTimeKind.Local);
            var nextTime2 = new DateTime(2013, 1, 16, 2, 0, 0, DateTimeKind.Local);

            var schedule = Mock.Create<ISchedule>(Behavior.CallOriginal);
            Mock.Arrange(() => schedule.GetNextTimeAfter(startTime)).Returns(nextTime1);
            Mock.Arrange(() => schedule.GetNextTimeAfter(nextTime1)).Returns(nextTime2);

            var target = new ESyncTrigger(schedule) { StartTimeUtc = startTime.ToUniversalTime() };

            // Act.
            target.ComputeFirstFireTimeUtc(null);
            target.Triggered(null);

            var previousTimeUtc = target.GetPreviousFireTimeUtc();
            var nextTimeUtc = target.GetNextFireTimeUtc();

            // Assert.
            Assert.IsNotNull(previousTimeUtc);
            Assert.IsNotNull(nextTimeUtc);
            Assert.AreEqual(nextTime1, previousTimeUtc.Value.ToLocalTime());
            Assert.AreEqual(nextTime2, nextTimeUtc.Value.ToLocalTime());
        }
Beispiel #2
0
        public void UpdateAfterMisfireWithFireOnceNowInstruction_Updates_NextFireTime()
        {
            // Arrange.
            var currentTime = new DateTime(2013, 1, 16, 0, 0, 0, DateTimeKind.Local);
            var nextTime = new DateTime(2013, 1, 16, 1, 0, 0, DateTimeKind.Local);

            var timeProvider = Mock.Create<ITimeProvider>(Behavior.CallOriginal);
            Mock.Arrange(() => timeProvider.UtcNow).Returns(currentTime.ToUniversalTime());

            var schedule = Mock.Create<ISchedule>(Behavior.CallOriginal);
            Mock.Arrange(() => schedule.GetNextTimeAfter(currentTime)).Returns(nextTime);

            var target = new ESyncTrigger(schedule)
            {
                TimeProvider = timeProvider,
                MisfireInstruction = ESyncTrigger.FireOnceNow
            };

            // Act.
            target.UpdateAfterMisfire(null);
            var result = target.GetNextFireTimeUtc();

            // Assert.
            Assert.IsNotNull(result);
            Assert.AreEqual(currentTime, result.Value.ToLocalTime());
        }
Beispiel #3
0
        public void ComputeFirstFireTimeUtc_Updates_NextFireTime()
        {
            // Arrange.
            var startTime = new DateTime(2013, 1, 16, 1, 0, 0, DateTimeKind.Local);
            var nextTime = new DateTime(2013, 1, 16, 2, 0, 0, DateTimeKind.Local);

            var schedule = Mock.Create<ISchedule>(Behavior.CallOriginal);
            Mock.Arrange(() => schedule.GetNextTimeAfter(startTime)).Returns(nextTime);

            var target = new ESyncTrigger(schedule)
            {
                StartTimeUtc = startTime.ToUniversalTime()
            };

            // Act.
            var result = target.ComputeFirstFireTimeUtc(null);
            var nextTimeUtc = target.GetNextFireTimeUtc();

            // Assert.
            Assert.IsNotNull(result);
            Assert.AreEqual(nextTime, result.Value.ToLocalTime());
            Assert.IsNotNull(nextTimeUtc);
            Assert.AreEqual(nextTime, nextTimeUtc.Value.ToLocalTime());
        }