csharp-sdk-upm/Test/Storage.Test/FileTest.cs

85 lines
2.9 KiB
C#
Raw Normal View History

using NUnit.Framework;
using System;
using System.Text;
using System.Threading.Tasks;
using LeanCloud.Storage;
2020-03-04 15:17:53 +08:00
using LeanCloud.Common;
namespace LeanCloud.Test {
public class FileTest {
static readonly string AvatarFilePath = "../../../assets/hello.png";
static readonly string APKFilePath = "../../../assets/test.apk";
* csharp-sdk.sln: chore: 重构 AVFile 为 AVObject 的子类 * RTM.csproj: * AVQuery2.cs: * AVRealtime.cs: * AVIMNotice.cs: * AVIMClient.cs: * AVIMMessage.cs: * Utils.cs: * ICacheEngine.cs: * IAVIMMessage.cs: * AVIMSignature.cs: * AVIMEventArgs.cs: * IAVIMListener.cs: * AVIMException.cs: * JustTest.cs: * FileTest.cs: * AVIMEnumerator.cs: * AVFile.cs: * QueryTest.cs: * AVIMTextMessage.cs: * AVQuery.cs: * AVObject.cs: * AVIMTypedMessage.cs: * AVIMImageMessage.cs: * IAVTimer.cs: * AVIMConversation.cs: * AVClient.cs: * AVIMAudioMessage.cs: * ISignatureFactory.cs: * AVIMCorePlugins.cs: * AVIMBinaryMessage.cs: * AVIMRecalledMessage.cs: * AVIMMessageListener.cs: * AckCommand.cs: * IAVIMPlatformHooks.cs: * AVIMConversationQuery.cs: * AVIMCommand.cs: * ReadCommand.cs: * PatchCommand.cs: * GoAwayListener.cs: * AVIMProtocol.cs: * MessageCommand.cs: * SessionListener.cs: * SessionCommand.cs: * AVIMTemporaryConversation.cs: * RouterState.cs: * AVRouterController.cs: * AVIMCommandRunner.cs: * IAVIMCommandRunner.cs: * AVDecoder.cs: * IAVRouterController.cs: * IWebSocketClient.cs: * MessagePatchListener.cs: * ConversationCommand.cs: * AVIMMessageFieldNameAttribute.cs: * AVIMMessageClassNameAttribute.cs: * QueryOperation.cs: * QueryCondition.cs: * OfflineMessageListener.cs: * AVIMTypedMessageTypeIntAttribute.cs: * AVTimer.Portable.cs: * AVIMConversationListener.cs: * ConversationUnreadListener.cs: * StringEngine.cs: * AWSUploader.cs: * DateTimeEngine.cs: * QiniuUploader.cs: * QCloudUploader.cs: * DictionaryEngine.cs: * AVFileController.cs: * FreeStyleMessageClassInfo.cs: * DefaultWebSocketClient.Portable.cs: * FreeStyleMessageClassingController.cs: * IFreeStyleMessageClassingController.cs:
2019-09-12 15:07:19 +08:00
[SetUp]
public void SetUp() {
Logger.LogDelegate += Utils.Print;
LeanCloud.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
}
[TearDown]
public void TearDown() {
Logger.LogDelegate -= Utils.Print;
}
[Test]
public async Task QueryFile() {
LCQuery<LCFile> query = LCFile.GetQuery();
LCFile file = await query.Get("5e0dbfa0562071008e21c142");
Assert.NotNull(file.Url);
TestContext.WriteLine(file.Url);
TestContext.WriteLine(file.GetThumbnailUrl(32, 32));
}
[Test]
public async Task SaveFromPath() {
LCFile file = new LCFile("avatar", AvatarFilePath);
await file.Save((count, total) => {
TestContext.WriteLine($"progress: {count}/{total}");
});
TestContext.WriteLine(file.ObjectId);
Assert.NotNull(file.ObjectId);
}
[Test]
public async Task SaveFromMemory() {
string text = "hello, world";
byte[] data = Encoding.UTF8.GetBytes(text);
LCFile file = new LCFile("text", data);
await file.Save();
TestContext.WriteLine(file.ObjectId);
Assert.NotNull(file.ObjectId);
}
[Test]
public async Task SaveFromUrl() {
LCFile file = new LCFile("scene", new Uri("http://img95.699pic.com/photo/50015/9034.jpg_wh300.jpg"));
file.AddMetaData("size", 1024);
file.AddMetaData("width", 128);
file.AddMetaData("height", 256);
file.MimeType = "image/jpg";
await file.Save();
TestContext.WriteLine(file.ObjectId);
Assert.NotNull(file.ObjectId);
}
[Test]
public async Task Qiniu() {
LCFile file = new LCFile("avatar", APKFilePath);
await file.Save();
TestContext.WriteLine(file.ObjectId);
Assert.NotNull(file.ObjectId);
}
[Test]
public async Task AWS() {
2020-03-09 12:31:25 +08:00
LeanCloud.Initialize("UlCpyvLm8aMzQsW6KnP6W3Wt-MdYXbMMI", "PyCTYoNoxCVoKKg394PBeS4r");
LCFile file = new LCFile("avatar", AvatarFilePath);
await file.Save((count, total) => {
TestContext.WriteLine($"progress: {count}/{total}");
});
TestContext.WriteLine(file.ObjectId);
Assert.NotNull(file.ObjectId);
}
}
}