public void NestTemplate()
        {
            var Deployment = DeploymentOrchestrationInput.Validate(new DeploymentOrchestrationInput()
            {
                DeploymentName  = "NestTemplate",
                SubscriptionId  = TestHelper.SubscriptionId,
                ResourceGroup   = TestHelper.ResourceGroup,
                TemplateContent = GetTemplate("NestTemplate"),
                DeploymentId    = Guid.NewGuid().ToString("N"),
                GroupId         = Guid.NewGuid().ToString("N"),
                GroupType       = "ResourceGroup",
                HierarchyId     = "001002003004005"
            }, functions, infrastructure);

            Assert.Single(Deployment.Deployments);
            var d = Deployment.Deployments.First().Value;

            Assert.Equal("nestedTemplate1", d.DeploymentName);
            Assert.Equal("2017-05-10", d.ApiVersion);
            Assert.Equal(Deployment.RootId, d.RootId);
            Assert.NotNull(d.DeploymentId);

            Assert.NotNull(d.Template);
            var t = d.Template;

            Assert.Single(t.Resources);
            var res = t.Resources.First();

            Assert.Equal("storageAccount1", res.FullName);
            Assert.Equal("Microsoft.Storage/storageAccounts", res.FullType);
            var s = Deployment.Template.ToString();

            using var doc1 = JsonDocument.Parse(s);
            var root1 = doc1.RootElement;
        }
        public void VariableIteration()
        {
            var Deployment = DeploymentOrchestrationInput.Validate(new DeploymentOrchestrationInput()
            {
                DeploymentName  = "VariableIteration",
                TemplateContent = TestHelper.GetJsonFileContent("Templates/CopyIndex/VariableIteration")
            }, functions, infrastructure);

            using var doc = JsonDocument.Parse(Deployment.Template.Variables);
            var root = doc.RootElement;

            Assert.True(root.TryGetProperty("disk-array-on-object", out JsonElement ele1));
            Assert.True(ele1.TryGetProperty("disks", out JsonElement disks));
            Assert.True(ele1.TryGetProperty("diskNames", out JsonElement diskNames));
            Assert.Equal(5, disks.GetArrayLength());
            Assert.Equal(5, diskNames.GetArrayLength());
            Assert.True(root.TryGetProperty("top-level-object-array", out JsonElement ele2));
            Assert.Equal(5, ele2.GetArrayLength());
            Assert.True(root.TryGetProperty("top-level-string-array", out JsonElement ele3));
            Assert.Equal(5, ele3.GetArrayLength());
            Assert.True(root.TryGetProperty("top-level-integer-array", out JsonElement ele4));
            Assert.Equal(5, ele4.GetArrayLength());

            var s = Deployment.Template.ToString();

            using var doc1 = JsonDocument.Parse(s);
            var root1 = doc1.RootElement;
        }
        public void ExpressionEvaluationScopeOuter()
        {
            var Deployment = DeploymentOrchestrationInput.Validate(new DeploymentOrchestrationInput()
            {
                DeploymentName  = "ExpressionEvaluationScopeOuter",
                SubscriptionId  = TestHelper.SubscriptionId,
                ResourceGroup   = TestHelper.ResourceGroup,
                TemplateContent = GetTemplate("ExpressionsInNestedTemplates-outer")
            }, functions, infrastructure);

            Assert.Single(Deployment.Deployments);
            var d = Deployment.Deployments.First().Value;

            Assert.Equal("nestedTemplate1", d.DeploymentName);
            Assert.Equal("2017-05-10", d.ApiVersion);
            Assert.NotNull(d.Template);
            var t = d.Template;

            Assert.Single(t.Resources);
            var res = t.Resources.First();

            Assert.Equal("from parent template", res.FullName);
            var s = Deployment.Template.ToString();

            using var doc1 = JsonDocument.Parse(s);
            var root1 = doc1.RootElement;
        }
        public void PropertyIteration()
        {
            var Deployment = DeploymentOrchestrationInput.Validate(new DeploymentOrchestrationInput()
            {
                DeploymentName  = "PropertyIteration",
                SubscriptionId  = TestHelper.SubscriptionId,
                ResourceGroup   = TestHelper.ResourceGroup,
                TemplateContent = TestHelper.GetJsonFileContent("Templates/CopyIndex/PropertyIteration")
            }, functions, infrastructure);

            Assert.Single(Deployment.Template.Resources);
            var resource = Deployment.Template.Resources.First();

            using var doc = JsonDocument.Parse(resource.Properties);
            var root = doc.RootElement;

            Assert.True(root.TryGetProperty("storageProfile", out JsonElement storageProfile));
            Assert.True(storageProfile.TryGetProperty("dataDisks", out JsonElement dataDisks));
            Assert.Equal(3, dataDisks.GetArrayLength());
            int index = 0;

            foreach (var item in dataDisks.EnumerateArray())
            {
                Assert.True(item.TryGetProperty("lun", out JsonElement lun));
                Assert.Equal(index, lun.GetInt32());
                index++;
            }
            var s = Deployment.Template.ToString();

            using var doc1 = JsonDocument.Parse(s);
            var root1 = doc1.RootElement;
        }
 public void NoResources()
 {
     Assert.Equal("not find resources in template",
                  Assert.Throws <Exception>(() =>
     {
         DeploymentOrchestrationInput.Validate(new DeploymentOrchestrationInput()
         {
             DeploymentName  = "NoResources",
             TemplateContent = GetTemplate("NoResources")
         }, functions, infrastructure);
     }).Message);
 }
        public void DoubleNestTemplate()
        {
            var Deployment = DeploymentOrchestrationInput.Validate(new DeploymentOrchestrationInput()
            {
                DeploymentName  = "DoubleNestTemplate",
                SubscriptionId  = TestHelper.SubscriptionId,
                ResourceGroup   = TestHelper.ResourceGroup,
                TemplateContent = GetTemplate("DoubleNestTemplate"),
                DeploymentId    = Guid.NewGuid().ToString("N"),
                GroupId         = Guid.NewGuid().ToString("N"),
                GroupType       = "ResourceGroup",
                HierarchyId     = "001002003004005"
            }, functions, infrastructure);

            Assert.Equal(2, Deployment.Deployments.Count);

            var d1 = Deployment.Deployments["nestedTemplate1"];

            Assert.Equal("2017-05-10", d1.ApiVersion);
            Assert.Equal(Deployment.RootId, d1.RootId);
            Assert.NotNull(d1.DeploymentId);
            Assert.Empty(d1.Deployments);

            Assert.NotNull(d1.Template);
            var t = d1.Template;

            Assert.Single(t.Resources);
            var res = t.Resources.First();

            Assert.Equal("nestedTemplate2", res.FullName);
            Assert.Equal("Microsoft.Resources/deployments", res.FullType);

            var d2 = Deployment.Deployments["nestedTemplate2"];

            Assert.Equal("2017-05-10", d2.ApiVersion);
            Assert.Equal(Deployment.RootId, d2.RootId);
            Assert.NotNull(d2.DeploymentId);
            Assert.Empty(d2.Deployments);

            Assert.NotNull(d2.Template);
            var t2 = d2.Template;

            Assert.Single(t2.Resources);
            var res2 = t2.Resources.First();

            Assert.Equal("storageAccount1", res2.FullName);
            Assert.Equal("Microsoft.Storage/storageAccounts", res2.FullType);
        }
        public void EmptyTemplate()
        {
            var r = DeploymentOrchestrationInput.Validate(new DeploymentOrchestrationInput()
            {
                DeploymentName  = "EmptyTemplate",
                TemplateContent = GetTemplate("Empty")
            }, functions, infrastructure);

            Assert.NotNull(r);
            Assert.Empty(r.Template.Resources);
            Assert.Empty(r.Deployments);
            var s = r.Template.ToString();

            using var doc = JsonDocument.Parse(s);
            var root = doc.RootElement;
        }
        public void ChildResource()
        {
            var Deployment = DeploymentOrchestrationInput.Validate(new DeploymentOrchestrationInput()
            {
                DeploymentName  = "ChildResource",
                SubscriptionId  = TestHelper.SubscriptionId,
                ResourceGroup   = TestHelper.ResourceGroup,
                TemplateContent = GetTemplate("ChildResource")
            }, functions, infrastructure);

            Assert.Equal(2, Deployment.Template.Resources.Count);
            Assert.True(Deployment.Template.Resources.TryGetValue("VNet1", out Resource v));
            Assert.True(Deployment.Template.Resources.TryGetValue("Subnet1", out Resource s));
            Assert.Equal("Microsoft.Network/virtualNetworks", v.FullType);
            Assert.Equal("Microsoft.Network/virtualNetworks/subnets", s.FullType);
            var s1 = Deployment.Template.ToString();

            using var doc1 = JsonDocument.Parse(s1);
            var root1 = doc1.RootElement;
        }
        public void ResourceIteration()
        {
            var Deployment = DeploymentOrchestrationInput.Validate(new DeploymentOrchestrationInput()
            {
                DeploymentName  = "ResourceIteration",
                SubscriptionId  = TestHelper.SubscriptionId,
                ResourceGroup   = TestHelper.ResourceGroup,
                TemplateContent = TestHelper.GetJsonFileContent("Templates/CopyIndex/ResourceIteration")
            }, functions, infrastructure);

            Assert.True(Deployment.Template.Resources.ContainsKey("storagecopy"));
            Assert.Equal(3, Deployment.Template.Resources["storagecopy"].Resources.Count);
            var resource = Deployment.Template.Resources["storagecopy"].Resources.First();

            Assert.Equal("0storage", resource);
            Assert.Equal(4, Deployment.Template.Resources.Count);
            Assert.Equal("Microsoft.Storage/storageAccounts", Deployment.Template.Resources["0storage"].Type);

            var s = Deployment.Template.ToString();

            using var doc1 = JsonDocument.Parse(s);
            var root1 = doc1.RootElement;
        }