Exemplo n.º 1
0
        public async Task CloudFileDirectoryApisInShareSnapshotAsync()
        {
            CloudFileShare share = GetRandomShareReference();
            await share.CreateAsync();

            CloudFileDirectory dir = share.GetRootDirectoryReference().GetDirectoryReference("dir1");
            await dir.CreateAsync();

            dir.Metadata["key1"] = "value1";
            await dir.SetMetadataAsync(null, null, null);

            CloudFileShare snapshot = await share.SnapshotAsync();

            CloudFileDirectory snapshotDir = snapshot.GetRootDirectoryReference().GetDirectoryReference("dir1");

            dir.Metadata["key2"] = "value2";
            await dir.SetMetadataAsync(null, null, null);

            await snapshotDir.FetchAttributesAsync();

            Assert.IsTrue(snapshotDir.Metadata.Count == 1 && snapshotDir.Metadata["key1"].Equals("value1"));
            Assert.IsNotNull(snapshotDir.Properties.ETag);

            await dir.FetchAttributesAsync();

            Assert.IsTrue(dir.Metadata.Count == 2 && dir.Metadata["key2"].Equals("value2"));
            Assert.IsNotNull(dir.Properties.ETag);
            Assert.AreNotEqual(dir.Properties.ETag, snapshotDir.Properties.ETag);

            await snapshot.DeleteAsync();

            await share.DeleteAsync();
        }
Exemplo n.º 2
0
        public async Task CloudFileApisInShareSnapshotAsync()
        {
            CloudFileClient client = GenerateCloudFileClient();
            string          name   = GetRandomShareName();
            CloudFileShare  share  = client.GetShareReference(name);
            await share.CreateAsync();

            CloudFileDirectory dir = share.GetRootDirectoryReference().GetDirectoryReference("dir1");
            await dir.CreateAsync();

            CloudFile file = dir.GetFileReference("file");
            await file.CreateAsync(1024);

            file.Metadata["key1"] = "value1";
            await file.SetMetadataAsync();

            CloudFileShare snapshot     = share.SnapshotAsync().Result;
            CloudFile      snapshotFile = snapshot.GetRootDirectoryReference().GetDirectoryReference("dir1").GetFileReference("file");

            file.Metadata["key2"] = "value2";
            await file.SetMetadataAsync();

            await snapshotFile.FetchAttributesAsync();

            Assert.IsTrue(snapshotFile.Metadata.Count == 1 && snapshotFile.Metadata["key1"].Equals("value1"));
            Assert.IsNotNull(snapshotFile.Properties.ETag);

            await file.FetchAttributesAsync();

            Assert.IsTrue(file.Metadata.Count == 2 && file.Metadata["key2"].Equals("value2"));
            Assert.IsNotNull(file.Properties.ETag);
            Assert.AreNotEqual(file.Properties.ETag, snapshotFile.Properties.ETag);

            CloudFile snapshotFile2 = new CloudFile(snapshotFile.SnapshotQualifiedStorageUri, client.Credentials);

            Assert.IsTrue(snapshotFile2.ExistsAsync().Result);
            Assert.IsTrue(snapshotFile2.Share.SnapshotTime.HasValue);

            await snapshot.DeleteAsync();

            await share.DeleteAsync();
        }
Exemplo n.º 3
0
        public async Task CloudFileDirectoryApisInvalidApisInShareSnapshotAsync()
        {
            CloudFileShare share = GetRandomShareReference();
            await share.CreateAsync();

            CloudFileShare snapshot = await share.SnapshotAsync();

            CloudFileDirectory dir = snapshot.GetRootDirectoryReference().GetDirectoryReference("dir1");

            try
            {
                dir.CreateAsync().Wait();
                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }
            try
            {
                dir.DeleteAsync().Wait();
                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }
            try
            {
                dir.SetMetadataAsync(null, null, null).Wait();
                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }

            snapshot.DeleteAsync().Wait();
            share.DeleteAsync().Wait();
        }
Exemplo n.º 4
0
        public async Task CloudFileInvalidApisInShareSnapshotAsync()
        {
            CloudFileClient client = GenerateCloudFileClient();
            string          name   = GetRandomShareName();
            CloudFileShare  share  = client.GetShareReference(name);
            await share.CreateAsync();

            CloudFileShare snapshot = share.SnapshotAsync().Result;
            CloudFile      file     = snapshot.GetRootDirectoryReference().GetDirectoryReference("dir1").GetFileReference("file");

            try
            {
                await file.CreateAsync(1024);

                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }
            try
            {
                await file.DeleteAsync();

                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }
            try
            {
                await file.SetMetadataAsync();

                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }
            try
            {
                await file.AbortCopyAsync(null);

                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }
            try
            {
                await file.ClearRangeAsync(0, 1024);

                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }
            try
            {
                await file.StartCopyAsync(file);

                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }
            try
            {
                await file.UploadFromByteArrayAsync(new byte[1024], 0, 1024);

                Assert.Fail("API should fail in a snapshot");
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(SR.CannotModifyShareSnapshot, e.Message);
            }

            await snapshot.DeleteAsync();

            await share.DeleteAsync();
        }
        public async Task CloudFileListSharesWithSnapshotAsync()
        {
            CloudFileShare share = GetRandomShareReference();
            await share.CreateAsync();

            share.Metadata["key1"] = "value1";
            await share.SetMetadataAsync();

            CloudFileShare snapshot = await share.SnapshotAsync();

            share.Metadata["key2"] = "value2";
            await share.SetMetadataAsync();

            CloudFileClient       client       = GenerateCloudFileClient();
            List <CloudFileShare> listedShares = new List <CloudFileShare>();
            FileContinuationToken token        = null;

            do
            {
                ShareResultSegment resultSegment = await client.ListSharesSegmentedAsync(share.Name, ShareListingDetails.All, null, token, null, null);

                token = resultSegment.ContinuationToken;

                foreach (CloudFileShare listResultShare in resultSegment.Results)
                {
                    listedShares.Add(listResultShare);
                }
            }while (token != null);

            int  count         = 0;
            bool originalFound = false;
            bool snapshotFound = false;

            foreach (CloudFileShare listShareItem in listedShares)
            {
                if (listShareItem.Name.Equals(share.Name) && !listShareItem.IsSnapshot && !originalFound)
                {
                    count++;
                    originalFound = true;
                    Assert.AreEqual(2, listShareItem.Metadata.Count);
                    Assert.AreEqual("value2", listShareItem.Metadata["key2"]);
                    Assert.AreEqual("value1", listShareItem.Metadata["key1"]);
                    Assert.AreEqual(share.StorageUri, listShareItem.StorageUri);
                }
                else if (listShareItem.Name.Equals(share.Name) &&
                         listShareItem.IsSnapshot && !snapshotFound)
                {
                    count++;
                    snapshotFound = true;
                    Assert.AreEqual(1, listShareItem.Metadata.Count);
                    Assert.AreEqual("value1", listShareItem.Metadata["key1"]);
                    Assert.AreEqual(snapshot.StorageUri, listShareItem.StorageUri);
                }
            }

            Assert.AreEqual(2, count);

            await snapshot.DeleteAsync();

            await share.DeleteAsync();
        }