public void ValidateInvalidVersionSet()
        {
            var options = new ArmClientOptions();

            Assert.Throws <ArgumentException>(() => { options.SetApiVersion(new ResourceType("Microsoft.Compute/virtualMachines"), ""); });
            Assert.Throws <ArgumentNullException>(() => { options.SetApiVersion(new ResourceType("Microsoft.Compute/virtualMachines"), null); });
        }
        public void DoubleAddOverride()
        {
            var vmType  = new ResourceType("Microsoft.Compute/virtualMachines");
            var options = new ArmClientOptions();

            options.SetApiVersion(vmType, "foo");
            options.SetApiVersion(vmType, "bar");
            options.TryGetApiVersion(vmType, out var actualVersion);
            Assert.AreEqual("bar", actualVersion);
        }
Пример #3
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"));
        }
Пример #4
0
        public async Task VerifyOverrideEnumVersionUsed()
        {
            ResourceGroupVersionTracker tracker1 = new ResourceGroupVersionTracker();
            ResourceGroupVersionTracker tracker2 = new ResourceGroupVersionTracker();
            ArmClientOptions            options1 = new ArmClientOptions();
            string versionOverride = "2021-01-01";

            options1.SetApiVersion(ResourceGroupResource.ResourceType, versionOverride);
            ArmClientOptions options2 = new ArmClientOptions();

            options1.AddPolicy(tracker1, HttpPipelinePosition.PerCall);
            options2.AddPolicy(tracker2, HttpPipelinePosition.PerCall);
            var client1       = GetArmClient(options1);
            var client2       = GetArmClient(options2);
            var subscription1 = await client1.GetDefaultSubscriptionAsync();

            var subscription2 = await client2.GetDefaultSubscriptionAsync();

            var rgCollection1 = subscription1.GetResourceGroups();
            var rgCollection2 = subscription2.GetResourceGroups();

            _ = await rgCollection1.CreateOrUpdateAsync(WaitUntil.Completed, Recording.GenerateAssetName("testRg-"), new ResourceGroupData(AzureLocation.WestUS));

            _ = await rgCollection2.CreateOrUpdateAsync(WaitUntil.Completed, Recording.GenerateAssetName("testRg-"), new ResourceGroupData(AzureLocation.WestUS));

            Assert.AreEqual(versionOverride, tracker1.VersionUsed);
            Assert.AreEqual(GetDefaultResourceGroupVersion(rgCollection2), tracker2.VersionUsed);
        }
        public async Task ValidateOptionsTestApiVersions()
        {
            var fakeVersion = "1500-10-10";
            var x           = new ArmClientOptions();
            var y           = new ArmClientOptions();

            var clientX = GetArmClient(x);
            var clientY = GetArmClient(y);
            var subX    = await clientX.GetDefaultSubscriptionAsync();

            var subY = await clientY.GetDefaultSubscriptionAsync();

            var versionX = await subX.GetProviders().GetApiVersionAsync(ResourceGroup.ResourceType);

            var versionY = await subY.GetProviders().GetApiVersionAsync(ResourceGroup.ResourceType);

            Assert.AreEqual(versionX, versionY);
            Assert.AreNotEqual(versionY, fakeVersion);
            Assert.AreNotEqual(versionX, fakeVersion);

            x.SetApiVersion(ResourceGroup.ResourceType, fakeVersion);
            clientX = GetArmClient(x);
            subX    = await clientX.GetDefaultSubscriptionAsync();

            versionX = await subX.GetProviders().GetApiVersionAsync(ResourceGroup.ResourceType);

            versionY = await subY.GetProviders().GetApiVersionAsync(ResourceGroup.ResourceType);

            Assert.AreNotEqual(versionX, versionY);
        }
Пример #6
0
        public async Task GetGenericsBadApiVersion()
        {
            var              rgName  = Recording.GenerateAssetName("testrg");
            var              rgOp    = await(await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false)).GetResourceGroups().Construct(AzureLocation.WestUS2).CreateOrUpdateAsync(rgName);
            ResourceGroup    rg      = rgOp.Value;
            ArmClientOptions options = new ArmClientOptions();

            options.SetApiVersion(rg.Id.ResourceType, "1500-10-10");
            var client = GetArmClient(options);
            var genericResourceOperations    = client.GetGenericResource(rg.Id);
            RequestFailedException exception = Assert.ThrowsAsync <RequestFailedException>(async() => await genericResourceOperations.GetAsync());

            Assert.IsTrue(exception.Message.Contains("InvalidApiVersionParameter"));
        }