示例#1
0
        public void ToDictionary_ShouldPopulateDictionary()
        {
            var id          = Guid.NewGuid();
            var body        = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr";
            var confirmText = "Got It!";
            var confirmUrl  = "https://confirm.notifo.com";
            var isConfirmed = true;
            var imageLarge  = "https://via.placeholder.com/600";
            var imageSmall  = "https://via.placeholder.com/100";
            var linkUrl     = "https://app.notifo.io";
            var linkText    = "Go to link";
            var subject     = "subject1";
            var silent      = true;
            var trackingUrl = "https://track.notifo.com";

            var notification = new NotificationDto
            {
                Id          = id,
                ConfirmUrl  = confirmUrl,
                Body        = body,
                ConfirmText = confirmText,
                ImageLarge  = imageLarge,
                ImageSmall  = imageSmall,
                LinkText    = linkText,
                LinkUrl     = linkUrl,
                Subject     = subject,
                Silent      = silent,
                IsConfirmed = isConfirmed,
                TrackingUrl = trackingUrl
            };

            var dictionary = notification.ToDictionary();

            Assert.Equal(dictionary[nameof(id)], id.ToString());
            Assert.Equal(dictionary[nameof(body)], body);
            Assert.Equal(dictionary[nameof(confirmText)], confirmText);
            Assert.Equal(dictionary[nameof(confirmUrl)], confirmUrl);
            Assert.Equal(dictionary[nameof(isConfirmed)], isConfirmed.ToString());
            Assert.Equal(dictionary[nameof(imageSmall)], imageSmall);
            Assert.Equal(dictionary[nameof(imageLarge)], imageLarge);
            Assert.Equal(dictionary[nameof(linkText)], linkText);
            Assert.Equal(dictionary[nameof(linkUrl)], linkUrl);
            Assert.Equal(dictionary[nameof(trackingUrl)], trackingUrl);
            Assert.Equal(dictionary[nameof(subject)], subject);
            Assert.Equal(dictionary[nameof(silent)], silent.ToString());
        }
示例#2
0
        private async Task ShowLocalNotificationAsync(NotificationDto notification)
        {
            var content = new UNMutableNotificationContent();

            content = await EnrichNotificationContentAsync(content, notification);

            content.UserInfo = notification.ToDictionary().ToNSDictionary();

            var request = UNNotificationRequest.FromIdentifier(notification.Id.ToString(), content, trigger: null);

            UNUserNotificationCenter.Current.AddNotificationRequest(request, (error) =>
            {
                if (error != null)
                {
                    Log.Debug(error.LocalizedDescription);
                }
            });
        }