Exemple #1
0
        public async Task <ValidationResult> Add(CreateBlogViewModel createBlogViewModel)
        {
            CreateBlogCommand createBlogCommand =
                _mapper.Map <CreateBlogCommand>(createBlogViewModel);

            return(await _mediator.Send(createBlogCommand));
        }
Exemple #2
0
        public void then_if_the_command_is_null_exception_is_thrown()
        {
            this._command = null;
            this.Execute();
            var expected = "Precondition failed: command != null";

            this._errorMessage.ShouldEqual(expected);
        }
Exemple #3
0
        public async Task <IActionResult> Create(CreateBlogCommand command, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(View(command));
            }

            await Mediator.Send(command, cancellationToken);

            return(RedirectToAction(nameof(Index)));
        }
Exemple #4
0
        public async Task <ActionResult> Post([FromBody] CreateBlogCommand command)
        {
            var result = await Mediator.Send(command);

            if (result > 0)
            {
                return(Ok(new ApiResponse(result, string.Format("Blog with Id {0} created.", result))));
            }
            else
            {
                return(BadRequest(new ApiResponse(new string[] { "Unable to create blog." }, "Unable to create blog.")));
            }
        }
        public async Task <IActionResult> Create(CreateBlogCommand blog)
        {
            if (ModelState.IsValid)
            {
                var result = await _mediator.Send(blog);

                if (result.Errors.Any())
                {
                    return(BadRequest(result.Errors));
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(blog));
        }
Exemple #6
0
        public void Should_call_validate_command_when_create_new_blog()
        {
            var blog    = Domain.Blog.Blog.CreateNew("Title");
            var command = new CreateBlogCommand(blog.Title);

            var blogRepository = new Mock <IBlogRepository>();

            var validator = new Mock <IValidator <CreateBlogCommand> >();

            validator.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var createBlogCommandHandler = new CreateBlogCommandHandler(blogRepository.Object, validator.Object);

            createBlogCommandHandler.Handle(command);

            validator.Verify(x => x.Validate(command));
        }
Exemple #7
0
 protected override void Establish_context()
 {
     base.Establish_context();
     this._command = new CreateBlogCommand("Blog name", "www.url.com");
 }
Exemple #8
0
 public async Task <ActionResult <int> > Create(CreateBlogCommand command)
 {
     return(await Mediator.Send(command));
 }
        public async Task <IActionResult> Post([FromBody] CreateBlogCommand command)
        {
            Guid id = await mediator.Send(command);

            return(CreatedAtRoute("GetBlog", new { id = id }, id));
        }
Exemple #10
0
 public IActionResult Create([FromBody, Required] CreateBlogCommand command)
 {
     Mediator.SendCommand(command);
     return(Ok());
 }
Exemple #11
0
 public Blog(CreateBlogCommand cmd)
 {
     Author  = cmd.Author;
     Title   = cmd.Title;
     Content = cmd.Content;
 }
Exemple #12
0
 public async Task <Guid> CreateAsync(CreateBlogCommand command)
 {
     return(await Mediator.Send(command));
 }