Exemplo n.º 1
0
        public async Task Should_Create_Notifications()
        {
            var userIds = new List <Guid>
            {
                NotificationServiceProviderMailingTestConsts.FakeUser1Id,
                NotificationServiceProviderMailingTestConsts.FakeUser2Id
            };

            await CreateSmsNotificationAsync(userIds, Text, new Dictionary <string, object>
            {
                { ExtraPropertyKey, ExtraPropertyValue }
            });

            var notifications = await NotificationRepository.GetListAsync();

            notifications.Count.ShouldBe(2);

            foreach (var notification in userIds.Select(userId => notifications.Find(x => x.UserId == userId)))
            {
                notification.ShouldNotBeNull();
            }

            var notificationInfo = await NotificationInfoRepository.GetAsync(notifications.First().NotificationInfoId);

            var text = notificationInfo.GetDataValue(NotificationProviderSmsConsts.NotificationInfoTextPropertyName)
                       .ToString();

            var properties = JsonSerializer.Deserialize <IDictionary <string, object> >(notificationInfo
                                                                                        .GetDataValue(NotificationProviderSmsConsts.NotificationInfoPropertiesPropertyName).ToString());

            text.ShouldBe(Text);
            properties.Count.ShouldBe(1);
            properties.First().Key.ShouldBe(ExtraPropertyKey);
            properties.First().Value.ShouldBe(ExtraPropertyValue);
        }
        public async Task Should_Create_Notifications()
        {
            var userIds = new List <Guid>
            {
                NotificationServiceProviderMailingTestConsts.FakeUser1Id,
                NotificationServiceProviderMailingTestConsts.FakeUser2Id
            };

            await CreateEmailNotificationAsync(userIds, Subject, Body);

            var notifications = await NotificationRepository.GetListAsync();

            notifications.Count.ShouldBe(2);

            foreach (var notification in userIds.Select(userId => notifications.Find(x => x.UserId == userId)))
            {
                notification.ShouldNotBeNull();
            }

            var notificationInfo = await NotificationInfoRepository.GetAsync(notifications.First().NotificationInfoId);

            var subject = notificationInfo
                          .GetDataValue(NotificationProviderMailingConsts.NotificationInfoSubjectPropertyName).ToString();

            var body = notificationInfo.GetDataValue(NotificationProviderMailingConsts.NotificationInfoBodyPropertyName)
                       .ToString();

            subject.ShouldBe(Subject);
            body.ShouldBe(Body);
        }