in firestore/testapp/Assets/Firebase/Sample/Firestore/UIHandlerAutomated.cs [1983:2111]
Task TestQueries() {
return Async(() => {
// Initialize collection with a few test documents to query against.
var c = TestCollection();
Await(c.Document("a").SetAsync(new Dictionary<string, object> {
{ "num", 1 },
{ "state", "created" },
{ "active", true },
{ "nullable", "value" },
}));
Await(c.Document("b").SetAsync(new Dictionary<string, object> {
{ "num", 2 },
{ "state", "done" },
{ "active", false },
{ "nullable", null },
}));
Await(c.Document("c").SetAsync(new Dictionary<string, object> {
{ "num", 3 },
{ "state", "done" },
{ "active", true },
{ "nullable", null },
}));
// Put in a nested collection (with same ID) for testing collection group queries.
Await(c.Document("d")
.Collection(c.Id)
.Document("d-nested")
.SetAsync(new Dictionary<string, object> {
{ "num", 4 },
{ "state", "created" },
{ "active", false },
{ "nullable", null },
}));
AssertQueryResults(
desc: "EqualTo",
query: c.WhereEqualTo("num", 1),
docIds: AsList("a"));
AssertQueryResults(
desc: "EqualTo (FieldPath)",
query: c.WhereEqualTo(new FieldPath("num"), 1),
docIds: AsList("a"));
AssertQueryResults(desc: "NotEqualTo", query: c.WhereNotEqualTo("num", 1),
docIds: AsList("b", "c"));
AssertQueryResults(desc: "NotEqualTo (FieldPath)",
query: c.WhereNotEqualTo(new FieldPath("num"), 1),
docIds: AsList("b", "c"));
AssertQueryResults(desc: "NotEqualTo (FieldPath) on nullable",
query: c.WhereNotEqualTo(new FieldPath("nullable"), null),
docIds: AsList("a"));
AssertQueryResults(desc: "LessThanOrEqualTo", query: c.WhereLessThanOrEqualTo("num", 2),
docIds: AsList("a", "b"));
AssertQueryResults(
desc: "LessThanOrEqualTo (FieldPath)",
query: c.WhereLessThanOrEqualTo(new FieldPath("num"), 2),
docIds: AsList("a", "b"));
AssertQueryResults(
desc: "LessThan",
query: c.WhereLessThan("num", 2),
docIds: AsList("a"));
AssertQueryResults(
desc: "LessThan (FieldPath)",
query: c.WhereLessThan(new FieldPath("num"), 2),
docIds: AsList("a"));
AssertQueryResults(
desc: "GreaterThanOrEqualTo",
query: c.WhereGreaterThanOrEqualTo("num", 2),
docIds: AsList("b", "c"));
AssertQueryResults(
desc: "GreaterThanOrEqualTo (FieldPath)",
query: c.WhereGreaterThanOrEqualTo(new FieldPath("num"), 2),
docIds: AsList("b", "c"));
AssertQueryResults(
desc: "GreaterThan",
query: c.WhereGreaterThan("num", 2),
docIds: AsList("c"));
AssertQueryResults(
desc: "GreaterThan (FieldPath)",
query: c.WhereGreaterThan(new FieldPath("num"), 2),
docIds: AsList("c"));
AssertQueryResults(
desc: "two EqualTos",
query: c.WhereEqualTo("state", "done").WhereEqualTo("active", false),
docIds: AsList("b"));
AssertQueryResults(
desc: "OrderBy, Limit",
query: c.OrderBy("num").Limit(2),
docIds: AsList("a", "b"));
AssertQueryResults(
desc: "OrderBy, Limit (FieldPath)",
query: c.OrderBy(new FieldPath("num")).Limit(2),
docIds: AsList("a", "b"));
AssertQueryResults(
desc: "OrderByDescending, Limit",
query: c.OrderByDescending("num").Limit(2),
docIds: AsList("c", "b"));
AssertQueryResults(
desc: "OrderByDescending, Limit (FieldPath)",
query: c.OrderByDescending(new FieldPath("num")).Limit(2),
docIds: AsList("c", "b"));
AssertQueryResults(
desc: "StartAfter",
query: c.OrderBy("num").StartAfter(2),
docIds: AsList("c"));
AssertQueryResults(
desc: "EndBefore",
query: c.OrderBy("num").EndBefore(2),
docIds: AsList("a"));
AssertQueryResults(
desc: "StartAt, EndAt",
query: c.OrderBy("num").StartAt(2).EndAt(2),
docIds: AsList("b"));
// Collection Group Query
AssertQueryResults(
desc: "CollectionGroup",
query: db.CollectionGroup(c.Id),
docIds: AsList("a", "b", "c", "d-nested")
);
});
}