* RelationTest.cs:
* Storage.Test.csproj: * AVRelation.cs: chore: 测试 Relation
parent
9266d6e115
commit
671b137721
|
|
@ -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<AVObject> relation = todo.GetRelation<AVObject>("tags");
|
||||
relation.Add(tag1);
|
||||
relation.Add(tag2);
|
||||
await todo.SaveAsync();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueryRelation() {
|
||||
AVQuery<AVObject> query = new AVQuery<AVObject>("Todo");
|
||||
query.OrderByDescending("createdAt");
|
||||
AVObject todo = await query.FirstAsync();
|
||||
AVRelation<AVObject> relation = todo.GetRelation<AVObject>("tags");
|
||||
AVQuery<AVObject> tagQuery = relation.Query;
|
||||
IEnumerable<AVObject> 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"]}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,9 +8,9 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="nunit" Version="3.11.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||
<PackageReference Include="nunit" Version="3.12.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.15.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue