public void NotificationSecondaryTile_Serialization_IsConsistent()
        {
            // Arrange
            NotificationSecondaryTile testTile = new NotificationSecondaryTile
            {
                PushChannel = "myPushChannel",
                Tags        = new List <string> {
                    "tag1", "tag2"
                },
                Templates = new Dictionary <string, NotificationTemplate>
                {
                    {
                        "templateName1",
                        new NotificationTemplate
                        {
                            Body    = "myTemplateBody",
                            Headers = new Dictionary <string, string>
                            {
                                { "headerName1", "headerValue1" },
                                { "headerName2", "headerValue2" }
                            }
                        }
                    }
                }
            };

            // Assert
            SerializationAssert.VerifySerialization(testTile, "{\"pushChannel\":\"myPushChannel\",\"tags\":[\"tag1\",\"tag2\"],\"templates\":{\"templateName1\":{\"body\":\"myTemplateBody\",\"headers\":{\"headerName1\":\"headerValue1\",\"headerName2\":\"headerValue2\"},\"tags\":[]}}}");
        }
        internal static WnsSecondaryTile CreateWnsSecondaryTile(NotificationSecondaryTile notificationSecondaryTile)
        {
            WnsSecondaryTile secondaryTile = new WnsSecondaryTile();

            // Strip the tags.
            secondaryTile.Tags = new List <string>();
            secondaryTile.PushChannelExpired = null;
            secondaryTile.Templates          = new Dictionary <string, InstallationTemplate>();
            if (notificationSecondaryTile != null)
            {
                secondaryTile.PushChannel = notificationSecondaryTile.PushChannel;

                // Parse each template for the Secondary Tile and add to installation object.
                foreach (string templateName in notificationSecondaryTile.Templates.Keys)
                {
                    NotificationTemplate template = notificationSecondaryTile.Templates[templateName];
                    secondaryTile.Templates[templateName] = CreateInstallationTemplate(template, NotificationPlatform.Wns);
                }
            }
            else
            {
                secondaryTile.PushChannel = string.Empty;
            }

            return(secondaryTile);
        }
Exemplo n.º 3
0
        private static NotificationSecondaryTile MakeTestNotificationSecondaryTile()
        {
            NotificationSecondaryTile tile = new NotificationSecondaryTile
            {
                PushChannel = "someChannel",
                Tags        = new List <string>
                {
                    "tag1",
                    "tag2"
                },
                Templates = new Dictionary <string, NotificationTemplate>
                {
                    {
                        "templateName", new NotificationTemplate
                        {
                            Body    = "someBody",
                            Headers = new Dictionary <string, string>
                            {
                                { "header1", "value1" }
                            },
                            Tags = new List <string>
                            {
                                "tagA",
                                "tagB"
                            }
                        }
                    }
                },
            };

            return(tile);
        }
Exemplo n.º 4
0
        public void ValidateSecondaryTile_ThrowsOnNullTemplateValue()
        {
            bool testPass = false;
            NotificationSecondaryTile tile = MakeTestNotificationSecondaryTile();

            tile.Templates = new Dictionary <string, NotificationTemplate>
            {
                {
                    "templateName",
                    null
                }
            };

            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            try
            {
                mock.ValidateSecondaryTile(tile);
            }
            catch
            {
                testPass = true;
            }

            Assert.True(testPass);
        }
Exemplo n.º 5
0
        public void NotificationInstallation_Serialization_IsConsistent()
        {
            // Arrange
            NotificationTemplate testSecondaryTemplate = new NotificationTemplate
            {
                Body    = "mySecondaryBody",
                Headers = new Dictionary <string, string>()
            };

            testSecondaryTemplate.Headers["mySecondaryHeaderName"] = "mySecondaryHeaderValue";

            NotificationSecondaryTile testSecondaryTile = new NotificationSecondaryTile
            {
                PushChannel = "myPushChannel",
                Tags        = new List <string>(),
                Templates   = new Dictionary <string, NotificationTemplate>()
            };

            testSecondaryTile.Tags.Add("myTag");
            testSecondaryTile.Templates["mySecondaryTemplateName"] = testSecondaryTemplate;

            NotificationInstallation installation = new NotificationInstallation
            {
                PushChannel    = "myPushChannel",
                Platform       = "myPlatform",
                InstallationId = "myId",
                SecondaryTiles = new Dictionary <string, NotificationSecondaryTile>(),
                Templates      = new Dictionary <string, NotificationTemplate>()
            };

            installation.SecondaryTiles["myTestTile"] = testSecondaryTile;
            NotificationTemplate testTemplate = new NotificationTemplate
            {
                Body    = "myBody",
                Headers = new Dictionary <string, string>()
            };

            testSecondaryTemplate.Headers["myHeaderName"] = "myHeaderValue";
            installation.Templates["myTemplateName"]      = testTemplate;

            // Assert
            SerializationAssert.VerifySerialization(installation, "{\"pushChannel\":\"myPushChannel\",\"platform\":\"myPlatform\",\"installationId\":\"myId\",\"templates\":{\"myTemplateName\":{\"body\":\"myBody\",\"headers\":{},\"tags\":[]}},\"secondaryTiles\":{\"myTestTile\":{\"pushChannel\":\"myPushChannel\",\"tags\":[\"myTag\"],\"templates\":{\"mySecondaryTemplateName\":{\"body\":\"mySecondaryBody\",\"headers\":{\"mySecondaryHeaderName\":\"mySecondaryHeaderValue\",\"myHeaderName\":\"myHeaderValue\"},\"tags\":[]}}}},\"tags\":[]}");
        }
Exemplo n.º 6
0
        public void ValidateSecondaryTile_ThrowsOnNullTemplates()
        {
            bool testPass = false;
            NotificationSecondaryTile tile = MakeTestNotificationSecondaryTile();

            tile.Templates = null;
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            try
            {
                mock.ValidateSecondaryTile(tile);
            }
            catch
            {
                testPass = true;
            }

            Assert.True(testPass);
        }
Exemplo n.º 7
0
        public void ValidateSecondaryTile_ThrowsOnEmptyPushChannel()
        {
            string pushChannel             = string.Empty;
            bool   testPass                = false;
            NotificationSecondaryTile tile = MakeTestNotificationSecondaryTile();

            tile.PushChannel = pushChannel;
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            try
            {
                mock.ValidateSecondaryTile(tile);
            }
            catch
            {
                testPass = true;
            }

            Assert.True(testPass);
        }
        internal void ValidateSecondaryTile(NotificationSecondaryTile secondaryTile)
        {
            if (secondaryTile == null)
            {
                throw new HttpResponseException(this.Request.CreateBadRequestResponse(RResources.NotificationHub_SecondaryTileWasNull.FormatForUser()));
            }

            if (string.IsNullOrEmpty(secondaryTile.PushChannel))
            {
                throw new HttpResponseException(this.Request.CreateBadRequestResponse(RResources.NotificationHub_EmptyPushChannelInSecondaryTile.FormatForUser()));
            }

            if (secondaryTile.Templates == null || secondaryTile.Templates.Count < 1)
            {
                throw new HttpResponseException(this.Request.CreateBadRequestResponse(RResources.NotificationHub_SecondaryTileTemplatesWasNullOrEmpty.FormatForUser()));
            }

            foreach (NotificationTemplate template in secondaryTile.Templates.Values)
            {
                this.ValidateTemplate(template, WindowsStorePlatform);
            }
        }
        internal Installation CreateInstallation(NotificationInstallation notificationInstallation)
        {
            if (notificationInstallation == null)
            {
                throw new ArgumentNullException("notificationInstallation");
            }

            if (notificationInstallation.Platform == null)
            {
                throw new ArgumentException("notificationInstallation.Platform is null");
            }

            Installation installation = new Installation();

            installation.InstallationId = notificationInstallation.InstallationId;
            installation.PushChannel    = notificationInstallation.PushChannel;

            // Set the Platform. Create and add WnsSecondaryTile objects to the installation if WNS.
            if (notificationInstallation.Platform.Equals(WindowsStorePlatform, StringComparison.OrdinalIgnoreCase))
            {
                installation.Platform = NotificationPlatform.Wns;

                // Parse each Secondary Tile passed in request and add to installation object.
                foreach (string tileName in notificationInstallation.SecondaryTiles.Keys)
                {
                    NotificationSecondaryTile notificationTile = notificationInstallation.SecondaryTiles[tileName];
                    if (installation.SecondaryTiles == null)
                    {
                        installation.SecondaryTiles = new Dictionary <string, WnsSecondaryTile>();
                    }

                    installation.SecondaryTiles[tileName] = CreateWnsSecondaryTile(notificationTile);
                }
            }
            else if (notificationInstallation.Platform.Equals(ApplePlatform, StringComparison.OrdinalIgnoreCase))
            {
                installation.Platform = NotificationPlatform.Apns;
            }
            else if (notificationInstallation.Platform.Equals(GooglePlatform, StringComparison.OrdinalIgnoreCase))
            {
                installation.Platform = NotificationPlatform.Gcm;
            }
            else
            {
                throw new HttpResponseException(this.Request.CreateBadRequestResponse(RResources.NotificationHub_UnsupportedPlatform.FormatForUser(notificationInstallation.Platform)));
            }

            // Create and add InstallationTemplate objects to the installation.
            foreach (string templateName in notificationInstallation.Templates.Keys)
            {
                NotificationTemplate template = notificationInstallation.Templates[templateName];
                if (installation.Templates == null)
                {
                    installation.Templates = new Dictionary <string, InstallationTemplate>();
                }

                installation.Templates[templateName] = CreateInstallationTemplate(template, installation.Platform);
            }

            return(installation);
        }
Exemplo n.º 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);
        }