2019-08-01 17:36:34 +08:00
|
|
|
|
using NUnit.Framework;
|
2019-08-07 14:58:24 +08:00
|
|
|
|
using System.Collections.Generic;
|
2019-08-01 17:36:34 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2019-08-07 14:58:24 +08:00
|
|
|
|
using System.Linq;
|
2019-08-01 17:36:34 +08:00
|
|
|
|
using LeanCloud;
|
|
|
|
|
|
|
|
|
|
namespace LeanCloudTests {
|
|
|
|
|
public class QueryTest {
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() {
|
2019-09-06 11:51:52 +08:00
|
|
|
|
Utils.InitNorthChina();
|
2019-08-01 17:36:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2019-08-07 14:58:24 +08:00
|
|
|
|
public async Task BasicQuery() {
|
2019-08-06 18:26:56 +08:00
|
|
|
|
var query = new AVQuery<AVObject>("Foo");
|
|
|
|
|
query.WhereEqualTo("content", "hello");
|
2019-08-06 15:21:39 +08:00
|
|
|
|
var results = await query.FindAsync();
|
|
|
|
|
foreach (var result in results) {
|
|
|
|
|
TestContext.Out.WriteLine(result.ObjectId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2019-08-07 14:58:24 +08:00
|
|
|
|
public async Task Count() {
|
2019-08-06 18:26:56 +08:00
|
|
|
|
var query = new AVQuery<AVObject>("Foo");
|
|
|
|
|
query.WhereEqualTo("content", "hello, world");
|
2019-08-01 17:36:34 +08:00
|
|
|
|
var count = await query.CountAsync();
|
|
|
|
|
Assert.Greater(count, 8);
|
|
|
|
|
}
|
2019-08-07 14:58:24 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Or() {
|
|
|
|
|
AVQuery<AVObject> q1 = new AVQuery<AVObject>("Foo");
|
|
|
|
|
q1.WhereEqualTo("content", "hello");
|
|
|
|
|
AVQuery<AVObject> q2 = new AVQuery<AVObject>("Foo");
|
|
|
|
|
q2.WhereEqualTo("content", "world");
|
|
|
|
|
AVQuery<AVObject> query = AVQuery<AVObject>.Or(new List<AVQuery<AVObject>> { q1, q2 });
|
|
|
|
|
IEnumerable<AVObject> results = await query.FindAsync();
|
|
|
|
|
foreach (AVObject result in results) {
|
|
|
|
|
TestContext.Out.WriteLine(result.ObjectId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task And() {
|
|
|
|
|
AVQuery<AVObject> q1 = new AVQuery<AVObject>("Foo");
|
|
|
|
|
q1.WhereContains("content", "hello");
|
|
|
|
|
AVQuery<AVObject> q2 = new AVQuery<AVObject>("Foo");
|
|
|
|
|
q2.WhereContains("content", "world");
|
|
|
|
|
AVQuery<AVObject> query = AVQuery<AVObject>.And(new List<AVQuery<AVObject>> { q1, q2 });
|
|
|
|
|
IEnumerable<AVObject> results = await query.FindAsync();
|
|
|
|
|
TestContext.Out.WriteLine($"Count: {results.Count()}");
|
|
|
|
|
foreach (AVObject result in results) {
|
|
|
|
|
TestContext.Out.WriteLine(result.ObjectId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-01 17:36:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|