Ejemplo n.º 1
0
        public void Should_have_error_when_post_content_is_empty()
        {
            var blogRepository = new Mock <IBlogRepository>();
            var postRepository = new Mock <IPostRepository>();
            var validator      = new CreatePostCommandValidator(blogRepository.Object, postRepository.Object);
            var command        = new CreatePostCommand(Guid.NewGuid(), "title", "", true, new List <Guid>(), new List <string>());

            validator.ShouldHaveValidationErrorFor(x => x.Content, command);
        }
Ejemplo n.º 2
0
        public void Should_have_error_when_blog_does_not_exist()
        {
            var blogId = Guid.NewGuid();

            var blogRepository = new Mock <IBlogRepository>();

            blogRepository.Setup(x => x.GetById(blogId)).Returns <Domain.Blog.Blog>(null);

            var postRepository = new Mock <IPostRepository>();
            var validator      = new CreatePostCommandValidator(blogRepository.Object, postRepository.Object);
            var command        = new CreatePostCommand(blogId, "title", "content", true, new List <Guid>(), new List <string>());

            validator.ShouldHaveValidationErrorFor(x => x.BlogId, command);
        }
Ejemplo n.º 3
0
        public void Should_have_error_when_post_title_already_exists()
        {
            var          blogId    = Guid.NewGuid();
            const string postTitle = "My Post";

            var postRepository = new Mock <IPostRepository>();

            postRepository
            .Setup(x => x.GetByBlogIdAndTitle(blogId, postTitle))
            .Returns(Post.CreateNew(blogId, postTitle, "content", true, new List <Guid>(), new List <string>()));

            var blogRepository = new Mock <IBlogRepository>();
            var validator      = new CreatePostCommandValidator(blogRepository.Object, postRepository.Object);
            var command        = new CreatePostCommand(blogId, postTitle, "content", true, new List <Guid>(), new List <string>());

            validator.ShouldHaveValidationErrorFor(x => x.Title, command);
        }
Ejemplo n.º 4
0
 public override bool IsValid()
 {
     ValidationResult = new CreatePostCommandValidator().Validate(this);
     return(base.IsValid());
 }