using NUnit.Framework; using LeanCloud; using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; namespace LeanCloudTests { public class RelationTest { [SetUp] public void SetUp() { Utils.InitNorthChina(); } [Test] public async Task CreateRelation() { AVObject tag1 = new AVObject("Tag") { ["name"] = "hello" }; await tag1.SaveAsync(); AVObject tag2 = new AVObject("Tag") { { "name", "world" } }; await tag2.SaveAsync(); AVObject todo = new AVObject("Todo"); AVRelation relation = todo.GetRelation("tags"); relation.Add(tag1); relation.Add(tag2); await todo.SaveAsync(); } [Test] public async Task QueryRelation() { AVQuery query = new AVQuery("Todo"); query.OrderByDescending("createdAt"); AVObject todo = await query.FirstAsync(); AVRelation relation = todo.GetRelation("tags"); AVQuery tagQuery = relation.Query; IEnumerable tags = await tagQuery.FindAsync(); Assert.Greater(tags.Count(), 0); TestContext.Out.WriteLine($"count: {tags.Count()}"); foreach (AVObject tag in tags) { TestContext.Out.WriteLine($"{tag.ObjectId}, {tag["name"]}"); } } } }