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

75 lines
2.6 KiB
C#
Raw Normal View History

2019-08-07 17:41:36 +08:00
using NUnit.Framework;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using System;
using LeanCloud;
namespace LeanCloudTests {
public class UserTest {
[SetUp]
public void SetUp() {
AVClient.Initialize(new AVClient.Configuration {
ApplicationId = "BMYV4RKSTwo8WSqt8q9ezcWF-gzGzoHsz",
ApplicationKey = "pbf6Nk5seyjilexdpyrPwjSp",
ApiServer = "https://avoscloud.com"
});
AVClient.HttpLog(TestContext.Out.WriteLine);
}
[Test]
public async Task Register() {
AVUser user = new AVUser {
Username = $"hello_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}",
Password = "world"
};
await user.SignUpAsync();
TestContext.Out.WriteLine($"{user.ObjectId} registered");
}
[Test]
2019-08-21 16:30:34 +08:00
public async Task LoginWithUsername() {
AVUser user = await AVUser.LogInAsync("hello", "111111");
TestContext.Out.WriteLine($"{user.ObjectId}, {user.SessionToken} login");
}
[Test]
public async Task LoginWithEmail() {
2019-08-22 11:52:26 +08:00
AVUser user = await AVUser.LogInWithEmailAsync("111111@qq.com", "111111");
2019-08-21 16:30:34 +08:00
Assert.AreEqual(user, AVUser.CurrentUser);
TestContext.Out.WriteLine($"{AVUser.CurrentUser.SessionToken} login");
}
[Test]
public async Task Become() {
AVUser user = await AVUser.BecomeAsync("36idbfnt8hlmdo4rki0f5hevq");
Assert.AreEqual(user, AVUser.CurrentUser);
TestContext.Out.WriteLine($"{AVUser.CurrentUser.SessionToken} login");
}
[Test]
public async Task IsAuthenticated() {
2019-08-22 11:52:26 +08:00
AVUser user = await AVUser.LogInWithEmailAsync("111111@qq.com", "111111");
2019-08-21 16:30:34 +08:00
Assert.IsTrue(user.IsCurrent);
Assert.AreEqual(user, AVUser.CurrentUser);
bool authenticated = await user.IsAuthenticatedAsync();
Assert.IsTrue(authenticated);
}
[Test]
public async Task RefreshSessionToken() {
2019-08-22 11:52:26 +08:00
AVUser user = await AVUser.LogInWithEmailAsync("111111@qq.com", "111111");
2019-08-21 16:30:34 +08:00
Assert.IsTrue(user.IsCurrent);
await user.RefreshSessionTokenAsync();
TestContext.Out.WriteLine(user.SessionToken);
}
[Test]
public async Task UpdatePassword() {
AVUser user = await AVUser.LogInAsync("111111", "111111");
await user.UpdatePasswordAsync("111111", "222222");
await user.UpdatePasswordAsync("222222", "111111");
2019-08-07 17:41:36 +08:00
}
}
}