示例#1
0
            public override async Task Run()
            {
                var blogPostId = await _blogPostService.AddBlogPostAsync("New post!", "Hello world.");

                await _commentService.AddCommentAsync(blogPostId, "Commenter 1", "Nice post.");

                await _commentService.AddCommentAsync(blogPostId, "Commenter 2", "Nice post!");

                // this instruction will not work normally since some of these methods will try to update
                // an entity that has changed in the mean time, failing the ETag validation
                await Task.WhenAll(
                    _commentService.AddLikeAsync(blogPostId),
                    _commentService.AddLikeAsync(blogPostId),
                    _commentService.AddLikeAsync(blogPostId),
                    _commentService.AddLikeAsync(blogPostId),
                    _commentService.AddLikeAsync(blogPostId));

                var blogPosts = await _blogPostService.GetBlogPostsAsync();

                Console.WriteLine(JsonConvert.SerializeObject(blogPosts));

                await Task.Delay(30000);

                blogPosts = await _blogPostService.GetBlogPostsAsync();

                Console.WriteLine(JsonConvert.SerializeObject(blogPosts));

                await _blogPostService.DeleteBlogPostAsync(blogPostId);
            }