public void Converter_String_NotificationPlatform_Valid(NotificationPlatform platform)
        {
            string       stringPayload = "native notification payload";
            Notification notification  = Converter.BuildNotificationFromString(stringPayload, platform);

            Assert.NotNull(notification);
            Assert.Equal(stringPayload, notification.Body);
        }
        public INotificationClient GetClient(NotificationPlatform notificationPlatform)
        {
            if (_clients.TryGetValue(notificationPlatform, out var client))
            {
                return(client);
            }

            throw new ArgumentOutOfRangeException(nameof(notificationPlatform));
        }
Beispiel #3
0
        public IPayLoadBuilder CreateBuilder(NotificationPlatform notificationPlatform)
        {
            switch (notificationPlatform)
            {
            case NotificationPlatform.Aps: return(new ApplePayLoadBuilder());

            default: throw new ArgumentOutOfRangeException(nameof(notificationPlatform));
            }
        }
Beispiel #4
0
        private void AddNotificationId(IDictionary <NotificationPlatform, List <string> > notificationIds,
                                       NotificationPlatform platform, string notificationId)
        {
            if (!notificationIds.TryGetValue(platform, out var notifications))
            {
                notifications             = new List <string>();
                notificationIds[platform] = notifications;
            }

            notifications.Add(notificationId);
        }
		public async Task UpdateToken(string deviceId, NotificationPlatform deviceType, string token)
		{
			var installation = await this.TryGetInstallation(deviceId);

			if (installation == null)
			{
				installation = new Installation()
				{
					InstallationId = deviceId,
					Platform = deviceType,
				};
			}

			installation.PushChannel = token;

			await this.notificationHubClient.CreateOrUpdateInstallationAsync(installation);
		}
        public static IRuntimePlatform ToRuntimePlatform(this NotificationPlatform notificationPlatform)
        {
            switch (notificationPlatform)
            {
            case NotificationPlatform.Wns:
                return(RuntimePlatform.UWP);

            case NotificationPlatform.Apns:
                return(RuntimePlatform.iOS);

            case NotificationPlatform.Fcm:
                return(RuntimePlatform.Android);

            default:
                throw new ArgumentException($"{notificationPlatform.ToString()} is not currently supported");
            }
        }
        internal static InstallationTemplate CreateInstallationTemplate(NotificationTemplate notificationTemplate, NotificationPlatform platform)
        {
            if (notificationTemplate != null)
            {
                InstallationTemplate installationTemplate = new InstallationTemplate();

                // strip tags
                installationTemplate.Tags = new List <string>();
                installationTemplate.Body = notificationTemplate.Body;
                if (platform == NotificationPlatform.Wns)
                {
                    installationTemplate.Headers = notificationTemplate.Headers;
                }
                else
                {
                    // Headers is not meaningful for all other platforms
                    installationTemplate.Headers = null;
                }

                return(installationTemplate);
            }

            return(null);
        }
Beispiel #8
0
        internal static Notification BuildNotificationFromString(string notificationAsString, NotificationPlatform platform)
        {
            Notification notification = null;

            if (platform == 0)
            {
                JObject jobj = JObject.Parse(notificationAsString);
                Dictionary <string, string> templateProperties = jobj.ToObject <Dictionary <string, string> >();
                notification = new TemplateNotification(templateProperties);
            }
            else
            {
                switch (platform)
                {
                case NotificationPlatform.Wns:
                    notification = new WindowsNotification(notificationAsString);
                    break;

                case NotificationPlatform.Apns:
                    notification = new AppleNotification(notificationAsString);
                    break;

                case NotificationPlatform.Gcm:
                    notification = new GcmNotification(notificationAsString);
                    break;

                case NotificationPlatform.Adm:
                    notification = new AdmNotification(notificationAsString);
                    break;

                case NotificationPlatform.Mpns:
                    notification = new MpnsNotification(notificationAsString);
                    break;
                }
            }

            return(notification);
        }
Beispiel #9
0
        internal static Notification BuildNotificationFromString(string notificationAsString, NotificationPlatform platform)
        {
            Notification notification = null;

            if (platform == 0)
            {
                return(BuildTemplateNotificationFromJsonString(notificationAsString));
            }
            else
            {
                switch (platform)
                {
                case NotificationPlatform.Wns:
                    notification = new WindowsNotification(notificationAsString);
                    break;

                case NotificationPlatform.Apns:
                    notification = new AppleNotification(notificationAsString);
                    break;

                case NotificationPlatform.Gcm:
                    notification = new GcmNotification(notificationAsString);
                    break;

                case NotificationPlatform.Adm:
                    notification = new AdmNotification(notificationAsString);
                    break;

                case NotificationPlatform.Mpns:
                    notification = new MpnsNotification(notificationAsString);
                    break;
                }
            }

            return(notification);
        }
Beispiel #10
0
        public void CreateInstallationObject_ParsingIsConsistent(string pushChannel, string platformAsString, NotificationPlatform platformAsEnum)
        {
            string installationId                  = "12345678-1234-1234-1234-123456789012";
            string tileName                        = "myTile";
            string tileTemplateName                = "templateNameTile";
            string tileTemplateBody                = "myTemplateBodyTile";
            string tileTemplateHeaderName          = "templateHeaderNameTile";
            string tileTemplateHeaderValue         = "templateHeaderValueTile";
            string installationTemplateName        = "installationTemplateName";
            string installationTemplateBody        = "installationTemplateBody";
            string installationTemplateHeaderName  = "installationTemplateHeaderName";
            string installationTemplateHeaderValue = "installationTemplateHeaderBody";

            // Arrange
            Dictionary <string, string> tileTemplateHeaders = new Dictionary <string, string>();

            tileTemplateHeaders[tileTemplateHeaderName] = tileTemplateHeaderValue;

            Dictionary <string, NotificationTemplate> tileTemplates = new Dictionary <string, NotificationTemplate>();

            tileTemplates[tileTemplateName] = new NotificationTemplate
            {
                Body    = tileTemplateBody,
                Headers = tileTemplateHeaders
            };

            Dictionary <string, NotificationSecondaryTile> tiles = new Dictionary <string, NotificationSecondaryTile>();

            tiles[tileName] = new NotificationSecondaryTile
            {
                PushChannel = pushChannel,
                Tags        = new List <string> {
                    "tag1", "tag2"
                },
                Templates = tileTemplates
            };

            Dictionary <string, string> installationTemplateHeaders = new Dictionary <string, string>();

            installationTemplateHeaders[installationTemplateHeaderName] = installationTemplateHeaderValue;

            Dictionary <string, NotificationTemplate> installationTemplates = new Dictionary <string, NotificationTemplate>();

            installationTemplates[installationTemplateName] = new NotificationTemplate
            {
                Body    = installationTemplateBody,
                Headers = installationTemplateHeaders
            };

            NotificationInstallation notificationInstallation = new NotificationInstallation
            {
                Platform       = platformAsString,
                PushChannel    = pushChannel,
                SecondaryTiles = tiles,
                Tags           = new List <string> {
                    "tagA", "tagB"
                },
                Templates = installationTemplates
            };

            notificationInstallation.InstallationId = installationId;

            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            // Act
            Installation testInstallation = mock.CreateInstallation(notificationInstallation);

            // Assert
            Assert.NotNull(testInstallation);
            Assert.Equal(installationId, testInstallation.InstallationId);
            Assert.Equal(platformAsEnum, testInstallation.Platform);
            Assert.Equal(pushChannel, testInstallation.PushChannel);
            if (platformAsEnum == NotificationPlatform.Wns)
            {
                Assert.NotNull(testInstallation.SecondaryTiles);
                Assert.NotNull(testInstallation.SecondaryTiles[tileName]);
                Assert.Equal(pushChannel, testInstallation.SecondaryTiles[tileName].PushChannel);
                Assert.Equal(0, testInstallation.SecondaryTiles[tileName].Tags.Count);
                Assert.NotNull(testInstallation.SecondaryTiles[tileName].Templates);
                Assert.NotNull(testInstallation.SecondaryTiles[tileName].Templates[tileTemplateName]);

                // Tags were stripped within the tile
                Assert.Equal(tileTemplateBody, testInstallation.SecondaryTiles[tileName].Templates[tileTemplateName].Body);
                Assert.Equal(installationTemplateHeaderValue, testInstallation.Templates[installationTemplateName].Headers[installationTemplateHeaderName]);
            }
            else
            {
                Assert.Null(testInstallation.SecondaryTiles);
                Assert.Null(testInstallation.Templates[installationTemplateName].Headers);
            }

            Assert.NotNull(testInstallation.Templates[installationTemplateName]);
            Assert.Equal(installationTemplateBody, testInstallation.Templates[installationTemplateName].Body);

            // Tags were stripped within the template
            Assert.Equal(0, testInstallation.Templates[installationTemplateName].Tags.Count);
        }
 internal static string GetRowKey(NotificationPlatform platform)
 => platform.ToString();
        internal static InstallationTemplate CreateInstallationTemplate(NotificationTemplate notificationTemplate, NotificationPlatform platform)
        {
            if (notificationTemplate != null)
            {
                InstallationTemplate installationTemplate = new InstallationTemplate();

                // strip tags
                installationTemplate.Tags = new List<string>();
                installationTemplate.Body = notificationTemplate.Body;
                if (platform == NotificationPlatform.Wns)
                {
                    installationTemplate.Headers = notificationTemplate.Headers;
                }
                else
                {
                    // Headers is not meaningful for all other platforms
                    installationTemplate.Headers = null;
                }

                return installationTemplate;
            }

            return null;
        }
        public void CreateInstallationObject_ParsingIsConsistent(string pushChannel, string platformAsString, NotificationPlatform platformAsEnum)
        {
            string installationId = "12345678-1234-1234-1234-123456789012";
            string tileName = "myTile";
            string tileTemplateName = "templateNameTile";
            string tileTemplateBody = "myTemplateBodyTile";
            string tileTemplateHeaderName = "templateHeaderNameTile";
            string tileTemplateHeaderValue = "templateHeaderValueTile";
            string installationTemplateName = "installationTemplateName";
            string installationTemplateBody = "installationTemplateBody";
            string installationTemplateHeaderName = "installationTemplateHeaderName";
            string installationTemplateHeaderValue = "installationTemplateHeaderBody";

            // Arrange
            Dictionary<string, string> tileTemplateHeaders = new Dictionary<string, string>();
            tileTemplateHeaders[tileTemplateHeaderName] = tileTemplateHeaderValue;

            Dictionary<string, NotificationTemplate> tileTemplates = new Dictionary<string, NotificationTemplate>();
            tileTemplates[tileTemplateName] = new NotificationTemplate
            {
                Body = tileTemplateBody,
                Headers = tileTemplateHeaders
            };

            Dictionary<string, NotificationSecondaryTile> tiles = new Dictionary<string, NotificationSecondaryTile>();
            tiles[tileName] = new NotificationSecondaryTile
            {
                PushChannel = pushChannel,
                Tags = new List<string> { "tag1", "tag2" },
                Templates = tileTemplates
            };

            Dictionary<string, string> installationTemplateHeaders = new Dictionary<string, string>();
            installationTemplateHeaders[installationTemplateHeaderName] = installationTemplateHeaderValue;

            Dictionary<string, NotificationTemplate> installationTemplates = new Dictionary<string, NotificationTemplate>();
            installationTemplates[installationTemplateName] = new NotificationTemplate
            {
                Body = installationTemplateBody,
                Headers = installationTemplateHeaders
            };

            NotificationInstallation notificationInstallation = new NotificationInstallation
            {
                Platform = platformAsString,
                PushChannel = pushChannel,
                SecondaryTiles = tiles,
                Tags = new List<string> { "tagA", "tagB" },
                Templates = installationTemplates
            };

            notificationInstallation.InstallationId = installationId;

            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            // Act
            Installation testInstallation = mock.CreateInstallation(notificationInstallation);

            // Assert
            Assert.NotNull(testInstallation);
            Assert.Equal(installationId, testInstallation.InstallationId);
            Assert.Equal(platformAsEnum, testInstallation.Platform);
            Assert.Equal(pushChannel, testInstallation.PushChannel);
            if (platformAsEnum == NotificationPlatform.Wns)
            {
                Assert.NotNull(testInstallation.SecondaryTiles);
                Assert.NotNull(testInstallation.SecondaryTiles[tileName]);
                Assert.Equal(pushChannel, testInstallation.SecondaryTiles[tileName].PushChannel);
                Assert.Equal(0, testInstallation.SecondaryTiles[tileName].Tags.Count);
                Assert.NotNull(testInstallation.SecondaryTiles[tileName].Templates);
                Assert.NotNull(testInstallation.SecondaryTiles[tileName].Templates[tileTemplateName]);

                // Tags were stripped within the tile 
                Assert.Equal(tileTemplateBody, testInstallation.SecondaryTiles[tileName].Templates[tileTemplateName].Body);
                Assert.Equal(installationTemplateHeaderValue, testInstallation.Templates[installationTemplateName].Headers[installationTemplateHeaderName]);
            }
            else
            {
                Assert.Null(testInstallation.SecondaryTiles);
                Assert.Null(testInstallation.Templates[installationTemplateName].Headers);
            }

            Assert.NotNull(testInstallation.Templates[installationTemplateName]);
            Assert.Equal(installationTemplateBody, testInstallation.Templates[installationTemplateName].Body);

            // Tags were stripped within the template
            Assert.Equal(0, testInstallation.Templates[installationTemplateName].Tags.Count);
        }