public Task InsertOrReplaceBatchAsync(IEnumerable <IAccountsStatReport> stats) { var tasks = BatchEntityInsertHelper.MakeBatchesByPartitionKey(stats.Select(m => AccountsStatReportEntity.Create(m))) .Select(b => _tableStorage.InsertOrReplaceBatchAsync(b)); return(Task.WhenAll(tasks)); }
public void Always_ShouldCorrectlySplitToBatches() { //arrange string GetPartitionKey(int i) { if (i < 150) { return("1"); // 2 batches } else if (i < 250) { return("2"); // 1 batch } else if (i < 300) { return("3"); // 1 batch } else { return("4"); // 1 batch } } var srcEntities = Enumerable.Range(0, 400) .Select(i => new TableEntity(GetPartitionKey(i), "")); //act var result = BatchEntityInsertHelper.MakeBatchesByPartitionKey(srcEntities); //assert var preparedResult = result.Select(b => b.Select(e => int.Parse(e.PartitionKey)).ToList()).ToList(); preparedResult.Should().OnlyContain(b => b.Distinct().Count() == 1); preparedResult.Should().OnlyContain(b => b.Count <= 100); preparedResult.Should().HaveCount(5); }