コード例 #1
0
        public async Task PostComments()
        {
            MobileServiceClient client = GetClient();
            IMobileServiceTable<BlogPost> postTable = client.GetTable<BlogPost>();
            IMobileServiceTable<BlogComment> commentTable = client.GetTable<BlogComment>();

            // Add a few posts and a comment
            Log("Adding posts");
            BlogPost post = new BlogPost { Title = "Windows 8" };
            await postTable.InsertAsync(post);
            BlogPost highlight = new BlogPost { Title = "ZUMO" };
            await postTable.InsertAsync(highlight);
            await commentTable.InsertAsync(new BlogComment {
                BlogPostId = post.Id,
                UserName = "******",
                Text = "Beta runs great" });
            await commentTable.InsertAsync(new BlogComment {
                BlogPostId = highlight.Id,
                UserName = "******",
                Text = "Whooooo" });
            Assert.AreEqual(2, (await postTable.Where(p => p.Id >= post.Id).ToListAsync()).Count);

            // Navigate to the first post and add a comment
            Log("Adding comment to first post");
            BlogPost first = await postTable.LookupAsync(post.Id);
            Assert.AreEqual("Windows 8", first.Title);
            BlogComment opinion = new BlogComment { BlogPostId = first.Id, Text = "Can't wait" };
            await commentTable.InsertAsync(opinion);
            Assert.AreNotEqual(0, opinion.Id);
        }