diff --git a/Realtime/Realtime/Conversation/LCIMConversationQuery.cs b/Realtime/Realtime/Conversation/LCIMConversationQuery.cs
index 5904ab1..700ba8d 100644
--- a/Realtime/Realtime/Conversation/LCIMConversationQuery.cs
+++ b/Realtime/Realtime/Conversation/LCIMConversationQuery.cs
@@ -184,7 +184,7 @@ namespace LeanCloud.Realtime {
///
///
public LCIMConversationQuery OrderBy(string key) {
- Condition.OrderBy(key);
+ Condition.OrderByAscending(key);
return this;
}
diff --git a/Storage/Storage.Test/QueryTest.cs b/Storage/Storage.Test/QueryTest.cs
index 8bd009a..27d3a89 100644
--- a/Storage/Storage.Test/QueryTest.cs
+++ b/Storage/Storage.Test/QueryTest.cs
@@ -1,4 +1,5 @@
using NUnit.Framework;
+using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Threading.Tasks;
using LeanCloud;
@@ -21,7 +22,7 @@ namespace Storage.Test {
public async Task BaseQuery() {
LCQuery query = new LCQuery("Hello");
query.Limit(2);
- List list = await query.Find();
+ ReadOnlyCollection list = await query.Find();
TestContext.WriteLine(list.Count);
Assert.AreEqual(list.Count, 2);
@@ -53,8 +54,8 @@ namespace Storage.Test {
[Test]
public async Task OrderBy() {
LCQuery query = new LCQuery("Account");
- query.OrderBy("balance");
- List results = await query.Find();
+ query.OrderByAscending("balance");
+ ReadOnlyCollection results = await query.Find();
Assert.LessOrEqual((int)results[0]["balance"], (int)results[1]["balance"]);
query = new LCQuery("Account");
@@ -63,6 +64,22 @@ namespace Storage.Test {
Assert.GreaterOrEqual((int)results[0]["balance"], (int)results[1]["balance"]);
}
+ [Test]
+ public async Task AddOrder() {
+ LCQuery query = new LCQuery("Account");
+ query.AddAscendingOrder("balance");
+ query.AddDescendingOrder("createdAt");
+ ReadOnlyCollection results = await query.Find();
+ for (int i = 0; i + 1 < results.Count; i++) {
+ LCObject a1 = results[i];
+ LCObject a2 = results[i + 1];
+ int b1 = (int)a1["balance"];
+ int b2 = (int)a2["balance"];
+ Assert.IsTrue(b1 < b2 ||
+ a1.CreatedAt.CompareTo(a2.CreatedAt) >= 0);
+ }
+ }
+
[Test]
public async Task Include() {
LCQuery query = new LCQuery("Hello");
@@ -91,7 +108,7 @@ namespace Storage.Test {
public async Task GreaterQuery() {
LCQuery query = new LCQuery("Account");
query.WhereGreaterThan("balance", 200);
- List list = await query.Find();
+ ReadOnlyCollection list = await query.Find();
TestContext.WriteLine(list.Count);
Assert.Greater(list.Count, 0);
}
@@ -103,12 +120,12 @@ namespace Storage.Test {
LCQuery q2 = new LCQuery("Account");
q2.WhereLessThan("balance", 500);
LCQuery query = LCQuery.And(new List> { q1, q2 });
- List results = await query.Find();
+ ReadOnlyCollection results = await query.Find();
TestContext.WriteLine(results.Count);
- results.ForEach(item => {
+ foreach (LCObject item in results) {
int balance = (int)item["balance"];
Assert.IsTrue(balance >= 100 || balance <= 500);
- });
+ }
}
[Test]
@@ -118,12 +135,12 @@ namespace Storage.Test {
LCQuery q2 = new LCQuery("Account");
q2.WhereGreaterThanOrEqualTo("balance", 500);
LCQuery query = LCQuery.Or(new List> { q1, q2 });
- List results = await query.Find();
+ ReadOnlyCollection results = await query.Find();
TestContext.WriteLine(results.Count);
- results.ForEach(item => {
+ foreach (LCObject item in results) {
int balance = (int)item["balance"];
Assert.IsTrue(balance <= 100 || balance >= 500);
- });
+ }
}
[Test]
@@ -141,28 +158,28 @@ namespace Storage.Test {
public async Task Exist() {
LCQuery query = new LCQuery("Account");
query.WhereExists("user");
- List results = await query.Find();
- results.ForEach(item => {
+ ReadOnlyCollection results = await query.Find();
+ foreach (LCObject item in results) {
Assert.NotNull(item["user"]);
- });
+ }
query = new LCQuery("Account");
query.WhereDoesNotExist("user");
results = await query.Find();
- results.ForEach(item => {
+ foreach (LCObject item in results) {
Assert.IsNull(item["user"]);
- });
+ }
}
[Test]
public async Task Select() {
LCQuery query = new LCQuery("Account");
query.Select("balance");
- List results = await query.Find();
- results.ForEach(item => {
+ ReadOnlyCollection results = await query.Find();
+ foreach (LCObject item in results) {
Assert.NotNull(item["balance"]);
Assert.IsNull(item["user"]);
- });
+ }
}
[Test]
@@ -170,29 +187,29 @@ namespace Storage.Test {
// Start
LCQuery query = new LCQuery("Hello");
query.WhereStartsWith("stringValue", "hello");
- List results = await query.Find();
- results.ForEach(item => {
+ ReadOnlyCollection results = await query.Find();
+ foreach (LCObject item in results) {
string str = item["stringValue"] as string;
Assert.IsTrue(str.StartsWith("hello"));
- });
+ }
// End
query = new LCQuery("Hello");
query.WhereEndsWith("stringValue", "world");
results = await query.Find();
- results.ForEach(item => {
+ foreach (LCObject item in results) {
string str = item["stringValue"] as string;
Assert.IsTrue(str.EndsWith("world"));
- });
+ }
// Contains
query = new LCQuery("Hello");
query.WhereContains("stringValue", ",");
results = await query.Find();
- results.ForEach(item => {
+ foreach (LCObject item in results) {
string str = item["stringValue"] as string;
Assert.IsTrue(str.Contains(','));
- });
+ }
}
[Test]
@@ -200,46 +217,60 @@ namespace Storage.Test {
// equal
LCQuery query = new LCQuery("Book");
query.WhereEqualTo("pages", 3);
- Listresults = await query.Find();
- results.ForEach(item => {
+ ReadOnlyCollectionresults = await query.Find();
+ foreach (LCObject item in results) {
List