Beispiel #1
0
        public async Task Should_Publish_A_New_Post()
        {
            const string testUserName = "******";
            const string testPassword = "******";
            Result <int> publishCommandResult;

            var testUser = new User((Nickname)testUserName, (FullName)"test1 user1", Password.Create(testPassword).Value, (Email)"*****@*****.**", "bio1");

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

            var command = new PublishPostCommand(testUser.ID, "test post 1", Convert.FromBase64String(DatabaseFixture.GetTestPictureBase64()));

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

            using (new AssertionScope())
            {
                publishCommandResult.IsSuccess.Should().BeTrue();
                using (var session = _testFixture.OpenSession(_output))
                {
                    (await session.GetAsync <Post>(publishCommandResult.Value)).Should().NotBeNull();
                }
            }
        }
        public void Should_call_save_method_when_publish_post()
        {
            var postId = Guid.NewGuid();

            var post = Post.CreateNew(Guid.NewGuid(), "Title", "Content", false, new List <Guid>(), new List <string>());

            post.GetType().GetProperty("Id").SetValue(post, postId, null);

            var postRepository = new Mock <IPostRepository>();

            postRepository.Setup(x => x.GetById(postId)).Returns(post);
            postRepository.Setup(x => x.Save(post));

            var publishPostCommandHandler = new PublishPostCommandHandler(postRepository.Object);

            publishPostCommandHandler.Handle(new PublishPostCommand(postId));

            postRepository.Verify(x => x.Save(post));
        }