예제 #1
0
        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
        }
예제 #2
0
        public void TestEncodeParseRelation()
        {
            var obj = new AVObject("Corgi");
            AVRelation <AVObject>        relation = AVRelationExtensions.Create <AVObject>(obj, "nano", "Husky");
            IDictionary <string, object> value    = ParseEncoderTestClass.Instance.Encode(relation) as IDictionary <string, object>;

            Assert.AreEqual("Relation", value["__type"]);
            Assert.AreEqual("Husky", value["className"]);
        }
예제 #3
0
        public void TestDecodeRelation()
        {
            IDictionary <string, object> value = new Dictionary <string, object>()
            {
                { "__type", "Relation" },
                { "className", "Corgi" },
                { "objectId", "lLaKcolnu" }
            };

            AVRelation <AVObject> relation = AVDecoder.Instance.Decode(value) as AVRelation <AVObject>;

            Assert.IsNotNull(relation);
            Assert.AreEqual("Corgi", relation.GetTargetClassName());
        }
예제 #4
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"]);
        }
예제 #5
0
 public static string GetTargetClassName <T>(this AVRelation <T> relation) where T : AVObject
 {
     return(relation.TargetClassName);
 }