private ActivePeriod PassOnePeriod(DateTime day) { var period = PeriodBuilder.New(day.AddHours(12)).Length(1.hours()).Active(); activityPeriodsListener.PeriodPassed(period); return(period); }
public void closeActiveAndIdlePeriodShouldNotBeMerged() { var period1 = PeriodBuilder.New(MIDDAY).Active(); var period2 = PeriodBuilder.NewAfter(period1, LESS_THAN_IDLE_TIMEOUT).Idle(); timeTableSUT.AddPeriod(period1); timeTableSUT.AddPeriod(period2); CollectionAssert.AreEquivalent(periodStorage.GetAll(), new ActivityPeriod[] { period2, period1 }); }
public void shouldNotNotifyIfWasntIdleBefore() { // arrange ActivePeriod period = PeriodBuilder.New(MIDDAY).Length(1.secs()).Active(); // act timeTableSUT.PeriodPassed(period); // assert A.CallTo(() => listenerActivityListnerMock.NotifyActiveAfterBreak(A <TimeSpan> .Ignored)).MustNotHaveHappened(); }
public void twoDistantActivePeriodShouldNotBeMerged() { var period1 = PeriodBuilder.New(MIDDAY).Active(); var period2 = PeriodBuilder.NewAfter(period1, MORE_THAN_IDLE_TIMEOUT).Active(); var returned1 = timeTableSUT.AddPeriod(period1); var returned2 = timeTableSUT.AddPeriod(period2); Assert.AreEqual(period1, returned1); Assert.AreEqual(period2, returned2); CollectionAssert.AreEquivalent(periodStorage.GetAll(), new[] { period2, period1 }); }
public void shouldNotNotifyIfWasShortIdleBefore() { // arrange var periodIdleShort = PeriodBuilder.New(MIDDAY).Length(LESS_THAN_IDLE_TIMEOUT).Idle(); var periodActive = periodIdleShort.NewPeriodAfter().Length(1.secs()).Active(); // act timeTableSUT.PeriodPassed(periodIdleShort); timeTableSUT.PeriodPassed(periodActive); // assert A.CallTo(() => listenerActivityListnerMock.NotifyActiveAfterBreak(A <TimeSpan> .Ignored)).MustNotHaveHappened(); }
public void shouldNotNotifyIfBeforeIsIdleAndOff() { // arrange var periodIdle = PeriodBuilder.New(MIDDAY).Length(MORE_THAN_IDLE_TIMEOUT).Idle(); var offTime = 1.secs(); var periodActive = periodIdle.NewPeriodAfter(offTime).Active(); // act timeTableSUT.PeriodPassed(periodIdle); timeTableSUT.PeriodPassed(periodActive); // assert A.CallTo(() => listenerActivityListnerMock.NotifyActiveAfterBreak(A <TimeSpan> .Ignored)).MustNotHaveHappened(); }
public void shouldNotifyWhenBeforeActiveThereIsLongIdlePeriod() { // arrange var idlePeriodLength = IDLE_TIMEOUT + 2.secs(); var periodIdleLong = PeriodBuilder.New(MIDDAY).Length(idlePeriodLength).Idle(); var periodActive = PeriodBuilder.NewAfter(periodIdleLong).Length(1.secs()).Active(); // act timeTableSUT.PeriodPassed(periodIdleLong); timeTableSUT.PeriodPassed(periodActive); // assert A.CallTo(() => listenerActivityListnerMock.NotifyActiveAfterBreak(idlePeriodLength)) .MustHaveHappened(Repeated.Exactly.Once); }
public void RemovePeriodShouldRemoveOnlyExactMatches() { var period1 = START_DATETIME.Length(5.secs()).Active(); var period2 = period1.NewPeriodAfter().Idle(); var notExactOutside2 = PeriodBuilder.New(period2.Start - 1.ms()).WithEnd(period2.End + 1.ms()).Active(); var notExactInside2 = PeriodBuilder.New(period2.Start + 1.ms()).WithEnd(period2.End - 1.ms()).Idle(); using (TestablePeriodStorage periodStorageSUT = GetStorage()) { periodStorageSUT.Add(period1); periodStorageSUT.Add(period2); periodStorageSUT.Remove(period1); periodStorageSUT.Remove(notExactOutside2); periodStorageSUT.Remove(notExactInside2); CollectionAssert.AreEquivalent(new[] { period2 }, periodStorageSUT.GetAll()); } }
public static PeriodBuilder NewPeriod(this DateTime dateTime) { return(PeriodBuilder.New(dateTime)); }
public static PeriodBuilder Length(this DateTime dateTime, TimeSpan length) { return(PeriodBuilder.New(dateTime).Length(length)); }