Exemple #1
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);
        }
Exemple #2
0
        public void CopyTagsToInstallation_IsConsistent_CopyUserFalse()
        {
            Installation     installation = MakeTestInstallation();
            HashSet <string> tags         = new HashSet <string>
            {
                "tag1",
                "tag2",
                string.Format(UserIdTagPlaceholder, "myId"),
                string.Format(InstallationIdTagPlaceholder, Guid.NewGuid().ToString())
            };

            NotificationInstallationsControllerMock.CopyTagsToInstallation(installation, tags, false);
            IList <string> tagsOutput = installation.Tags;

            foreach (string tag in tags)
            {
                if (tag.StartsWith(InstallationIdTagPrefix, StringComparison.OrdinalIgnoreCase))
                {
                    Assert.False(tagsOutput.Contains(tag));
                }
                else if (tag.StartsWith(UserIdTagPrefix, StringComparison.OrdinalIgnoreCase))
                {
                    Assert.False(tagsOutput.Contains(tag));
                }
                else
                {
                    Assert.True(tagsOutput.Contains(tag));
                }
            }
        }
Exemple #3
0
        public void ValidateTemplate_NonWnsPlatformThrowsWhenHeadersNonNull(string platform)
        {
            // Pass condition = exception thrown.
            bool testPass = false;
            NotificationTemplate template = new NotificationTemplate()
            {
                Body = "someString",
                Tags = new List <string>
                {
                    "tag1",
                    "tag2"
                },
                Headers = new Dictionary <string, string>()
            };
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            try
            {
                mock.ValidateTemplate(template, platform);
            }
            catch
            {
                testPass = true;
            }

            Assert.True(testPass);
        }
Exemple #4
0
        public void ValidateTemplate_DoesNotThrowWhenHeadersIsNull(string platform)
        {
            NotificationTemplate template = MakeTestNotificationTemplate();

            template.Headers = null;
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            mock.ValidateTemplate(template, platform);
        }
Exemple #5
0
        public void ValidateTemplate_WnsPlatformDoesNotThrowOnEmptyHeaders()
        {
            NotificationTemplate template = MakeTestNotificationTemplate();

            template.Headers = new Dictionary <string, string>();
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            mock.ValidateTemplate(template, "wns");
        }
Exemple #6
0
        public void CopyTagsToInstallation_DoesNotThrowForNullTags()
        {
            Installation installation = MakeTestInstallation();

            NotificationInstallationsControllerMock.CopyTagsToInstallation(installation, null, true);
            IList <string> tagsOutput = installation.Tags;

            Assert.Null(tagsOutput);
        }
Exemple #7
0
        public void CopyTagsToInstallation_DoesNotThrowForEmptyTagsSet()
        {
            Installation     installation = MakeTestInstallation();
            HashSet <string> tags         = new HashSet <string>();

            NotificationInstallationsControllerMock.CopyTagsToInstallation(installation, tags, true);
            IList <string> tagsOutput = installation.Tags;

            Assert.NotNull(tagsOutput);
            Assert.True(tagsOutput.Count == 0);
        }
Exemple #8
0
        public void ValidateTemplate_DoesNotThrowOnNullTags(string platform)
        {
            NotificationTemplate template = MakeTestNotificationTemplate();

            template.Tags = null;
            if (!platform.Equals("wns", StringComparison.OrdinalIgnoreCase))
            {
                template.Headers = null;
            }

            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            mock.ValidateTemplate(template, platform);
        }
Exemple #9
0
        public void ValidateInstallationId_ThrowsOnNonGuid(string id)
        {
            bool testPass = false;
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            try
            {
                mock.ValidateInstallationId(id);
            }
            catch
            {
                testPass = true;
            }

            Assert.True(testPass);
        }
Exemple #10
0
        public void ValidateSecondaryTile_ThrowsOnNull()
        {
            bool testPass = false;
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

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

            Assert.True(testPass);
        }
Exemple #11
0
        public void ValidateTemplate_DoesNotThrowOnNullBody(string platform)
        {
            NotificationTemplate template = MakeTestNotificationTemplate();

            template.Headers = null;
            template.Body    = null;
            if (platform.Equals("wns", StringComparison.OrdinalIgnoreCase))
            {
                template.Headers = new Dictionary <string, string> {
                    { "header1", "value1" }
                };
            }

            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            mock.ValidateTemplate(template, platform);
        }
Exemple #12
0
        public void ValidateTemplate_ThrowsOnNullTemplate(string platform)
        {
            bool testPass = false;
            NotificationTemplate template = null;
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            try
            {
                mock.ValidateTemplate(template, platform);
            }
            catch
            {
                testPass = true;
            }

            Assert.True(testPass);
        }
Exemple #13
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);
        }
Exemple #14
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);
        }
Exemple #15
0
        public void ValidateTemplate_DoesNotThrowOnEmptyTags(string platform)
        {
            NotificationTemplate template = new NotificationTemplate()
            {
                Body    = "someString",
                Tags    = new List <string>(),
                Headers = null
            };

            if (platform.Equals("wns", StringComparison.OrdinalIgnoreCase))
            {
                template.Headers = new Dictionary <string, string>
                {
                    { "header1", "value1" }
                };
            }

            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            mock.ValidateTemplate(template, platform);
        }
 public void ValidateTemplate_WnsPlatformDoesNotThrowOnEmptyHeaders()
 {
     NotificationTemplate template = MakeTestNotificationTemplate();
     template.Headers = new Dictionary<string, string>();
     NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();
     mock.ValidateTemplate(template, "wns");
 }
Exemple #17
0
        public void ValidateInstallationId_PassesOnGuid(string id)
        {
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();

            mock.ValidateInstallationId(id);
        }
        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);
        }
        public void ValidateTemplate_DoesNotThrowOnNullBody(string platform)
        {
            NotificationTemplate template = MakeTestNotificationTemplate();
            template.Headers = null;
            template.Body = null;
            if (platform.Equals("wns", StringComparison.OrdinalIgnoreCase))
            {
                template.Headers = new Dictionary<string, string> { { "header1", "value1" } };
            }

            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();
            mock.ValidateTemplate(template, platform);
        }
 public void ValidateInstallationId_PassesOnGuid(string id)
 {
     NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();
     mock.ValidateInstallationId(id);
 }
        public void ValidateTemplate_DoesNotThrowOnEmptyTags(string platform)
        {
            NotificationTemplate template = new NotificationTemplate()
            {
                Body = "someString",
                Tags = new List<string>(),
                Headers = null
            };
            if (platform.Equals("wns", StringComparison.OrdinalIgnoreCase))
            {
                template.Headers = new Dictionary<string, string> 
                {
                    { "header1", "value1" }
                };
            }

            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();
            mock.ValidateTemplate(template, platform);
        }
        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);
        }
 public void ValidateTemplate_DoesNotThrowWhenHeadersIsNull(string platform)
 {
     NotificationTemplate template = MakeTestNotificationTemplate();
     template.Headers = null;
     NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();
     mock.ValidateTemplate(template, platform);
 }
        public void ValidateTemplate_ThrowsOnNullTemplate(string platform)
        {
            bool testPass = false;
            NotificationTemplate template = null;
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();
            try
            {
                mock.ValidateTemplate(template, platform);
            }
            catch
            {
                testPass = true;
            }

            Assert.True(testPass);
        }
        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);
        }
        public void ValidateSecondaryTile_ThrowsOnNull()
        {
            bool testPass = false;
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();
            try
            {
                mock.ValidateSecondaryTile(null);
            }
            catch
            {
                testPass = true;
            }

            Assert.True(testPass);
        }
        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);
        }
Exemple #28
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);
        }
        public void ValidateTemplate_DoesNotThrowOnNullTags(string platform)
        {
            NotificationTemplate template = MakeTestNotificationTemplate();
            template.Tags = null;
            if (!platform.Equals("wns", StringComparison.OrdinalIgnoreCase))
            {
                template.Headers = null;
            }

            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();
            mock.ValidateTemplate(template, platform);
        }
        public void ValidateTemplate_NonWnsPlatformThrowsWhenHeadersNonNull(string platform)
        {
            // Pass condition = exception thrown.
            bool testPass = false;
            NotificationTemplate template = new NotificationTemplate()
            {
                Body = "someString",
                Tags = new List<string>
                { 
                    "tag1",
                    "tag2"
                },
                Headers = new Dictionary<string, string>()
            };
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();
            try
            {
                mock.ValidateTemplate(template, platform);
            }
            catch
            {
                testPass = true;
            }

            Assert.True(testPass);
        }
        public void ValidateInstallationId_ThrowsOnNonGuid(string id)
        {
            bool testPass = false;
            NotificationInstallationsControllerMock mock = new NotificationInstallationsControllerMock();
            try
            {
                mock.ValidateInstallationId(id);
            }
            catch
            {
                testPass = true;
            }

            Assert.True(testPass);
        }