diff --git a/Storage/Storage.Test/RelationTest.cs b/Storage/Storage.Test/RelationTest.cs new file mode 100644 index 0000000..6cd8982 --- /dev/null +++ b/Storage/Storage.Test/RelationTest.cs @@ -0,0 +1,46 @@ +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"]}"); + } + } + } +} diff --git a/Storage/Storage.Test/Storage.Test.csproj b/Storage/Storage.Test/Storage.Test.csproj index 50c6279..55e014f 100644 --- a/Storage/Storage.Test/Storage.Test.csproj +++ b/Storage/Storage.Test/Storage.Test.csproj @@ -8,9 +8,9 @@ - - - + + + diff --git a/Storage/Storage/Public/AVRelation.cs b/Storage/Storage/Public/AVRelation.cs index d66ba80..739a80b 100644 --- a/Storage/Storage/Public/AVRelation.cs +++ b/Storage/Storage/Public/AVRelation.cs @@ -3,10 +3,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; -using System.Linq; using System.Linq.Expressions; -using System.Reflection; -using System.Text; namespace LeanCloud { ///