private async void Button_Click_2(object sender, RoutedEventArgs e) { #region 一对多的关系,在保存在服务端之前,所有对象必须已经存在于服务端。 AVObject weibo = new AVObject("Weibo"); weibo["content"] = "AVOS Cloud 什么的最萌了!"; //weibo["user"] = new AVUser() { Username = "******", Password = "******" }; //王校长的用户名已被别人抢注了,所以要正确关联用户,请开发者自定义个名字。 AVObject comment1 = new AVObject("Comment"); comment1["words"] = "第一条,好鸡冻!"; AVObject comment2 = new AVObject("Comment"); comment2["words"] = "点赞必回粉!"; AVObject comment3 = new AVObject("Comment"); comment3["words"] = "优质新西兰奶粉代购,请加q12345789"; AVObject comment4 = new AVObject("Comment"); comment4["words"] = "5元千粉,需要的请联系138XXXX"; await Task.WhenAll(new Task[] { weibo.SaveAsync(), comment1.SaveAsync(), comment2.SaveAsync(), comment3.SaveAsync(), comment4.SaveAsync() }).ContinueWith(t => { AVRelation<AVObject> weiboRelation = weibo.GetRelation<AVObject>("comments"); weiboRelation.Add(comment1); weiboRelation.Add(comment2); weiboRelation.Add(comment3); weiboRelation.Add(comment4); return weibo.SaveAsync(); }); #endregion }
private async void Button_Click_2(object sender, RoutedEventArgs e) { #region 一对多的关系,在保存在服务端之前,所有对象必须已经存在于服务端。 AVObject weibo = new AVObject("Weibo"); weibo["content"] = "AVOS Cloud 什么的最萌了!"; //weibo["user"] = new AVUser() { Username = "******", Password = "******" }; //王校长的用户名已被别人抢注了,所以要正确关联用户,请开发者自定义个名字。 AVObject comment1 = new AVObject("Comment"); comment1["words"] = "第一条,好鸡冻!"; AVObject comment2 = new AVObject("Comment"); comment2["words"] = "点赞必回粉!"; AVObject comment3 = new AVObject("Comment"); comment3["words"] = "优质新西兰奶粉代购,请加q12345789"; AVObject comment4 = new AVObject("Comment"); comment4["words"] = "5元千粉,需要的请联系138XXXX"; await Task.WhenAll(new Task[] { weibo.SaveAsync(), comment1.SaveAsync(), comment2.SaveAsync(), comment3.SaveAsync(), comment4.SaveAsync() }).ContinueWith(t => { AVRelation <AVObject> weiboRelation = weibo.GetRelation <AVObject>("comments"); weiboRelation.Add(comment1); weiboRelation.Add(comment2); weiboRelation.Add(comment3); weiboRelation.Add(comment4); return(weibo.SaveAsync()); }); #endregion }
public Task RelationReverseQueryTest() { var hangzhou = new AVObject("City"); hangzhou["name"] = "杭州"; var wenzhou = new AVObject("City"); wenzhou["name"] = "温州"; var zhejiang = new AVObject("Province"); zhejiang.Set("name", "浙江"); return(AVObject.SaveAllAsync(new AVObject[] { hangzhou, wenzhou }).ContinueWith(t => { var relation = zhejiang.GetRelation <AVObject>("includedCities"); relation.Add(hangzhou); relation.Add(wenzhou); return zhejiang.SaveAsync(); }).Unwrap().ContinueWith(s => { var reverseQuery = hangzhou.GetRelationRevserseQuery <AVObject>("Province", "includedCities"); return reverseQuery.FindAsync(); }).Unwrap().ContinueWith(x => { var provinces = x.Result; Assert.IsTrue(provinces.Count() == 1); return Task.FromResult(0); })); }
public void TestRelationQuery() { AVObject parent = AVObject.CreateWithoutData("Foo", "abcxyz"); AVRelation <AVObject> relation = parent.GetRelation <AVObject>("child"); AVQuery <AVObject> query = relation.Query; // Client side, the query will appear to be for the wrong class. // When the server recieves it, the class name will be redirected using the 'redirectClassNameForKey' option. Assert.AreEqual("Foo", query.GetClassName()); IDictionary <string, object> encoded = query.BuildParameters(); Assert.AreEqual("child", encoded["redirectClassNameForKey"]); }
public void TestIsValidType() { var corgi = new AVObject("Corgi"); var corgiRelation = corgi.GetRelation <AVObject>("corgi"); Assert.IsTrue(AVEncoder.IsValidType(322)); Assert.IsTrue(AVEncoder.IsValidType(0.3f)); Assert.IsTrue(AVEncoder.IsValidType(new byte[] { 1, 2, 3, 4 })); Assert.IsTrue(AVEncoder.IsValidType("corgi")); Assert.IsTrue(AVEncoder.IsValidType(corgi)); Assert.IsTrue(AVEncoder.IsValidType(new AVACL())); Assert.IsTrue(AVEncoder.IsValidType(new AVFile("Corgi", new byte[0]))); Assert.IsTrue(AVEncoder.IsValidType(new AVGeoPoint(1, 2))); Assert.IsTrue(AVEncoder.IsValidType(corgiRelation)); Assert.IsTrue(AVEncoder.IsValidType(new DateTime())); Assert.IsTrue(AVEncoder.IsValidType(new List <object>())); Assert.IsTrue(AVEncoder.IsValidType(new Dictionary <string, string>())); Assert.IsTrue(AVEncoder.IsValidType(new Dictionary <string, object>())); Assert.IsFalse(AVEncoder.IsValidType(new AVAddOperation(new List <object>()))); Assert.IsFalse(AVEncoder.IsValidType(Task <AVObject> .FromResult(new AVObject("Corgi")))); Assert.Throws <MissingMethodException>(() => AVEncoder.IsValidType(new Dictionary <object, object>())); Assert.Throws <MissingMethodException>(() => AVEncoder.IsValidType(new Dictionary <object, string>())); }
public void TestIsValidType() { var corgi = new AVObject("Corgi"); var corgiRelation = corgi.GetRelation<AVObject>("corgi"); Assert.IsTrue(AVEncoder.IsValidType(322)); Assert.IsTrue(AVEncoder.IsValidType(0.3f)); Assert.IsTrue(AVEncoder.IsValidType(new byte[]{ 1, 2, 3, 4 })); Assert.IsTrue(AVEncoder.IsValidType("corgi")); Assert.IsTrue(AVEncoder.IsValidType(corgi)); Assert.IsTrue(AVEncoder.IsValidType(new AVACL())); Assert.IsTrue(AVEncoder.IsValidType(new AVFile("Corgi", new byte[0]))); Assert.IsTrue(AVEncoder.IsValidType(new AVGeoPoint(1, 2))); Assert.IsTrue(AVEncoder.IsValidType(corgiRelation)); Assert.IsTrue(AVEncoder.IsValidType(new DateTime())); Assert.IsTrue(AVEncoder.IsValidType(new List<object>())); Assert.IsTrue(AVEncoder.IsValidType(new Dictionary<string, string>())); Assert.IsTrue(AVEncoder.IsValidType(new Dictionary<string, object>())); Assert.IsFalse(AVEncoder.IsValidType(new AVAddOperation(new List<object>()))); Assert.IsFalse(AVEncoder.IsValidType(Task<AVObject>.FromResult(new AVObject("Corgi")))); Assert.Throws<MissingMethodException>(() => AVEncoder.IsValidType(new Dictionary<object, object>())); Assert.Throws<MissingMethodException>(() => AVEncoder.IsValidType(new Dictionary<object, string>())); }