示例#1
0
 public void Initialize()
 {
     this.webNotificationItemEntity = new WebNotificationItemEntity
     {
         NotificationId = Guid.NewGuid().ToString(),
         Title          = "Notice Title",
         Body           = "This is a notice body.",
         Properties     = new Dictionary <string, string> {
             { "DeepLink", "https://www.microsoft.com" },
         },
         Priority            = NotificationPriority.Normal,
         ReadStatus          = NotificationReadStatus.New,
         TrackingId          = Guid.NewGuid().ToString(),
         SendOnUtcDate       = DateTime.UtcNow,
         PublishOnUTCDate    = DateTime.UtcNow,
         ExpiresOnUTCDate    = DateTime.UtcNow.AddDays(1),
         AppNotificationType = "Test Type",
         Sender = new Person
         {
             Name             = "Software Engineer",
             Email            = "*****@*****.**",
             ObjectIdentifier = Guid.NewGuid().ToString(),
         },
     };
 }
示例#2
0
        public void ToEntity_ValidWebNotificationRequestItemWithNonDefaultValues()
        {
            this.webNotificationRequestItem.SendOnUtcDate = DateTime.UtcNow;
            this.webNotificationRequestItem.Priority      = NotificationPriority.High;
            this.webNotificationRequestItem.TrackingId    = null;
            this.webNotificationRequestItem.Properties    = null;
            WebNotificationItemEntity webNotificationItemEntity = this.webNotificationRequestItem.ToEntity("Application 1");

            Assert.IsTrue(this.webNotificationRequestItem.Title.Equals(webNotificationItemEntity.Title, StringComparison.Ordinal));
            Assert.IsTrue(this.webNotificationRequestItem.Body.Equals(webNotificationItemEntity.Body, StringComparison.Ordinal));
            Assert.IsNull(webNotificationItemEntity.Properties);
            Assert.IsTrue(this.webNotificationRequestItem.Sender.Name.Equals(webNotificationItemEntity.Sender.Name, StringComparison.Ordinal));
            Assert.IsTrue(this.webNotificationRequestItem.Sender.Email.Equals(webNotificationItemEntity.Sender.Email, StringComparison.Ordinal));
            Assert.IsTrue(this.webNotificationRequestItem.Sender.ObjectIdentifier.Equals(webNotificationItemEntity.Sender.ObjectIdentifier, StringComparison.Ordinal));
            Assert.IsTrue(this.webNotificationRequestItem.Recipient.Name.Equals(webNotificationItemEntity.Recipient.Name, StringComparison.Ordinal));
            Assert.IsTrue(this.webNotificationRequestItem.Recipient.Email.Equals(webNotificationItemEntity.Recipient.Email, StringComparison.Ordinal));
            Assert.IsTrue(this.webNotificationRequestItem.Recipient.ObjectIdentifier.Equals(webNotificationItemEntity.Recipient.ObjectIdentifier, StringComparison.Ordinal));
            Assert.IsTrue(this.webNotificationRequestItem.PublishOnUTCDate == webNotificationItemEntity.PublishOnUTCDate);
            Assert.IsTrue(webNotificationItemEntity.TrackingId == null);
            Assert.IsTrue(this.webNotificationRequestItem.ExpiresOnUTCDate == webNotificationItemEntity.ExpiresOnUTCDate);
            Assert.IsTrue(this.webNotificationRequestItem.SendOnUtcDate == webNotificationItemEntity.SendOnUtcDate);
            Assert.IsTrue(webNotificationItemEntity.Priority == NotificationPriority.High);
            Assert.IsTrue(webNotificationItemEntity.NotifyType == NotificationType.Web);
            Assert.IsTrue(!string.IsNullOrWhiteSpace(webNotificationItemEntity.Id));
            Assert.IsTrue(!string.IsNullOrWhiteSpace(webNotificationItemEntity.NotificationId));
            Assert.IsTrue(webNotificationItemEntity.Application.Equals("Application 1", StringComparison.Ordinal));
            Assert.IsTrue(webNotificationItemEntity.AppNotificationType.Equals(webNotificationItemEntity.AppNotificationType, StringComparison.Ordinal));
        }
示例#3
0
        public async Task ReadAsync_WithExistentEntityId()
        {
            this.NotificationId = "Notification Id #2";
            WebNotificationItemEntity webNotificationItemEntity = this.NotificationEntities.Where(nt => nt.NotificationId.Equals(this.NotificationId, StringComparison.Ordinal)).FirstOrDefault();

            _ = this.MockItemResponse.SetupGet(ir => ir.Resource).Returns(webNotificationItemEntity);
            _ = this.MockItemResponse.SetupGet(ir => ir.StatusCode).Returns(webNotificationItemEntity == null ? HttpStatusCode.BadRequest : HttpStatusCode.OK);
            var webNotificationEntity = await this.NotificationRepository.ReadAsync(this.NotificationId).ConfigureAwait(false);

            Assert.IsTrue(webNotificationEntity.NotificationId.Equals(webNotificationItemEntity.NotificationId, StringComparison.Ordinal));
        }
        public void DeleteAsync_WithExistentEntityId_FailedResponse()
        {
            this.NotificationId = "Notification Id #2";
            WebNotificationItemEntity webNotificationItemEntity = this.NotificationEntities.Where(nt => nt.NotificationId.Equals(this.NotificationId, StringComparison.Ordinal)).FirstOrDefault();

            _ = this.MockItemResponse.SetupGet(ir => ir.Resource).Returns(webNotificationItemEntity);
            _ = this.MockItemResponse.SetupGet(ir => ir.StatusCode).Returns(HttpStatusCode.BadRequest);
            var ex = Assert.ThrowsAsync <NotificationServiceException>(async() => await this.NotificationRepository.DeleteAsync(this.NotificationId).ConfigureAwait(false));

            Assert.IsTrue(typeof(NotificationServiceException).FullName.Equals(ex.GetType().FullName, StringComparison.Ordinal));
            Assert.IsTrue(ex.Message.Equals($"The deletion of entity with identifier '{this.NotificationId}' failed with status code response of '{HttpStatusCode.BadRequest}'.", StringComparison.Ordinal));
        }
示例#5
0
        /// <summary>
        /// Updates the notification entities with exiting ids asynchronously if any.
        /// </summary>
        /// <param name="webNotificationItemEntities">The instance for <see cref="IEnumerable{WebNotificationItemEntity}"/>.</param>
        /// <returns>The instance of <see cref="Task"/> representing an asynchronous operation.</returns>
        private async Task UpdateNotificationEntitiesWithExitingIdsAsync(IEnumerable <WebNotificationItemEntity> webNotificationItemEntities)
        {
            Debug.Assert(webNotificationItemEntities?.Any() ?? false, "Missing web notification entities.");
            IEnumerable <string> notificationIds = webNotificationItemEntities.Select(wbn => wbn.NotificationId);
            EntityCollection <WebNotificationItemEntity> notificationCollection = await this.LoadNotificationsWithIdsInternalAsync(notificationIds).ConfigureAwait(false);

            foreach (var wbn in webNotificationItemEntities)
            {
                WebNotificationItemEntity notificationItemEntity = notificationCollection.Items
                                                                   .Where(notif => notif.NotificationId.Equals(wbn.NotificationId, StringComparison.Ordinal))
                                                                   .FirstOrDefault();
                if (notificationItemEntity != null && !string.IsNullOrWhiteSpace(notificationItemEntity.Id))
                {
                    wbn.Id = notificationItemEntity.Id;
                }
            }
        }