public void MissingContentTest()
        {
            var message = new PostLikedPush
            {
                Body = null, Title = null, BodyLocalizationKey = null, TitleLocalizationKey = null
            };

            Assert.Throws <ValidationException>(() => PlatformNotificationFactory.CreateTemplateProperties(message));
        }
        public void ContentFormattingTest()
        {
            var message = new TemplatedPush
            {
                Name = "Alex"
            };

            var push = PlatformNotificationFactory.CreateTemplateProperties(message);

            Assert.NotNull(push);
            Assert.Equal("Alex liked your post", push["title"]);
            Assert.Equal("Alex liked your post. Check it out!", push["body"]);
        }
        public void PropertyPopulationTest()
        {
            var message = new PostLikedPush
            {
                PostId = Guid.NewGuid()
            };

            var push = PlatformNotificationFactory.CreateTemplateProperties(message);

            Assert.NotNull(push);
            Assert.Equal(8, push.Count);
            Assert.Equal(message.Title, push["title"]);
            Assert.Equal(message.Body, push["body"]);
            Assert.Equal(message.BodyLocalizationKey, push["body_loc_key"]);
            Assert.Equal(message.TitleLocalizationKey, push["title_loc_key"]);
            Assert.Equal(message.NotificationType.ToString(), push["type"]);
            Assert.Equal(message.Badge.ToString(), push["badge"]);
            Assert.Equal(message.Sound, push["sound"]);
            Assert.Equal(message.PostId, JObject.Parse(push["data"])["postId"]);
        }
コード例 #4
0
        private async Task <bool> TrySendAsync(PushNotificationMessage message, string tagExpression)
        {
            var notification = PlatformNotificationFactory.CreateTemplateProperties(message);

            try
            {
                var outcome = await _hub.SendTemplateNotificationAsync(notification, tagExpression);

                if (outcome == null)
                {
                    return(false);
                }

                return(!(outcome.State == NotificationOutcomeState.Abandoned ||
                         outcome.State == NotificationOutcomeState.Unknown));
            }
            catch (MessagingException ex)
            {
                throw new PushNotificationException("Error while sending push notification", ex);
            }
        }
        public void LocalizationArgumentsPopulationTest()
        {
            var message = new TemplatedArgsPush
            {
                Name     = "Alex",
                PostName = "SomePost"
            };

            var push = PlatformNotificationFactory.CreateTemplateProperties(message);

            Assert.NotNull(push);
            Assert.Equal(12, push.Count);
            Assert.Equal("Alex liked your SomePost post", push["title"]);
            Assert.Equal("Alex liked your SomePost post. Check it out!", push["body"]);
            Assert.Equal(message.BodyLocalizationKey, push["body_loc_key"]);
            Assert.Equal(message.TitleLocalizationKey, push["title_loc_key"]);
            Assert.Equal(message.NotificationType.ToString(), push["type"]);
            Assert.Equal(message.Badge.ToString(), push["badge"]);
            Assert.Equal(message.Sound, push["sound"]);
            Assert.Equal(message.Name, push["body_loc_arg1"]);
            Assert.Equal(message.PostName, push["body_loc_arg2"]);
            Assert.Equal(message.Name, push["title_loc_arg1"]);
            Assert.Equal(message.PostName, push["title_loc_arg2"]);
        }