Exemple #1
0
        internal static string ToSerializedValue(this PoolAllocationMode value)
        {
            switch (value)
            {
            case PoolAllocationMode.BatchService:
                return("BatchService");

            case PoolAllocationMode.UserSubscription:
                return("UserSubscription");
            }
            return(null);
        }
Exemple #2
0
        public void BatchAccountContextFromResourceTest()
        {
            string             account         = "account";
            string             tenantUrlEnding = "batch-test.windows-int.net";
            string             endpoint        = string.Format("{0}.{1}", account, tenantUrlEnding);
            string             subscription    = "00000000-0000-0000-0000-000000000000";
            string             resourceGroup   = "resourceGroup";
            string             id             = string.Format("id/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Batch/batchAccounts/abc", subscription, resourceGroup);
            PoolAllocationMode allocationMode = PoolAllocationMode.UserSubscription;
            KeyVaultReference  keyVault       = new KeyVaultReference(
                string.Format("/subscriptions{0}/resourceGroups/{1}/providers/Microsoft.KeyVault/vaults/foo", subscription, resourceGroup),
                "https://foo.vaults.azure.com");

            BatchAccount resource = new BatchAccount(
                dedicatedCoreQuota: BatchTestHelpers.DefaultQuotaCount,
                lowPriorityCoreQuota: BatchTestHelpers.DefaultQuotaCount,
                poolQuota: BatchTestHelpers.DefaultQuotaCount,
                activeJobAndJobScheduleQuota: BatchTestHelpers.DefaultQuotaCount,
                accountEndpoint: endpoint,
                id: id,
                type: "type",
                location: "location",
                provisioningState: ProvisioningState.Succeeded,
                poolAllocationMode: allocationMode,
                keyVaultReference: keyVault);

            BatchAccountContext context = BatchAccountContext.ConvertAccountResourceToNewAccountContext(resource, null);

            Assert.Equal(resource.Id, context.Id);
            Assert.Equal(resource.AccountEndpoint, context.AccountEndpoint);
            Assert.Equal(resource.Location, context.Location);
            Assert.Equal(resource.ProvisioningState.ToString(), context.State);
            Assert.Equal(account, context.AccountName);
            Assert.Equal(string.Format("https://{0}", endpoint), context.TaskTenantUrl);
            Assert.Equal(subscription, context.Subscription);
            Assert.Equal(resourceGroup, context.ResourceGroupName);
            Assert.Equal(allocationMode, context.PoolAllocationMode);
            Assert.Equal(keyVault.Id, context.KeyVaultReference.Id);
            Assert.Equal(keyVault.Url, context.KeyVaultReference.Url);
        }
        public void CanCreateUserSubscriptionBatchAccount()
        {
            string                  accountName            = "account01";
            string                  resourceGroup          = "resourceGroup";
            string                  location               = "location";
            string                  keyVaultId             = "subscriptions/0000/resourceGroups/resourceGroup/providers/Microsoft.KeyVault/vaults/myVault";
            string                  keyVaultUrl            = "https://myVault.vault.azure.com";
            PoolAllocationMode      allocationMode         = PoolAllocationMode.UserSubscription;
            AccountCreateParameters actualCreateParameters = null;

            // Setup the mock client to return a fake response and capture the account create parameters
            BatchAccount        accountResource = BatchTestHelpers.CreateAccountResource(accountName, resourceGroup, location);
            BatchAccountContext fakeResponse    = BatchAccountContext.ConvertAccountResourceToNewAccountContext(accountResource, null);

            batchClientMock.Setup(b => b.CreateAccount(It.IsAny <AccountCreateParameters>()))
            .Returns(fakeResponse)
            .Callback((AccountCreateParameters p) => actualCreateParameters = p);

            // Setup and run the cmdlet
            cmdlet.AccountName        = accountName;
            cmdlet.ResourceGroupName  = resourceGroup;
            cmdlet.Location           = location;
            cmdlet.PoolAllocationMode = allocationMode;
            cmdlet.KeyVaultId         = keyVaultId;
            cmdlet.KeyVaultUrl        = keyVaultUrl;
            cmdlet.ExecuteCmdlet();

            // Verify the fake response was written to the pipeline and that the captured account create
            // parameters matched expectations.
            commandRuntimeMock.Verify(r => r.WriteObject(fakeResponse), Times.Once());
            Assert.Equal(accountName, actualCreateParameters.BatchAccount);
            Assert.Equal(resourceGroup, actualCreateParameters.ResourceGroup);
            Assert.Equal(location, actualCreateParameters.Location);
            Assert.Equal(allocationMode, actualCreateParameters.PoolAllocationMode);
            Assert.Equal(keyVaultId, actualCreateParameters.KeyVaultId);
            Assert.Equal(keyVaultUrl, actualCreateParameters.KeyVaultUrl);
        }