public async Task If_AsNumericRange_BlocksDoNotShareIds() { // ARRANGE // ACT and // ASSERT bool startedOk; using (var executionContext = CreateTaskExecutionContext()) { startedOk = await executionContext.TryStartAsync(); Assert.True(startedOk); if (startedOk) { var fromNumber = 0; var toNumber = 100; var maxBlockRange = 10; var blocks = await executionContext.GetNumericRangeBlocksAsync(x => x.WithRange(fromNumber, toNumber, maxBlockRange)); int counter = 0; INumericRangeBlockContext lastBlock = null; foreach (var block in blocks) { if (counter > 0) { Assert.Equal(lastBlock.NumericRangeBlock.EndNumber + 1, block.NumericRangeBlock.StartNumber); } lastBlock = block; counter++; } } } }
private async Task ProcessBlockAsync(INumericRangeBlockContext blockContext) { try { await blockContext.StartAsync(); var journeys = await _travelDataService.GetJourneysAsync(blockContext.NumericRangeBlock.StartNumber, blockContext.NumericRangeBlock.EndNumber); var travelInsights = new List <TravelInsight>(); foreach (var journey in journeys) { var insight = new TravelInsight() { InsightDate = journey.TravelDate.Date, InsightText = "Some useful insight", PassengerName = journey.PassengerName }; travelInsights.Add(insight); } await _travelInsightsService.AddAsync(travelInsights); int itemCountProcessed = travelInsights.Count; await blockContext.CompleteAsync(itemCountProcessed); } catch (Exception ex) { await blockContext.FailedAsync(ex.ToString()); } }