Example #1
0
        public async Task GetUsedResourceApiVersionWithOverride()
        {
            ProviderCounterPolicy policy  = new ProviderCounterPolicy();
            ArmClientOptions      options = new ArmClientOptions();

            options.AddPolicy(policy, HttpPipelinePosition.PerCall);

            string expectedVersion     = "myVersion";
            var    computeResourceType = new ResourceType("Microsoft.Compute/virtualMachines");

            options.SetApiVersion(computeResourceType, expectedVersion);

            var client       = GetArmClient(options);
            var subscription = await client.GetDefaultSubscriptionAsync();

            var version = await subscription.GetResourceProviders().GetApiVersionAsync(computeResourceType);

            Assert.AreEqual(expectedVersion, version);
            Assert.AreEqual(0, policy.GetCount("Microsoft.Compute"));
            Assert.AreEqual(0, policy.GetCount("Microsoft.Network"));

            policy  = new ProviderCounterPolicy();
            options = new ArmClientOptions();
            options.AddPolicy(policy, HttpPipelinePosition.PerCall);

            client       = GetArmClient(options);
            subscription = await client.GetDefaultSubscriptionAsync();

            version = await subscription.GetResourceProviders().GetApiVersionAsync(computeResourceType);

            Assert.AreNotEqual(expectedVersion, version);
            Assert.AreEqual(1, policy.GetCount("Microsoft.Compute"));
            Assert.AreEqual(0, policy.GetCount("Microsoft.Network"));
        }
        public async Task GetUsedResourceApiVersion()
        {
            ProviderCounterPolicy policy  = new ProviderCounterPolicy();
            ArmClientOptions      options = new ArmClientOptions();

            options.AddPolicy(policy, HttpPipelinePosition.PerCall);
            var client       = GetArmClient(options);
            var subscription = await client.GetDefaultSubscriptionAsync();

            var version = await subscription.GetProviders().TryGetApiVersionAsync(new ResourceType("Microsoft.Compute/virtualMachines"));

            Assert.NotNull(version);
            Assert.AreEqual(1, policy.GetCount("Microsoft.Compute"));
            Assert.AreEqual(0, policy.GetCount("Microsoft.Network"));

            version = await subscription.GetProviders().TryGetApiVersionAsync(new ResourceType("Microsoft.Compute/availabilitySets"));

            Assert.NotNull(version);
            Assert.AreEqual(1, policy.GetCount("Microsoft.Compute"));
            Assert.AreEqual(0, policy.GetCount("Microsoft.Network"));
        }