public ActionResult <IEnumerable <CategoryDTO> > GetCategories() { var query = new GetAllCategoriesQuery(); var categories = _queryHandler.Handle(query); var itemsDTO = _mapper.Map <IEnumerable <CategoryDTO> >(categories); return(Ok(itemsDTO)); }
public async void GetCategoryByIdFalseTest() { using (var context = new ShopContext(_dbContextOptions)) { var categoryQueryHandler = new CategoryQueryHandler(context); await Assert.ThrowsAnyAsync <DomainException>((async() => await categoryQueryHandler.Handle(new GetCategoryById() { Id = context.Categories.Max(x => x.Id) + 1, }, CancellationToken.None))); } }
public async void GetCategoriesTest() { using (var context = new ShopContext(_dbContextOptions)) { var categoryQueryHandler = new CategoryQueryHandler(context); var result = await categoryQueryHandler.Handle(new GetCategories(), CancellationToken.None); Assert.NotNull(result); Assert.IsType <QueryResult <CategoryResponse> >(result); } }
public async Task Get_ReturnsListAsync() { var queryHandler = new CategoryQueryHandler(BasicNeeds); var query = new GetCategory() { Id = null }; var actual = await queryHandler.Handle(query, CancellationToken.None); Assert.AreEqual(2, actual.Count); }
public async void GetCategoryByIdTest() { using (var context = new ShopContext(_dbContextOptions)) { var categoryQueryHandler = new CategoryQueryHandler(context); var result = await categoryQueryHandler.Handle(new GetCategoryById() { Id = context.Categories.First().Id, }, CancellationToken.None); Assert.NotNull(result); Assert.IsType <CategoryWithGoodsResponse>(result); Assert.Equal(result.Id, context.Categories.First().Id); } }