コード例 #1
0
        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
            };
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public EditCategoryCommand(CategoryCreateOrEditDto categoryCreateOrEditDto)
 {
     Id    = categoryCreateOrEditDto.Id;
     Title = categoryCreateOrEditDto.Title;
 }
コード例 #4
0
        public async Task <ActionResult> Update([FromBody] CategoryCreateOrEditDto editCategory)
        {
            await Mediator.Send(new EditCategoryCommand(editCategory));

            return(NoContent());
        }
コード例 #5
0
 public async Task <ActionResult <Guid> > Create([FromBody] CategoryCreateOrEditDto newCategory)
 {
     return(Ok(await Mediator.Send(new CreateCategoryCommand(newCategory))));
 }