public Task ThenWithinSecondsTheFirstNotificationsStoredInTheTransientTenantForTheUserWithIdHaveTheDeliveryStatusForTheDeliveryChannelWithId( int timeoutSeconds, int count, string userId, UserNotificationDeliveryStatus expectedDeliveryStatus, string deliveryChannelId) { var tokenSource = new CancellationTokenSource(); tokenSource.CancelAfter(TimeSpan.FromSeconds(timeoutSeconds)); return(Retriable.RetryAsync( async() => { GetNotificationsResult userNotifications = await this.GetNotificationsForUserAsync(userId, count).ConfigureAwait(false); foreach (UserNotification current in userNotifications.Results) { if (current.GetDeliveryStatusForChannel(deliveryChannelId) != expectedDeliveryStatus) { throw new Exception($"Notification with Id '{current.Id}' has delivery status '{current.GetDeliveryStatusForChannel(deliveryChannelId)}' instead of expected value '{expectedDeliveryStatus}'"); } } }, tokenSource.Token, new Linear(TimeSpan.FromSeconds(5), int.MaxValue), new AnyExceptionPolicy(), false)); }
/// <summary> /// Creates an updated version of the supplied <see cref="UserNotification"/> with the delivery status for the /// specified channel set. /// </summary> /// <param name="notification">The notification to which the status change applies.</param> /// <param name="deliveryChannelId">The delivery channel that the status applies to.</param> /// <param name="newDeliveryStatus">The new status.</param> /// <param name="effectiveDateTime">The time at which the status change happened.</param> /// <returns>A copy of the notification with the updated delivery status.</returns> public static UserNotification WithChannelDeliveryStatus( this UserNotification notification, string deliveryChannelId, UserNotificationDeliveryStatus newDeliveryStatus, DateTimeOffset effectiveDateTime) { if (notification is null) { throw new ArgumentNullException(nameof(notification)); } if (string.IsNullOrEmpty(deliveryChannelId)) { throw new ArgumentNullException(nameof(deliveryChannelId)); } ImmutableArray <UserNotificationStatus> deliveryStatuses = notification.ChannelStatuses; UserNotificationStatus?existingStatusForChannel = deliveryStatuses.FirstOrDefault(s => s.DeliveryChannelId == deliveryChannelId); var builder = deliveryStatuses.ToBuilder(); if (!(existingStatusForChannel is null)) { builder.Remove(existingStatusForChannel); builder.Add(existingStatusForChannel.WithDeliveryStatus(newDeliveryStatus, effectiveDateTime)); }
/// <summary> /// Initializes a new instance of the <see cref="BatchDeliveryStatusUpdateRequestItem"/> class. /// </summary> /// <param name="notificationId">The <see cref="UpdateNotificationStatusRequestItem.NotificationId"/>.</param> /// <param name="newStatus">The <see cref="NewStatus" />.</param> /// <param name="updateTimestamp">The <see cref="UpdateNotificationStatusRequestItem.UpdateTimestamp" />.</param> /// <param name="deliveryChannelId">The <see cref="UpdateNotificationStatusRequestItem.DeliveryChannelId" />.</param> public BatchDeliveryStatusUpdateRequestItem( string notificationId, UserNotificationDeliveryStatus newStatus, DateTimeOffset updateTimestamp, string deliveryChannelId) : base(notificationId, updateTimestamp, deliveryChannelId) { this.NewStatus = newStatus; }
public void GivenIUpdateTheDeliveryStatusOfTheNotificationCalledToForTheDeliveryChannelAndCallIt( string originalName, UserNotificationDeliveryStatus deliveryStatus, string deliveryChannelId, string newName) { UserNotification notification = this.scenarioContext.Get <UserNotification>(originalName); UserNotification updatedNotification = notification.WithChannelDeliveryStatus(deliveryChannelId, deliveryStatus, DateTimeOffset.UtcNow); this.scenarioContext.Set(updatedNotification, newName); }
/// <summary> /// Creates a new instance of the class with the delivery status to the specified value. /// </summary> /// <param name="existing">The <see cref="UserNotificationStatus" /> to create a modified copy of.</param> /// <param name="newStatus">The new delivery status.</param> /// <param name="effectiveDateTime">The time at which the update occurred.</param> /// <returns>An updated instance of the <see cref="UserNotificationStatus"/>.</returns> public static UserNotificationStatus WithDeliveryStatus( this UserNotificationStatus existing, UserNotificationDeliveryStatus newStatus, DateTimeOffset effectiveDateTime) { return(new UserNotificationStatus( existing.DeliveryChannelId, newStatus, effectiveDateTime.ToUniversalTime(), existing.ReadStatus, existing.ReadStatusLastUpdated)); }
public async Task ThenTheFirstNotificationsStoredInTheTransientTenantForTheUserWithIdHaveTheDeliveryStatusForTheDeliveryChannelWithId( int count, string userId, UserNotificationDeliveryStatus expectedDeliveryStatus, string deliveryChannelId) { GetNotificationsResult userNotifications = await this.GetNotificationsForUserAsync(userId, count).ConfigureAwait(false); foreach (UserNotification current in userNotifications.Results) { Assert.AreEqual(expectedDeliveryStatus, current.GetDeliveryStatusForChannel(deliveryChannelId)); } }
public UserNotificationStatus( string deliveryChannelId, UserNotificationDeliveryStatus deliveryStatus, DateTimeOffset deliveryStatusLastUpdated, UserNotificationReadStatus readStatus, DateTimeOffset readStatusLastUpdated) { this.DeliveryChannelId = deliveryChannelId; this.DeliveryStatus = deliveryStatus; this.DeliveryStatusLastUpdated = deliveryStatusLastUpdated.ToUniversalTime(); this.ReadStatus = readStatus; this.ReadStatusLastUpdated = readStatusLastUpdated.ToUniversalTime(); }
public Task WhenISendAManagementAPIRequestToBatchUpdateTheDeliveryStatusOfTheFirstStoredNotificationsToForTheDeliveryChannelWithId(int countToUpdate, string userId, UserNotificationDeliveryStatus targetStatus, string deliveryChannelId) { // Get the notifications from session state List <UserNotification> notifications = this.scenarioContext.Get <List <UserNotification> >(DataSetupSteps.CreatedNotificationsKey); BatchDeliveryStatusUpdateRequestItem[] requestBatch = notifications .Where(n => n.UserId == userId) .Take(countToUpdate) .Select( n => new BatchDeliveryStatusUpdateRequestItem( n.Id !, targetStatus, DateTimeOffset.UtcNow, deliveryChannelId)).ToArray(); string transientTenantId = this.featureContext.GetTransientTenantId(); return(this.SendPostRequest(FunctionsApiBindings.ManagementApiBaseUri, $"/{transientTenantId}/marain/usernotifications/batchdeliverystatusupdate", requestBatch)); }
private async Task UpdateNotificationDeliveryStatusAsync(string deliveryChannelId, string notificationId, UserNotificationDeliveryStatus deliveryStatus, ITenant tenant, string?failureMessage = null) { IUserNotificationStore store = await this.notificationStoreFactory.GetUserNotificationStoreForTenantAsync(tenant).ConfigureAwait(false); UserNotification originalNotification = await store.GetByIdAsync(notificationId).ConfigureAwait(false); UserNotification modifiedNotification = originalNotification.WithChannelDeliveryStatus( deliveryChannelId, deliveryStatus, DateTimeOffset.UtcNow, failureMessage); await store.StoreAsync(modifiedNotification).ConfigureAwait(false); }