internal static TemplateSpecsListResult DeserializeTemplateSpecsListResult(JsonElement element) { Optional <IReadOnlyList <TemplateSpecData> > 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 <TemplateSpecData> array = new List <TemplateSpecData>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(TemplateSpecData.DeserializeTemplateSpecData(item)); } value = array; continue; } if (property.NameEquals("nextLink")) { nextLink = property.Value.GetString(); continue; } } return(new TemplateSpecsListResult(Optional.ToList(value), nextLink.Value)); }
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 templateSpecName = Recording.GenerateAssetName("templateSpec-G-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(templateSpecName, templateSpecData)).Value; TemplateSpec getTemplateSpec = await rg.GetTemplateSpecs().GetAsync(templateSpecName); AssertValidTemplateSpec(templateSpec, getTemplateSpec); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetTemplateSpecs().GetAsync(null)); }
public async Task Delete() { 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 templateSpecName = Recording.GenerateAssetName("templateSpec-G-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(templateSpecName, templateSpecData)).Value; await templateSpec.DeleteAsync(); var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await templateSpec.GetAsync()); Assert.AreEqual(404, ex.Status); }
public async Task CreateOrUpdate() { Subscription subscription = await Client.GetDefaultSubscriptionAsync(); string rgName = Recording.GenerateAssetName("testRg-1-"); ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2); var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, rgName, rgData); ResourceGroup rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-C-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(true, templateSpecName, templateSpecData)).Value; Assert.AreEqual(templateSpecName, templateSpec.Data.Name); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetTemplateSpecs().CreateOrUpdateAsync(true, null, templateSpecData)); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg.GetTemplateSpecs().CreateOrUpdateAsync(true, templateSpecName, null)); }
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 templateSpecName = Recording.GenerateAssetName("templateSpec-L-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); _ = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(templateSpecName, templateSpecData)).Value; int count = 0; await foreach (var tempTemplateSpec in rg.GetTemplateSpecs().GetAllAsync()) { count++; } Assert.AreEqual(count, 1); }
public async Task Get() { Subscription subscription = await Client.GetDefaultSubscriptionAsync(); string rgName = Recording.GenerateAssetName("testRg-3-"); ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2); var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, rgData); ResourceGroup rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-G-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(WaitUntil.Completed, templateSpecName, templateSpecData)).Value; const string version = "v1"; TemplateSpecVersionData templateSpecVersionData = CreateTemplateSpecVersionData(); TemplateSpecVersion templateSpecVersion = (await templateSpec.GetTemplateSpecVersions().CreateOrUpdateAsync(WaitUntil.Completed, version, templateSpecVersionData)).Value; TemplateSpecVersion getTemplateSpecVersion = await templateSpec.GetTemplateSpecVersions().GetAsync(version); AssertValidTemplateSpecVersion(templateSpecVersion, getTemplateSpecVersion); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await templateSpec.GetTemplateSpecVersions().GetAsync(null)); }
public async Task Delete() { SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync(); string rgName = Recording.GenerateAssetName("testRg-1-"); ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2); var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, rgData); ResourceGroupResource rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-C-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpecResource templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(WaitUntil.Completed, templateSpecName, templateSpecData)).Value; const string version = "v1"; TemplateSpecVersionData templateSpecVersionData = CreateTemplateSpecVersionData(); TemplateSpecVersionResource templateSpecVersion = (await templateSpec.GetTemplateSpecVersions().CreateOrUpdateAsync(WaitUntil.Completed, version, templateSpecVersionData)).Value; await templateSpecVersion.DeleteAsync(WaitUntil.Completed); var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await templateSpecVersion.GetAsync()); Assert.AreEqual(404, ex.Status); }
public async Task ListBySubscription() { 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 templateSpecName = Recording.GenerateAssetName("templateSpec-L-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(true, templateSpecName, templateSpecData)).Value; int count = 0; await foreach (var tempTemplateSpec in subscription.GetTemplateSpecsAsync()) { if (tempTemplateSpec.Data.Id == templateSpec.Data.Id) { count++; } } Assert.AreEqual(count, 1); }
public async Task List() { Subscription subscription = await Client.GetDefaultSubscriptionAsync(); string rgName = Recording.GenerateAssetName("testRg-2-"); ResourceGroupData rgData = new ResourceGroupData(AzureLocation.WestUS2); var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, rgData); ResourceGroup rg = lro.Value; string templateSpecName = Recording.GenerateAssetName("templateSpec-L-"); TemplateSpecData templateSpecData = CreateTemplateSpecData(templateSpecName); TemplateSpec templateSpec = (await rg.GetTemplateSpecs().CreateOrUpdateAsync(WaitUntil.Completed, templateSpecName, templateSpecData)).Value; const string version = "v1"; TemplateSpecVersionData templateSpecVersionData = CreateTemplateSpecVersionData(); _ = (await templateSpec.GetTemplateSpecVersions().CreateOrUpdateAsync(WaitUntil.Completed, version, templateSpecVersionData)).Value; int count = 0; await foreach (var tempTemplateSpecVersion in templateSpec.GetTemplateSpecVersions().GetAllAsync()) { count++; } Assert.AreEqual(count, 1); }