chore: storage unit test
parent
d3a1f055af
commit
0908e9e3d9
|
@ -1,46 +1,41 @@
|
|||
using NUnit.Framework;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.ObjectModel;
|
||||
using System;
|
||||
using LeanCloud;
|
||||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class ACLTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
public class ACLTest : BaseTest {
|
||||
private Account account;
|
||||
|
||||
[Test]
|
||||
[Order(0)]
|
||||
public async Task PrivateReadAndWrite() {
|
||||
LCObject account = new LCObject("Account");
|
||||
LCACL acl = new LCACL();
|
||||
acl.PublicReadAccess = false;
|
||||
acl.PublicWriteAccess = false;
|
||||
account.ACL = acl;
|
||||
Account account = new Account();
|
||||
account.ACL = new LCACL {
|
||||
PublicReadAccess = false,
|
||||
PublicWriteAccess = false
|
||||
};
|
||||
account.Balance = 1024;
|
||||
account["balance"] = 1024;
|
||||
await account.Save();
|
||||
Assert.IsFalse(acl.PublicReadAccess);
|
||||
Assert.IsFalse(acl.PublicWriteAccess);
|
||||
Assert.IsFalse(account.ACL.PublicReadAccess);
|
||||
Assert.IsFalse(account.ACL.PublicWriteAccess);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(1)]
|
||||
public async Task UserReadAndWrite() {
|
||||
await LCUser.Login("hello", "world");
|
||||
LCObject account = new LCObject("Account");
|
||||
await LCUser.Login(TestPhone, TestPhone);
|
||||
account = new Account();
|
||||
LCUser currentUser = await LCUser.GetCurrent();
|
||||
LCACL acl = LCACL.CreateWithOwner(currentUser);
|
||||
account.ACL = acl;
|
||||
account["balance"] = 512;
|
||||
account.ACL = LCACL.CreateWithOwner(currentUser);
|
||||
account.Balance = 512;
|
||||
await account.Save();
|
||||
|
||||
Assert.IsTrue(acl.GetUserReadAccess(currentUser));
|
||||
Assert.IsTrue(acl.GetUserWriteAccess(currentUser));
|
||||
Assert.IsTrue(account.ACL.GetUserReadAccess(currentUser));
|
||||
Assert.IsTrue(account.ACL.GetUserWriteAccess(currentUser));
|
||||
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Account");
|
||||
LCObject result = await query.Get(account.ObjectId);
|
||||
|
@ -57,29 +52,39 @@ namespace Storage.Test {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Order(2)]
|
||||
public async Task RoleReadAndWrite() {
|
||||
LCQuery<LCRole> query = LCRole.GetQuery();
|
||||
LCRole owner = await query.Get("5e1440cbfc36ed006add1b8d");
|
||||
LCObject account = new LCObject("Account");
|
||||
LCUser currentUser = await LCUser.Login(TestPhone, TestPhone);
|
||||
string name = $"role_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}";
|
||||
LCACL roleACL = new LCACL();
|
||||
roleACL.SetUserReadAccess(currentUser, true);
|
||||
roleACL.SetUserWriteAccess(currentUser, true);
|
||||
LCRole role = LCRole.Create(name, roleACL);
|
||||
role.AddRelation("users", currentUser);
|
||||
await role.Save();
|
||||
|
||||
account = new Account();
|
||||
LCACL acl = new LCACL();
|
||||
acl.SetRoleReadAccess(owner, true);
|
||||
acl.SetRoleWriteAccess(owner, true);
|
||||
acl.SetRoleReadAccess(role, true);
|
||||
acl.SetRoleWriteAccess(role, true);
|
||||
account.ACL = acl;
|
||||
await account.Save();
|
||||
Assert.IsTrue(acl.GetRoleReadAccess(owner));
|
||||
Assert.IsTrue(acl.GetRoleWriteAccess(owner));
|
||||
Assert.IsTrue(acl.GetRoleReadAccess(role));
|
||||
Assert.IsTrue(acl.GetRoleWriteAccess(role));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(3)]
|
||||
public async Task Query() {
|
||||
await LCUser.Login("game", "play");
|
||||
await LCUser.Login(TestPhone, TestPhone);
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Account");
|
||||
LCObject account = await query.Get("5e144525dd3c13006a8f8de2");
|
||||
TestContext.WriteLine(account.ObjectId);
|
||||
Assert.NotNull(account.ObjectId);
|
||||
Account queryAccount = (await query.Get(account.ObjectId)) as Account;
|
||||
TestContext.WriteLine(queryAccount.ObjectId);
|
||||
Assert.NotNull(queryAccount.ObjectId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(4)]
|
||||
public async Task Serialization() {
|
||||
await LCUser.Login("hello", "world");
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Account") {
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
using NUnit.Framework;
|
||||
using LeanCloud;
|
||||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
internal class Hello : LCObject {
|
||||
internal World World {
|
||||
get => this["objectValue"] as World;
|
||||
set {
|
||||
this["objectValue"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal Hello() : base("Hello") { }
|
||||
}
|
||||
|
||||
internal class World : LCObject {
|
||||
internal string Content {
|
||||
get => this["content"] as string;
|
||||
set {
|
||||
this["content"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal World() : base("World") { }
|
||||
}
|
||||
|
||||
internal class Account : LCObject {
|
||||
internal int Balance {
|
||||
get => (int)this["balance"];
|
||||
set {
|
||||
this["balance"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal LCUser User {
|
||||
get => this["user"] as LCUser;
|
||||
set {
|
||||
this["user"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal Account() : base("Account") { }
|
||||
}
|
||||
|
||||
public class BaseTest {
|
||||
internal const string AppId = "ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz";
|
||||
internal const string AppKey = "NUKmuRbdAhg1vrb2wexYo1jo";
|
||||
internal const string MasterKey = "pyvbNSh5jXsuFQ3C8EgnIdhw";
|
||||
internal const string AppServer = "https://ikggdre2.lc-cn-n1-shared.com";
|
||||
|
||||
internal const string TestPhone = "18888888888";
|
||||
internal const string TestSMSCode = "235750";
|
||||
|
||||
[SetUp]
|
||||
public virtual void SetUp() {
|
||||
LCLogger.LogDelegate += Print;
|
||||
LCApplication.Initialize(AppId, AppKey, AppServer);
|
||||
LCObject.RegisterSubclass("Account", () => new Account());
|
||||
LCObject.RegisterSubclass<Hello>("Hello", () => new Hello());
|
||||
LCObject.RegisterSubclass<World>("World", () => new World());
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public virtual void TearDown() {
|
||||
LCLogger.LogDelegate -= Print;
|
||||
}
|
||||
|
||||
internal static void Print(LCLogLevel level, string info) {
|
||||
switch (level) {
|
||||
case LCLogLevel.Debug:
|
||||
TestContext.Out.WriteLine($"[DEBUG] {info}");
|
||||
break;
|
||||
case LCLogLevel.Warn:
|
||||
TestContext.Out.WriteLine($"[WARNING] {info}");
|
||||
break;
|
||||
case LCLogLevel.Error:
|
||||
TestContext.Out.WriteLine($"[ERROR] {info}");
|
||||
break;
|
||||
default:
|
||||
TestContext.Out.WriteLine(info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +1,11 @@
|
|||
using NUnit.Framework;
|
||||
using System.Threading.Tasks;
|
||||
using LeanCloud;
|
||||
using LeanCloud.Storage;
|
||||
|
||||
using static NUnit.Framework.TestContext;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class CaptchaTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
public class CaptchaTest : BaseTest {
|
||||
//[Test]
|
||||
public async Task Request() {
|
||||
LCCapture captcha = await LCCaptchaClient.RequestCaptcha();
|
||||
|
|
|
@ -2,83 +2,60 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using LeanCloud;
|
||||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class CloudTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
LCLogger.LogDelegate += Utils.Print;
|
||||
//LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
|
||||
LCApplication.Initialize("8ijVI3gBAnPGynW0rVfh5gHP-gzGzoHsz", "265r8JSHhNYpV0qIJBvUWrQY", "https://8ijvi3gb.lc-cn-n1-shared.com");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
LCLogger.LogDelegate -= Utils.Print;
|
||||
public class CloudTest : BaseTest {
|
||||
[Test]
|
||||
public async Task Ping() {
|
||||
Dictionary<string, object> response = await LCCloud.Run("ping");
|
||||
TestContext.WriteLine(response["result"]);
|
||||
Assert.AreEqual(response["result"], "pong");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Call() {
|
||||
Dictionary<string, object> response = await LCCloud.Run("hello", parameters: new Dictionary<string, object> {
|
||||
public async Task Hello() {
|
||||
string result = await LCCloud.Run<string>("hello", new Dictionary<string, object> {
|
||||
{ "name", "world" }
|
||||
});
|
||||
TestContext.WriteLine(response["result"]);
|
||||
Assert.AreEqual(response["result"], "Hello, world!");
|
||||
TestContext.WriteLine(result);
|
||||
Assert.AreEqual(result, "hello, world");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RunAverageScore() {
|
||||
float score = await LCCloud.Run<float>("averageStars", new Dictionary<string, object> {
|
||||
{ "movie", "夏洛特烦恼" }
|
||||
public async Task GetObject() {
|
||||
LCObject hello = new LCObject("Hello");
|
||||
await hello.Save();
|
||||
object reponse = await LCCloud.RPC("getObject", new Dictionary<string, object> {
|
||||
{ "className", "Hello" },
|
||||
{ "id", hello.ObjectId }
|
||||
});
|
||||
TestContext.WriteLine($"score: {score}");
|
||||
Assert.True(score.Equals(3.8f));
|
||||
LCObject obj = reponse as LCObject;
|
||||
Assert.AreEqual(obj.ObjectId, hello.ObjectId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CallWithoutParams() {
|
||||
await LCCloud.Run("hello");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RPC() {
|
||||
List<object> result = await LCCloud.RPC("getTycoonList") as List<object>;
|
||||
IEnumerable<LCObject> tycoonList = result.Cast<LCObject>();
|
||||
foreach (LCObject item in tycoonList) {
|
||||
TestContext.WriteLine(item.ObjectId);
|
||||
Assert.NotNull(item.ObjectId);
|
||||
public async Task GetObjects() {
|
||||
object response = await LCCloud.RPC("getObjects");
|
||||
List<object> list = response as List<object>;
|
||||
IEnumerable<LCObject> objects = list.Cast<LCObject>();
|
||||
TestContext.WriteLine(objects.Count());
|
||||
Assert.Greater(objects.Count(), 0);
|
||||
foreach (LCObject obj in objects) {
|
||||
int balance = (int)obj["balance"];
|
||||
Assert.Greater(balance, 100);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RPCObject() {
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Todo");
|
||||
LCObject todo = await query.Get("6052cd87b725a143ea83dbf8");
|
||||
object result = await LCCloud.RPC("getTodo", todo);
|
||||
LCObject obj = result as LCObject;
|
||||
TestContext.WriteLine(obj.ToString());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RPCObjects() {
|
||||
Dictionary<string, object> parameters = new Dictionary<string, object> {
|
||||
{ "limit", 20 }
|
||||
};
|
||||
List<object> result = await LCCloud.RPC("getTodos", parameters) as List<object>;
|
||||
IEnumerable<LCObject> todos = result.Cast<LCObject>();
|
||||
foreach (LCObject todo in todos) {
|
||||
TestContext.WriteLine(todo.ObjectId);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RPCObjectMap() {
|
||||
Dictionary<string, object> result = await LCCloud.RPC("getTodoMap") as Dictionary<string, object>;
|
||||
foreach (KeyValuePair<string, object> kv in result) {
|
||||
LCObject todo = kv.Value as LCObject;
|
||||
TestContext.WriteLine(todo.ObjectId);
|
||||
public async Task GetObjectMap() {
|
||||
object response = await LCCloud.RPC("getObjectMap");
|
||||
Dictionary<string, object> dict = response as Dictionary<string, object>;
|
||||
TestContext.WriteLine(dict.Count);
|
||||
Assert.Greater(dict.Count, 0);
|
||||
foreach (KeyValuePair<string, object> kv in dict) {
|
||||
LCObject obj = kv.Value as LCObject;
|
||||
Assert.AreEqual(kv.Key, obj.ObjectId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using LeanCloud;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class ExceptionTest {
|
||||
public class ExceptionTest : BaseTest {
|
||||
[Test]
|
||||
public void LeanCloudException() {
|
||||
try {
|
||||
|
|
|
@ -6,39 +6,33 @@ using LeanCloud;
|
|||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class FileTest {
|
||||
public class FileTest : BaseTest {
|
||||
static readonly string AvatarFilePath = "../../../../../assets/hello.png";
|
||||
static readonly string APKFilePath = "../../../../../assets/test.apk";
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
private LCFile avatar;
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
[Test]
|
||||
[Order(0)]
|
||||
public async Task SaveFromPath() {
|
||||
avatar = new LCFile("avatar", AvatarFilePath);
|
||||
await avatar.Save((count, total) => {
|
||||
TestContext.WriteLine($"progress: {count}/{total}");
|
||||
});
|
||||
TestContext.WriteLine(avatar.ObjectId);
|
||||
Assert.NotNull(avatar.ObjectId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(1)]
|
||||
public async Task QueryFile() {
|
||||
LCQuery<LCFile> query = LCFile.GetQuery();
|
||||
LCFile file = await query.Get("5e0dbfa0562071008e21c142");
|
||||
LCFile file = await query.Get(avatar.ObjectId);
|
||||
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";
|
||||
|
@ -69,17 +63,6 @@ namespace Storage.Test {
|
|||
Assert.NotNull(file.ObjectId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWS() {
|
||||
LCApplication.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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task FileACL() {
|
||||
LCUser user = await LCUser.LoginAnonymously();
|
||||
|
@ -101,5 +84,16 @@ namespace Storage.Test {
|
|||
Assert.AreEqual(e.Code, 403);
|
||||
}
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//public async Task AWS() {
|
||||
// LCApplication.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);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ using LeanCloud;
|
|||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class FriendTest {
|
||||
public class FriendTest : BaseTest {
|
||||
async Task<LCUser> SignUp() {
|
||||
LCUser user = new LCUser {
|
||||
Username = Guid.NewGuid().ToString(),
|
||||
|
@ -36,16 +36,6 @@ namespace Storage.Test {
|
|||
private LCUser user1;
|
||||
private LCUser user2;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(0)]
|
||||
public async Task Init() {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class GeoTest {
|
||||
public class GeoTest : BaseTest {
|
||||
[Test]
|
||||
public void Calculate() {
|
||||
LCGeoPoint p1 = new LCGeoPoint(20.0059, 110.3665);
|
||||
|
|
|
@ -9,21 +9,21 @@ using LeanCloud.Storage;
|
|||
using static NUnit.Framework.TestContext;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class LeaderboardTest {
|
||||
public class LeaderboardTest : BaseTest {
|
||||
private string leaderboardName;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
LCLogger.LogDelegate += Utils.Print;
|
||||
LCApplication.Initialize(Utils.AppId, Utils.AppKey, Utils.AppServer, Utils.MasterKey);
|
||||
public override void SetUp() {
|
||||
base.SetUp();
|
||||
LCApplication.Initialize(AppId, AppKey, AppServer, MasterKey);
|
||||
LCApplication.UseMasterKey = true;
|
||||
leaderboardName = $"Leaderboard_{DateTimeOffset.Now.DayOfYear}";
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
public override void TearDown() {
|
||||
base.TearDown();
|
||||
LCApplication.UseMasterKey = false;
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -2,26 +2,17 @@ using NUnit.Framework;
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LeanCloud;
|
||||
using LeanCloud.Storage;
|
||||
|
||||
using static NUnit.Framework.TestContext;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class ObjectTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
public class ObjectTest : BaseTest {
|
||||
[Test]
|
||||
public async Task CreateObject() {
|
||||
LCObject @object = new LCObject("Hello");
|
||||
Hello @object = new Hello();
|
||||
@object["intValue"] = 123;
|
||||
@object["boolValue"] = true;
|
||||
@object["stringValue"] = "hello, world";
|
||||
|
@ -38,19 +29,19 @@ namespace Storage.Test {
|
|||
@object["pointerList"] = new List<object> { new LCObject("World"), nestedObj };
|
||||
await @object.Save();
|
||||
|
||||
TestContext.WriteLine(@object.ClassName);
|
||||
TestContext.WriteLine(@object.ObjectId);
|
||||
TestContext.WriteLine(@object.CreatedAt);
|
||||
TestContext.WriteLine(@object.UpdatedAt);
|
||||
TestContext.WriteLine(@object["intValue"]);
|
||||
TestContext.WriteLine(@object["boolValue"]);
|
||||
TestContext.WriteLine(@object["stringValue"]);
|
||||
TestContext.WriteLine(@object["objectValue"]);
|
||||
TestContext.WriteLine(@object["time"]);
|
||||
WriteLine(@object.ClassName);
|
||||
WriteLine(@object.ObjectId);
|
||||
WriteLine(@object.CreatedAt);
|
||||
WriteLine(@object.UpdatedAt);
|
||||
WriteLine(@object["intValue"]);
|
||||
WriteLine(@object["boolValue"]);
|
||||
WriteLine(@object["stringValue"]);
|
||||
WriteLine(@object["objectValue"]);
|
||||
WriteLine(@object["time"]);
|
||||
|
||||
Assert.AreEqual(nestedObj, @object["objectValue"]);
|
||||
TestContext.WriteLine(nestedObj.ClassName);
|
||||
TestContext.WriteLine(nestedObj.ObjectId);
|
||||
WriteLine(nestedObj.ClassName);
|
||||
WriteLine(nestedObj.ObjectId);
|
||||
|
||||
Assert.NotNull(@object.ObjectId);
|
||||
Assert.NotNull(@object.ClassName);
|
||||
|
@ -77,8 +68,9 @@ namespace Storage.Test {
|
|||
public async Task SaveAll() {
|
||||
List<LCObject> list = new List<LCObject>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
LCObject world = new LCObject("World");
|
||||
world["content"] = $"word_{i}";
|
||||
World world = new World {
|
||||
Content = $"word_{i}"
|
||||
};
|
||||
list.Add(world);
|
||||
}
|
||||
await LCObject.SaveAll(list);
|
||||
|
@ -89,18 +81,18 @@ namespace Storage.Test {
|
|||
|
||||
[Test]
|
||||
public async Task Delete() {
|
||||
LCObject world = new LCObject("World");
|
||||
World world = new World();
|
||||
await world.Save();
|
||||
await world.Delete();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteAll() {
|
||||
List<LCObject> list = new List<LCObject> {
|
||||
new LCObject("World"),
|
||||
new LCObject("World"),
|
||||
new LCObject("World"),
|
||||
new LCObject("World")
|
||||
List<World> list = new List<World> {
|
||||
new World(),
|
||||
new World(),
|
||||
new World(),
|
||||
new World(),
|
||||
};
|
||||
await LCObject.SaveAll(list);
|
||||
await LCObject.DeleteAll(list);
|
||||
|
@ -108,47 +100,53 @@ namespace Storage.Test {
|
|||
|
||||
[Test]
|
||||
public async Task Fetch() {
|
||||
LCObject hello = LCObject.CreateWithoutData("Hello", "5e14392743c257006fb769d5");
|
||||
await hello.Fetch(includes: new List<string> { "objectValue" });
|
||||
LCObject world = hello["objectValue"] as LCObject;
|
||||
TestContext.WriteLine(world["content"]);
|
||||
Assert.AreEqual(world["content"], "7788");
|
||||
Hello hello = new Hello {
|
||||
World = new World {
|
||||
Content = "7788"
|
||||
}
|
||||
};
|
||||
await hello.Save();
|
||||
|
||||
hello = LCObject.CreateWithoutData("Hello", hello.ObjectId) as Hello;
|
||||
await hello.Fetch(includes: new string[] { "objectValue" });
|
||||
World world = hello.World;
|
||||
WriteLine(world.Content);
|
||||
Assert.AreEqual(world.Content, "7788");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveWithOption() {
|
||||
LCObject account = new LCObject("Account");
|
||||
account["balance"] = 10;
|
||||
Account account = new Account {
|
||||
Balance = 10
|
||||
};
|
||||
await account.Save();
|
||||
|
||||
account["balance"] = 1000;
|
||||
LCQuery<LCObject> q = new LCQuery<LCObject>("Account");
|
||||
q.WhereGreaterThan("balance", 100);
|
||||
try {
|
||||
await account.Save(fetchWhenSave: true, query: q);
|
||||
} catch(LCException e) {
|
||||
TestContext.WriteLine($"{e.Code} : {e.Message}");
|
||||
WriteLine($"{e.Code} : {e.Message}");
|
||||
Assert.AreEqual(e.Code, 305);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Unset() {
|
||||
LCObject hello = new LCObject("Hello");
|
||||
hello["content"] = "hello, world";
|
||||
Hello hello = new Hello {
|
||||
World = new World()
|
||||
};
|
||||
await hello.Save();
|
||||
TestContext.WriteLine(hello["content"]);
|
||||
Assert.AreEqual(hello["content"], "hello, world");
|
||||
Assert.NotNull(hello.World);
|
||||
|
||||
hello.Unset("content");
|
||||
hello.Unset("objectValue");
|
||||
await hello.Save();
|
||||
TestContext.WriteLine(hello["content"]);
|
||||
Assert.IsNull(hello["content"]);
|
||||
Assert.IsNull(hello.World);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OperateNullProperty() {
|
||||
LCObject obj = new LCObject("Hello");
|
||||
Hello obj = new Hello();
|
||||
obj.Increment("intValue", 123);
|
||||
obj.Increment("intValue", 321);
|
||||
obj.Add("intList", 1);
|
||||
|
@ -168,21 +166,19 @@ namespace Storage.Test {
|
|||
|
||||
[Test]
|
||||
public async Task FetchAll() {
|
||||
List<LCObject> list = new List<LCObject> {
|
||||
LCObject.CreateWithoutData("Hello", "5e8fe86938ed12000870ae82"),
|
||||
LCObject.CreateWithoutData("Hello", "5e8fe867158a7a0006be0feb"),
|
||||
LCObject.CreateWithoutData("Hello", "5e8fe84e5c385800081a1d64"),
|
||||
};
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Hello");
|
||||
IEnumerable<string> ids = (await query.Find()).Select(obj => obj.ObjectId);
|
||||
IEnumerable<LCObject> list = ids.Select(id => LCObject.CreateWithoutData("Hello", id));
|
||||
await LCObject.FetchAll(list);
|
||||
Assert.Greater(list.Count, 0);
|
||||
Assert.Greater(list.Count(), 0);
|
||||
foreach (LCObject obj in list) {
|
||||
Assert.NotNull(obj["intList"]);
|
||||
Assert.NotNull(obj.CreatedAt);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Serialization() {
|
||||
LCObject obj = new LCObject("Hello");
|
||||
Hello obj = new Hello();
|
||||
obj["intValue"] = 123;
|
||||
obj["boolValue"] = true;
|
||||
obj["stringValue"] = "hello, world";
|
||||
|
|
|
@ -4,39 +4,31 @@ using System.Threading.Tasks;
|
|||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class OperationTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
public class OperationTest : BaseTest {
|
||||
[Test]
|
||||
public async Task Increment() {
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Account");
|
||||
LCObject account = await query.Get("5e154a5143c257006fbff63f");
|
||||
TestContext.WriteLine(account["balance"]);
|
||||
int balance = (int)account["balance"];
|
||||
Account account = new Account {
|
||||
Balance = 10
|
||||
};
|
||||
await account.Save();
|
||||
TestContext.WriteLine(account.Balance);
|
||||
account.Increment("balance", 100);
|
||||
await account.Save();
|
||||
TestContext.WriteLine(account["balance"]);
|
||||
Assert.AreEqual((int)account["balance"], balance + 100);
|
||||
TestContext.WriteLine(account.Balance);
|
||||
Assert.AreEqual(account.Balance, 110);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Decrement() {
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Account");
|
||||
LCObject account = await query.Get("5e154a5143c257006fbff63f");
|
||||
TestContext.WriteLine(account["balance"]);
|
||||
int balance = (int)account["balance"];
|
||||
Account account = new Account {
|
||||
Balance = 100
|
||||
};
|
||||
await account.Save();
|
||||
TestContext.WriteLine(account.Balance);
|
||||
account.Increment("balance", -10);
|
||||
await account.Save();
|
||||
TestContext.WriteLine(account["balance"]);
|
||||
Assert.AreEqual((int)account["balance"], balance - 10);
|
||||
TestContext.WriteLine(account.Balance);
|
||||
Assert.AreEqual(account.Balance, 90);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -5,17 +5,7 @@ using System.Threading.Tasks;
|
|||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class QueryTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
public class QueryTest : BaseTest {
|
||||
[Test]
|
||||
public async Task BaseQuery() {
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Hello");
|
||||
|
@ -80,19 +70,30 @@ namespace Storage.Test {
|
|||
|
||||
[Test]
|
||||
public async Task Include() {
|
||||
Hello hello = new Hello {
|
||||
World = new World {
|
||||
Content = "7788"
|
||||
}
|
||||
};
|
||||
await hello.Save();
|
||||
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Hello");
|
||||
query.Include("objectValue");
|
||||
LCObject hello = await query.Get("5e0d55aedd3c13006a53cd87");
|
||||
LCObject world = hello["objectValue"] as LCObject;
|
||||
TestContext.WriteLine(world["content"]);
|
||||
Assert.AreEqual(world["content"], "7788");
|
||||
Hello queryHello = (await query.Get(hello.ObjectId)) as Hello;
|
||||
World world = queryHello.World;
|
||||
TestContext.WriteLine(world.Content);
|
||||
Assert.AreEqual(world.Content, "7788");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get() {
|
||||
Account account = new Account {
|
||||
Balance = 1024
|
||||
};
|
||||
await account.Save();
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Account");
|
||||
LCObject account = await query.Get("5e0d9f7fd4b56c008e5d048a");
|
||||
Assert.AreEqual(account["balance"], 400);
|
||||
Account newAccount = (await query.Get(account.ObjectId)) as Account;
|
||||
Assert.AreEqual(newAccount.Balance, 1024);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -143,13 +144,19 @@ namespace Storage.Test {
|
|||
|
||||
[Test]
|
||||
public async Task WhereObjectEquals() {
|
||||
World world = new World();
|
||||
Hello hello = new Hello {
|
||||
World = world
|
||||
};
|
||||
await hello.Save();
|
||||
|
||||
LCQuery<LCObject> worldQuery = new LCQuery<LCObject>("World");
|
||||
LCObject world = await worldQuery.Get("5e0d55ae21460d006a1ec931");
|
||||
LCObject queryWorld = await worldQuery.Get(world.ObjectId);
|
||||
LCQuery<LCObject> helloQuery = new LCQuery<LCObject>("Hello");
|
||||
helloQuery.WhereEqualTo("objectValue", world);
|
||||
LCObject hello = await helloQuery.First();
|
||||
TestContext.WriteLine(hello.ObjectId);
|
||||
Assert.AreEqual(hello.ObjectId, "5e0d55aedd3c13006a53cd87");
|
||||
helloQuery.WhereEqualTo("objectValue", queryWorld);
|
||||
LCObject queryHello = await helloQuery.First();
|
||||
TestContext.WriteLine(queryHello.ObjectId);
|
||||
Assert.AreEqual(queryHello.ObjectId, hello.ObjectId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -4,23 +4,18 @@ using System.Collections.ObjectModel;
|
|||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class RelationTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
public class RelationTest : BaseTest {
|
||||
private LCObject parent;
|
||||
private LCObject c1;
|
||||
private LCObject c2;
|
||||
|
||||
[Test]
|
||||
[Order(0)]
|
||||
public async Task AddAndRemove() {
|
||||
LCObject parent = new LCObject("Parent");
|
||||
LCObject c1 = new LCObject("Child");
|
||||
parent = new LCObject("Parent");
|
||||
c1 = new LCObject("Child");
|
||||
parent.AddRelation("children", c1);
|
||||
LCObject c2 = new LCObject("Child");
|
||||
c2 = new LCObject("Child");
|
||||
parent.AddRelation("children", c2);
|
||||
await parent.Save();
|
||||
|
||||
|
@ -40,10 +35,11 @@ namespace Storage.Test {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Order(1)]
|
||||
public async Task Query() {
|
||||
LCQuery<LCObject> query = new LCQuery<LCObject>("Parent");
|
||||
LCObject parent = await query.Get("5e13112021b47e0070ed0922");
|
||||
LCRelation<LCObject> relation = parent["children"] as LCRelation<LCObject>;
|
||||
LCObject queryParent = await query.Get(parent.ObjectId);
|
||||
LCRelation<LCObject> relation = queryParent["children"] as LCRelation<LCObject>;
|
||||
|
||||
TestContext.WriteLine(relation.Key);
|
||||
TestContext.WriteLine(relation.Parent);
|
||||
|
|
|
@ -5,23 +5,13 @@ using System.Threading.Tasks;
|
|||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
[TestFixture]
|
||||
public class RoleTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
public class RoleTest : BaseTest {
|
||||
[Test]
|
||||
public async Task NewRole() {
|
||||
LCUser currentUser = await LCUser.Login("game", "play");
|
||||
LCACL acl = new LCACL();
|
||||
acl.PublicReadAccess = true;
|
||||
LCUser currentUser = await LCUser.Login(TestPhone, TestPhone);
|
||||
LCACL acl = new LCACL {
|
||||
PublicReadAccess = true
|
||||
};
|
||||
acl.SetUserWriteAccess(currentUser, true);
|
||||
string name = $"role_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}";
|
||||
LCRole role = LCRole.Create(name, acl);
|
||||
|
|
|
@ -4,20 +4,10 @@ using System.Threading.Tasks;
|
|||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class SMSTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
public class SMSTest : BaseTest {
|
||||
//[Test]
|
||||
public async Task RequestSMS() {
|
||||
await LCSMSClient.RequestSMSCode("15101006007",
|
||||
await LCSMSClient.RequestSMSCode(TestPhone,
|
||||
template: "test_template",
|
||||
signature: "flutter-test",
|
||||
variables: new Dictionary<string, object> {
|
||||
|
@ -27,12 +17,12 @@ namespace Storage.Test {
|
|||
|
||||
//[Test]
|
||||
public async Task RequestVoice() {
|
||||
await LCSMSClient.RequestVoiceCode("+8615101006007");
|
||||
await LCSMSClient.RequestVoiceCode(TestPhone);
|
||||
}
|
||||
|
||||
//[Test]
|
||||
[Test]
|
||||
public async Task Verify() {
|
||||
await LCSMSClient.VerifyMobilePhone("15101006007", "");
|
||||
await LCSMSClient.VerifyMobilePhone(TestPhone, TestSMSCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,21 +6,11 @@ using System.Collections.ObjectModel;
|
|||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class StatusTest {
|
||||
public class StatusTest : BaseTest {
|
||||
private LCUser user1;
|
||||
private LCUser user2;
|
||||
private LCUser user3;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(0)]
|
||||
public async Task Init() {
|
||||
|
|
|
@ -1,55 +1,12 @@
|
|||
using NUnit.Framework;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.ObjectModel;
|
||||
using LeanCloud;
|
||||
using LeanCloud.Storage;
|
||||
|
||||
namespace Storage.Test {
|
||||
internal class Hello : LCObject {
|
||||
internal World World => this["objectValue"] as World;
|
||||
|
||||
internal Hello() : base("Hello") { }
|
||||
}
|
||||
|
||||
internal class World : LCObject {
|
||||
internal string Content {
|
||||
get {
|
||||
return this["content"] as string;
|
||||
} set {
|
||||
this["content"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal World() : base("World") { }
|
||||
}
|
||||
|
||||
internal class Account : LCObject {
|
||||
internal int Balance {
|
||||
get {
|
||||
return (int)this["balance"];
|
||||
} set {
|
||||
this["balance"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal Account() : base("Account") { }
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class SubClassTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
public class SubClassTest : BaseTest {
|
||||
[Test]
|
||||
public async Task Create() {
|
||||
LCObject.RegisterSubclass<Account>("Account", () => new Account());
|
||||
Account account = new Account();
|
||||
account.Balance = 1000;
|
||||
await account.Save();
|
||||
|
@ -59,7 +16,6 @@ namespace Storage.Test {
|
|||
|
||||
[Test]
|
||||
public async Task Query() {
|
||||
LCObject.RegisterSubclass<Account>("Account", () => new Account());
|
||||
LCQuery<Account> query = new LCQuery<Account>("Account");
|
||||
query.WhereGreaterThan("balance", 500);
|
||||
ReadOnlyCollection<Account> list = await query.Find();
|
||||
|
@ -72,29 +28,11 @@ namespace Storage.Test {
|
|||
|
||||
[Test]
|
||||
public async Task Delete() {
|
||||
LCObject.RegisterSubclass<Account>("Account", () => new Account());
|
||||
Account account = new Account() {
|
||||
Balance = 1024
|
||||
};
|
||||
await account.Save();
|
||||
await account.Delete();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Include() {
|
||||
LCObject.RegisterSubclass<Hello>("Hello", () => new Hello());
|
||||
LCObject.RegisterSubclass<World>("World", () => new World());
|
||||
|
||||
LCQuery<Hello> helloQuery = new LCQuery<Hello>("Hello");
|
||||
helloQuery.Include("objectValue");
|
||||
Hello hello = await helloQuery.Get("5e0d55aedd3c13006a53cd87");
|
||||
World world = hello.World;
|
||||
|
||||
TestContext.WriteLine(hello.ObjectId);
|
||||
Assert.AreEqual(hello.ObjectId, "5e0d55aedd3c13006a53cd87");
|
||||
TestContext.WriteLine(world.ObjectId);
|
||||
Assert.AreEqual(world.ObjectId, "5e0d55ae21460d006a1ec931");
|
||||
Assert.AreEqual(world.Content, "7788");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,18 +7,9 @@ using LeanCloud.Storage;
|
|||
using LC.Newtonsoft.Json;
|
||||
|
||||
namespace Storage.Test {
|
||||
public class UserTest {
|
||||
[SetUp]
|
||||
public void SetUp() {
|
||||
Utils.SetUp();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown() {
|
||||
Utils.TearDown();
|
||||
}
|
||||
|
||||
public class UserTest : BaseTest {
|
||||
[Test]
|
||||
[Order(0)]
|
||||
public async Task SignUp() {
|
||||
LCUser user = new LCUser();
|
||||
long unixTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
|
@ -26,9 +17,9 @@ namespace Storage.Test {
|
|||
user.Password = "world";
|
||||
string email = $"{unixTime}@qq.com";
|
||||
user.Email = email;
|
||||
Random random = new Random();
|
||||
string mobile = $"151{random.Next(10000000, 99999999)}";
|
||||
user.Mobile = mobile;
|
||||
//Random random = new Random();
|
||||
//string mobile = $"151{random.Next(10000000, 99999999)}";
|
||||
//user.Mobile = mobile;
|
||||
await user.SignUp();
|
||||
|
||||
TestContext.WriteLine(user.Username);
|
||||
|
@ -42,40 +33,63 @@ namespace Storage.Test {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Order(1)]
|
||||
public async Task Login() {
|
||||
await LCUser.Login("hello", "world");
|
||||
try {
|
||||
await LCUser.Login(TestPhone, TestPhone);
|
||||
} catch (LCException e) {
|
||||
if (e.Code == 211) {
|
||||
LCUser user = new LCUser {
|
||||
Username = TestPhone,
|
||||
Password = TestPhone,
|
||||
Mobile = TestPhone,
|
||||
Email = GetTestEmail()
|
||||
};
|
||||
await user.SignUp();
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
await LCUser.Login(TestPhone, TestPhone);
|
||||
LCUser current = await LCUser.GetCurrent();
|
||||
Assert.NotNull(current.ObjectId);
|
||||
Assert.IsFalse(current.EmailVerified);
|
||||
Assert.IsFalse(!current.MobileVerified);
|
||||
Assert.AreEqual(current.Mobile, "15101006007");
|
||||
Assert.IsTrue(current.MobileVerified);
|
||||
Assert.AreEqual(current.Mobile, TestPhone);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(2)]
|
||||
public async Task LoginByEmail() {
|
||||
await LCUser.LoginByEmail("171253484@qq.com", "world");
|
||||
await LCUser.LoginByEmail(GetTestEmail(), TestPhone);
|
||||
LCUser current = await LCUser.GetCurrent();
|
||||
Assert.NotNull(current.ObjectId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(3)]
|
||||
public async Task LoginBySessionToken() {
|
||||
LCUser user = await LCUser.Login(TestPhone, TestPhone);
|
||||
string sessionToken = user.SessionToken;
|
||||
await LCUser.Logout();
|
||||
string sessionToken = "luo2fpl4qij2050e7enqfz173";
|
||||
|
||||
await LCUser.BecomeWithSessionToken(sessionToken);
|
||||
LCUser current = await LCUser.GetCurrent();
|
||||
Assert.NotNull(current.ObjectId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(4)]
|
||||
public async Task RelateObject() {
|
||||
LCUser user = await LCUser.LoginByMobilePhoneNumber("15101006007", "world");
|
||||
LCObject account = new LCObject("Account");
|
||||
account["user"] = user;
|
||||
LCUser user = await LCUser.LoginByMobilePhoneNumber(TestPhone, TestPhone);
|
||||
Account account = new Account();
|
||||
account.User = user;
|
||||
await account.Save();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(5)]
|
||||
public async Task LoginAnonymous() {
|
||||
LCUser user = await LCUser.LoginAnonymously();
|
||||
Assert.NotNull(user.ObjectId);
|
||||
|
@ -83,6 +97,7 @@ namespace Storage.Test {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Order(6)]
|
||||
public async Task LoginWithAuthData() {
|
||||
string uuid = Guid.NewGuid().ToString();
|
||||
Dictionary<string, object> authData = new Dictionary<string, object> {
|
||||
|
@ -109,6 +124,7 @@ namespace Storage.Test {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Order(7)]
|
||||
public async Task AssociateAuthData() {
|
||||
string uuid = Guid.NewGuid().ToString();
|
||||
LCUser currentUser = await LCUser.Login("hello", "world");
|
||||
|
@ -123,12 +139,14 @@ namespace Storage.Test {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Order(8)]
|
||||
public async Task DisassociateAuthData() {
|
||||
LCUser currentUser = await LCUser.Login("hello", "world");
|
||||
await currentUser.DisassociateWithAuthData("weixin");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(9)]
|
||||
public async Task IsAuthenticated() {
|
||||
LCUser currentUser = await LCUser.Login("hello", "world");
|
||||
bool isAuthenticated = await currentUser.IsAuthenticated();
|
||||
|
@ -137,6 +155,7 @@ namespace Storage.Test {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Order(10)]
|
||||
public async Task UpdatePassword() {
|
||||
LCUser currentUser = await LCUser.Login("hello", "world");
|
||||
await currentUser.UpdatePassword("world", "newWorld");
|
||||
|
@ -144,6 +163,7 @@ namespace Storage.Test {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Order(11)]
|
||||
public async Task LoginWithAuthDataWithUnionId() {
|
||||
string uuid = Guid.NewGuid().ToString();
|
||||
Dictionary<string, object> authData = new Dictionary<string, object> {
|
||||
|
@ -174,8 +194,9 @@ namespace Storage.Test {
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Order(12)]
|
||||
public async Task AssociateAuthDataWithUnionId() {
|
||||
LCUser currentUser = await LCUser.Login("hello", "world");
|
||||
LCUser currentUser = await LCUser.Login(TestPhone, TestPhone);
|
||||
string uuid = Guid.NewGuid().ToString();
|
||||
Dictionary<string, object> authData = new Dictionary<string, object> {
|
||||
{ "expires_in", 7200 },
|
||||
|
@ -188,22 +209,24 @@ namespace Storage.Test {
|
|||
|
||||
// 手动测试
|
||||
|
||||
//[Test]
|
||||
//public async Task LoginByMobile() {
|
||||
// LCUser user = await LCUser.LoginByMobilePhoneNumber("15101006007", "112358");
|
||||
// Assert.NotNull(user.ObjectId);
|
||||
//}
|
||||
[Test]
|
||||
[Order(13)]
|
||||
public async Task LoginByMobile() {
|
||||
LCUser user = await LCUser.LoginByMobilePhoneNumber(TestPhone, TestPhone);
|
||||
Assert.NotNull(user.ObjectId);
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//public async Task RequestLoginSMSCode() {
|
||||
// await LCUser.RequestLoginSMSCode("15101006007");
|
||||
//}
|
||||
|
||||
//[Test]
|
||||
//public async Task LoginBySMSCode() {
|
||||
// LCUser user = await LCUser.LoginBySMSCode("15101006007", "194998");
|
||||
// Assert.NotNull(user.ObjectId);
|
||||
//}
|
||||
[Test]
|
||||
[Order(14)]
|
||||
public async Task LoginBySMSCode() {
|
||||
LCUser user = await LCUser.LoginBySMSCode(TestPhone, TestSMSCode);
|
||||
Assert.NotNull(user.ObjectId);
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//public async Task RequestEmailVerify() {
|
||||
|
@ -215,10 +238,11 @@ namespace Storage.Test {
|
|||
// await LCUser.RequestMobilePhoneVerify("15101006007");
|
||||
//}
|
||||
|
||||
//[Test]
|
||||
//public async Task VerifyMobile() {
|
||||
// await LCUser.VerifyMobilePhone("15101006007", "506993");
|
||||
//}
|
||||
[Test]
|
||||
[Order(15)]
|
||||
public async Task VerifyMobile() {
|
||||
await LCUser.VerifyMobilePhone(TestPhone, TestSMSCode);
|
||||
}
|
||||
|
||||
//[Test]
|
||||
//public async Task RequestResetPasswordBySMSCode() {
|
||||
|
@ -230,19 +254,21 @@ namespace Storage.Test {
|
|||
// await LCUser.ResetPasswordBySmsCode("15101006007", "732552", "112358");
|
||||
//}
|
||||
|
||||
[Test]
|
||||
public async Task RequestSMSCodeForUpdatingPhoneNumber() {
|
||||
await LCUser.Login("hello", "world");
|
||||
await LCUser.RequestSMSCodeForUpdatingPhoneNumber("15101006007");
|
||||
}
|
||||
//[Test]
|
||||
//public async Task RequestSMSCodeForUpdatingPhoneNumber() {
|
||||
// await LCUser.Login(TestPhone, TestPhone);
|
||||
// await LCUser.RequestSMSCodeForUpdatingPhoneNumber(TestPhone);
|
||||
//}
|
||||
|
||||
[Test]
|
||||
[Order(16)]
|
||||
public async Task VerifyCodeForUpdatingPhoneNumber() {
|
||||
await LCUser.Login("hello", "world");
|
||||
await LCUser.VerifyCodeForUpdatingPhoneNumber("15101006007", "969327");
|
||||
await LCUser.Login(TestPhone, TestPhone);
|
||||
await LCUser.VerifyCodeForUpdatingPhoneNumber(TestPhone, TestSMSCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Order(17)]
|
||||
public async Task AuthData() {
|
||||
string uuid = Guid.NewGuid().ToString();
|
||||
Dictionary<string, object> authData = new Dictionary<string, object> {
|
||||
|
@ -270,5 +296,9 @@ namespace Storage.Test {
|
|||
TestContext.WriteLine(JsonConvert.SerializeObject(currentUser.AuthData));
|
||||
}
|
||||
}
|
||||
|
||||
private string GetTestEmail() {
|
||||
return $"{TestPhone}@leancloud.rocks";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
using NUnit.Framework;
|
||||
using LeanCloud;
|
||||
|
||||
namespace Storage.Test {
|
||||
public static class Utils {
|
||||
internal const string AppId = "ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz";
|
||||
internal const string AppKey = "NUKmuRbdAhg1vrb2wexYo1jo";
|
||||
internal const string MasterKey = "pyvbNSh5jXsuFQ3C8EgnIdhw";
|
||||
internal const string AppServer = "https://ikggdre2.lc-cn-n1-shared.com";
|
||||
|
||||
internal static void Print(LCLogLevel level, string info) {
|
||||
switch (level) {
|
||||
case LCLogLevel.Debug:
|
||||
TestContext.Out.WriteLine($"[DEBUG] {info}");
|
||||
break;
|
||||
case LCLogLevel.Warn:
|
||||
TestContext.Out.WriteLine($"[WARNING] {info}");
|
||||
break;
|
||||
case LCLogLevel.Error:
|
||||
TestContext.Out.WriteLine($"[ERROR] {info}");
|
||||
break;
|
||||
default:
|
||||
TestContext.Out.WriteLine(info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SetUp() {
|
||||
LCLogger.LogDelegate += Print;
|
||||
LCApplication.Initialize(AppId, AppKey, AppServer);
|
||||
}
|
||||
|
||||
internal static void TearDown() {
|
||||
LCLogger.LogDelegate -= Print;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue