/// <summary>
 /// Initializes a new instance of the <see cref="MarkNotificationAsReadService"/> class.
 /// </summary>
 /// <param name="marainServicesTenancy">Marain tenancy services.</param>
 /// <param name="managementApiClient">The client for the management API.</param>
 public MarkNotificationAsReadService(
     IUserNotificationsManagementClient managementApiClient,
     IMarainServicesTenancy marainServicesTenancy)
 {
     this.marainServicesTenancy = marainServicesTenancy
                                  ?? throw new ArgumentNullException(nameof(marainServicesTenancy));
     this.managementApiClient = managementApiClient
                                ?? throw new ArgumentNullException(nameof(managementApiClient));
 }
        public async Task WhenIUseTheClientToSendAManagementAPIRequestToCreateANewNotification(Table table)
        {
            IJsonSerializerSettingsProvider jsonSerializerSettingsProvider = this.serviceProvider.GetRequiredService <IJsonSerializerSettingsProvider>();
            CreateNotificationsRequest      data = BuildCreateNotificationsRequestFrom(table.Rows[0], jsonSerializerSettingsProvider.Instance);

            string transientTenantId = this.featureContext.GetTransientTenantId();
            IUserNotificationsManagementClient client = this.serviceProvider.GetRequiredService <IUserNotificationsManagementClient>();

            try
            {
                ApiResponse result = await client.CreateNotificationsAsync(transientTenantId, data, CancellationToken.None).ConfigureAwait(false);

                this.StoreApiResponseDetails(result.StatusCode, result.Headers);
            }
            catch (Exception ex)
            {
                ExceptionSteps.StoreLastExceptionInScenarioContext(ex, this.scenarioContext);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetNotificationsForUserService"/> class.
 /// </summary>
 /// <param name="marainServicesTenancy">Marain tenancy services.</param>
 /// <param name="userNotificationStoreFactory">The user notification store factory.</param>
 /// <param name="userNotificationsMapper">The user notifications mapper.</param>
 /// <param name="managementApiClient">The client for the management API.</param>
 /// <param name="exceptionsInstrumentation">The <see cref="IExceptionsInstrumentation{T}"/> for this class.</param>
 /// <param name="logger">The logger.</param>
 public GetNotificationsForUserService(
     IMarainServicesTenancy marainServicesTenancy,
     ITenantedUserNotificationStoreFactory userNotificationStoreFactory,
     UserNotificationsMapper userNotificationsMapper,
     IUserNotificationsManagementClient managementApiClient,
     IExceptionsInstrumentation <GetNotificationsForUserService> exceptionsInstrumentation,
     ILogger <GetNotificationsForUserService> logger)
 {
     this.marainServicesTenancy = marainServicesTenancy
                                  ?? throw new ArgumentNullException(nameof(marainServicesTenancy));
     this.userNotificationStoreFactory = userNotificationStoreFactory
                                         ?? throw new ArgumentNullException(nameof(userNotificationStoreFactory));
     this.userNotificationsMapper = userNotificationsMapper
                                    ?? throw new ArgumentNullException(nameof(userNotificationsMapper));
     this.managementApiClient = managementApiClient
                                ?? throw new ArgumentNullException(nameof(managementApiClient));
     this.logger = logger
                   ?? throw new ArgumentNullException(nameof(logger));
     this.exceptionsInstrumentation = exceptionsInstrumentation
                                      ?? throw new ArgumentNullException(nameof(exceptionsInstrumentation));
 }
        public async Task WhenIUseTheClientToSendAManagementAPIRequestToBatchUpdateTheDeliveryStatusOfTheFirstStoredNotificationsForUserToForTheDeliveryChannelWithId(
            int countToUpdate,
            string userId,
            UpdateNotificationDeliveryStatusRequestNewStatus targetStatus,
            string deliveryChannelId)
        {
            string transientTenantId = this.featureContext.GetTransientTenantId();
            IUserNotificationsManagementClient client = this.serviceProvider.GetRequiredService <IUserNotificationsManagementClient>();

            List <UserNotification> notifications = this.scenarioContext.Get <List <UserNotification> >(DataSetupSteps.CreatedNotificationsKey);

            BatchDeliveryStatusUpdateRequestItem[] requestBatch = notifications
                                                                  .Where(n => n.UserId == userId)
                                                                  .Take(countToUpdate)
                                                                  .Select(
                n =>
                new BatchDeliveryStatusUpdateRequestItem
            {
                DeliveryChannelId = deliveryChannelId,
                NewStatus         = targetStatus,
                NotificationId    = n.Id !,
                UpdateTimestamp   = DateTimeOffset.UtcNow,
            }).ToArray();