예제 #1
0
        public void If_AsNumericRange_NoPreviousBlock_ThenLastBlockIsNull()
        {
            // ARRANGE
            // all previous blocks were deleted in TestInitialize

            // ACT
            INumericRangeBlock lastBlock = null;

            using (var executionContext = CreateTaskExecutionContext())
            {
                var startedOk = executionContext.TryStart();
                if (startedOk)
                {
                    lastBlock = executionContext.GetLastNumericRangeBlock(LastBlockOrder.LastCreated);
                }
            }

            // ASSERT
            Assert.IsNull(lastBlock);
        }
        public async Task If_AsNumericRange_PreviousBlockIsPhantom_ThenLastBlockIsNotThePhantom()
        {
            // ARRANGE
            // Create previous blocks
            using (var executionContext = CreateTaskExecutionContext())
            {
                var startedOk = await executionContext.TryStartAsync();

                if (startedOk)
                {
                    var rangeBlocks = await executionContext.GetNumericRangeBlocksAsync(x => x.WithRange(1000, 2000, 2000));

                    foreach (var rangeBlock in rangeBlocks)
                    {
                        await rangeBlock.StartAsync();

                        await rangeBlock.CompleteAsync();
                    }
                }
            }

            _blocksHelper.InsertPhantomNumericBlock(TestConstants.ApplicationName, TestConstants.TaskName, 0, 100);

            // ACT
            INumericRangeBlock lastBlock = null;

            using (var executionContext = CreateTaskExecutionContext())
            {
                var startedOk = await executionContext.TryStartAsync();

                if (startedOk)
                {
                    lastBlock = await executionContext.GetLastNumericRangeBlockAsync(LastBlockOrder.LastCreated);
                }
            }

            // ASSERT
            Assert.Equal(1000, (int)lastBlock.StartNumber);
            Assert.Equal(2000, (int)lastBlock.EndNumber);
        }
        public async Task If_AsNumericRange_PreviousBlock_ThenLastBlockContainsDates()
        {
            // ARRANGE
            // Create previous blocks
            using (var executionContext = CreateTaskExecutionContext())
            {
                var startedOk = await executionContext.TryStartAsync();

                if (startedOk)
                {
                    var rangeBlocks = await executionContext.GetNumericRangeBlocksAsync(x => x.WithRange(1, 1000, 100));

                    foreach (var rangeBlock in rangeBlocks)
                    {
                        await rangeBlock.StartAsync();

                        await rangeBlock.CompleteAsync();
                    }
                }
            }

            var expectedLastBlock = new RangeBlock("0", 1, 901, 1000, BlockType.NumericRange);

            // ACT
            INumericRangeBlock lastBlock = null;

            using (var executionContext = CreateTaskExecutionContext())
            {
                var startedOk = await executionContext.TryStartAsync();

                if (startedOk)
                {
                    lastBlock = await executionContext.GetLastNumericRangeBlockAsync(LastBlockOrder.MaxRangeStartValue);
                }
            }

            // ASSERT
            Assert.Equal(expectedLastBlock.RangeBeginAsInt(), lastBlock.StartNumber);
            Assert.Equal(expectedLastBlock.RangeEndAsInt(), lastBlock.EndNumber);
        }