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\":[]}}}");
        }
        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\":[]}");
        }
        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 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;
        }
        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;
        }
        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);
        }