private async Task <GetNotificationsResult> GetNotificationsForUserAsync(string userId, int count)
        {
            ITenantedUserNotificationStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedUserNotificationStoreFactory>();
            IUserNotificationStore store = await storeFactory.GetUserNotificationStoreForTenantAsync(this.featureContext.GetTransientTenant()).ConfigureAwait(false);

            return(await store.GetAsync(userId, null, count).ConfigureAwait(false));
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateNotificationActivity"/> class.
 /// </summary>
 /// <param name="tenantProvider">The tenant provider.</param>
 /// <param name="notificationStoreFactory">The factory for the notification store.</param>
 public CreateNotificationActivity(
     ITenantProvider tenantProvider,
     ITenantedUserNotificationStoreFactory notificationStoreFactory)
 {
     this.tenantProvider = tenantProvider
                           ?? throw new ArgumentNullException(nameof(tenantProvider));
     this.notificationStoreFactory = notificationStoreFactory
                                     ?? throw new ArgumentNullException(nameof(notificationStoreFactory));
 }
        public async Task GivenIHaveCreatedAndStoredANotificationInTheCurrentTransientTenantAndCalledTheResult(string resultName, Table table)
        {
            ITenantedUserNotificationStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedUserNotificationStoreFactory>();
            IJsonSerializerSettingsProvider       serializerSettingsProvider = this.serviceProvider.GetRequiredService <IJsonSerializerSettingsProvider>();
            UserNotification       notification = BuildNotificationFrom(table.Rows[0], serializerSettingsProvider.Instance);
            IUserNotificationStore store        = await storeFactory.GetUserNotificationStoreForTenantAsync(this.featureContext.GetTransientTenant()).ConfigureAwait(false);

            UserNotification result = await store.StoreAsync(notification).ConfigureAwait(false);

            this.scenarioContext.Set(result, resultName);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GetNotificationService"/> class.
 /// </summary>
 /// <param name="marainServicesTenancy">Marain tenancy services.</param>
 /// <param name="userNotificationStoreFactory">The user notification store factory.</param>
 /// <param name="userNotificationMapper">The mapper for the result notification.</param>
 public GetNotificationService(
     IMarainServicesTenancy marainServicesTenancy,
     ITenantedUserNotificationStoreFactory userNotificationStoreFactory,
     UserNotificationMapper userNotificationMapper)
 {
     this.marainServicesTenancy = marainServicesTenancy
                                  ?? throw new ArgumentNullException(nameof(marainServicesTenancy));
     this.userNotificationStoreFactory = userNotificationStoreFactory
                                         ?? throw new ArgumentNullException(nameof(userNotificationStoreFactory));
     this.userNotificationMapper = userNotificationMapper
                                   ?? throw new ArgumentNullException(nameof(userNotificationMapper));
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DispatchNotificationActivity"/> class.
 /// </summary>
 /// <param name="tenantProvider">The tenant provider.</param>
 /// <param name="notificationStoreFactory">The factory for the notification store.</param>
 /// <param name="tenantedTemplateStoreFactory">The factory for the templated store.</param>
 /// <param name="generateTemplateComposer">The composer to generate the templated notification per communication channel.</param>
 /// <param name="airshipClientFactory">The Airship Factory.</param>
 /// <param name="configuration">IConfiguration.</param>
 public DispatchNotificationActivity(
     ITenantProvider tenantProvider,
     ITenantedUserNotificationStoreFactory notificationStoreFactory,
     ITenantedNotificationTemplateStoreFactory tenantedTemplateStoreFactory,
     IGenerateTemplateComposer generateTemplateComposer,
     IAirshipClientFactory airshipClientFactory,
     IConfiguration configuration)
 {
     this.tenantProvider = tenantProvider
                           ?? throw new ArgumentNullException(nameof(tenantProvider));
     this.notificationStoreFactory = notificationStoreFactory
                                     ?? throw new ArgumentNullException(nameof(notificationStoreFactory));
     this.tenantedTemplateStoreFactory = tenantedTemplateStoreFactory
                                         ?? throw new ArgumentNullException(nameof(tenantedTemplateStoreFactory));
     this.generateTemplateComposer = generateTemplateComposer
                                     ?? throw new ArgumentNullException(nameof(generateTemplateComposer));
     this.airshipClientFactory = airshipClientFactory
                                 ?? throw new ArgumentNullException(nameof(airshipClientFactory));
     this.configuration = configuration
                          ?? throw new ArgumentNullException(nameof(configuration));
 }
 /// <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 GivenIHaveCreatedAndStoredNotificationsInTheCurrentTransientTenantWithTimestampsAtSecondIntervalsForTheUserWithId(int notificationCount, int interval, string userId)
        {
            ITenantedUserNotificationStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedUserNotificationStoreFactory>();
            IUserNotificationStore store = await storeFactory.GetUserNotificationStoreForTenantAsync(this.featureContext.GetTransientTenant()).ConfigureAwait(false);

            IPropertyBagFactory propertyBagFactory = this.serviceProvider.GetRequiredService <IPropertyBagFactory>();

            var            offset    = TimeSpan.FromSeconds(interval);
            DateTimeOffset timestamp = DateTimeOffset.UtcNow - offset;

            var tasks = new List <Task <UserNotification> >();
            var propertiesDictionary = new Dictionary <string, object>
            {
                { "prop1", "val1" },
                { "prop2", 2 },
                { "prop3", DateTime.Now },
            };

            IPropertyBag properties = propertyBagFactory.Create(propertiesDictionary);

            for (int i = 0; i < notificationCount; i++)
            {
                string[] correlationIds = Enumerable.Range(0, 3).Select(_ => Guid.NewGuid().ToString()).ToArray();
                var      metadata       = new UserNotificationMetadata(correlationIds, null);
                tasks.Add(store.StoreAsync(new UserNotification(null, "marain.usernotifications.test", userId, timestamp, properties, metadata)));
                timestamp -= offset;
            }

            UserNotification[] newlyCreatedNotifications = await Task.WhenAll(tasks).ConfigureAwait(false);

            // Store the notifications in session state
            if (!this.scenarioContext.TryGetValue(CreatedNotificationsKey, out List <UserNotification> createdNotifications))
            {
                createdNotifications = new List <UserNotification>();
                this.scenarioContext.Set(createdNotifications, CreatedNotificationsKey);
            }

            createdNotifications.AddRange(newlyCreatedNotifications);
        }