public void BlobServiceTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                var    account     = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, true);

                // implement case
                try
                {
                    BlobServiceProperties properties1 = storageMgmtClient.BlobServices.GetServiceProperties(rgName, accountName);
                    Assert.False(properties1.DeleteRetentionPolicy.Enabled);
                    Assert.Null(properties1.DeleteRetentionPolicy.Days);
                    Assert.Null(properties1.DefaultServiceVersion);
                    Assert.Equal(0, properties1.Cors.CorsRulesProperty.Count);
                    //Assert.Null(properties1.AutomaticSnapshotPolicyEnabled);
                    BlobServiceProperties properties2 = properties1;
                    properties2.DeleteRetentionPolicy         = new DeleteRetentionPolicy();
                    properties2.DeleteRetentionPolicy.Enabled = true;
                    properties2.DeleteRetentionPolicy.Days    = 300;
                    properties2.DefaultServiceVersion         = "2017-04-17";
                    //properties2.AutomaticSnapshotPolicyEnabled = true;
                    storageMgmtClient.BlobServices.SetServiceProperties(rgName, accountName, properties2);
                    BlobServiceProperties properties3 = storageMgmtClient.BlobServices.GetServiceProperties(rgName, accountName);
                    Assert.True(properties3.DeleteRetentionPolicy.Enabled);
                    Assert.Equal(300, properties3.DeleteRetentionPolicy.Days);
                    Assert.Equal("2017-04-17", properties3.DefaultServiceVersion);
                    //Assert.True(properties3.AutomaticSnapshotPolicyEnabled);
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Пример #2
0
        public void BlobContainersCreateDeleteTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                var    account     = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, true);

                // implement case
                try
                {
                    string        containerName = TestUtilities.GenerateName("container");
                    BlobContainer blobContainer = storageMgmtClient.BlobContainers.Create(rgName, accountName, containerName);
                    Assert.Null(blobContainer.Metadata);
                    Assert.Null(blobContainer.PublicAccess);

                    blobContainer = storageMgmtClient.BlobContainers.Get(rgName, accountName, containerName);
                    Assert.Null(blobContainer.Metadata);
                    Assert.Equal(PublicAccess.None, blobContainer.PublicAccess);
                    Assert.False(blobContainer.HasImmutabilityPolicy);
                    Assert.False(blobContainer.HasLegalHold);

                    //Delete container, then no container in the storage account
                    storageMgmtClient.BlobContainers.Delete(rgName, accountName, containerName);
                    IPage <ListContainerItem> blobContainers = storageMgmtClient.BlobContainers.List(rgName, accountName);
                    Assert.Empty(blobContainers.ToList());

                    //Delete not exist container, won't fail (return 204)
                    storageMgmtClient.BlobContainers.Delete(rgName, accountName, containerName);
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Пример #3
0
        public void FileSharesUpdateGetTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                var    account     = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, true);

                // implement case
                try
                {
                    string    shareName = TestUtilities.GenerateName("share");
                    FileShare share     = storageMgmtClient.FileShares.Create(rgName, accountName, shareName);
                    Assert.Null(share.Metadata);

                    Dictionary <string, string> metaData = new Dictionary <string, string>();
                    metaData.Add("metadata1", "true");
                    metaData.Add("metadata2", "value2");
                    int shareQuota = 501;
                    var shareSet   = storageMgmtClient.FileShares.Update(rgName, accountName, shareName, metaData, shareQuota);
                    Assert.NotNull(shareSet.Metadata);
                    Assert.Equal(shareQuota, shareSet.ShareQuota);
                    Assert.Equal(metaData, shareSet.Metadata);

                    var shareGet = storageMgmtClient.FileShares.Get(rgName, accountName, shareName);
                    Assert.NotNull(shareGet.Metadata);
                    Assert.Equal(metaData, shareGet.Metadata);
                    Assert.Equal(shareQuota, shareGet.ShareQuota);
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
        public void StorageAccountCreateTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();

                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                StorageAccountCreateParameters parameters = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                var createRequest = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);

                Assert.Equal(createRequest.StorageAccount.Location, StorageManagementTestUtilities.DefaultLocation);
                Assert.Equal(createRequest.StorageAccount.AccountType, AccountType.StandardGRS);
                Assert.Equal(createRequest.StorageAccount.Tags.Count, 2);

                // Make sure a second create returns immediately
                createRequest = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                Assert.Equal(createRequest.StatusCode, HttpStatusCode.OK);

                Assert.Equal(createRequest.StorageAccount.Location, StorageManagementTestUtilities.DefaultLocation);
                Assert.Equal(createRequest.StorageAccount.AccountType, AccountType.StandardGRS);
                Assert.Equal(createRequest.StorageAccount.Tags.Count, 2);

                // Create storage account with only required params
                accountName = TestUtilities.GenerateName("sto");
                parameters  = new StorageAccountCreateParameters
                {
                    AccountType = AccountType.StandardGRS,
                    Location    = StorageManagementTestUtilities.DefaultLocation
                };
                createRequest = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);

                Assert.Equal(createRequest.StorageAccount.Location, StorageManagementTestUtilities.DefaultLocation);
                Assert.Equal(createRequest.StorageAccount.AccountType, AccountType.StandardGRS);
                Assert.Empty(createRequest.StorageAccount.Tags);
            }
        }
Пример #5
0
        public void StorageAccountCreateWithAccessTierTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account with hot
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Sku = new Sku {
                        Name = SkuName.StandardGRS
                    },
                    Kind       = Kind.BlobStorage,
                    Location   = StorageManagementTestUtilities.DefaultLocation,
                    AccessTier = AccessTier.Hot
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, false);
                Assert.Equal(AccessTier.Hot, account.AccessTier);
                Assert.Equal(Kind.BlobStorage, account.Kind);

                // Create storage account with cool
                accountName = TestUtilities.GenerateName("sto");
                parameters  = new StorageAccountCreateParameters
                {
                    Sku = new Sku {
                        Name = SkuName.StandardGRS
                    },
                    Kind       = Kind.BlobStorage,
                    Location   = StorageManagementTestUtilities.DefaultLocation,
                    AccessTier = AccessTier.Cool
                };
                account = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, false);
                Assert.Equal(AccessTier.Cool, account.AccessTier);
                Assert.Equal(Kind.BlobStorage, account.Kind);
            }
        }
Пример #6
0
        public void StorageAccountGetStandardTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Default parameters
                var parameters = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();

                // Create and get a LRS storage account
                string accountName = TestUtilities.GenerateName("sto");
                parameters.Sku.Name = SkuName.StandardLRS;
                storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                var account = storageMgmtClient.StorageAccounts.GetProperties(rgname, accountName);
                StorageManagementTestUtilities.VerifyAccountProperties(account, false);

                // Create and get a GRS storage account
                accountName         = TestUtilities.GenerateName("sto");
                parameters.Sku.Name = SkuName.StandardGRS;
                storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                account = storageMgmtClient.StorageAccounts.GetProperties(rgname, accountName);
                StorageManagementTestUtilities.VerifyAccountProperties(account, true);

                // Create and get a RAGRS storage account
                accountName         = TestUtilities.GenerateName("sto");
                parameters.Sku.Name = SkuName.StandardRAGRS;
                storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                account = storageMgmtClient.StorageAccounts.GetProperties(rgname, accountName);
                StorageManagementTestUtilities.VerifyAccountProperties(account, false);

                // Create and get a ZRS storage account
                accountName         = TestUtilities.GenerateName("sto");
                parameters.Sku.Name = SkuName.StandardZRS;
                storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                account = storageMgmtClient.StorageAccounts.GetProperties(rgname, accountName);
                StorageManagementTestUtilities.VerifyAccountProperties(account, false);
            }
        }
Пример #7
0
        public void StorageAccountBeginCreateTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();

                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                StorageAccountCreateParameters parameters = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                StorageAccountCreateResponse   response   = storageMgmtClient.StorageAccounts.BeginCreate(rgname, accountName, parameters);
                Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);

                // Poll for creation
                while (response.StatusCode == HttpStatusCode.Accepted)
                {
                    TestUtilities.Wait(response.RetryAfter * 1000);
                    response = storageMgmtClient.GetCreateOperationStatus(response.OperationStatusLink);
                }

                // Verify create succeeded
                StorageAccount result = response.StorageAccount;
                Assert.Equal(result.Location, StorageManagementTestUtilities.DefaultLocation);
                Assert.Equal(result.AccountType, AccountType.StandardGRS);
                Assert.Equal(result.Tags.Count, 2);

                // Make sure a second create returns immediately
                response = storageMgmtClient.StorageAccounts.BeginCreate(rgname, accountName, parameters);
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                // Verify create succeeded
                Assert.Equal(result.Location, StorageManagementTestUtilities.DefaultLocation);
                Assert.Equal(result.AccountType, AccountType.StandardGRS);
                Assert.Equal(result.Tags.Count, 2);
            }
        }
Пример #8
0
        public void StorageAccountBeginCreateTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                var    response    = storageMgmtClient.StorageAccounts.BeginCreate(rgname, accountName, parameters);
            }
        }
Пример #9
0
        public void StorageAccountUpdateMultipleTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = StorageManagementTestUtilities.CreateStorageAccount(storageMgmtClient, rgname);

                // Update storage account type
                var parameters = new StorageAccountUpdateParameters
                {
                    Sku = new Sku {
                        Name = SkuName.StandardLRS
                    },
                    Tags = new Dictionary <string, string>
                    {
                        { "key3", "value3" },
                        { "key4", "value4" },
                        { "key5", "value6" }
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Update(rgname, accountName, parameters);
                Assert.Equal(account.Sku.Name, SkuName.StandardLRS);
                Assert.Equal(account.Tags.Count, parameters.Tags.Count);

                // Validate
                account = storageMgmtClient.StorageAccounts.GetProperties(rgname, accountName);
                Assert.Equal(account.Sku.Name, SkuName.StandardLRS);
                Assert.Equal(account.Tags.Count, parameters.Tags.Count);
            }
        }
Пример #10
0
        public void StorageAccountCheckNameTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();

                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(handler);
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(handler);

                // Create resource group
                string rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Check valid name
                string accountName      = TestUtilities.GenerateName("sto");
                var    checkNameRequest = storageMgmtClient.StorageAccounts.CheckNameAvailability(accountName);
                Assert.Equal(true, checkNameRequest.NameAvailable);
                Assert.Equal(null, checkNameRequest.Reason);
                Assert.Equal(null, checkNameRequest.Message);

                // Check invalid name
                accountName      = "CAPS";
                checkNameRequest = storageMgmtClient.StorageAccounts.CheckNameAvailability(accountName);
                Assert.Equal(false, checkNameRequest.NameAvailable);
                Assert.Equal(Reason.AccountNameInvalid, checkNameRequest.Reason);
                Assert.Equal("CAPS is not a valid storage account name. Storage account name must be between 3 and 24 "
                             + "characters in length and use numbers and lower-case letters only.", checkNameRequest.Message);

                // Check name of account that already exists
                accountName      = StorageManagementTestUtilities.CreateStorageAccount(storageMgmtClient, rgname);
                checkNameRequest = storageMgmtClient.StorageAccounts.CheckNameAvailability(accountName);
                Assert.Equal(false, checkNameRequest.NameAvailable);
                Assert.Equal(Reason.AlreadyExists, checkNameRequest.Reason);
                Assert.Equal("The storage account named " + accountName + " is already taken.", checkNameRequest.Message);
            }
        }
Пример #11
0
        public void StorageAccountCreateTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                var    account     = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, true);

                // Make sure a second create returns immediately
                var createRequest = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, true);

                // Create storage account with only required params
                accountName = TestUtilities.GenerateName("sto");
                parameters  = new StorageAccountCreateParameters
                {
                    Sku = new Sku {
                        Name = StorageManagementTestUtilities.DefaultSkuName
                    },
                    Kind     = Kind.Storage,
                    Location = StorageManagementTestUtilities.DefaultLocation,
                };
                storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, false);
            }
        }
Пример #12
0
        public void StorageAccountListWithEncryptionTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                parameters.Encryption = new Encryption()
                {
                    Services = new EncryptionServices {
                        Blob = new EncryptionService {
                            Enabled = true
                        }
                    },
                };
                storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);

                // List account and verify
                var accounts = storageMgmtClient.StorageAccounts.ListByResourceGroup(rgname);
                Assert.Equal(1, accounts.Count());

                var account = accounts.ToArray()[0];
                StorageManagementTestUtilities.VerifyAccountProperties(account, true);
                Assert.NotNull(account.Encryption.Services.Blob);
                Assert.NotNull(account.Encryption.Services.Blob.LastEnabledTime);
            }
        }
Пример #13
0
        public void StorageAccountListKeysTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                string rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = StorageManagementTestUtilities.CreateStorageAccount(storageMgmtClient, rgname);

                // List keys
                var keys = storageMgmtClient.StorageAccounts.ListKeys(rgname, accountName);
                Assert.NotNull(keys);

                // Validate Key1
                StorageAccountKey key1 = keys.Keys.First(
                    t => StringComparer.OrdinalIgnoreCase.Equals(t.KeyName, "key1"));
                Assert.NotNull(key1);
                Assert.Equal(KeyPermission.FULL, key1.Permissions);
                Assert.NotNull(key1.Value);

                // Validate Key2
                StorageAccountKey key2 = keys.Keys.First(
                    t => StringComparer.OrdinalIgnoreCase.Equals(t.KeyName, "key2"));
                Assert.NotNull(key2);
                Assert.Equal(KeyPermission.FULL, key2.Permissions);
                Assert.NotNull(key2.Value);
            }
        }
Пример #14
0
        public void ListBlobServiceTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                var    account     = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, true);

                // implement case
                try
                {
                    var properties = storageMgmtClient.BlobServices.List(rgName, accountName);
                    List <BlobServiceProperties> propertiesList = new List <BlobServiceProperties>(properties);
                    Assert.Equal(1, propertiesList.Count);
                    Assert.Equal("default", propertiesList[0].Name);
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
        public void FileServiceCorsTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                var    account     = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, true);

                // implement case
                try
                {
                    FileServiceProperties properties1 = storageMgmtClient.FileServices.GetServiceProperties(rgName, accountName);
                    Assert.Equal(0, properties1.Cors.CorsRulesProperty.Count);

                    CorsRules cors = new CorsRules();
                    cors.CorsRulesProperty = new List <CorsRule>();
                    cors.CorsRulesProperty.Add(new CorsRule()
                    {
                        AllowedHeaders  = new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x-ms-meta-target*" },
                        AllowedMethods  = new string[] { "GET", "HEAD", "POST", "OPTIONS", "MERGE", "PUT" },
                        AllowedOrigins  = new string[] { "http://www.contoso.com", "http://www.fabrikam.com" },
                        ExposedHeaders  = new string[] { "x-ms-meta-*" },
                        MaxAgeInSeconds = 100
                    });
                    cors.CorsRulesProperty.Add(new CorsRule()
                    {
                        AllowedHeaders  = new string[] { "*" },
                        AllowedMethods  = new string[] { "GET" },
                        AllowedOrigins  = new string[] { "*" },
                        ExposedHeaders  = new string[] { "*" },
                        MaxAgeInSeconds = 2
                    });
                    cors.CorsRulesProperty.Add(new CorsRule()
                    {
                        AllowedHeaders  = new string[] { "x-ms-meta-12345675754564*" },
                        AllowedMethods  = new string[] { "GET", "PUT", "CONNECT" },
                        AllowedOrigins  = new string[] { "http://www.abc23.com", "https://www.fabrikam.com/*" },
                        ExposedHeaders  = new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x -ms-meta-target*" },
                        MaxAgeInSeconds = 2000
                    });

                    FileServiceProperties properties3 = storageMgmtClient.FileServices.SetServiceProperties(rgName, accountName, new FileServiceProperties(cors: cors));

                    //Validate CORS Rules
                    Assert.Equal(cors.CorsRulesProperty.Count, properties3.Cors.CorsRulesProperty.Count);
                    for (int i = 0; i < cors.CorsRulesProperty.Count; i++)
                    {
                        CorsRule putRule = cors.CorsRulesProperty[i];
                        CorsRule getRule = properties3.Cors.CorsRulesProperty[i];

                        Assert.Equal(putRule.AllowedHeaders, getRule.AllowedHeaders);
                        Assert.Equal(putRule.AllowedMethods, getRule.AllowedMethods);
                        Assert.Equal(putRule.AllowedOrigins, getRule.AllowedOrigins);
                        Assert.Equal(putRule.ExposedHeaders, getRule.ExposedHeaders);
                        Assert.Equal(putRule.MaxAgeInSeconds, getRule.MaxAgeInSeconds);
                    }

                    FileServiceProperties properties4 = storageMgmtClient.FileServices.GetServiceProperties(rgName, accountName);

                    //Validate CORS Rules
                    Assert.Equal(cors.CorsRulesProperty.Count, properties4.Cors.CorsRulesProperty.Count);
                    for (int i = 0; i < cors.CorsRulesProperty.Count; i++)
                    {
                        CorsRule putRule = cors.CorsRulesProperty[i];
                        CorsRule getRule = properties4.Cors.CorsRulesProperty[i];

                        Assert.Equal(putRule.AllowedHeaders, getRule.AllowedHeaders);
                        Assert.Equal(putRule.AllowedMethods, getRule.AllowedMethods);
                        Assert.Equal(putRule.AllowedOrigins, getRule.AllowedOrigins);
                        Assert.Equal(putRule.ExposedHeaders, getRule.ExposedHeaders);
                        Assert.Equal(putRule.MaxAgeInSeconds, getRule.MaxAgeInSeconds);
                    }
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Пример #16
0
        public void QueueCreateDeleteUpdateListTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Location = "centraluseuap",
                    Kind     = Kind.StorageV2,
                    Sku      = new Sku {
                        Name = SkuName.StandardLRS
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // implement case
                try
                {
                    //create queue
                    string       queueName = TestUtilities.GenerateName("queue1");
                    StorageQueue queue     = storageMgmtClient.Queue.Create(rgName, accountName, queueName);
                    Assert.Equal(0, queue.Metadata.Count);

                    queue = storageMgmtClient.Queue.Get(rgName, accountName, queueName);
                    Assert.Equal(0, queue.Metadata.Count);

                    string queueName2 = TestUtilities.GenerateName("queue2");
                    Dictionary <string, string> metaData = new Dictionary <string, string>();
                    metaData.Add("metadata1", "true");
                    metaData.Add("metadata2", "value2");
                    StorageQueue queue2 = storageMgmtClient.Queue.Create(rgName, accountName, queueName2, metadata: metaData);
                    Assert.Equal(2, queue2.Metadata.Count);
                    Assert.Equal(metaData, queue2.Metadata);

                    queue2 = storageMgmtClient.Queue.Get(rgName, accountName, queueName2);
                    Assert.Equal(2, queue2.Metadata.Count);
                    Assert.Equal(metaData, queue2.Metadata);

                    // Update queue: Update still not so work, uncomment the case when the server works with update
                    queue = storageMgmtClient.Queue.Update(rgName, accountName, queueName, metaData);
                    Assert.Equal(2, queue.Metadata.Count);
                    Assert.Equal(metaData, queue.Metadata);

                    queue = storageMgmtClient.Queue.Get(rgName, accountName, queueName);
                    Assert.Equal(2, queue.Metadata.Count);
                    Assert.Equal(metaData, queue.Metadata);

                    //list queues
                    IPage <ListQueue> queues = storageMgmtClient.Queue.List(rgName, accountName);
                    Assert.Equal(2, queues.Count());

                    //Delete queue
                    storageMgmtClient.Queue.Delete(rgName, accountName, queueName);
                    queues = storageMgmtClient.Queue.List(rgName, accountName);
                    Assert.Equal(1, queues.Count());

                    storageMgmtClient.Queue.Delete(rgName, accountName, queueName2);
                    queues = storageMgmtClient.Queue.List(rgName, accountName);
                    Assert.Equal(0, queues.Count());
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Пример #17
0
        public void BlobContainersListTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                parameters.Kind = Kind.StorageV2;
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, false);

                // implement case
                try
                {
                    string        containerName1 = TestUtilities.GenerateName("container");
                    BlobContainer blobContainer  = storageMgmtClient.BlobContainers.Create(rgName, accountName, containerName1);
                    Assert.Null(blobContainer.Metadata);
                    Assert.Null(blobContainer.PublicAccess);

                    blobContainer.Metadata = new Dictionary <string, string>();
                    blobContainer.Metadata.Add("metadata", "true");
                    blobContainer.PublicAccess = PublicAccess.Container;
                    var blobContainerSet = storageMgmtClient.BlobContainers.Update(rgName, accountName, containerName1, metadata: blobContainer.Metadata, publicAccess: blobContainer.PublicAccess);
                    Assert.NotNull(blobContainer.Metadata);
                    Assert.NotNull(blobContainer.PublicAccess);
                    Assert.Equal(blobContainer.Metadata, blobContainerSet.Metadata);
                    Assert.Equal(blobContainer.PublicAccess, blobContainerSet.PublicAccess);
                    Assert.False(blobContainerSet.HasImmutabilityPolicy);
                    Assert.False(blobContainerSet.HasLegalHold);

                    string        containerName2 = TestUtilities.GenerateName("container");
                    BlobContainer blobContainer2 = storageMgmtClient.BlobContainers.Create(rgName, accountName, containerName2);
                    Assert.Null(blobContainer2.Metadata);
                    Assert.Null(blobContainer2.PublicAccess);

                    var storageAccount = new CloudStorageAccount(new StorageCredentials(accountName, storageMgmtClient.StorageAccounts.ListKeys(rgName, accountName).Keys.ElementAt(0).Value), false);
                    var container      = storageAccount.CreateCloudBlobClient().GetContainerReference(containerName2);
                    //container.AcquireLeaseAsync(TimeSpan.FromSeconds(45)).Wait();

                    IPage <ListContainerItem> containerList = storageMgmtClient.BlobContainers.List(rgName, accountName);
                    foreach (ListContainerItem blobContainerList in containerList)
                    {
                        Assert.NotNull(blobContainer.Metadata);
                        Assert.NotNull(blobContainer.PublicAccess);
                        Assert.False(blobContainerSet.HasImmutabilityPolicy);
                        Assert.False(blobContainerSet.HasLegalHold);
                    }
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
        public void FileShareLease()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Location = "eastus2euap",
                    Kind     = Kind.StorageV2,
                    Sku      = new Sku {
                        Name = SkuName.StandardLRS
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // implement case
                try
                {
                    // create base share
                    string    shareName = TestUtilities.GenerateName("share");
                    FileShare share     = storageMgmtClient.FileShares.Create(rgName, accountName, shareName, new FileShare());;

                    // create share snapshots
                    FileShare shareSnapshot = storageMgmtClient.FileShares.Create(rgName, accountName, shareName,
                                                                                  new FileShare(), "snapshots");
                    Assert.NotNull(shareSnapshot.SnapshotTime);

                    // Acquire lease share
                    string             proposedLeaseID1 = "ca761232-ed42-11ce-bacd-00aa0057b223";
                    string             proposedLeaseID2 = "dd761232-ed42-11ce-bacd-00aa0057b444";
                    LeaseShareResponse leaseReponds;
                    //try
                    //{
                    leaseReponds = storageMgmtClient.FileShares.Lease(rgName, accountName, shareName, new LeaseShareRequest(LeaseShareAction.Acquire, leaseDuration: 60, proposedLeaseId: proposedLeaseID1));
                    Assert.Equal(proposedLeaseID1, leaseReponds.LeaseId);
                    //}
                    //catch (Microsoft.Rest.ValidationException)
                    //{
                    //}

                    share = storageMgmtClient.FileShares.Get(rgName, accountName, shareName);
                    Assert.Equal("fixed", share.LeaseDuration);
                    Assert.Equal("leased", share.LeaseState);
                    Assert.Equal("locked", share.LeaseStatus);

                    // Renew lease share
                    leaseReponds = storageMgmtClient.FileShares.Lease(rgName, accountName, shareName, new LeaseShareRequest(LeaseShareAction.Renew, leaseId: proposedLeaseID1));
                    Assert.Equal(proposedLeaseID1, leaseReponds.LeaseId);

                    // change lease share
                    leaseReponds = storageMgmtClient.FileShares.Lease(rgName, accountName, shareName, new LeaseShareRequest(LeaseShareAction.Change, leaseId: proposedLeaseID1, proposedLeaseId: proposedLeaseID2));
                    Assert.Equal(proposedLeaseID2, leaseReponds.LeaseId);

                    // break lease share
                    leaseReponds = storageMgmtClient.FileShares.Lease(rgName, accountName, shareName, new LeaseShareRequest(LeaseShareAction.Break, breakPeriod: 20));
                    //Assert.Equal(proposedLeaseID2, leaseReponds.LeaseId);
                    Assert.Equal("20", leaseReponds.LeaseTimeSeconds);

                    // release lease share
                    leaseReponds = storageMgmtClient.FileShares.Lease(rgName, accountName, shareName, new LeaseShareRequest(LeaseShareAction.Release, leaseId: proposedLeaseID2));
                    Assert.Null(leaseReponds.LeaseId);

                    // lease Share Snapshot
                    //try
                    //{

                    leaseReponds = storageMgmtClient.FileShares.Lease(rgName, accountName, shareName, new LeaseShareRequest(LeaseShareAction.Acquire, leaseDuration: 60, proposedLeaseId: proposedLeaseID1), shareSnapshot.SnapshotTime.Value.ToUniversalTime().ToString("o"));
                    Assert.Equal(proposedLeaseID1, leaseReponds.LeaseId);
                    //}
                    //catch (Microsoft.Rest.ValidationException e)
                    //{
                    //}
                    shareSnapshot = storageMgmtClient.FileShares.Get(rgName, accountName, shareName, xMsSnapshot: shareSnapshot.SnapshotTime.Value.ToUniversalTime().ToString("o"));
                    Assert.Equal("fixed", shareSnapshot.LeaseDuration);
                    Assert.Equal("leased", shareSnapshot.LeaseState);
                    Assert.Equal("locked", shareSnapshot.LeaseStatus);

                    bool DeleteFail = false;
                    // try delete with include = none
                    try
                    {
                        storageMgmtClient.FileShares.Delete(rgName, accountName, shareName, include: "none");
                    }
                    catch (Microsoft.Rest.Azure.CloudException e) when(e.Response.StatusCode == HttpStatusCode.Conflict)
                    {
                        DeleteFail = true;
                    }
                    Assert.True(DeleteFail, "Delete should fail with include = none");
                    DeleteFail = false;

                    // try delete with include = snapshots
                    try
                    {
                        storageMgmtClient.FileShares.Delete(rgName, accountName, shareName, include: "snapshots");
                    }
                    catch (Microsoft.Rest.Azure.CloudException e) when(e.Response.StatusCode == HttpStatusCode.Conflict)
                    {
                        DeleteFail = true;
                    }
                    Assert.True(DeleteFail, "Delete should fail with include = snapshots");
                    DeleteFail = false;

                    // try delete with default include (snapshots)
                    try
                    {
                        storageMgmtClient.FileShares.Delete(rgName, accountName, shareName, include: "snapshots");
                    }
                    catch (Microsoft.Rest.Azure.CloudException e) when(e.Response.StatusCode == HttpStatusCode.Conflict)
                    {
                        DeleteFail = true;
                    }

                    Assert.True(DeleteFail, "Delete should fail with default include (snapshots)");
                    DeleteFail = false;

                    // delete with include = leased-snapshots
                    storageMgmtClient.FileShares.Delete(rgName, accountName, shareName, include: "leased-snapshots");
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
        public void FileShareAccessPolicy()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Location = "eastus2euap",
                    Kind     = Kind.StorageV2,
                    Sku      = new Sku {
                        Name = SkuName.StandardLRS
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // implement case
                try
                {
                    // create share
                    string    shareName = TestUtilities.GenerateName("share");
                    FileShare share     = storageMgmtClient.FileShares.Create(rgName, accountName, shareName, new FileShare());;

                    // Prepare signedIdentifiers to set
                    List <SignedIdentifier> sigs = new List <SignedIdentifier>();
                    DateTime datenow             = DateTime.Now;
                    datenow = new DateTime(datenow.Year, datenow.Month, datenow.Day, datenow.Hour, datenow.Minute, datenow.Second);
                    DateTime         start1 = datenow;
                    DateTime         end1   = datenow.AddHours(2);
                    DateTime         start2 = datenow.AddMinutes(1);
                    DateTime         end2   = datenow.AddMinutes(40);
                    SignedIdentifier sig1   = new SignedIdentifier("testSig1",
                                                                   new AccessPolicy(startTime: start1,
                                                                                    expiryTime: end1,
                                                                                    permission: "rw"));
                    SignedIdentifier sig2 = new SignedIdentifier("testSig2",
                                                                 new AccessPolicy(startTime: start2,
                                                                                  expiryTime: end2,
                                                                                  permission: "rwdl"));
                    sigs.Add(sig1);
                    sigs.Add(sig2);

                    // Update share
                    share = storageMgmtClient.FileShares.Update(rgName, accountName, shareName, new FileShare(signedIdentifiers: sigs));
                    Assert.Equal(2, share.SignedIdentifiers.Count);
                    Assert.Equal("testSig1", share.SignedIdentifiers[0].Id);
                    //Assert.Equal(start1, share.SignedIdentifiers[0].AccessPolicy.Start);
                    //Assert.Equal(end1, share.SignedIdentifiers[0].AccessPolicy.Expiry);
                    Assert.Equal("rw", share.SignedIdentifiers[0].AccessPolicy.Permission);

                    // Get share
                    share = storageMgmtClient.FileShares.Get(rgName, accountName, shareName);
                    Assert.Equal(2, share.SignedIdentifiers.Count);
                    Assert.Equal("testSig1", share.SignedIdentifiers[0].Id);
                    //Assert.Equal(start1, share.SignedIdentifiers[0].AccessPolicy.Start);
                    //Assert.Equal(end1, share.SignedIdentifiers[0].AccessPolicy.Expiry);
                    Assert.Equal("rw", share.SignedIdentifiers[0].AccessPolicy.Permission);

                    // delete share
                    storageMgmtClient.FileShares.Delete(rgName, accountName, shareName);
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Пример #20
0
        public void StorageAccountUpdateTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = StorageManagementTestUtilities.CreateStorageAccount(storageMgmtClient, rgname);

                // Update storage account type
                var parameters = new StorageAccountUpdateParameters
                {
                    Sku = new Sku {
                        Name = SkuName.StandardLRS
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Update(rgname, accountName, parameters);
                Assert.Equal(account.Sku.Name, SkuName.StandardLRS);

                // Validate
                account = storageMgmtClient.StorageAccounts.GetProperties(rgname, accountName);
                Assert.Equal(account.Sku.Name, SkuName.StandardLRS);

                // Update storage tags
                parameters = new StorageAccountUpdateParameters
                {
                    Tags = new Dictionary <string, string>
                    {
                        { "key3", "value3" },
                        { "key4", "value4" },
                        { "key5", "value6" }
                    }
                };
                account = storageMgmtClient.StorageAccounts.Update(rgname, accountName, parameters);
                Assert.Equal(account.Tags.Count, parameters.Tags.Count);

                // Validate
                account = storageMgmtClient.StorageAccounts.GetProperties(rgname, accountName);
                Assert.Equal(account.Tags.Count, parameters.Tags.Count);

                // Update storage encryption
                parameters = new StorageAccountUpdateParameters
                {
                    Encryption = new Encryption()
                    {
                        Services = new EncryptionServices {
                            Blob = new EncryptionService {
                                Enabled = true
                            }
                        }
                    }
                };
                account = storageMgmtClient.StorageAccounts.Update(rgname, accountName, parameters);
                Assert.NotNull(account.Encryption);

                // Validate
                account = storageMgmtClient.StorageAccounts.GetProperties(rgname, accountName);
                Assert.NotNull(account.Encryption.Services.Blob);
                Assert.NotNull(account.Encryption.Services.Blob.LastEnabledTime);

                // Update storage custom domains
                parameters = new StorageAccountUpdateParameters
                {
                    CustomDomain = new CustomDomain
                    {
                        Name         = "foo.example.com",
                        UseSubDomain = true
                    }
                };

                try
                {
                    storageMgmtClient.StorageAccounts.Update(rgname, accountName, parameters);
                    Assert.True(false, "This request should fail with the below code.");
                }
                catch (CloudException ex)
                {
                    Assert.Equal(HttpStatusCode.Conflict, ex.Response.StatusCode);
                    Assert.Equal("StorageDomainNameCouldNotVerify", ex.Body.Code);
                    Assert.True(ex.Message != null && ex.Message.StartsWith("The custom domain " +
                                                                            "name could not be verified. CNAME mapping from foo.example.com to "));
                }
            }
        }
Пример #21
0
        public void TableServiceCorsTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Location = "eastus2euap",
                    Kind     = Kind.StorageV2,
                    Sku      = new Sku {
                        Name = SkuName.StandardLRS
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // implement case
                try
                {
                    TableServiceProperties properties1 = storageMgmtClient.TableServices.GetServiceProperties(rgName, accountName);
                    Assert.Equal(0, properties1.Cors.CorsRulesProperty.Count);

                    CorsRules cors = new CorsRules();
                    cors.CorsRulesProperty = new List <CorsRule>();
                    cors.CorsRulesProperty.Add(new CorsRule()
                    {
                        AllowedHeaders  = new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x-ms-meta-target*" },
                        AllowedMethods  = new string[] { "GET", "HEAD", "POST", "OPTIONS", "MERGE", "PUT" },
                        AllowedOrigins  = new string[] { "http://www.contoso.com", "http://www.fabrikam.com" },
                        ExposedHeaders  = new string[] { "x-ms-meta-*" },
                        MaxAgeInSeconds = 100
                    });
                    cors.CorsRulesProperty.Add(new CorsRule()
                    {
                        AllowedHeaders  = new string[] { "*" },
                        AllowedMethods  = new string[] { "GET" },
                        AllowedOrigins  = new string[] { "*" },
                        ExposedHeaders  = new string[] { "*" },
                        MaxAgeInSeconds = 2
                    });
                    cors.CorsRulesProperty.Add(new CorsRule()
                    {
                        AllowedHeaders  = new string[] { "x-ms-meta-12345675754564*" },
                        AllowedMethods  = new string[] { "GET", "PUT", "CONNECT" },
                        AllowedOrigins  = new string[] { "http://www.abc23.com", "https://www.fabrikam.com/*" },
                        ExposedHeaders  = new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x -ms-meta-target*" },
                        MaxAgeInSeconds = 2000
                    });

                    TableServiceProperties properties3 = storageMgmtClient.TableServices.SetServiceProperties(rgName, accountName, cors);

                    //Validate CORS Rules
                    if (HttpMockServer.Mode == HttpRecorderMode.Record)
                    {
                        // Need wait for cors rules setting take effect when record case
                        System.Threading.Thread.Sleep(30000);
                    }
                    Assert.Equal(cors.CorsRulesProperty.Count, properties3.Cors.CorsRulesProperty.Count);
                    for (int i = 0; i < cors.CorsRulesProperty.Count; i++)
                    {
                        CorsRule putRule = cors.CorsRulesProperty[i];
                        CorsRule getRule = properties3.Cors.CorsRulesProperty[i];

                        Assert.Equal(putRule.AllowedHeaders, getRule.AllowedHeaders);
                        Assert.Equal(putRule.AllowedMethods, getRule.AllowedMethods);
                        Assert.Equal(putRule.AllowedOrigins, getRule.AllowedOrigins);
                        Assert.Equal(putRule.ExposedHeaders, getRule.ExposedHeaders);
                        Assert.Equal(putRule.MaxAgeInSeconds, getRule.MaxAgeInSeconds);
                    }

                    TableServiceProperties properties4 = storageMgmtClient.TableServices.GetServiceProperties(rgName, accountName);

                    //Validate CORS Rules
                    Assert.Equal(cors.CorsRulesProperty.Count, properties4.Cors.CorsRulesProperty.Count);
                    for (int i = 0; i < cors.CorsRulesProperty.Count; i++)
                    {
                        CorsRule putRule = cors.CorsRulesProperty[i];
                        CorsRule getRule = properties4.Cors.CorsRulesProperty[i];

                        Assert.Equal(putRule.AllowedHeaders, getRule.AllowedHeaders);
                        Assert.Equal(putRule.AllowedMethods, getRule.AllowedMethods);
                        Assert.Equal(putRule.AllowedOrigins, getRule.AllowedOrigins);
                        Assert.Equal(putRule.ExposedHeaders, getRule.ExposedHeaders);
                        Assert.Equal(putRule.MaxAgeInSeconds, getRule.MaxAgeInSeconds);
                    }
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Пример #22
0
        public void BlobContainersGetTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                parameters.Kind = Kind.StorageV2;
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);
                StorageManagementTestUtilities.VerifyAccountProperties(account, false);

                // implement case
                try
                {
                    string        containerName = TestUtilities.GenerateName("container");
                    BlobContainer blobContainer = storageMgmtClient.BlobContainers.Create(rgName, accountName, containerName);
                    Assert.Null(blobContainer.Metadata);
                    Assert.Null(blobContainer.PublicAccess);

                    LegalHold legalHold = storageMgmtClient.BlobContainers.SetLegalHold(rgName, accountName, containerName, new List <string> {
                        "tag1", "tag2", "tag3"
                    });
                    Assert.True(legalHold.HasLegalHold);
                    Assert.Equal(new List <string> {
                        "tag1", "tag2", "tag3"
                    }, legalHold.Tags);

                    ImmutabilityPolicy immutabilityPolicy = storageMgmtClient.BlobContainers.CreateOrUpdateImmutabilityPolicy(rgName, accountName, containerName, ifMatch: "", immutabilityPeriodSinceCreationInDays: 3);
                    Assert.NotNull(immutabilityPolicy.Id);
                    Assert.NotNull(immutabilityPolicy.Type);
                    Assert.NotNull(immutabilityPolicy.Name);
                    Assert.Equal(3, immutabilityPolicy.ImmutabilityPeriodSinceCreationInDays);
                    Assert.Equal(ImmutabilityPolicyState.Unlocked, immutabilityPolicy.State);


                    immutabilityPolicy = storageMgmtClient.BlobContainers.LockImmutabilityPolicy(rgName, accountName, containerName, ifMatch: immutabilityPolicy.Etag);
                    Assert.NotNull(immutabilityPolicy.Id);
                    Assert.NotNull(immutabilityPolicy.Type);
                    Assert.NotNull(immutabilityPolicy.Name);
                    Assert.Equal(3, immutabilityPolicy.ImmutabilityPeriodSinceCreationInDays);
                    Assert.Equal(ImmutabilityPolicyState.Locked, immutabilityPolicy.State);

                    immutabilityPolicy = storageMgmtClient.BlobContainers.ExtendImmutabilityPolicy(rgName, accountName, containerName, ifMatch: immutabilityPolicy.Etag, immutabilityPeriodSinceCreationInDays: 100);
                    Assert.NotNull(immutabilityPolicy.Id);
                    Assert.NotNull(immutabilityPolicy.Type);
                    Assert.NotNull(immutabilityPolicy.Name);
                    Assert.Equal(100, immutabilityPolicy.ImmutabilityPeriodSinceCreationInDays);
                    Assert.Equal(ImmutabilityPolicyState.Locked, immutabilityPolicy.State);

                    blobContainer = storageMgmtClient.BlobContainers.Get(rgName, accountName, containerName);
                    Assert.Null(blobContainer.Metadata);
                    Assert.Equal(PublicAccess.None, blobContainer.PublicAccess);
                    Assert.Equal(3, blobContainer.ImmutabilityPolicy.UpdateHistory.Count);
                    Assert.Equal(ImmutabilityPolicyUpdateType.Put, blobContainer.ImmutabilityPolicy.UpdateHistory[0].Update);
                    Assert.Equal(ImmutabilityPolicyUpdateType.Lock, blobContainer.ImmutabilityPolicy.UpdateHistory[1].Update);
                    Assert.Equal(ImmutabilityPolicyUpdateType.Extend, blobContainer.ImmutabilityPolicy.UpdateHistory[2].Update);
                    Assert.True(blobContainer.LegalHold.HasLegalHold);
                    Assert.Equal(3, blobContainer.LegalHold.Tags.Count);
                    Assert.Equal("tag1", blobContainer.LegalHold.Tags[0].Tag);
                    Assert.Equal("tag2", blobContainer.LegalHold.Tags[1].Tag);
                    Assert.Equal("tag3", blobContainer.LegalHold.Tags[2].Tag);

                    legalHold = storageMgmtClient.BlobContainers.ClearLegalHold(rgName, accountName, containerName, new List <string> {
                        "tag1", "tag2", "tag3"
                    });
                    Assert.False(legalHold.HasLegalHold);
                    //Assert.Equal(null, legalHold.Tags);

                    storageMgmtClient.BlobContainers.Delete(rgName, accountName, containerName);
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
        public void FileServiceTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Sku = new Sku {
                        Name = SkuName.PremiumLRS
                    },
                    Kind     = Kind.FileStorage,
                    Location = "centraluseuap"
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // implement case
                try
                {
                    // Get after account create
                    FileServiceProperties properties1 = storageMgmtClient.FileServices.GetServiceProperties(rgName, accountName);
                    Assert.Equal(0, properties1.Cors.CorsRulesProperty.Count);

                    //Set and validated
                    FileServiceProperties properties2 = new FileServiceProperties();
                    properties2.ProtocolSettings     = new ProtocolSettings();
                    properties2.ProtocolSettings.Smb = new SmbSetting();
                    properties2.ProtocolSettings.Smb.Multichannel             = new Multichannel(true);
                    properties2.ProtocolSettings.Smb.Versions                 = "SMB2.1;SMB3.0;SMB3.1.1";
                    properties2.ProtocolSettings.Smb.AuthenticationMethods    = "NTLMv2;Kerberos";
                    properties2.ProtocolSettings.Smb.KerberosTicketEncryption = "RC4-HMAC;AES-256";
                    properties2.ProtocolSettings.Smb.ChannelEncryption        = "AES-128-CCM;AES-128-GCM;AES-256-GCM";
                    FileServiceProperties properties3 = storageMgmtClient.FileServices.SetServiceProperties(rgName, accountName, properties2);
                    Assert.True(properties3.ProtocolSettings.Smb.Multichannel.Enabled);
                    Assert.Equal("SMB2.1;SMB3.0;SMB3.1.1", properties3.ProtocolSettings.Smb.Versions);
                    Assert.Equal("NTLMv2;Kerberos", properties3.ProtocolSettings.Smb.AuthenticationMethods);
                    Assert.Equal("RC4-HMAC;AES-256", properties3.ProtocolSettings.Smb.KerberosTicketEncryption);
                    Assert.Equal("AES-128-CCM;AES-128-GCM;AES-256-GCM", properties3.ProtocolSettings.Smb.ChannelEncryption);

                    // Get and validate
                    FileServiceProperties properties4 = storageMgmtClient.FileServices.GetServiceProperties(rgName, accountName);
                    Assert.True(properties3.ProtocolSettings.Smb.Multichannel.Enabled);
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
        public void TableCreateDeleteUpdateListTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Location = "eastus2euap",
                    Kind     = Kind.StorageV2,
                    Sku      = new Sku {
                        Name = SkuName.StandardLRS
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // implement case
                try
                {
                    // prepare SignedIdentifier
                    List <TableSignedIdentifier> tableSi = new List <TableSignedIdentifier>();
                    tableSi.Add(new TableSignedIdentifier("PTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODklMTI", accessPolicy: new TableAccessPolicy("raud", null, DateTime.Now.AddDays(2))));
                    tableSi.Add(new TableSignedIdentifier("MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI", accessPolicy: new TableAccessPolicy("ra", DateTime.Now, DateTime.Now.AddDays(7))));

                    //create Table
                    string tableName = TestUtilities.GenerateName("table1");
                    Table  table     = storageMgmtClient.Table.Create(rgName, accountName, tableName, tableSi);
                    Assert.Equal(tableName, table.TableName);
                    Assert.Equal(2, table.SignedIdentifiers.Count);

                    table = storageMgmtClient.Table.Get(rgName, accountName, tableName);
                    Assert.Equal(tableName, table.TableName);

                    string tableName2 = TestUtilities.GenerateName("table2");
                    Table  table2     = storageMgmtClient.Table.Create(rgName, accountName, tableName2);
                    Assert.Equal(tableName2, table2.TableName);
                    Assert.Equal(2, table.SignedIdentifiers.Count);

                    table2 = storageMgmtClient.Table.Get(rgName, accountName, tableName2);
                    Assert.Equal(tableName2, table2.TableName);

                    // Update Table: Update still not update any thing, will add update parameter when add things to update
                    tableSi.Add(new TableSignedIdentifier("eC1tcy1yZXF1ZXN0LWlk", accessPolicy: new TableAccessPolicy("r", DateTime.Now.AddHours(1), DateTime.Now.AddDays(70))));
                    table = storageMgmtClient.Table.Update(rgName, accountName, tableName, tableSi);
                    Assert.Equal(tableName, table.TableName);
                    Assert.Equal(3, table.SignedIdentifiers.Count);

                    //list Table
                    IPage <Table> tables = storageMgmtClient.Table.List(rgName, accountName);
                    Assert.Equal(2, tables.Count());

                    //Delete Table
                    storageMgmtClient.Table.Delete(rgName, accountName, tableName);
                    tables = storageMgmtClient.Table.List(rgName, accountName);
                    Assert.Equal(1, tables.Count());

                    storageMgmtClient.Table.Delete(rgName, accountName, tableName2);
                    tables = storageMgmtClient.Table.List(rgName, accountName);
                    Assert.Equal(0, tables.Count());
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
        public void FileSharesUpdateGetTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName      = TestUtilities.GenerateName("sto");
                var    createParameters = new StorageAccountCreateParameters
                {
                    Location = "eastus2euap",
                    Kind     = Kind.StorageV2,
                    Sku      = new Sku {
                        Name = SkuName.StandardLRS
                    },
                    LargeFileSharesState = LargeFileSharesState.Enabled
                };
                var account          = storageMgmtClient.StorageAccounts.Create(rgName, accountName, createParameters);
                var updateParameters = new StorageAccountUpdateParameters
                {
                    LargeFileSharesState = LargeFileSharesState.Enabled
                };
                account = storageMgmtClient.StorageAccounts.Update(rgName, accountName, updateParameters);

                // implement case
                try
                {
                    string    shareName = TestUtilities.GenerateName("share");
                    FileShare share     = storageMgmtClient.FileShares.Create(rgName, accountName, shareName, new FileShare());
                    Assert.Null(share.Metadata);

                    Dictionary <string, string> metaData = new Dictionary <string, string>();
                    metaData.Add("metadata1", "true");
                    metaData.Add("metadata2", "value2");
                    int shareQuota = 5200;
                    var shareSet   = storageMgmtClient.FileShares.Update(rgName, accountName, shareName,
                                                                         new FileShare(metadata: metaData, shareQuota: shareQuota, accessTier: ShareAccessTier.Cool));
                    Assert.NotNull(shareSet.Metadata);
                    Assert.Equal(shareQuota, shareSet.ShareQuota);
                    Assert.Equal(metaData, shareSet.Metadata);
                    Assert.Equal(ShareAccessTier.Cool, shareSet.AccessTier);

                    var shareGet = storageMgmtClient.FileShares.Get(rgName, accountName, shareName);
                    Assert.NotNull(shareGet.Metadata);
                    Assert.Equal(metaData, shareGet.Metadata);
                    Assert.Equal(shareQuota, shareGet.ShareQuota);
                    Assert.Equal(ShareAccessTier.Cool, shareGet.AccessTier);
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
        public void StorageAccountUpdateTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();

                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = StorageManagementTestUtilities.CreateStorageAccount(storageMgmtClient, rgname);

                // TODO: Remove wait when CSM is fixed
                TestUtilities.Wait(30000);

                // Update storage account type
                var parameters = new StorageAccountUpdateParameters
                {
                    AccountType = AccountType.StandardLRS
                };
                var updateAccountTypeRequest = storageMgmtClient.StorageAccounts.Update(rgname, accountName, parameters);
                Assert.Equal(updateAccountTypeRequest.StorageAccount.AccountType, AccountType.StandardLRS);

                var getRequest = storageMgmtClient.StorageAccounts.GetProperties(rgname, accountName);
                Assert.Equal(getRequest.StorageAccount.AccountType, AccountType.StandardLRS);

                // Update storage tags
                parameters = new StorageAccountUpdateParameters
                {
                    Tags = new Dictionary <string, string>
                    {
                        { "key3", "value3" },
                        { "key4", "value4" },
                        { "key5", "value6" }
                    }
                };

                var updateTagsRequest = storageMgmtClient.StorageAccounts.Update(rgname, accountName, parameters);
                Assert.Equal(updateTagsRequest.StorageAccount.Tags.Count, parameters.Tags.Count);
                Assert.Equal(updateTagsRequest.StorageAccount.Tags.ElementAt(0), parameters.Tags.ElementAt(0));

                getRequest = storageMgmtClient.StorageAccounts.GetProperties(rgname, accountName);
                Assert.Equal(getRequest.StorageAccount.Tags.Count, parameters.Tags.Count);

                // Update storage custom domains
                parameters = new StorageAccountUpdateParameters
                {
                    CustomDomain = new CustomDomain
                    {
                        Name         = "foo.example.com",
                        UseSubDomain = true
                    }
                };

                StorageAccountUpdateResponse updateCustomDomainsRequest;
                try
                {
                    updateCustomDomainsRequest = storageMgmtClient.StorageAccounts.Update(rgname, accountName, parameters);
                    Assert.True(false, "This request should fail with the below code.");
                } catch (Hyak.Common.CloudException ex)
                {
                    Assert.Equal(HttpStatusCode.BadRequest, ex.Response.StatusCode);
                    Assert.Equal("StorageDomainNameCouldNotVerify", ex.Error.Code);
                    Assert.True(ex.Error.Message != null && ex.Error.Message.StartsWith("The custom domain " +
                                                                                        "name could not be verified. CNAME mapping from foo.example.com to "));
                }
            }
        }
        public void FileSharesCreateDeleteListTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Location = "eastus2euap",
                    Kind     = Kind.StorageV2,
                    Sku      = new Sku {
                        Name = SkuName.StandardLRS
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // implement case
                try
                {
                    string    shareName = TestUtilities.GenerateName("share");
                    FileShare share     = storageMgmtClient.FileShares.Create(rgName, accountName, shareName, new FileShare());
                    Assert.Null(share.Metadata);

                    share = storageMgmtClient.FileShares.Get(rgName, accountName, shareName);
                    Assert.Null(share.Metadata);

                    string shareName2 = TestUtilities.GenerateName("share");
                    Dictionary <string, string> metaData = new Dictionary <string, string>();
                    metaData.Add("metadata1", "true");
                    metaData.Add("metadata2", "value2");
                    int       shareQuota = 500;
                    FileShare share2     = storageMgmtClient.FileShares.Create(rgName, accountName, shareName2,
                                                                               new FileShare(metadata: metaData, shareQuota: shareQuota, accessTier: ShareAccessTier.Hot));
                    Assert.Equal(2, share2.Metadata.Count);
                    Assert.Equal(metaData, share2.Metadata);
                    Assert.Equal(shareQuota, share2.ShareQuota);
                    Assert.Equal(ShareAccessTier.Hot, share2.AccessTier);

                    share2 = storageMgmtClient.FileShares.Get(rgName, accountName, shareName2);
                    Assert.Equal(2, share2.Metadata.Count);
                    Assert.Equal(metaData, share2.Metadata);
                    Assert.Equal(shareQuota, share2.ShareQuota);
                    Assert.Equal(ShareAccessTier.Hot, share2.AccessTier);

                    //Delete share
                    storageMgmtClient.FileShares.Delete(rgName, accountName, shareName);
                    IPage <FileShareItem> fileShares = storageMgmtClient.FileShares.List(rgName, accountName);
                    Assert.Equal(1, fileShares.Count());

                    storageMgmtClient.FileShares.Delete(rgName, accountName, shareName2);
                    fileShares = storageMgmtClient.FileShares.List(rgName, accountName);
                    Assert.Equal(0, fileShares.Count());

                    //Delete not exist share, won't fail (return 204)
                    storageMgmtClient.FileShares.Delete(rgName, accountName, "notexistshare");
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
        public void FileSharesSoftDeleteTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Location = "eastus2euap",
                    Kind     = Kind.StorageV2,
                    Sku      = new Sku {
                        Name = SkuName.StandardLRS
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // implement case
                try
                {
                    // Enable share soft delete in service properties
                    FileServiceProperties properties = storageMgmtClient.FileServices.GetServiceProperties(rgName, accountName);
                    properties.ShareDeleteRetentionPolicy         = new DeleteRetentionPolicy();
                    properties.ShareDeleteRetentionPolicy.Enabled = true;
                    properties.ShareDeleteRetentionPolicy.Days    = 5;
                    properties = storageMgmtClient.FileServices.SetServiceProperties(rgName, accountName, new FileServiceProperties(shareDeleteRetentionPolicy: properties.ShareDeleteRetentionPolicy));
                    Assert.True(properties.ShareDeleteRetentionPolicy.Enabled);
                    Assert.Equal(5, properties.ShareDeleteRetentionPolicy.Days);

                    //Create 2 shares
                    string    shareName1 = TestUtilities.GenerateName("share1");
                    string    shareName2 = TestUtilities.GenerateName("share2");
                    FileShare share1     = storageMgmtClient.FileShares.Create(rgName, accountName, shareName1,
                                                                               new FileShare(accessTier: ShareAccessTier.Hot,
                                                                                             enabledProtocols: EnabledProtocols.NFS,
                                                                                             rootSquash: RootSquashType.AllSquash));
                    Assert.Equal(shareName1, share1.Name);
                    Assert.Equal(EnabledProtocols.NFS, share1.EnabledProtocols);
                    Assert.Equal(RootSquashType.AllSquash, share1.RootSquash);
                    //Assert.Equal(ShareAccessTier.Hot, share1.AccessTier);
                    FileShare share2 = storageMgmtClient.FileShares.Create(rgName, accountName, shareName2,
                                                                           new FileShare(accessTier: ShareAccessTier.Cool,
                                                                                         enabledProtocols: EnabledProtocols.SMB));
                    Assert.Equal(shareName2, share2.Name);
                    Assert.Equal(EnabledProtocols.SMB, share2.EnabledProtocols);

                    //Update 1 share
                    share1 = storageMgmtClient.FileShares.Update(rgName, accountName, shareName1,
                                                                 new FileShare(accessTier: ShareAccessTier.TransactionOptimized,
                                                                               rootSquash: RootSquashType.RootSquash));
                    Assert.Equal(shareName1, share1.Name);
                    Assert.Equal(RootSquashType.RootSquash, share1.RootSquash);
                    //Assert.Equal(ShareAccessTier.TransactionOptimized, share1.AccessTier);


                    // Delete 1 share
                    storageMgmtClient.FileShares.Delete(rgName, accountName, shareName1);

                    //List normally
                    IPage <FileShareItem> shares = storageMgmtClient.FileShares.List(rgName, accountName);
                    Assert.Single(shares);

                    //List with includeDeleted
                    string deletedShareVersion = null;
                    shares = storageMgmtClient.FileShares.List(rgName, accountName, expand: "deleted");
                    Assert.Equal(2, shares.Count());
                    foreach (FileShareItem share in shares)
                    {
                        if (share.Name == shareName1)
                        {
                            Assert.True(share.Deleted);
                            Assert.NotNull(share.Version);
                            deletedShareVersion = share.Version;
                        }
                    }

                    //Get not deleted share
                    share2 = storageMgmtClient.FileShares.Get(rgName, accountName, shareName2, expand: "stats");
                    Assert.NotNull(share2.ShareQuota);
                    Assert.NotNull(share2.ShareUsageBytes);

                    //Get Deleted Share
                    try {
                        share2 = storageMgmtClient.FileShares.Get(rgName, accountName, shareName1);
                        Assert.True(false, "Get Share on deleted Share should fail with NotFound.");
                    }
                    catch (CloudException ex)
                    {
                        Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
                    }

                    // restore deleted share
                    //Don't need sleep when playback, or Unit test will be very slow. Need sleep when record.
                    if (HttpMockServer.Mode == HttpRecorderMode.Record)
                    {
                        System.Threading.Thread.Sleep(30000);
                    }
                    storageMgmtClient.FileShares.Restore(rgName, accountName, shareName1, shareName1, deletedShareVersion);

                    //List normally
                    shares = storageMgmtClient.FileShares.List(rgName, accountName);
                    Assert.Equal(2, shares.Count());

                    //List with includeDeleted
                    shares = storageMgmtClient.FileShares.List(rgName, accountName, expand: "deleted");
                    Assert.Equal(2, shares.Count());
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
        public void FileShareSnapshotCreateDeleteListTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Location = "eastus2euap",
                    Kind     = Kind.StorageV2,
                    Sku      = new Sku {
                        Name = SkuName.StandardLRS
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // Enable share soft delete in service properties
                FileServiceProperties properties = storageMgmtClient.FileServices.GetServiceProperties(rgName, accountName);
                properties.ShareDeleteRetentionPolicy         = new DeleteRetentionPolicy();
                properties.ShareDeleteRetentionPolicy.Enabled = true;
                properties.ShareDeleteRetentionPolicy.Days    = 5;
                properties = storageMgmtClient.FileServices.SetServiceProperties(rgName, accountName, new FileServiceProperties(shareDeleteRetentionPolicy: properties.ShareDeleteRetentionPolicy));

                // implement case
                try
                {
                    // create 2 base share, delete one
                    string    shareName  = TestUtilities.GenerateName("share");
                    FileShare share      = storageMgmtClient.FileShares.Create(rgName, accountName, shareName, new FileShare());
                    string    shareName2 = TestUtilities.GenerateName("share");
                    FileShare share2     = storageMgmtClient.FileShares.Create(rgName, accountName, shareName2, new FileShare());
                    storageMgmtClient.FileShares.Delete(rgName, accountName, shareName2);

                    // create 2 share snapshots
                    FileShare shareSnapshot1 = storageMgmtClient.FileShares.Create(rgName, accountName, shareName,
                                                                                   new FileShare(), "snapshots");
                    Assert.NotNull(shareSnapshot1.SnapshotTime);
                    FileShare shareSnapshot2 = storageMgmtClient.FileShares.Create(rgName, accountName, shareName,
                                                                                   new FileShare(), "snapshots");
                    Assert.NotNull(shareSnapshot2.SnapshotTime);

                    // Get single share snapsshot
                    FileShare shareSnapshot = storageMgmtClient.FileShares.Get(rgName, accountName, shareName, "stats", shareSnapshot1.SnapshotTime.Value.ToUniversalTime().ToString("o"));
                    Assert.Equal(shareSnapshot.SnapshotTime, shareSnapshot1.SnapshotTime);

                    // List share with snapshot
                    IPage <FileShareItem> fileShares = storageMgmtClient.FileShares.List(rgName, accountName, expand: "snapshots");
                    Assert.Equal(3, fileShares.Count());

                    // Delete share snapshot
                    storageMgmtClient.FileShares.Delete(rgName, accountName, shareName2, shareSnapshot2.SnapshotTime.Value.ToUniversalTime().ToString("o"));

                    // List share with snapshot
                    fileShares = storageMgmtClient.FileShares.List(rgName, accountName, expand: "snapshots");
                    //Assert.Equal(2, fileShares.Count());

                    // List share with deleted
                    fileShares = storageMgmtClient.FileShares.List(rgName, accountName, expand: "deleted");
                    Assert.Equal(2, fileShares.Count());
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }
Пример #30
0
        public void TableCreateDeleteUpdateListTest()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient   = StorageManagementTestUtilities.GetResourceManagementClient(context, handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler);

                // Create resource group
                var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                var    parameters  = new StorageAccountCreateParameters
                {
                    Location = "eastus2euap",
                    Kind     = Kind.StorageV2,
                    Sku      = new Sku {
                        Name = SkuName.StandardLRS
                    }
                };
                var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters);

                // implement case
                try
                {
                    //create Table
                    string tableName = TestUtilities.GenerateName("table1");
                    Table  table     = storageMgmtClient.Table.Create(rgName, accountName, tableName);
                    Assert.Equal(tableName, table.TableName);

                    table = storageMgmtClient.Table.Get(rgName, accountName, tableName);
                    Assert.Equal(tableName, table.TableName);

                    string tableName2 = TestUtilities.GenerateName("table2");
                    Table  table2     = storageMgmtClient.Table.Create(rgName, accountName, tableName2);
                    Assert.Equal(tableName2, table2.TableName);

                    table2 = storageMgmtClient.Table.Get(rgName, accountName, tableName2);
                    Assert.Equal(tableName2, table2.TableName);

                    // Update Table: Update still not update any thing, will add update parameter when add things to update
                    table = storageMgmtClient.Table.Update(rgName, accountName, tableName);

                    //list Table
                    IPage <Table> tables = storageMgmtClient.Table.List(rgName, accountName);
                    Assert.Equal(2, tables.Count());

                    //Delete Table
                    storageMgmtClient.Table.Delete(rgName, accountName, tableName);
                    tables = storageMgmtClient.Table.List(rgName, accountName);
                    Assert.Equal(1, tables.Count());

                    storageMgmtClient.Table.Delete(rgName, accountName, tableName2);
                    tables = storageMgmtClient.Table.List(rgName, accountName);
                    Assert.Equal(0, tables.Count());
                }
                finally
                {
                    // clean up
                    storageMgmtClient.StorageAccounts.Delete(rgName, accountName);
                    resourcesClient.ResourceGroups.Delete(rgName);
                }
            }
        }