Example #1
0
        protected async Task <DeviceUpdateInstanceResource> CreateInstance(DeviceUpdateAccountResource account, string instanceName)
        {
            DeviceUpdateInstanceData input = ResourceDataHelper.CreateInstanceData();

            input.IotHubs.Add(new IotHubSettings("/subscriptions/cf65b9a6-fe0f-4011-881c-aba5a5fb8603/resourcegroups/edgarse/providers/Microsoft.Devices/IotHubs/orange-aducpsdktestaccount-iothub"));
            var lro = await account.GetDeviceUpdateInstances().CreateOrUpdateAsync(WaitUntil.Completed, instanceName, input);

            return(lro.Value);
        }
Example #2
0
        protected async Task <DeviceUpdateInstanceResource> CreateInstance(DeviceUpdateAccountResource account, string instanceName)
        {
            DeviceUpdateInstanceData input = ResourceDataHelper.CreateInstanceData();

            input.IotHubs.Add(new IotHubSettings("/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c/resourceGroups/DeviceUpdateResourceGroup/providers/Microsoft.Devices/IotHubs/orange-aducpsdktestaccount-iothub"));
            var lro = await account.GetDeviceUpdateInstances().CreateOrUpdateAsync(WaitUntil.Completed, instanceName, input);

            return(lro.Value);
        }
 public static void AssertAccountUpdate(DeviceUpdateAccountResource updatedAccount, DeviceUpdateAccountPatch updateParameters)
 {
     Assert.AreEqual(updatedAccount.Data.Location.ToString(), updateParameters.Location);
     if (updatedAccount.Data.Identity != null || updateParameters.Identity != null)
     {
         Assert.NotNull(updatedAccount.Data.Identity);
         Assert.NotNull(updateParameters.Identity);
         Assert.AreEqual(updatedAccount.Data.Identity.ManagedServiceIdentityType, updateParameters.Identity.ManagedServiceIdentityType);
     }
 }
Example #4
0
        public async Task CreateAccounts()
        {
            #region Snippet:Managing_Accounts_CreateAnAccount
            // Get the account collection from the specific resource group and create an account
            string accountName            = "myAccount";
            DeviceUpdateAccountData input = new DeviceUpdateAccountData(AzureLocation.WestUS2);
            ArmOperation <DeviceUpdateAccountResource> lro = await resourceGroup.GetDeviceUpdateAccounts().CreateOrUpdateAsync(WaitUntil.Completed, accountName, input);

            DeviceUpdateAccountResource account = lro.Value;
            #endregion Snippet:Managing_Accounts_CreateAnAccount
        }
Example #5
0
        public async Task CreateOrUpdate()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string accountName = Recording.GenerateAssetName("Account-");
            DeviceUpdateAccountResource account = await CreateAccount(rg, accountName);

            Assert.AreEqual(accountName, account.Data.Name);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetDeviceUpdateAccounts().CreateOrUpdateAsync(WaitUntil.Completed, null, account.Data));
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetDeviceUpdateAccounts().CreateOrUpdateAsync(WaitUntil.Completed, accountName, null));
        }
Example #6
0
        public async Task DeleteAccounts()
        {
            #region Snippet:Managing_Accounts_DeleteAnAccount
            // First we need to get the account collection from the specific resource group
            DeviceUpdateAccountCollection accountCollection = resourceGroup.GetDeviceUpdateAccounts();
            // Now we can get the account with GetAsync()
            DeviceUpdateAccountResource account = await accountCollection.GetAsync("myAccount");

            // With DeleteAsync(), we can delete the account
            await account.DeleteAsync(WaitUntil.Completed);

            #endregion Snippet:Managing_Accounts_DeleteAnAccount
        }
Example #7
0
        public async Task Get()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string accountName = Recording.GenerateAssetName("Account-");
            DeviceUpdateAccountResource account = await CreateAccount(rg, accountName);

            DeviceUpdateAccountResource getAccount = await rg.GetDeviceUpdateAccounts().GetAsync(accountName);

            ResourceDataHelper.AssertValidAccount(account, getAccount);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetDeviceUpdateAccounts().GetAsync(null));
        }
Example #8
0
        public async Task ListInstances()
        {
            #region Snippet:Managing_Instances_ListAllInstances
            // First we need to get the instance collection from the specific account
            DeviceUpdateAccountResource account = await resourceGroup.GetDeviceUpdateAccounts().GetAsync("myAccount");

            DeviceUpdateInstanceCollection instanceCollection = account.GetDeviceUpdateInstances();
            // With GetAllAsync(), we can get a list of the instances in the collection
            AsyncPageable <DeviceUpdateInstanceResource> response = instanceCollection.GetAllAsync();
            await foreach (DeviceUpdateInstanceResource instance in response)
            {
                Console.WriteLine(instance.Data.Name);
            }
            #endregion Snippet:Managing_Instances_ListAllInstances
        }
        public async Task Delete()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string accountName = Recording.GenerateAssetName("Account-");
            DeviceUpdateAccountResource account = await CreateAccount(rg, accountName);

            await account.DeleteAsync(WaitUntil.Completed);

            var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await account.GetAsync());

            Assert.AreEqual(404, ex.Status);
        }
Example #10
0
        public async Task DeleteInstances()
        {
            #region Snippet:Managing_Instances_DeleteAnInstance
            // First we need to get the instance collection from the specific account
            DeviceUpdateAccountResource account = await resourceGroup.GetDeviceUpdateAccounts().GetAsync("myAccount");

            DeviceUpdateInstanceCollection instanceCollection = account.GetDeviceUpdateInstances();
            // Now we can get the instance with GetAsync()
            DeviceUpdateInstanceResource instance = await instanceCollection.GetAsync("myInstance");

            // With DeleteAsync(), we can delete the instance
            await instance.DeleteAsync(WaitUntil.Completed);

            #endregion Snippet:Managing_Instances_DeleteAnInstance
        }
Example #11
0
        public async Task UpdateInstances()
        {
            #region Snippet:Managing_Instances_UpdateAnInstance
            // First we need to get the instance collection from the specific account
            DeviceUpdateAccountResource account = await resourceGroup.GetDeviceUpdateAccounts().GetAsync("myAccount");

            DeviceUpdateInstanceCollection instanceCollection = account.GetDeviceUpdateInstances();
            // Now we can get the instance with GetAsync()
            DeviceUpdateInstanceResource instance = await instanceCollection.GetAsync("myInstance");

            // With AddTagAsync(), we can add tag to the instance
            instance = await instance.AddTagAsync("newTag", "newValue");

            #endregion Snippet:Managing_Instances_UpdateAnInstance
        }
Example #12
0
        public async Task CreateInstances()
        {
            #region Snippet:Managing_Instances_CreateAnInstance
            // Create a new account
            string accountName             = "myAccount";
            DeviceUpdateAccountData input1 = new DeviceUpdateAccountData(AzureLocation.WestUS2);
            ArmOperation <DeviceUpdateAccountResource> lro1 = await resourceGroup.GetDeviceUpdateAccounts().CreateOrUpdateAsync(WaitUntil.Completed, accountName, input1);

            DeviceUpdateAccountResource account = lro1.Value;
            // Get the instance collection from the specific account and create an instance
            string instanceName             = "myInstance";
            DeviceUpdateInstanceData input2 = new DeviceUpdateInstanceData(AzureLocation.WestUS2);
            input2.IotHubs.Add(new IotHubSettings("/subscriptions/.../resourceGroups/.../providers/Microsoft.Devices/IotHubs/..."));
            ArmOperation <DeviceUpdateInstanceResource> lro2 = await account.GetDeviceUpdateInstances().CreateOrUpdateAsync(WaitUntil.Completed, instanceName, input2);

            DeviceUpdateInstanceResource instance = lro2.Value;
            #endregion Snippet:Managing_Instances_CreateAnInstance
        }
Example #13
0
        public async Task AddTag()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string accountName = Recording.GenerateAssetName("Account-");
            DeviceUpdateAccountResource account = await CreateAccount(rg, accountName);

            string instanceName = Recording.GenerateAssetName("Instance-");
            DeviceUpdateInstanceResource instance = await CreateInstance(account, instanceName);

            string key = "newTag", value = "newValue";
            DeviceUpdateInstanceResource updatedInstance = await instance.AddTagAsync(key, value);

            CollectionAssert.AreEquivalent(new Dictionary <string, string> {
                { key, value }
            }, updatedInstance.Data.Tags);
        }
Example #14
0
        public async Task UpdateAccounts()
        {
            #region Snippet:Managing_Accounts_UpdateAnAccount
            // First we need to get the account collection from the specific resource group
            DeviceUpdateAccountCollection accountCollection = resourceGroup.GetDeviceUpdateAccounts();
            // Now we can get the account with GetAsync()
            DeviceUpdateAccountResource account = await accountCollection.GetAsync("myAccount");

            // With UpdateAsync(), we can update the account
            DeviceUpdateAccountPatch updateOptions = new DeviceUpdateAccountPatch()
            {
                Location = AzureLocation.WestUS2,
                Identity = new ManagedServiceIdentity(ResourceManager.Models.ManagedServiceIdentityType.None)
            };
            ArmOperation <DeviceUpdateAccountResource> lro = await account.UpdateAsync(WaitUntil.Completed, updateOptions);

            account = lro.Value;
            #endregion Snippet:Managing_Accounts_UpdateAnAccount
        }
Example #15
0
        public async Task ListBySubscription()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string accountName = Recording.GenerateAssetName("Account-");
            DeviceUpdateAccountResource account = await CreateAccount(rg, accountName);

            int count = 0;

            await foreach (var tempAccount in subscription.GetDeviceUpdateAccountsAsync())
            {
                if (tempAccount.Data.Id == account.Data.Id)
                {
                    count++;
                }
            }
            Assert.AreEqual(count, 1);
        }
        public async Task Update()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string accountName = Recording.GenerateAssetName("Account-");
            DeviceUpdateAccountResource account = await CreateAccount(rg, accountName);

            DeviceUpdateAccountPatch updateOptions = new DeviceUpdateAccountPatch()
            {
                Location = AzureLocation.WestUS2,
                Identity = new ManagedServiceIdentity(ResourceManager.Models.ManagedServiceIdentityType.None)
            };
            var lro = await account.UpdateAsync(WaitUntil.Completed, updateOptions);

            DeviceUpdateAccountResource updatedAccount = lro.Value;

            ResourceDataHelper.AssertAccountUpdate(updatedAccount, updateOptions);
        }
Example #17
0
        public async Task List()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string accountName = Recording.GenerateAssetName("Account-");
            DeviceUpdateAccountResource account = await CreateAccount(rg, accountName);

            string instanceName = Recording.GenerateAssetName("Instance-");

            _ = await CreateInstance(account, instanceName);

            int count = 0;

            await foreach (var tempInstance in account.GetDeviceUpdateInstances().GetAllAsync())
            {
                count++;
            }
            Assert.AreEqual(count, 1);
        }
 public static void AssertValidAccount(DeviceUpdateAccountResource model, DeviceUpdateAccountResource getResult)
 {
     Assert.AreEqual(model.Data.Name, getResult.Data.Name);
     Assert.AreEqual(model.Data.Id, getResult.Data.Id);
     Assert.AreEqual(model.Data.ResourceType, getResult.Data.ResourceType);
     Assert.AreEqual(model.Data.Location, getResult.Data.Location);
     if (model.Data.Identity != null || getResult.Data.Identity != null)
     {
         Assert.NotNull(model.Data.Identity);
         Assert.NotNull(getResult.Data.Identity);
         Assert.AreEqual(model.Data.Identity.PrincipalId, getResult.Data.Identity.PrincipalId);
         Assert.AreEqual(model.Data.Identity.TenantId, getResult.Data.Identity.TenantId);
         Assert.AreEqual(model.Data.Identity.ManagedServiceIdentityType, getResult.Data.Identity.ManagedServiceIdentityType);
         Assert.AreEqual(model.Data.Identity.UserAssignedIdentities.Count, getResult.Data.Identity.UserAssignedIdentities.Count);
         foreach (var kv in model.Data.Identity.UserAssignedIdentities)
         {
             Assert.True(getResult.Data.Identity.UserAssignedIdentities.ContainsKey(kv.Key));
             Assert.AreEqual(kv.Value, getResult.Data.Identity.UserAssignedIdentities[kv.Key]);
         }
     }
     Assert.AreEqual(model.Data.ProvisioningState, getResult.Data.ProvisioningState);
     Assert.AreEqual(model.Data.HostName, getResult.Data.HostName);
     Assert.AreEqual(model.Data.PublicNetworkAccess, getResult.Data.PublicNetworkAccess);
 }