public void NewBatchWithAutoStorageAccountTest()
        {
            string accountName   = "account01";
            string resourceGroup = "resourceGroup";
            string location      = "location";
            string storageId     = "storageId";
            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.AutoStorageAccountId = storageId;
            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(storageId, actualCreateParameters.AutoStorageAccountId);
        }
        protected override void ExecuteCmdletImpl()
        {
            Dictionary <string, UserAssignedIdentities> identityDictionary = null;

            if (IdentityType == ResourceIdentityType.UserAssigned)
            {
                if (IdentityId == null)
                {
                    throw new PSArgumentNullException("IdentityId", "IdentityId must be provided when IdentityType is set to UserAssigned.");
                }

                identityDictionary = IdentityId.ToDictionary(i => i, i => new UserAssignedIdentities());
            }

            AccountCreateParameters parameters = new AccountCreateParameters(this.ResourceGroupName, this.AccountName, this.Location)
            {
                AutoStorageAccountId = this.AutoStorageAccountId,
                PoolAllocationMode   = this.PoolAllocationMode,
                KeyVaultId           = this.KeyVaultId,
                KeyVaultUrl          = this.KeyVaultUrl,
                Tags = this.Tag,
                PublicNetworkAccess = this.PublicNetworkAccess,
                Identity            = new BatchAccountIdentity(IdentityType, null, null, identityDictionary)
            };

            BatchAccountContext context = BatchClient.CreateAccount(parameters);

            WriteObject(context);
        }
        public override void ExecuteCmdlet()
        {
            AccountCreateParameters parameters = new AccountCreateParameters(this.ResourceGroupName, this.AccountName, this.Location)
            {
                AutoStorageAccountId = this.AutoStorageAccountId,
                PoolAllocationMode   = this.PoolAllocationMode,
                KeyVaultId           = this.KeyVaultId,
                KeyVaultUrl          = this.KeyVaultUrl,
                Tags = this.Tag
            };
            BatchAccountContext context = BatchClient.CreateAccount(parameters);

            WriteObject(context);
        }
        protected override void ExecuteCmdletImpl()
        {
            AccountCreateParameters parameters = new AccountCreateParameters(this.ResourceGroupName, this.AccountName, this.Location)
            {
                AutoStorageAccountId = this.AutoStorageAccountId,
                PoolAllocationMode   = this.PoolAllocationMode,
                KeyVaultId           = this.KeyVaultId,
                KeyVaultUrl          = this.KeyVaultUrl,
                Tags = this.Tag,
                PublicNetworkAccess = this.PublicNetworkAccess,
                Identity            = new BatchAccountIdentity(this.IdentityType)
            };
            BatchAccountContext context = BatchClient.CreateAccount(parameters);

            WriteObject(context);
        }
        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);
        }