コード例 #1
0
        public async Task ShouldDownloadSingle()
        {
            string contentId = await _fixture.GetRandomContentIdAsync(".jpg", 20);

            Assert.False(string.IsNullOrEmpty(contentId));
            ContentDetail contentDetail = await _client.Contents.GetAsync(contentId);

            var fileMetadata = contentDetail.GetFileMetadata();
            var fileName     = new Random().Next(0, 999999).ToString() + "-" + fileMetadata.FileName + ".jpg";
            var filePath     = Path.Combine(_fixture.TempDirectory, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            using (var response = await _client.Contents.DownloadAsync(contentId, "Original", null, null, "bytes=0-20000000"))
            {
                var stream = response.Stream;
                Assert.Equal(true, stream.CanRead);

                await response.Stream.WriteToFileAsync(filePath);

                Assert.True(File.Exists(filePath));
            }
        }
コード例 #2
0
        public async Task ShouldGetDocumentMetadata()
        {
            var contentId = await _fixture.GetRandomContentIdAsync(".jpg", 20);

            if (string.IsNullOrEmpty(contentId))
            {
                contentId = await _fixture.GetRandomContentIdAsync(".docx", 20);
            }

            Assert.False(string.IsNullOrEmpty(contentId));

            ContentDetail result = await _client.Contents.GetAsync(contentId);

            FileMetadata fileMetadata = result.GetFileMetadata();

            Assert.False(string.IsNullOrEmpty(fileMetadata.FileName));
        }
コード例 #3
0
        public async Task ShouldDownloadSingleResized()
        {
            // Download a resized version of an image file
            var contentId = await _fixture.GetRandomContentIdAsync(".jpg", 20);

            Assert.False(string.IsNullOrEmpty(contentId));
            ContentDetail contentDetail = await _client.Contents.GetAsync(contentId);

            var fileMetadata = contentDetail.GetFileMetadata();
            var fileName     = new Random().Next(0, 999999).ToString() + "-" + fileMetadata.FileName + ".jpg";
            var filePath     = Path.Combine(_fixture.TempDirectory, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            using (var response = await _client.Contents.DownloadAsync(contentId, "Original", 200, 200))
            {
                await response.Stream.WriteToFileAsync(filePath);
            }

            Assert.True(File.Exists(filePath));
        }