2019-08-27 11:52:53 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using LeanCloud;
|
|
|
|
|
using System.IO;
|
2019-09-12 15:07:19 +08:00
|
|
|
|
using System.Threading;
|
2019-08-27 11:52:53 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2019-09-17 11:53:28 +08:00
|
|
|
|
namespace LeanCloud.Test {
|
2019-08-27 11:52:53 +08:00
|
|
|
|
public class FileTest {
|
2019-09-12 15:07:19 +08:00
|
|
|
|
string saveFileId;
|
|
|
|
|
|
2019-08-27 11:52:53 +08:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() {
|
2020-02-19 18:50:51 +08:00
|
|
|
|
//Utils.InitNorthChina();
|
2019-08-27 12:07:47 +08:00
|
|
|
|
//Utils.InitEastChina();
|
2019-09-12 15:07:19 +08:00
|
|
|
|
//Utils.InitOldEastChina();
|
2020-02-19 18:50:51 +08:00
|
|
|
|
Utils.InitUS();
|
2019-08-27 11:52:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 15:07:19 +08:00
|
|
|
|
[Test, Order(0)]
|
2019-08-27 11:52:53 +08:00
|
|
|
|
public async Task SaveImage() {
|
2019-08-27 12:07:47 +08:00
|
|
|
|
AVFile file = new AVFile("hello.png", File.ReadAllBytes("../../../assets/hello.png"));
|
2019-08-27 11:52:53 +08:00
|
|
|
|
await file.SaveAsync();
|
|
|
|
|
Assert.NotNull(file.ObjectId);
|
2019-09-12 15:07:19 +08:00
|
|
|
|
saveFileId = file.ObjectId;
|
2019-08-27 11:52:53 +08:00
|
|
|
|
TestContext.Out.WriteLine($"file: {file.ObjectId}, {file.Url}");
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 15:07:19 +08:00
|
|
|
|
[Test, Order(1)]
|
2019-08-27 11:52:53 +08:00
|
|
|
|
public async Task SaveBigFile() {
|
2019-08-27 12:07:47 +08:00
|
|
|
|
AVFile file = new AVFile("test.apk", File.ReadAllBytes("../../../assets/test.apk"));
|
2019-08-27 11:52:53 +08:00
|
|
|
|
await file.SaveAsync();
|
|
|
|
|
Assert.NotNull(file.ObjectId);
|
|
|
|
|
TestContext.Out.WriteLine($"file: {file.ObjectId}, {file.Url}");
|
|
|
|
|
}
|
2019-08-27 17:05:49 +08:00
|
|
|
|
|
2019-09-12 15:07:19 +08:00
|
|
|
|
[Test, Order(2)]
|
2019-08-29 16:37:16 +08:00
|
|
|
|
public async Task SaveUrl() {
|
|
|
|
|
AVFile file = new AVFile("test.jpg", "http://pic33.nipic.com/20131007/13639685_123501617185_2.jpg");
|
|
|
|
|
await file.SaveAsync();
|
|
|
|
|
Assert.NotNull(file.ObjectId);
|
|
|
|
|
TestContext.Out.WriteLine($"file: {file.ObjectId}, {file.Url}");
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 15:07:19 +08:00
|
|
|
|
[Test, Order(3)]
|
2019-08-27 17:05:49 +08:00
|
|
|
|
public async Task Thumbnail() {
|
2019-09-12 15:07:19 +08:00
|
|
|
|
AVQuery<AVFile> query = new AVQuery<AVFile>();
|
|
|
|
|
AVFile file = await query.GetAsync(saveFileId, CancellationToken.None);
|
2019-08-27 17:05:49 +08:00
|
|
|
|
Assert.NotNull(file);
|
|
|
|
|
TestContext.Out.WriteLine($"url: {file.Url}");
|
|
|
|
|
TestContext.Out.WriteLine($"thumbnail url: {file.GetThumbnailUrl(28, 28)}");
|
|
|
|
|
}
|
2019-08-29 16:37:16 +08:00
|
|
|
|
|
2019-09-12 15:07:19 +08:00
|
|
|
|
[Test, Order(4)]
|
2019-08-29 16:37:16 +08:00
|
|
|
|
public async Task DeleteFile() {
|
|
|
|
|
AVFile file = new AVFile("hello.png", File.ReadAllBytes("../../../assets/hello.png"));
|
|
|
|
|
await file.SaveAsync();
|
|
|
|
|
Assert.NotNull(file.ObjectId);
|
|
|
|
|
await file.DeleteAsync();
|
|
|
|
|
}
|
2019-08-27 11:52:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|