示例#1
0
        public async Task Upload_LowLevelApi()
        {
            var uploadRootPath = "/Root/UploadTests";
            var uploadFolder   = await Content.LoadAsync(uploadRootPath).ConfigureAwait(false);

            if (uploadFolder == null)
            {
                uploadFolder = Content.CreateNew("/Root", "SystemFolder", "UploadTests");
                await uploadFolder.SaveAsync().ConfigureAwait(false);
            }

            //var file = Content.CreateNew(uploadFolder.Path, "File", Guid.NewGuid().ToString());
            //await file.SaveAsync().ConfigureAwait(false);

            var fileName     = Guid.NewGuid().ToString() + ".txt";
            var uploadStream = Tools.GenerateStreamFromString(_fileContent);

            UploadData uploadData = new UploadData
            {
                FileName    = fileName,
                ContentType = "File"
            };

            // ACTION
            await RESTCaller.UploadAsync(uploadStream, uploadData, uploadFolder.Path).ConfigureAwait(false);

            // ASSERT
            var filePath = RepositoryPath.Combine(uploadRootPath, fileName);
            var content  = await Content.LoadAsync(filePath).ConfigureAwait(false);

            string downloadedFileContent = null;
            await RESTCaller.GetStreamResponseAsync(content.Id, async response =>
            {
                if (response == null)
                {
                    return;
                }
                using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
                    using (var reader = new StreamReader(stream))
                        downloadedFileContent = reader.ReadToEnd();
            }, CancellationToken.None).ConfigureAwait(false);

            Assert.AreEqual(_fileContent, downloadedFileContent);
        }