public async Task List() { TenantResource tenant = await Client.GetTenants().GetAllAsync().FirstOrDefaultAsync(_ => true); SubscriptionResource subscription = await tenant.GetSubscriptions().GetAllAsync().FirstOrDefaultAsync(_ => true); string rgName = Recording.GenerateAssetName("testRg-"); ResourceGroupResource rg = await CreateResourceGroup(subscription, rgName); string vnName1 = Recording.GenerateAssetName("testVn-"); string vnName2 = Recording.GenerateAssetName("testVn-"); string vnName3 = Recording.GenerateAssetName("testVn-"); GenericResource vn1 = await CreateGenericVirtualNetwork(subscription, rg, vnName1); GenericResource vn2 = await CreateGenericVirtualNetwork(subscription, rg, vnName2); GenericResource vn3 = await CreateGenericVirtualNetwork(subscription, rg, vnName3); string resourceLinkName1 = Recording.GenerateAssetName("link-"); string resourceLinkName2 = Recording.GenerateAssetName("link-"); _ = await CreateResourceLink(tenant, vn1, vn2, resourceLinkName1); _ = await CreateResourceLink(tenant, vn1, vn3, resourceLinkName2); int count = 0; await foreach (var resourceLink in tenant.GetResourceLinks(vn1.Id).GetAllAsync()) { count++; } Assert.AreEqual(count, 2); }
protected async Task <ResourceLinkResource> CreateResourceLink(TenantResource tenant, GenericResource vn1, GenericResource vn2, string resourceLinkName) { ResourceIdentifier resourceLinkId = new ResourceIdentifier(vn1.Id + "/providers/Microsoft.Resources/links/" + resourceLinkName); ResourceLinkProperties properties = new ResourceLinkProperties(vn2.Id); ResourceLinkData data = new ResourceLinkData() { Properties = properties }; ArmOperation <ResourceLinkResource> lro = await tenant.GetResourceLinks(resourceLinkId).CreateOrUpdateAsync(WaitUntil.Completed, data); return(lro.Value); }
public async Task CreateOrUpdate() { TenantResource tenant = await Client.GetTenants().GetAllAsync().FirstOrDefaultAsync(_ => true); SubscriptionResource subscription = await tenant.GetSubscriptions().GetAllAsync().FirstOrDefaultAsync(_ => true); string rgName = Recording.GenerateAssetName("testRg-"); ResourceGroupResource rg = await CreateResourceGroup(subscription, rgName); string vnName1 = Recording.GenerateAssetName("testVn-"); string vnName2 = Recording.GenerateAssetName("testVn-"); GenericResource vn1 = await CreateGenericVirtualNetwork(subscription, rg, vnName1); GenericResource vn2 = await CreateGenericVirtualNetwork(subscription, rg, vnName2); string resourceLinkName = Recording.GenerateAssetName("link-"); ResourceLinkResource resourceLink = await CreateResourceLink(tenant, vn1, vn2, resourceLinkName); Assert.AreEqual(resourceLinkName, resourceLink.Data.Name); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await tenant.GetResourceLinks(null).CreateOrUpdateAsync(WaitUntil.Completed, null)); Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await tenant.GetResourceLinks(rg.Id).CreateOrUpdateAsync(WaitUntil.Completed, null)); }