public async Task If_AsDateRange_PreviousBlock_ThenLastBlockContainsDates() { // ARRANGE // Create previous blocks using (var executionContext = CreateTaskExecutionContext()) { var startedOk = await executionContext.TryStartAsync(); if (startedOk) { var rangeBlocks = await executionContext.GetDateRangeBlocksAsync(x => x.WithRange(new DateTime(2016, 1, 1), new DateTime(2016, 1, 31, 23, 59, 59, 999).AddMilliseconds(-1), new TimeSpan(1, 0, 0, 0)) .OverrideConfiguration() .MaximumBlocksToGenerate(50)); foreach (var rangeBlock in rangeBlocks) { await rangeBlock.StartAsync(); await rangeBlock.CompleteAsync(); } } } IDateRangeBlock expectedLastBlock = new RangeBlock("0", 1, new DateTime(2016, 1, 31).Ticks, new DateTime(2016, 1, 31, 23, 59, 59, 997).Ticks, BlockType.DateRange); // ACT IDateRangeBlock lastBlock = null; using (var executionContext = CreateTaskExecutionContext()) { var startedOk = await executionContext.TryStartAsync(); if (startedOk) { lastBlock = await executionContext.GetLastDateRangeBlockAsync(LastBlockOrder.LastCreated); } } // ASSERT Assert.Equal(expectedLastBlock.StartDate, lastBlock.StartDate); Assert.Equal(expectedLastBlock.EndDate, lastBlock.EndDate); }
public async Task If_AsDateRange_PreviousBlockIsPhantom_ThenLastBlockIsNotThePhantom() { // ARRANGE // Create previous blocks using (var executionContext = CreateTaskExecutionContext()) { var startedOk = await executionContext.TryStartAsync(); if (startedOk) { var rangeBlocks = await executionContext.GetDateRangeBlocksAsync(x => x.WithRange(new DateTime(2016, 1, 1), new DateTime(2016, 1, 2), new TimeSpan(2, 0, 0, 0)) .OverrideConfiguration() .MaximumBlocksToGenerate(50)); foreach (var rangeBlock in rangeBlocks) { await rangeBlock.StartAsync(); await rangeBlock.CompleteAsync(); } } } _blocksHelper.InsertPhantomDateRangeBlock(TestConstants.ApplicationName, TestConstants.TaskName, new DateTime(2015, 1, 1), new DateTime(2015, 1, 2)); // ACT IDateRangeBlock lastBlock = null; using (var executionContext = CreateTaskExecutionContext()) { var startedOk = await executionContext.TryStartAsync(); if (startedOk) { lastBlock = await executionContext.GetLastDateRangeBlockAsync(LastBlockOrder.LastCreated); } } // ASSERT Assert.Equal(new DateTime(2016, 1, 1), lastBlock.StartDate); Assert.Equal(new DateTime(2016, 1, 2), lastBlock.EndDate); }
public void If_AsDateRange_NoPreviousBlock_ThenLastBlockIsNull() { // ARRANGE // all previous blocks were deleted in TestInitialize // ACT IDateRangeBlock lastBlock = null; using (var executionContext = CreateTaskExecutionContext()) { var startedOk = executionContext.TryStart(); if (startedOk) { lastBlock = executionContext.GetLastDateRangeBlock(LastBlockOrder.LastCreated); } } // ASSERT Assert.IsNull(lastBlock); }