public async Task FileServiceCors()
        {
            FileServiceData properties1 = _fileService.Data;
            FileServiceData properties2 = new FileServiceData();

            properties2.Cors = new CorsRules();
            properties2.Cors.CorsRulesValue.Add(new CorsRule(new string[] { "http://www.contoso.com", "http://www.fabrikam.com" },
                                                             new CorsRuleAllowedMethodsItem[] { CorsRuleAllowedMethodsItem.GET, CorsRuleAllowedMethodsItem.PUT },
                                                             100, new string[] { "x-ms-meta-*" },
                                                             new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x-ms-meta-target*" }
                                                             ));
            properties2.Cors.CorsRulesValue.Add(new CorsRule(new string[] { "*" },
                                                             new CorsRuleAllowedMethodsItem[] { CorsRuleAllowedMethodsItem.GET },
                                                             2, new string[] { "*" },
                                                             new string[] { "*" }
                                                             ));
            properties2.Cors.CorsRulesValue.Add(new CorsRule(new string[] { "http://www.abc23.com", "https://www.fabrikam.com/*" },
                                                             new CorsRuleAllowedMethodsItem[] { CorsRuleAllowedMethodsItem.GET, CorsRuleAllowedMethodsItem.PUT, CorsRuleAllowedMethodsItem.Post },
                                                             2000, new string[] { "x-ms-meta-12345675754564*" },
                                                             new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x-ms-meta-target*" }
                                                             ));

            _fileService = (await _fileService.CreateOrUpdateAsync(true, properties2)).Value;
            FileServiceData properties3 = _fileService.Data;

            //validate CORS rules
            Assert.AreEqual(properties2.Cors.CorsRulesValue.Count, properties3.Cors.CorsRulesValue.Count);
            for (int i = 0; i < properties2.Cors.CorsRulesValue.Count; i++)
            {
                CorsRule putRule = properties2.Cors.CorsRulesValue[i];
                CorsRule getRule = properties3.Cors.CorsRulesValue[i];

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

            _fileService = await _fileService.GetAsync();

            FileServiceData properties4 = _fileService.Data;

            //validate CORS rules
            Assert.AreEqual(properties2.Cors.CorsRulesValue.Count, properties4.Cors.CorsRulesValue.Count);
            for (int i = 0; i < properties2.Cors.CorsRulesValue.Count; i++)
            {
                CorsRule putRule = properties2.Cors.CorsRulesValue[i];
                CorsRule getRule = properties4.Cors.CorsRulesValue[i];

                Assert.AreEqual(putRule.AllowedHeaders, getRule.AllowedHeaders);
                Assert.AreEqual(putRule.AllowedMethods, getRule.AllowedMethods);
                Assert.AreEqual(putRule.AllowedOrigins, getRule.AllowedOrigins);
                Assert.AreEqual(putRule.ExposedHeaders, getRule.ExposedHeaders);
                Assert.AreEqual(putRule.MaxAgeInSeconds, getRule.MaxAgeInSeconds);
            }
        }
        public async Task CreateDeleteListFileShareSnapshot()
        {
            //update storage account to v2
            StorageAccountUpdateParameters updateParameters = new StorageAccountUpdateParameters()
            {
                Kind = Kind.StorageV2
            };
            await _storageAccount.UpdateAsync(updateParameters);

            // Enable share soft delete in service properties
            _fileService = await _fileService.GetAsync();

            FileServiceData properties = new FileServiceData()
            {
                ShareDeleteRetentionPolicy = new DeleteRetentionPolicy()
                {
                    Enabled = true,
                    Days    = 5
                }
            };

            _fileService = (await _fileService.CreateOrUpdateAsync(true, properties)).Value;

            //create 2 file share and delete 1
            string    fileShareName1 = Recording.GenerateAssetName("testfileshare1");
            string    fileShareName2 = Recording.GenerateAssetName("testfileshare2");
            FileShare share1         = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName1, new FileShareData())).Value;
            FileShare share2         = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName2, new FileShareData())).Value;
            await share2.DeleteAsync(true);

            //create 2 share snapshots
            FileShare shareSnapshot1 = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName1, new FileShareData(), expand: "snapshots")).Value;
            FileShare shareSnapshot2 = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName1, new FileShareData(), expand: "snapshots")).Value;

            //get single share snapshot
            FileShare shareSnapshot = await _fileShareCollection.GetAsync(fileShareName1, "stats", shareSnapshot1.Data.SnapshotTime.Value.UtcDateTime.ToString("o"));

            Assert.AreEqual(shareSnapshot.Data.SnapshotTime, shareSnapshot1.Data.SnapshotTime);

            //list share with snapshot
            List <FileShare> fileShares = await _fileShareCollection.GetAllAsync(expand : "snapshots").ToEnumerableAsync();

            Assert.AreEqual(3, fileShares.Count);

            //delete share snapshot
            await shareSnapshot.DeleteAsync(true);

            // List share with deleted
            fileShares = await _fileShareCollection.GetAllAsync(expand : "deleted").ToEnumerableAsync();

            Assert.AreEqual(2, fileShares.Count);
        }
        public async Task UpdateFileService()
        {
            //update service property
            FileServiceData parameter = new FileServiceData()
            {
                ShareDeleteRetentionPolicy = new DeleteRetentionPolicy()
                {
                    Enabled = true,
                    Days    = 5
                }
            };

            _fileService = (await _fileService.CreateOrUpdateAsync(true, parameter)).Value;

            //validate
            Assert.IsTrue(_fileService.Data.ShareDeleteRetentionPolicy.Enabled);
            Assert.AreEqual(_fileService.Data.ShareDeleteRetentionPolicy.Days, 5);
        }
        public async Task RestoreFileShare()
        {
            //enable soft delete in service property
            FileServiceData parameter = new FileServiceData()
            {
                ShareDeleteRetentionPolicy = new DeleteRetentionPolicy()
                {
                    Enabled = true,
                    Days    = 5
                }
            };

            _fileService = (await _fileService.CreateOrUpdateAsync(true, parameter)).Value;

            //create file share
            string    fileShareName = Recording.GenerateAssetName("testfileshare");
            FileShare share1        = (await _fileShareCollection.CreateOrUpdateAsync(true, fileShareName, new FileShareData())).Value;

            Assert.AreEqual(share1.Id.Name, fileShareName);

            //delete this share
            await share1.DeleteAsync(true);

            //get the deleted share version
            string           deletedShareVersion = null;
            List <FileShare> fileShares          = await _fileShareCollection.GetAllAsync(expand : "deleted").ToEnumerableAsync();

            deletedShareVersion = fileShares[0].Data.Version;

            //restore file share
            //Don't need sleep when playback, or test will be very slow. Need sleep when live and record.
            if (Mode != RecordedTestMode.Playback)
            {
                await Task.Delay(30000);
            }
            DeletedShare deletedShare = new DeletedShare(fileShareName, deletedShareVersion);
            await share1.RestoreAsync(deletedShare);

            //validate
            fileShares = await _fileShareCollection.GetAllAsync().ToEnumerableAsync();

            Assert.AreEqual(fileShares.Count, 1);
        }
예제 #5
0
        internal static FileServiceItems DeserializeFileServiceItems(JsonElement element)
        {
            Optional <IReadOnlyList <FileServiceData> > value = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <FileServiceData> array = new List <FileServiceData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(FileServiceData.DeserializeFileServiceData(item));
                    }
                    value = array;
                    continue;
                }
            }
            return(new FileServiceItems(Optional.ToList(value)));
        }