public void CreateBatchPartitionKey_CorrectParameters_ShouldBeSuccess() { // Arrange string notificationId = "notificationId"; int batchIndex = 1; var expectedResult = $"{notificationId}:{batchIndex}"; // Act var result = PartitionKeyUtility.CreateBatchPartitionKey(notificationId, batchIndex); // Assert Assert.Equal(expectedResult, result); }
/// <inheritdoc/> public async Task <RecipientsInfo> BatchRecipients(IEnumerable <SentNotificationDataEntity> recipients) { if (recipients == null) { throw new ArgumentNullException(nameof(IEnumerable <SentNotificationDataEntity>)); } var notificationId = recipients.FirstOrDefault().PartitionKey; var recipientBatches = recipients.AsBatches(Constants.MaximumNumberOfRecipientsInBatch); var recipientInfo = new RecipientsInfo(notificationId) { TotalRecipientCount = recipients.ToList().Count, }; int batchIndex = 1; foreach (var recipientBatch in recipientBatches) { var recipientBatchList = recipientBatch.ToList(); // Update PartitionKey to Batch Key recipientBatchList.ForEach(s => { s.PartitionKey = PartitionKeyUtility.CreateBatchPartitionKey(s.PartitionKey, batchIndex); // Update if there is any recipient which has no conversation id. recipientInfo.HasRecipientsPendingInstallation |= string.IsNullOrEmpty(s.ConversationId); }); // Store. await this.sentNotificationDataRepository.BatchInsertOrMergeAsync(recipientBatch); recipientInfo.BatchKeys.Add(recipientBatch.FirstOrDefault().PartitionKey); batchIndex++; } return(recipientInfo); }