public override async Task <RequestResult <IEnumerable <ProductCategoryDto> > > Handle( GetProductCategoriesQuery request, CancellationToken cancellationToken) { var categories = await _productCategoriesRepository.GetActiveProductCategories(); return(request.Success(_mapper.Map <IEnumerable <ProductCategoryDto> >(categories))); }
public async Task Handle_ProductCategoriesExists_ReturnProductCategories( List <Entities.ProductCategory> productCategories, [Frozen] Mock <IRepository <Entities.ProductCategory> > categoriesRepoMock, GetProductCategoriesQueryHandler sut, GetProductCategoriesQuery query ) { // Arrange categoriesRepoMock.Setup(x => x.ListAsync( It.IsAny <GetProductCategoriesSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(productCategories); //Act var result = await sut.Handle(query, CancellationToken.None); //Assert result.Should().NotBeNull(); categoriesRepoMock.Verify(x => x.ListAsync( It.IsAny <ISpecification <Entities.ProductCategory> >(), It.IsAny <CancellationToken>() )); for (int i = 0; i < result.Count; i++) { result[i].Name.Should().Be(productCategories[i].Name); } }
public void Handle_NoProductCategoriesExists_ThrowArgumentNullException( [Frozen] Mock <IRepository <Entities.ProductCategory> > categoriesRepoMock, GetProductCategoriesQueryHandler sut, GetProductCategoriesQuery query ) { //Arrange categoriesRepoMock.Setup(x => x.ListAsync( It.IsAny <GetProductCategoriesSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync((List <Entities.ProductCategory>)null); //Act Func <Task> func = async() => await sut.Handle(query, CancellationToken.None); //Assert func.Should().ThrowAsync <ArgumentNullException>(); categoriesRepoMock.Verify(x => x.ListAsync( It.IsAny <ISpecification <Entities.ProductCategory> >(), It.IsAny <CancellationToken>() )); }