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); } }
public virtual void setUp() { TimeTablePolicies policies = new TimeTablePolicies() { IdleTimeout = IDLE_TIMEOUT, }; periodStorage = new MemoryPeriodStorage(); timeTableSUT = new TimeTable(policies, periodStorage); }
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 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); } }
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()); } } }