public void NotificationTemplate_Serialization_IsConsistent() { // Arrange NotificationTemplate testTemplate = new NotificationTemplate { Body = "myBody", Headers = new Dictionary<string, string>() }; testTemplate.Headers["myHeader2Name"] = "myHeader2Value"; testTemplate.Headers["myHeader1Name"] = "myHeader1Value"; testTemplate.Headers["myHeader3Name"] = "myHeader3Value"; // Assert SerializationAssert.VerifySerialization(testTemplate, "{\"body\":\"myBody\",\"headers\":{\"myHeader2Name\":\"myHeader2Value\",\"myHeader1Name\":\"myHeader1Value\",\"myHeader3Name\":\"myHeader3Value\"},\"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 ValidateTemplate(NotificationTemplate template, string platform) { if (template == null) { throw new HttpResponseException(this.Request.CreateBadRequestResponse(RResources.NotificationHub_TemplateWasNull.FormatForUser())); } if (template.Body == null) { template.Body = string.Empty; } if (platform.Equals(WindowsStorePlatform, StringComparison.OrdinalIgnoreCase)) { if (template.Headers != null) { foreach (string headerName in template.Headers.Keys) { if (string.IsNullOrEmpty(template.Headers[headerName])) { throw new HttpResponseException(this.Request.CreateBadRequestResponse(RResources.NotificationHub_EmptyHeaderValueInSecondaryTileForHeaderName.FormatForUser(headerName))); } } } } else if (platform.Equals(ApplePlatform, StringComparison.OrdinalIgnoreCase) || platform.Equals(GooglePlatform, StringComparison.OrdinalIgnoreCase)) { if (template.Headers != null) { throw new HttpResponseException(this.Request.CreateBadRequestResponse(RResources.NotificationHub_DoesNotSupportTemplateHeaders.FormatForUser(platform))); } } }
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; }
private static NotificationTemplate MakeTestNotificationTemplate() { NotificationTemplate template = new NotificationTemplate() { Body = "someString", Tags = new List<string> { "tag1", "tag2" }, Headers = new Dictionary<string, string> { { "headerName", "headerValue" } } }; return template; }
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_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_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); }