示例#1
0
        public void ExecuteInTransactionShouldNotBeExecutedWhenExceptionOccured()
        {
            var firstPeriod  = START_DATETIME.NewPeriod().Active();
            var secondPeriod = firstPeriod.NewPeriodAfter().Active();

            using (TestablePeriodStorage periodStorageSUT = GetStorage())
            {
                periodStorageSUT.Add(firstPeriod);
                try
                {
                    periodStorageSUT.ExecuteInTransaction(() =>
                    {
                        periodStorageSUT.Remove(firstPeriod);
                        periodStorageSUT.Add(secondPeriod);
                        throw new ArgumentException();
                    });
                    Assert.Fail("Exception in action should be propagated");
                }
                catch (Exception e) {
                }

                var found = periodStorageSUT.GetAll();
                CollectionAssert.AreEqual(new ActivityPeriod[] { firstPeriod }, found);
            }
        }
示例#2
0
            public virtual void setUp()
            {
                TimeTablePolicies policies = new TimeTablePolicies()
                {
                    IdleTimeout = IDLE_TIMEOUT,
                };

                periodStorage = new MemoryPeriodStorage();
                timeTableSUT  = new TimeTable(policies, periodStorage);
            }
示例#3
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());
            }
        }
示例#4
0
        public void ExecuteInTransactionShouldBeExecuted()
        {
            var firstPeriod  = START_DATETIME.NewPeriod().Active();
            var secondPeriod = firstPeriod.NewPeriodAfter().Active();

            using (TestablePeriodStorage periodStorageSUT = GetStorage())
            {
                periodStorageSUT.Add(firstPeriod);
                periodStorageSUT.ExecuteInTransaction(() =>
                {
                    periodStorageSUT.Remove(firstPeriod);
                    periodStorageSUT.Add(secondPeriod);
                });

                var found = periodStorageSUT.GetAll();
                CollectionAssert.AreEqual(new ActivityPeriod[] { secondPeriod }, found);
            }
        }
示例#5
0
        public void AddedPeriodsShouldBeReaderByAnotherInstance()
        {
            var period1  = START_DATETIME.Length(1.secs()).Active();
            var period2  = period1.NewPeriodAfter(2.secs()).Idle();
            var expected = new ActivityPeriod[] { period1, period2 };

            using (TestablePeriodStorage instance1 = GetStorage())
            {
                instance1.Add(period1);
                instance1.Add(period2);

                CollectionAssert.AreEquivalent(expected, instance1.GetAll());
            }

            if (IsStoragePersisent())
            {
                WaitForConnectionToDbClosed();
                using (TestablePeriodStorage instance2 = GetStorage())
                {
                    CollectionAssert.AreEquivalent(expected, instance2.GetAll());
                }
            }
        }