Exemple #1
0
        public async Task Should_Put_A_Like_To_A_Post()
        {
            Result likeResult;
            var    author = new User((Nickname)"author2", (FullName)"author two", 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");

            using (var session = _testFixture.OpenSession(_output))
            {
                await session.SaveAsync(author);

                await session.SaveAsync(reader);

                await session.SaveAsync(post);
            }

            var command = new LikePostCommand(post.ID, reader.ID);

            using (var session = _testFixture.OpenSession(_output))
            {
                var sut = new LikeOrDislikePostCommandHandler(session, Log.Logger);
                likeResult = await sut.Handle(command, default);
            }

            using (new AssertionScope())
            {
                likeResult.IsSuccess.Should().BeTrue();
                using (var session = _testFixture.OpenSession(_output))
                {
                    (await session.GetAsync <Post>(post.ID)).Likes.Count().Should().Be(1);
                }
            }
        }
Exemple #2
0
        public async Task Cannot_Like_A_Post_Twice()
        {
            Result likeResult;
            var    author = new User((Nickname)"author5", (FullName)"author five", Password.Create("password").Value, (Email)"*****@*****.**", "my bio");
            var    reader = new User((Nickname)"reader4", (FullName)"reader four", Password.Create("password").Value, (Email)"*****@*****.**", "my bio");
            var    post   = new Post(author, (Picture)Convert.FromBase64String(DatabaseFixture.GetTestPictureBase64()), (PostText)"test post");

            using (var session = _testFixture.OpenSession(_output))
            {
                await session.SaveAsync(author);

                await session.SaveAsync(reader);

                await session.SaveAsync(post);
            }

            var command = new LikePostCommand(post.ID, reader.ID);

            using (var session = _testFixture.OpenSession(_output))
            {
                var sut = new LikeOrDislikePostCommandHandler(session, Log.Logger);
                await sut.Handle(command, default);

                likeResult = await sut.Handle(command, default);
            }

            likeResult.IsSuccess.Should().BeFalse($"User [{reader.Nickname}] already 'Liked' this post.");
        }
Exemple #3
0
        public async Task Author_Cannot_Put_Likes_On_Their_Own_Posts()
        {
            Result likeResult;
            var    author = new User((Nickname)"author6", (FullName)"author six", Password.Create("password").Value, (Email)"*****@*****.**", "my bio");
            var    post   = new Post(author, (Picture)Convert.FromBase64String(DatabaseFixture.GetTestPictureBase64()), (PostText)"test post");

            using (var session = _testFixture.OpenSession(_output))
            {
                await session.SaveAsync(author);

                await session.SaveAsync(post);
            }

            var command = new LikePostCommand(post.ID, author.ID);

            using (var session = _testFixture.OpenSession(_output))
            {
                var sut = new LikeOrDislikePostCommandHandler(session, Log.Logger);
                likeResult = await sut.Handle(command, default);
            }

            likeResult.IsSuccess.Should().BeFalse("You cannot put a 'Like' on your own posts.");
        }