Exemple #1
0
        public async Task <IEnumerable <ThreadViewModel> > GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default)
        {
            int totalReply = _post.Hr + _post.Replys.Count;

            if (pageIndex * pageSize > totalReply)
            {
                return(Enumerable.Empty <ThreadViewModel>());
            }
            var pocos = await _threadController.GetThreadsAsync(_post.No, pageIndex + 1).ConfigureAwait(false);

            if (pageIndex == 0)
            {
                var SelfAsJson = (Thread)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(_post), typeof(Thread));
                pocos.Insert(0, SelfAsJson);
            }
            var threads = pocos.Select(i => new ThreadViewModel(i, _post.Id)).ToList();

            foreach (var t in threads)
            {
                t.AstNodeTask = AstHelper.LoadHtmlAsync(t.Content);
            }
            var result = await Task.WhenAll(threads.Select(i => i.AstNodeTask));

            foreach (var item in result)
            {
                resolver.Resolve(item, new ResolveContext()
                {
                    Controller = new ReplyController(_config)
                });
            }
            return(threads);
        }
Exemple #2
0
        public async Task ThreadRetriveTest(ApiConfig config)
        {
            var pc     = new PostController(config);
            var fc     = new ForumController(config);
            var forums = await fc.GetForumsAsync();

            var posts = await pc.GetPostAsync(forums.First().Id, 1);

            var post = posts.FirstOrDefault(p => p.Hr + p.Replys.Count > 0);

            if (post != null)
            {
                var tc      = new ThreadController(config);
                var threads = await tc.GetThreadsAsync(post.No, 1);

                foreach (var item in threads)
                {
                    Assert.IsInstanceOfType(item, typeof(Thread));
                }
            }
        }