Exemplo n.º 1
0
        public async Task list_objects()
        {
            var file1 = "file1.txt";
            var file2 = "folder1/file2.txt";

            using (var client = new RavenGoogleCloudClient(GoogleCloudFact.GoogleCloudSettings))
            {
                try
                {
                    // Upload some files
                    var content = Encoding.UTF8.GetBytes("hello, world");
                    await client.UploadObjectAsync(file1, new MemoryStream(content));

                    await client.UploadObjectAsync(file2, new MemoryStream(content));

                    var objects = await client.ListObjectsAsync();

                    Assert.Contains(objects, o => o.Name == file1);
                    Assert.Contains(objects, o => o.Name == file2);
                }

                finally
                {
                    await client.DeleteObjectAsync(file1);

                    await client.DeleteObjectAsync(file2);
                }
            }
        }
Exemplo n.º 2
0
        public async Task upload_object_with_metadata()
        {
            var fileName = Guid.NewGuid().ToString();

            using (var client = new RavenGoogleCloudClient(GoogleCloudFact.GoogleCloudSettings))
            {
                try
                {
                    await client.UploadObjectAsync(
                        fileName,
                        new MemoryStream(Encoding.UTF8.GetBytes("456")),
                        new Dictionary <string, string>
                    {
                        { "key1", "value1" },
                        { "key2", "value2" }
                    });

                    var obj = await client.GetObjectAsync(fileName);

                    Assert.Equal("value1", obj.Metadata["key1"]);
                    Assert.Equal("value2", obj.Metadata["key2"]);
                }

                finally
                {
                    await client.DeleteObjectAsync(fileName);
                }
            }
        }
Exemplo n.º 3
0
        public async Task download_objects()
        {
            var fileName = Guid.NewGuid().ToString();

            using (var client = new RavenGoogleCloudClient(GoogleCloudFact.GoogleCloudSettings))
            {
                try
                {
                    await client.UploadObjectAsync(
                        fileName,
                        new MemoryStream(Encoding.UTF8.GetBytes("123"))
                        );

                    var file = new MemoryStream();
                    await client.DownloadObjectAsync(fileName, file);

                    Assert.Equal("123", Encoding.ASCII.GetString(file.ToArray()));
                }

                finally
                {
                    await client.DeleteObjectAsync(fileName);
                }
            }
        }
Exemplo n.º 4
0
        public async Task download_objects()
        {
            var fileName = Guid.NewGuid().ToString();

            using (var client = new RavenGoogleCloudClient(GoogleCloudFactAttribute.GoogleCloudSettings))
            {
                try
                {
                    await client.UploadObjectAsync(
                        fileName,
                        new MemoryStream(Encoding.UTF8.GetBytes("123"))
                        );

                    var stream = client.DownloadObject(fileName);
                    using (var sr = new StreamReader(stream))
                    {
                        Assert.Equal("123", sr.ReadToEnd());
                    }
                }

                finally
                {
                    await client.DeleteObjectAsync(fileName);
                }
            }
        }
Exemplo n.º 5
0
        public async Task delete_objects()
        {
            var fileName = Guid.NewGuid().ToString();

            using (var client = new RavenGoogleCloudClient(GoogleCloudFact.GoogleCloudSettings))
            {
                await client.UploadObjectAsync(
                    fileName,
                    new MemoryStream(Encoding.UTF8.GetBytes("123"))
                    );

                await client.DeleteObjectAsync(fileName);

                Assert.Empty(await client.ListObjectsAsync());
            }
        }
Exemplo n.º 6
0
        public async Task uploading_objects()
        {
            var fileName = Guid.NewGuid().ToString();

            using (var client = new RavenGoogleCloudClient(GoogleCloudFact.GoogleCloudSettings))
            {
                try
                {
                    await client.UploadObjectAsync(
                        fileName,
                        new MemoryStream(Encoding.UTF8.GetBytes("123"))
                        );
                }

                finally
                {
                    await client.DeleteObjectAsync(fileName);
                }
            }
        }
Exemplo n.º 7
0
        public async Task delete_objects()
        {
            var fileName = Guid.NewGuid().ToString();

            using (var client = new RavenGoogleCloudClient(GoogleCloudFactAttribute.GoogleCloudSettings))
            {
                await client.UploadObjectAsync(
                    fileName,
                    new MemoryStream(Encoding.UTF8.GetBytes("123"))
                    );

                var fileExists = await WaitForValueAsync(() => IsFileNameInCloudObjects(client, fileName), true);

                Assert.True(fileExists);

                await client.DeleteObjectAsync(fileName);

                fileExists = await WaitForValueAsync(() => IsFileNameInCloudObjects(client, fileName), false);

                Assert.False(fileExists);
            }
        }