public NotificationHubAttributes UpdateNotificationHub(string resourceGroupName, string namespaceName, NotificationHubAttributes nhAttributes) { var parameter = new NotificationHubCreateOrUpdateParameters() { Location = nhAttributes.Location, Tags = new Dictionary<string, string>(nhAttributes.Tags), Properties = new NotificationHubProperties() { AdmCredential = nhAttributes.AdmCredential, ApnsCredential = nhAttributes.ApnsCredential, BaiduCredential = nhAttributes.BaiduCredential, GcmCredential = nhAttributes.GcmCredential, MpnsCredential = nhAttributes.MpnsCredential, WnsCredential = nhAttributes.WnsCredential, Name = nhAttributes.Name, RegistrationTtl = nhAttributes.RegistrationTtl } }; var response = Client.NotificationHubs.Update(resourceGroupName, namespaceName, nhAttributes.Name, parameter); return new NotificationHubAttributes(response.Value); }
/// <summary> /// Creates a new NotificationHub in a namespace. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/jj856303.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.NotificationHubs.INotificationHubOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='namespaceName'> /// Required. The namespace name. /// </param> /// <param name='notificationHubName'> /// Required. The notification hub name. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the create a Namespace Resource. /// </param> /// <returns> /// Response of the CreateOrUpdate operation on the NotificationHub /// </returns> public static Task<NotificationHubCreateOrUpdateResponse> UpdateAsync(this INotificationHubOperations operations, string resourceGroupName, string namespaceName, string notificationHubName, NotificationHubCreateOrUpdateParameters parameters) { return operations.UpdateAsync(resourceGroupName, namespaceName, notificationHubName, parameters, CancellationToken.None); }
public void NotificationHubCreateGetUpdateDelete() { using (var context = UndoContext.Current) { context.Start("ScenarioTests", "NotificationHubCreateGetUpdateDelete"); var location = NotificationHubsManagementHelper.DefaultLocation; var resourceGroup = this.ResourceManagementClient.TryGetResourceGroup(location); if (string.IsNullOrWhiteSpace(resourceGroup)) { resourceGroup = TestUtilities.GenerateName(NotificationHubsManagementHelper.ResourceGroupPrefix); this.ResourceManagementClient.TryRegisterResourceGroup(location, resourceGroup); } var namespaceName = TestUtilities.GenerateName(NotificationHubsManagementHelper.NamespacePrefix); var createNamespaceResponse = NotificationHubsManagementClient.Namespaces.CreateOrUpdate(resourceGroup, namespaceName, new NamespaceCreateOrUpdateParameters() { Location = location, Properties = new NamespaceProperties() { NamespaceType = NamespaceType.NotificationHub } }); Assert.NotNull(createNamespaceResponse); Assert.NotNull(createNamespaceResponse.Value); Assert.Equal(createNamespaceResponse.Value.Properties.Name, namespaceName); TestUtilities.Wait(TimeSpan.FromSeconds(30)); //Get the created namespace var getNamespaceResponse = NotificationHubsManagementClient.Namespaces.Get(resourceGroup, namespaceName); Assert.NotNull(getNamespaceResponse); Assert.NotNull(getNamespaceResponse.Value); if (string.Compare(getNamespaceResponse.Value.Properties.ProvisioningState, "Succeeded", true) != 0) TestUtilities.Wait(TimeSpan.FromSeconds(5)); Assert.Equal("Succeeded", getNamespaceResponse.Value.Properties.ProvisioningState, StringComparer.CurrentCultureIgnoreCase); Assert.Equal("Active", getNamespaceResponse.Value.Properties.Status, StringComparer.CurrentCultureIgnoreCase); //Create a notificationHub var notificationHubList = CreateNotificationHubs(location, resourceGroup, namespaceName, 1); var notificationHubName = notificationHubList.FirstOrDefault(); //Get the created notificationHub var getNotificationHubResponse = NotificationHubsManagementClient.NotificationHubs.Get(resourceGroup, namespaceName, notificationHubName); Assert.NotNull(getNotificationHubResponse); Assert.NotNull(getNotificationHubResponse.Value); Assert.Equal(getNotificationHubResponse.Value.Name, notificationHubName); //Get all namespaces created within a namespace var getAllNotificationHubsResponse = NotificationHubsManagementClient.NotificationHubs.List(resourceGroup, namespaceName); Assert.NotNull(getAllNotificationHubsResponse); Assert.NotNull(getAllNotificationHubsResponse.Value); Assert.True(getAllNotificationHubsResponse.Value.Count >= 1); Assert.True(getAllNotificationHubsResponse.Value.Any(nh => string.Compare(nh.Name, notificationHubName, true) == 0)); Assert.True(getAllNotificationHubsResponse.Value.All(nh => nh.Id.Contains(resourceGroup))); //Update notificationHub tags and add PNS credentials var updateNotificationHubParameter = new NotificationHubCreateOrUpdateParameters() { Location = location, Properties = new NotificationHubProperties() { WnsCredential = new WnsCredential() { Properties = new WnsCredentialProperties() { PackageSid = "ms-app://s-1-15-2-1817505189-427745171-3213743798-2985869298-800724128-1004923984-4143860699", SecretKey = "w7TBprR-9tJxn9mUOdK4PPHLCAzSYFhp", WindowsLiveEndpoint = @"http://pushtestservice.cloudapp.net/LiveID/accesstoken.srf" } } } }; updateNotificationHubParameter.Tags.Add(new KeyValuePair<string,string>("tag1", "value1")); updateNotificationHubParameter.Tags.Add(new KeyValuePair<string,string>("tag2", "value2")); updateNotificationHubParameter.Tags.Add(new KeyValuePair<string,string>("tag3", "value3")); var jsonStr = NotificationHubsManagementHelper.ConvertObjectToJSon(updateNotificationHubParameter); var updateNotificationHubResponse = NotificationHubsManagementClient.NotificationHubs.Update(resourceGroup, namespaceName, notificationHubName, updateNotificationHubParameter); Assert.NotNull(updateNotificationHubResponse); Assert.NotNull(updateNotificationHubResponse.Value); TestUtilities.Wait(TimeSpan.FromSeconds(30)); //Get the updated notificationHub getNotificationHubResponse = NotificationHubsManagementClient.NotificationHubs.Get(resourceGroup, namespaceName, notificationHubName); Assert.NotNull(getNotificationHubResponse); Assert.NotNull(getNotificationHubResponse.Value); Assert.Equal(getNotificationHubResponse.Value.Tags.Count, 3); foreach (var tag in updateNotificationHubParameter.Tags) { Assert.True(getNotificationHubResponse.Value.Tags.Any(t => t.Key.Equals(tag.Key))); Assert.True(getNotificationHubResponse.Value.Tags.Any(t => t.Value.Equals(tag.Value))); } //Get the updated notificationHub PNSCredentials var getNotificationHubPnsCredentialsResponse = NotificationHubsManagementClient.NotificationHubs.GetPnsCredentials(resourceGroup, namespaceName, notificationHubName); Assert.NotNull(getNotificationHubPnsCredentialsResponse); Assert.NotNull(getNotificationHubPnsCredentialsResponse.Value); Assert.Equal(notificationHubName, getNotificationHubPnsCredentialsResponse.Value.Name); Assert.NotNull(getNotificationHubPnsCredentialsResponse.Value.Properties); Assert.NotNull(getNotificationHubPnsCredentialsResponse.Value.Properties.WnsCredential); Assert.Equal(getNotificationHubPnsCredentialsResponse.Value.Properties.WnsCredential.Properties.PackageSid, updateNotificationHubParameter.Properties.WnsCredential.Properties.PackageSid); Assert.Equal(getNotificationHubPnsCredentialsResponse.Value.Properties.WnsCredential.Properties.SecretKey, updateNotificationHubParameter.Properties.WnsCredential.Properties.SecretKey); Assert.Equal(getNotificationHubPnsCredentialsResponse.Value.Properties.WnsCredential.Properties.WindowsLiveEndpoint, updateNotificationHubParameter.Properties.WnsCredential.Properties.WindowsLiveEndpoint); //Delete notificationHub var deleteResponse = NotificationHubsManagementClient.NotificationHubs.Delete(resourceGroup, namespaceName, notificationHubName); Assert.NotNull(deleteResponse); Assert.Equal(deleteResponse.StatusCode, HttpStatusCode.OK); TestUtilities.Wait(TimeSpan.FromSeconds(30)); try { NotificationHubsManagementClient.NotificationHubs.Get(resourceGroup, namespaceName, notificationHubName); Assert.True(false, "this step should have failed"); } catch (CloudException ex) { Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode); } //Delete namespace var deleteNSResponse = NotificationHubsManagementClient.Namespaces.Delete(resourceGroup, namespaceName); Assert.NotNull(deleteNSResponse); Assert.True(HttpStatusCode.NotFound == deleteNSResponse.StatusCode || HttpStatusCode.OK == deleteNSResponse.StatusCode); } }
/// <summary> /// Creates a new NotificationHub in a namespace. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/jj856303.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.NotificationHubs.INotificationHubOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='namespaceName'> /// Required. The namespace name. /// </param> /// <param name='notificationHubName'> /// Required. The notification hub name. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the create a Namespace Resource. /// </param> /// <returns> /// Response of the CreateOrUpdate operation on the NotificationHub /// </returns> public static NotificationHubCreateOrUpdateResponse Update(this INotificationHubOperations operations, string resourceGroupName, string namespaceName, string notificationHubName, NotificationHubCreateOrUpdateParameters parameters) { return Task.Factory.StartNew((object s) => { return ((INotificationHubOperations)s).UpdateAsync(resourceGroupName, namespaceName, notificationHubName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
private List<string> CreateNotificationHubs(string location, string resourceGroup, string namespaceName, int count) { List<string> notificationHubNameList = new List<string>(); for (int i = 0; i < count; i++) { var notificationHubName = TestUtilities.GenerateName(NotificationHubsManagementHelper.NotificationHubPrefix) + TestUtilities.GenerateName(); notificationHubNameList.Add(notificationHubName); Console.WriteLine(notificationHubName); var parameter = new NotificationHubCreateOrUpdateParameters() { Location = location, Properties = new NotificationHubProperties() }; var jsonStr = NotificationHubsManagementHelper.ConvertObjectToJSon(parameter); var createNotificationHubResponse = NotificationHubsManagementClient.NotificationHubs.Create(resourceGroup, namespaceName, notificationHubName, parameter); Assert.NotNull(createNotificationHubResponse); Assert.NotNull(createNotificationHubResponse.Value); } return notificationHubNameList; }