public void WhenScheduleIsNull_GetFireTimeAfter_ThrowsException() { // Arrange. var target = new ESyncTrigger(); // Act. target.GetFireTimeAfter(null); }
public void WhenNextScheduleTimeIsNull_GetFireTimeAfter_ReturnsNull() { // Arrange. var schedule = Mock.Create<ISchedule>(Behavior.CallOriginal); Mock.Arrange(() => schedule.GetNextTimeAfter(Arg.IsAny<DateTime>())).Returns(null as DateTime?); var target = new ESyncTrigger(schedule); // Act. var result = target.GetFireTimeAfter(null); // Assert. Assert.IsNull(result); }
public void WhenNextScheduleTimeIsGreaterThanEndTime_GetFireTimeAfter_ReturnsNull() { // Arrange. var endTime = new DateTime(2013, 1, 16, 0, 0, 0, DateTimeKind.Local); var nextTime = new DateTime(2013, 1, 16, 0, 0, 1, DateTimeKind.Local); var schedule = Mock.Create<ISchedule>(Behavior.CallOriginal); Mock.Arrange(() => schedule.GetNextTimeAfter(Arg.IsAny<DateTime>())).Returns(nextTime); var target = new ESyncTrigger(schedule) { EndTimeUtc = endTime.ToUniversalTime() }; // Act. var result = target.GetFireTimeAfter(null); // Assert. Assert.IsNull(result); }
public void GetFireTimeAfter_ReturnsNextScheduleTime() { // Arrange. var afterTime = new DateTime(2013, 1, 16, 0, 0, 0, DateTimeKind.Local); var nextTime = new DateTime(2013, 1, 16, 0, 0, 1, DateTimeKind.Local); var schedule = Mock.Create<ISchedule>(Behavior.CallOriginal); Mock.Arrange(() => schedule.GetNextTimeAfter(afterTime)).Returns(nextTime); var target = new ESyncTrigger(schedule); // Act. var result = target.GetFireTimeAfter(afterTime.ToUniversalTime()); // Assert. Assert.IsNotNull(result); Assert.AreEqual(nextTime, result.Value.ToLocalTime()); }
public void GetFireTimeAfter_Returns_NextFireTimeIncludedInCalendar() { // 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 nextTime3 = new DateTime(2013, 1, 16, 3, 0, 0, DateTimeKind.Local); var nextTime4 = new DateTime(2013, 1, 16, 4, 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); Mock.Arrange(() => schedule.GetNextTimeAfter(nextTime2)).Returns(nextTime3); Mock.Arrange(() => schedule.GetNextTimeAfter(nextTime3)).Returns(nextTime4); var calendar = Mock.Create<ICalendar>(Behavior.CallOriginal); Mock.Arrange(() => calendar.IsTimeIncluded(nextTime1.ToUniversalTime())).Returns(false); Mock.Arrange(() => calendar.IsTimeIncluded(nextTime2.ToUniversalTime())).Returns(false); Mock.Arrange(() => calendar.IsTimeIncluded(nextTime3.ToUniversalTime())).Returns(true); Mock.Arrange(() => calendar.IsTimeIncluded(nextTime4.ToUniversalTime())).Returns(true); var target = new ESyncTrigger(schedule) { StartTimeUtc = startTime.ToUniversalTime() }; // Act. var result = target.GetFireTimeAfter(startTime.ToUniversalTime(), calendar); // Assert. Assert.IsNotNull(result); Assert.AreEqual(nextTime3, result.Value.ToLocalTime()); }
public void WhenAfterTimeIsNull_GetFireTimeAfter_ReturnsNextTimeAfterCurrentDate() { // Arrange. var currentTime = new DateTime(2013, 1, 16, 0, 0, 0, DateTimeKind.Local); var nextTime = new DateTime(2013, 1, 16, 0, 0, 1, DateTimeKind.Local); var schedule = Mock.Create<ISchedule>(Behavior.CallOriginal); Mock.Arrange(() => schedule.GetNextTimeAfter(currentTime)).Returns(nextTime); var timeProvider = Mock.Create<ITimeProvider>(Behavior.CallOriginal); Mock.Arrange(() => timeProvider.UtcNow).Returns(currentTime.ToUniversalTime()); var target = new ESyncTrigger(schedule) { TimeProvider = timeProvider }; // Act. var result = target.GetFireTimeAfter(null); // Assert. Assert.IsNotNull(result); Assert.AreEqual(nextTime, result.Value.ToLocalTime()); }