public EditCategoryCommandTest() { dbSetCategory = new Mock <DbSet <Category> >(); context = new Mock <IApplicationDbContext>(); stringLocalizer = new Mock <IStringLocalizer <CategoriesResource> >(); mapper = new Mock <IMapper>(); category = new Category { Id = id }; categoryDto = new CategoryCreateOrEditDto { Id = id }; }
public async Task ShouldCallHandle() { var id = new Guid(); var categoryDto = new CategoryCreateOrEditDto { Id = id }; var category = new Category { Id = id }; context.Setup(x => x.Categories).Returns(dbSetCategory.Object); context.Setup(x => x.SaveChangesAsync(It.IsAny <CancellationToken>())).Returns(Task.FromResult(1)); CreateCategoryCommandHandler createCategoryCommandHandler = new CreateCategoryCommandHandler(context.Object, stringLocalizer.Object, mapper.Object); CreateCategoryCommand createCategoryCommand = new CreateCategoryCommand(categoryDto); mapper.Setup(x => x.Map <Category>(createCategoryCommand)).Returns(category); var result = await createCategoryCommandHandler.Handle(createCategoryCommand, new CancellationToken()); result.Should().Be(id); }
public EditCategoryCommand(CategoryCreateOrEditDto categoryCreateOrEditDto) { Id = categoryCreateOrEditDto.Id; Title = categoryCreateOrEditDto.Title; }
public async Task <ActionResult> Update([FromBody] CategoryCreateOrEditDto editCategory) { await Mediator.Send(new EditCategoryCommand(editCategory)); return(NoContent()); }
public async Task <ActionResult <Guid> > Create([FromBody] CategoryCreateOrEditDto newCategory) { return(Ok(await Mediator.Send(new CreateCategoryCommand(newCategory)))); }