public async Task CreateRegistrationAsync_PassValidMpnsTemplateRegistration_GetCreatedRegistrationBack() { LoadMockData(); await DeleteAllRegistrationsAndInstallations(); var registration = new MpnsTemplateRegistrationDescription(_configuration["MpnsDeviceToken"], "<wp:Notification xmlns:wp=\"WPNotification\" Version=\"2.0\"><wp:Tile Id=\"TileId\" Template=\"IconicTile\"><wp:Title Action=\"Clear\">Title</wp:Title></wp:Tile></wp:Notification>", new [] { "tag1" }); registration.PushVariables = new Dictionary <string, string>() { { "var1", "value1" } }; registration.SecondaryTileName = "Tile name"; registration.TemplateName = "Template Name"; var createdRegistration = await _hubClient.CreateRegistrationAsync(registration); Assert.NotNull(createdRegistration.RegistrationId); Assert.NotNull(createdRegistration.ETag); Assert.NotNull(createdRegistration.ExpirationTime); Assert.Contains(new KeyValuePair <string, string>("var1", "value1"), createdRegistration.PushVariables); Assert.Contains("tag1", createdRegistration.Tags); Assert.Equal(registration.ChannelUri, createdRegistration.ChannelUri); Assert.Equal(registration.SecondaryTileName, createdRegistration.SecondaryTileName); Assert.Equal(registration.BodyTemplate.Value, createdRegistration.BodyTemplate.Value); Assert.Equal(registration.TemplateName, createdRegistration.TemplateName); RecordTestResults(); }
// PUT api/register/5 // This creates or updates a registration (with provided channelURI) at the specified id public async Task <HttpResponseMessage> Put(string id, DeviceRegistration deviceUpdate) { RegistrationDescription registration = null; switch (deviceUpdate.Platform) { case "mpns": var toastTemplate = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1>$(message)</wp:Text1>" + "</wp:Toast> " + "</wp:Notification>"; registration = new MpnsTemplateRegistrationDescription(deviceUpdate.Handle, toastTemplate); break; case "wns": toastTemplate = @"<toast><visual><binding template=""ToastText01""><text id=""1"">$(message)</text></binding></visual></toast>"; registration = new WindowsTemplateRegistrationDescription(deviceUpdate.Handle, toastTemplate); break; case "apns": var alertTemplate = "{\"aps\":{\"alert\":\"$(nameandmsg)\",\"badge\":1}}"; registration = new AppleTemplateRegistrationDescription(deviceUpdate.Handle, alertTemplate); break; case "gcm": var messageTemplate = "{\"data\":{\"msg\":\"$(message)\",\"senderid\":\"$(userid)\",\"sender\":\"$(username)\",\"icon\":\"$(usericon)\"}}"; registration = new GcmTemplateRegistrationDescription(deviceUpdate.Handle, messageTemplate); break; default: throw new HttpResponseException(HttpStatusCode.BadRequest); } registration.RegistrationId = id; registration.Tags = new HashSet <string>(deviceUpdate.Tags); try { await _hub.CreateOrUpdateRegistrationAsync(registration); } catch (MessagingException e) { ReturnGoneIfHubResponseIsGone(e); } return(Request.CreateResponse(HttpStatusCode.OK)); }
// PUT api/register/5 // This creates or updates a registration (with provided channelURI) at the specified id public async Task<HttpResponseMessage> Put(string id, DeviceRegistration deviceUpdate) { RegistrationDescription registration = null; switch (deviceUpdate.Platform) { case "mpns": var toastTemplate = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<wp:Notification xmlns:wp=\"WPNotification\">" + "<wp:Toast>" + "<wp:Text1>$(message)</wp:Text1>" + "</wp:Toast> " + "</wp:Notification>"; registration = new MpnsTemplateRegistrationDescription(deviceUpdate.Handle, toastTemplate); break; case "wns": toastTemplate = @"<toast><visual><binding template=""ToastText01""><text id=""1"">$(message)</text></binding></visual></toast>"; registration = new WindowsTemplateRegistrationDescription(deviceUpdate.Handle, toastTemplate); break; case "apns": var alertTemplate = "{\"aps\":{\"alert\":\"$(message)\"}}"; registration = new AppleTemplateRegistrationDescription(deviceUpdate.Handle, alertTemplate); break; case "gcm": var messageTemplate = "{\"data\":{\"msg\":\"$(message)\"}}"; registration = new GcmTemplateRegistrationDescription(deviceUpdate.Handle, messageTemplate); break; default: throw new HttpResponseException(HttpStatusCode.BadRequest); } registration.RegistrationId = id; registration.Tags = new HashSet<string>(deviceUpdate.Tags); try { await _hub.CreateOrUpdateRegistrationAsync(registration); } catch (MessagingException e) { ReturnGoneIfHubResponseIsGone(e); } return Request.CreateResponse(HttpStatusCode.OK); }