예제 #1
0
        public async Task ListBySub()
        {
            Subscription subscription = await Client.GetDefaultSubscriptionAsync();

            string            rgName = Recording.GenerateAssetName("testRg-3-");
            ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2);
            var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, rgName, rgData);

            ResourceGroup        rg = lro.Value;
            string               deployScriptName     = Recording.GenerateAssetName("deployScript-L-");
            DeploymentScriptData deploymentScriptData = await GetDeploymentScriptDataAsync();

            _ = await rg.GetDeploymentScripts().CreateOrUpdateAsync(true, deployScriptName, deploymentScriptData);

            int count = 0;

            await foreach (var tempDeploymentScript in subscription.GetDeploymentScriptsAsync())
            {
                if (tempDeploymentScript.Data.Name == deployScriptName)
                {
                    count++;
                }
            }
            Assert.AreEqual(count, 1);
        }
예제 #2
0
        internal static DeploymentScriptListResult DeserializeDeploymentScriptListResult(JsonElement element)
        {
            Optional <IReadOnlyList <DeploymentScriptData> > value = default;
            Optional <string> nextLink = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <DeploymentScriptData> array = new List <DeploymentScriptData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(DeploymentScriptData.DeserializeDeploymentScriptData(item));
                    }
                    value = array;
                    continue;
                }
                if (property.NameEquals("nextLink"))
                {
                    nextLink = property.Value.GetString();
                    continue;
                }
            }
            return(new DeploymentScriptListResult(Optional.ToList(value), nextLink.Value));
        }
        DeploymentScript IOperationSource <DeploymentScript> .CreateResult(Response response, CancellationToken cancellationToken)
        {
            using var document = JsonDocument.Parse(response.ContentStream);
            var data = DeploymentScriptData.DeserializeDeploymentScriptData(document.RootElement);

            return(new DeploymentScript(_armClient, data));
        }
예제 #4
0
        public async Task CreateOrUpdate()
        {
            string            rgName = Recording.GenerateAssetName("testRg-1-");
            ResourceGroupData rgData = new ResourceGroupData(Location.WestUS2);
            var lro = await Client.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(rgName, rgData);

            ResourceGroup        rg = lro.Value;
            string               deployScriptName     = Recording.GenerateAssetName("deployScript-C-");
            DeploymentScriptData deploymentScriptData = await GetDeploymentScriptDataAsync();

            DeploymentScript deploymentScript = (await rg.GetDeploymentScripts().CreateOrUpdateAsync(deployScriptName, deploymentScriptData)).Value;

            Assert.AreEqual(deployScriptName, deploymentScript.Data.Name);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetDeploymentScripts().CreateOrUpdateAsync(null, deploymentScriptData));
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetDeploymentScripts().CreateOrUpdateAsync(deployScriptName, null));
        }
        public async Task Delete()
        {
            string            rgName = Recording.GenerateAssetName("testRg-5-");
            ResourceGroupData rgData = new ResourceGroupData(Location.WestUS2);
            var lro = await Client.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(rgName, rgData);

            ResourceGroup        rg = lro.Value;
            string               deployScriptName     = Recording.GenerateAssetName("deployScript-D-");
            DeploymentScriptData deploymentScriptData = await GetDeploymentScriptDataAsync();

            DeploymentScript deploymentScript = (await rg.GetDeploymentScripts().CreateOrUpdateAsync(deployScriptName, deploymentScriptData)).Value;
            await deploymentScript.DeleteAsync();

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

            Assert.AreEqual(404, ex.Status);
        }
예제 #6
0
        public async Task Get()
        {
            string            rgName = Recording.GenerateAssetName("testRg-4-");
            ResourceGroupData rgData = new ResourceGroupData(Location.WestUS2);
            var lro = await Client.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(rgName, rgData);

            ResourceGroup        rg = lro.Value;
            string               deployScriptName     = Recording.GenerateAssetName("deployScript-G-");
            DeploymentScriptData deploymentScriptData = await GetDeploymentScriptDataAsync();

            DeploymentScript      tempDeploymentScript    = (await rg.GetDeploymentScripts().CreateOrUpdateAsync(deployScriptName, deploymentScriptData)).Value;
            AzurePowerShellScript deploymentScript        = tempDeploymentScript.Data as AzurePowerShellScript;
            DeploymentScript      tempGetDeploymentScript = await rg.GetDeploymentScripts().GetAsync(deployScriptName);

            AzurePowerShellScript getdeploymentScript = tempGetDeploymentScript.Data as AzurePowerShellScript;

            AssertValidDeploymentScript(deploymentScript, getdeploymentScript);
        }
예제 #7
0
        public async Task ListByRg()
        {
            string            rgName = Recording.GenerateAssetName("testRg-2-");
            ResourceGroupData rgData = new ResourceGroupData(Location.WestUS2);
            var lro = await Client.DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync(rgName, rgData);

            ResourceGroup        rg = lro.Value;
            string               deployScriptName     = Recording.GenerateAssetName("deployScript-L-");
            DeploymentScriptData deploymentScriptData = await GetDeploymentScriptDataAsync();

            _ = await rg.GetDeploymentScripts().CreateOrUpdateAsync(deployScriptName, deploymentScriptData);

            int count = 0;

            await foreach (var tempDeploymentScript in rg.GetDeploymentScripts().GetAllAsync())
            {
                count++;
            }
            Assert.AreEqual(count, 1);
        }