Ejemplo n.º 1
0
                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 });
                }
Ejemplo n.º 2
0
                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();
                }
Ejemplo n.º 3
0
                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();
                }
Ejemplo n.º 4
0
                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);
                }
Ejemplo n.º 5
0
        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());
            }
        }
Ejemplo n.º 6
0
 public static PeriodBuilder NewPeriodAfter(this ActivityPeriod activityPeriod, TimeSpan gap = default(TimeSpan))
 {
     return(PeriodBuilder.NewAfter(activityPeriod, gap));
 }
Ejemplo n.º 7
0
 public static PeriodBuilder NewPeriod(this DateTime dateTime)
 {
     return(PeriodBuilder.New(dateTime));
 }
Ejemplo n.º 8
0
 public static PeriodBuilder Length(this DateTime dateTime, TimeSpan length)
 {
     return(PeriodBuilder.New(dateTime).Length(length));
 }