public async Task Setup()
        {
            _post = PostFactories.Post();
            _post.Publish();

            _command = new WithdrawPost
            {
                BlogId          = Guid.NewGuid(),
                AggregateRootId = Guid.NewGuid()
            };

            _postRepositoryMock = new Mock <IPostRepository>();
            _postRepositoryMock
            .Setup(x => x.GetByIdAsync(_command.BlogId, _command.AggregateRootId))
            .ReturnsAsync(_post);
            _postRepositoryMock
            .Setup(x => x.UpdateAsync(It.IsAny <Post>()))
            .Callback <Post>(p => _updatedPost = p)
            .Returns(Task.CompletedTask);

            _commandHandler = new WithdrawPostHandler(_postRepositoryMock.Object);
            _result         = await _commandHandler.HandleAsync(_command);

            _event = _updatedPost.Events.OfType <PostWithdrew>().Single();
        }
        public void ThrowsExceptionWhenPostIsNotFound()
        {
            _postRepositoryMock
            .Setup(x => x.GetByIdAsync(_command.BlogId, _command.AggregateRootId))
            .ReturnsAsync((Post)null);

            Assert.ThrowsAsync <ApplicationException>(async() => await _commandHandler.HandleAsync(_command));
        }
        public async Task Setup()
        {
            _command = PostFactories.CreatePostCommand();

            _validatorMock = new Mock <IValidator <CreatePost> >();
            _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());

            _postRepositoryMock = new Mock <IPostRepository>();
            _postRepositoryMock
            .Setup(x => x.CreateAsync(It.IsAny <Post>()))
            .Callback <Post>(p => _post = p)
            .Returns(Task.CompletedTask);

            _commandHandler = new CreatePostHandler(_postRepositoryMock.Object, _validatorMock.Object);
            _result         = await _commandHandler.HandleAsync(_command);

            _event = _post.Events.OfType <PostCreated>().Single();
        }
Ejemplo n.º 4
0
        public async Task Setup()
        {
            _command = BlogFactories.CreateBlogCommand();

            _validatorMock = new Mock <IValidator <CreateBlog> >();
            _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());

            _blogRepositoryMock = new Mock <IBlogRepository>();
            _blogRepositoryMock
            .Setup(x => x.CreateAsync(It.IsAny <Domain.Blogs.Blog>()))
            .Callback <Domain.Blogs.Blog>(b => _blog = b)
            .Returns(Task.CompletedTask);

            _commandHandler = new CreateBlogHandler(_blogRepositoryMock.Object, _validatorMock.Object);
            _result         = await _commandHandler.HandleAsync(_command);

            _event = _blog.Events.OfType <BlogCreated>().Single();
        }
        public async Task Setup()
        {
            _post = PostFactories.Post();

            _command = PostFactories.UpdatePostCommand();

            _validatorMock = new Mock <IValidator <UpdatePost> >();
            _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());

            _postRepositoryMock = new Mock <IPostRepository>();
            _postRepositoryMock
            .Setup(x => x.GetByIdAsync(_command.BlogId, _command.AggregateRootId))
            .ReturnsAsync(_post);
            _postRepositoryMock
            .Setup(x => x.UpdateAsync(It.IsAny <Post>()))
            .Callback <Post>(p => _updatedPost = p)
            .Returns(Task.CompletedTask);

            _commandHandler = new UpdatePostHandler(_postRepositoryMock.Object, _validatorMock.Object);
            _result         = await _commandHandler.HandleAsync(_command);

            _event = _updatedPost.Events.OfType <PostUpdated>().Single();
        }