示例#1
0
        public async Task Should_Load_All_Details_For_A_Post()
        {
            PostModel result;
            var       author  = new User((Nickname)"author7", (FullName)"author seven", Password.Create("password").Value, (Email)"*****@*****.**", "my bio");
            var       reader  = new User((Nickname)"reader1", (FullName)"reader one", Password.Create("password").Value, (Email)"*****@*****.**", "my bio");
            var       post    = new Post(author, (Picture)Convert.FromBase64String(DatabaseFixture.GetTestPictureBase64()), (PostText)"test post");
            var       comment = new Comment(post, reader, CommentText.Create("My comment").Value);

            using (var session = _testFixture.OpenSession(_output))
            {
                post.AddComment(comment);
                post.PutLikeBy(reader);
                await session.SaveAsync(reader);

                await session.SaveAsync(author);

                await session.SaveAsync(post);
            }

            var query = new PostDetailQuery(post.ID, reader.ID);

            using (var session = _testFixture.OpenSession(_output))
            {
                var sut = new PostDetailQueryHandler(session, Log.Logger);
                result = await sut.Handle(query, default);
            }

            using (new AssertionScope())
            {
                result.Should().NotBeNull();
                result.LikesCount.Should().Be(1);
                result.Comments.Length.Should().Be(1);
                result.IsLikedByCurrentUser.Should().BeTrue();
            }
        }
示例#2
0
        public async Task <IActionResult> Detail(int id)
        {
            var postQuery = new PostDetailQuery(id, User.GetIdentifier());
            var model     = await _dispatcher.Send(postQuery);

            return(View(model));
        }
 public async Task <Post> Handle(PostDetailQuery query)
 {
     return(await _context.Posts
            .Include(p => p.Author)
            .Include(p => p.Blog)
            .Include(p => p.Category)
            .FirstOrDefaultAsync(x => x.Id == query.Id));
 }