Пример #1
0
        public void ShouldCreateTextFileAsync()
        {
            // Arrange
            IFilesApi filesApi = CreateFilesApi();

            // Act
            FileResponse fileResponse = filesApi.CreateFileAsync("calendar/test.txt", "Hello").Result;

            // Assert
            fileResponse.Path.ShouldBe("calendar/test.txt");

            Should.Throw <ArgumentNullException>(() => filesApi.CreateFileAsync(null, "Hello"));
            Should.Throw <ArgumentNullException>(() => filesApi.CreateFileAsync("calendar/test.txt", (string)null));
        }
Пример #2
0
        public void ShouldCreateTextFileAsync()
        {
            // Arrange
            IFilesApi filesApi = CreateFilesApi();

            // Act
            FileResponse fileResponse = filesApi.CreateFileAsync("applications", "calendar/test.txt", "Hello").Result;

            // Assert
            fileResponse.path.ShouldBe("applications/calendar/test.txt");
        }
Пример #3
0
        public void ShouldCreateBinaryFileAsync()
        {
            // Arrange
            IFilesApi filesApi = CreateFilesApi();

            byte[] data = { 50, 51, 52, 53, 54, 55, 56, 57 };

            // Act
            FileResponse fileResponse = filesApi.CreateFileAsync("calendar/test.bin", data).Result;

            // Assert
            fileResponse.Path.ShouldBe("calendar/test.bin");
        }
        private async Task <string> UploadImage(HttpPostedFileBase upload)
        {
            if (upload != null && upload.ContentLength > 0)
            {
                MemoryStream target = new MemoryStream();
                upload.InputStream.CopyTo(target);
                byte[] data       = target.ToArray();
                string base64Data = string.Format("data:{0};base64,{1}", upload.ContentType,
                                                  Convert.ToBase64String(data));
                FileResponse result = await filesApi.CreateFileAsync(Guid.NewGuid().ToString(), base64Data);

                return(result.Name);
            }

            return(null);
        }
Пример #5
0
        public async Task RunAsync(IRestContext context)
        {
            IFilesApi filesApi = context.Factory.CreateFilesApi("files");

            // Display existing containers
            IEnumerable <string> names = await filesApi.GetContainerNamesAsync();

            Console.WriteLine("GetContainerNamesAsync(): {0}", names.ToStringList());

            // Creating a test container - tank
            await filesApi.CreateContainersAsync(false, TestContainer);

            // Creating a file
            FileResponse response = await filesApi.CreateFileAsync(TestContainer, "test.txt", "test", false);

            Console.WriteLine("Created file: {0}", response.path);

            // Reading the file
            string content = await filesApi.GetTextFileAsync(TestContainer, "test.txt");

            Console.WriteLine("GetFile content: {0}", content);

            // Deleting the file
            response = await filesApi.DeleteFileAsync(TestContainer, "test.txt");

            Console.WriteLine("Deleted file: {0}", response.path);

            // Deleting the container
            await filesApi.DeleteContainersAsync(TestContainer);

            Console.WriteLine("Container '{0}' deleted.", TestContainer);

            // Downloading a container
            Console.WriteLine("Downloading 'applications' container as zip archive...");
            byte[] zip = await filesApi.DownloadContainerAsync("applications");

            File.WriteAllBytes("applications-container.zip", zip);
            Console.WriteLine("Open applications-container.zip to see the contents.");
        }
Пример #6
0
        public async Task RunAsync(IRestContext context)
        {
            IFilesApi filesApi = context.Factory.CreateFilesApi("files");

            // Display resources
            IEnumerable <string> names = await filesApi.GetResourceNamesAsync();

            Console.WriteLine("GetResourcesAsync():");
            foreach (string name in names)
            {
                Console.WriteLine("\t{0}", name);
            }

            // Creating a folder
            await filesApi.CreateFolderAsync("test", true);

            Console.WriteLine("Folder 'test' created.");

            // Creating a file
            FileResponse response = await filesApi.CreateFileAsync("test/test.txt", "test", true);

            Console.WriteLine("Created file: {0}", response.Path);

            // Reading the file
            string content = await filesApi.GetTextFileAsync("test/test.txt");

            Console.WriteLine("GetFile content: {0}", content);

            // Deleting the file
            response = await filesApi.DeleteFileAsync("test/test.txt");

            Console.WriteLine("Deleted file: {0}", response.Path);

            // Deleting the folder
            await filesApi.DeleteFolderAsync("test", true);

            Console.WriteLine("Folder 'test' deleted.");
        }