Example #1
0
        public async Task AddBlogAsync()
        {
            // Arrange.
            string expectedDescription = "desc001";
            string expectedTitle       = "test";

            var command = new AddBlogAsyncCommand
            {
                Description = expectedDescription,
                OwnerId     = DefaultAccount.Id,
                Tags        = "",
                Title       = expectedTitle
            };

            var handler = new AddBlogAsyncCommandHandler(DbContext, Provider.GetService <IMapper>(), command);

            // Act.
            await handler.Execute();

            // Assert.
            Assert.True(DbContext.Blogs.Any(blog => blog.Title == expectedTitle));
        }
 public ICommandHandler <AddBlogAsyncCommand, Task <CommandResponse> > Build(AddBlogAsyncCommand command)
 {
     return(new AddBlogAsyncCommandHandler(_context, _mapper, command));
 }
Example #3
0
 public AddBlogAsyncCommandHandler(ApplicationDbContext dbContext,
                                   IMapper mapper, AddBlogAsyncCommand command) : base(dbContext)
 {
     _mapper  = mapper;
     _command = command;
 }
Example #4
0
        public async Task <IActionResult> Create([FromServices] BlogCommandHandlerFactory blogCommandHandlerFactory, AddBlogAsyncCommand command)
        {
            command.OwnerId = _userManager.GetUserId(User);
            var handler  = blogCommandHandlerFactory.Build(command);
            var response = await handler.Execute();

            return(RedirectToAction("Profile", "Account"));
        }