2019-07-30 16:47:10 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using LeanCloud;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
2019-09-17 11:53:28 +08:00
|
|
|
namespace LeanCloud.Test {
|
2019-07-30 16:47:10 +08:00
|
|
|
public class ObjectTests {
|
|
|
|
[SetUp]
|
|
|
|
public void SetUp() {
|
2019-08-28 12:10:59 +08:00
|
|
|
Utils.InitNorthChina();
|
2019-07-30 16:47:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAVObjectConstructor() {
|
|
|
|
AVObject obj = new AVObject("Foo");
|
|
|
|
Assert.AreEqual("Foo", obj.ClassName);
|
|
|
|
Assert.Null(obj.CreatedAt);
|
|
|
|
Assert.True(obj.IsDataAvailable);
|
|
|
|
Assert.True(obj.IsDirty);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAVObjectCreate() {
|
|
|
|
AVObject obj = AVObject.CreateWithoutData("Foo", "5d356b1cd5de2b00837162ca");
|
|
|
|
Assert.AreEqual("Foo", obj.ClassName);
|
|
|
|
Assert.AreEqual("5d356b1cd5de2b00837162ca", obj.ObjectId);
|
|
|
|
Assert.Null(obj.CreatedAt);
|
|
|
|
Assert.False(obj.IsDataAvailable);
|
|
|
|
Assert.False(obj.IsDirty);
|
|
|
|
}
|
|
|
|
|
2019-08-23 16:16:18 +08:00
|
|
|
[Test]
|
|
|
|
public async Task TestMassiveRequest() {
|
2019-09-09 16:34:49 +08:00
|
|
|
ThreadPool.SetMaxThreads(1, 1);
|
2019-08-23 16:16:18 +08:00
|
|
|
await Task.Run(() => {
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
for (int j = 0; j < 50; j++) {
|
|
|
|
AVObject obj = AVObject.Create("Foo");
|
|
|
|
obj.SaveAsync().ContinueWith(_ => {
|
2019-09-09 16:34:49 +08:00
|
|
|
TestContext.Out.WriteLine($"{obj.ObjectId} saved at {Thread.CurrentThread.ManagedThreadId}");
|
2019-08-23 16:16:18 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-07-30 16:47:10 +08:00
|
|
|
}
|
|
|
|
}
|