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

65 lines
2.3 KiB
C#
Raw Normal View History

using NUnit.Framework;
2019-08-07 14:58:24 +08:00
using System.Collections.Generic;
using System.Threading.Tasks;
2019-08-07 14:58:24 +08:00
using System.Linq;
using LeanCloud;
namespace LeanCloudTests {
public class QueryTest {
[SetUp]
public void SetUp() {
AVClient.Initialize(new AVClient.Configuration {
ApplicationId = "BMYV4RKSTwo8WSqt8q9ezcWF-gzGzoHsz",
ApplicationKey = "pbf6Nk5seyjilexdpyrPwjSp",
2019-08-06 15:21:39 +08:00
ApiServer = "https://avoscloud.com"
});
AVClient.HttpLog(TestContext.Out.WriteLine);
}
[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");
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);
}
}
}
}