public async Task GivenValidQuery_ReturnTotalListOfProductVm() { var result = await _handler.Handle(_query, CancellationToken.None); var productsCount = TestContext.Context.Products.Count(); Assert.Equal(productsCount, result.Total); Assert.Equal(productsCount, result.Items.Count); Assert.Equal(TestContext.TestProductCommon.Name, result.Items.First().Name); }
public async Task Handle_ValidAscOrderBy_ReturnProducts( List <Entities.Product> products, [Frozen] Mock <IRepository <Entities.Product> > productRepoMock, GetProductsQueryHandler sut, GetProductsQuery query ) { //Arrange productRepoMock.Setup(x => x.ListAsync( It.IsAny <GetProductsPaginatedSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync(products); query.OrderBy = "asc(name)"; //Act var result = await sut.Handle(query, CancellationToken.None); //Assert result.Should().NotBeNull(); productRepoMock.Verify(x => x.ListAsync( It.IsAny <ISpecification <Entities.Product> >(), It.IsAny <CancellationToken>() )); for (int i = 0; i < result.Products.Count; i++) { result.Products[i].ProductNumber.Should().Be(products[i].ProductNumber); } }
public void Handle_NoProductsExists_ThrowArgumentNullException( [Frozen] Mock <IRepository <Entities.Product> > productRepoMock, GetProductsQueryHandler sut, GetProductsQuery query ) { // Arrange query.OrderBy = ""; productRepoMock.Setup(x => x.ListAsync( It.IsAny <GetProductsPaginatedSpecification>(), It.IsAny <CancellationToken>() )) .ReturnsAsync((List <Entities.Product>)null); //Act Func <Task> func = async() => await sut.Handle(query, CancellationToken.None); //Assert func.Should().ThrowAsync <ArgumentNullException>(); productRepoMock.Verify(x => x.ListAsync( It.IsAny <ISpecification <Entities.Product> >(), It.IsAny <CancellationToken>() )); }
public async Task ShouldReturnAllProducts() { var query = new GetProductsQueryHandler(_context, Mapper); var result = await query.Handle(new GetProductsQuery(), CancellationToken.None); Assert.That(result, Is.TypeOf <List <GetProductDto> >()); Assert.AreEqual(result.Count, 4); }
public async Task GetProducts() { var sut = new GetProductsQueryHandler(_context, _mapper); var result = await sut.Handle(new GetProductsQuery { }, CancellationToken.None); result.ShouldBeOfType <List <ProductDto> >(); result.ShouldNotBeNull(); }
public async Task GetProductsQueryHandler_Success() { //Arrange searchProductService.Setup(x => x.GetProducts(It.IsAny <FilteringData>())).Returns(Task.FromResult(products)); mapper.Setup(x => x.Map <List <GetProductsDto> >(products)).Returns(productsDto); //Act var action = await queryHandler.Handle(query, It.IsAny <CancellationToken>()); //Assert Assert.Equal(productsDto.Count, action.Count()); }
public void WhenBartViewsHisListOfProducts(string userName) { var user = sessionFactory.OpenSession().Query <User>().First(u => u.UserName == userName); var query = new GetProductsQuery { UserId = user.Id }; var handler = new GetProductsQueryHandler(sessionFactory.OpenSession()); var response = handler.Handle(query); ScenarioContext.Current.Set(response); }
public async Task GetAllAsync() { var dataAccess = new ProductDataAccess(this.Context, Mapper()); //Act var sutCreate = new CreateProductCommandHandler(dataAccess); var resultCreate = await sutCreate.Handle(new CreateProductCommand { Data = ProductTestData.ProductDTO }, CancellationToken.None); //Act var sutGetAll = new GetProductsQueryHandler(dataAccess); var resultGetAll = await sutGetAll.Handle(new GetProductsQuery(), CancellationToken.None); Assert.IsTrue(resultGetAll?.Data.Count == 1); }
Handle_SortOptionRecommended_ShouldInvokeProductServiceGetShopperHistoryOnce() { // Arrange var productService = new Mock <IProductService>(); var sortingProductLogic = new Mock <ISortingProductLogic>(); var recommendedProductLogic = new Mock <IRecommendedProductLogic>(); var queryHandler = new GetProductsQueryHandler(productService.Object, sortingProductLogic.Object, recommendedProductLogic.Object); var productRequest = new GetProductsRequest { SortOption = SortOption.Recommended }; // Act await queryHandler.Handle(productRequest, CancellationToken.None); // Assert productService.Verify(x => x.GetShopperHistoryAsync(), Times.Once); }
public async void Should_GetProductsQueryHandler_ReturnProductsSortedByHighPrices_WhenSortOptionsIsHigh() { // Arrange var query = new GetProductsQuery() { SortOption = Application.Enum.SortOptions.High }; var handler = new GetProductsQueryHandler(_mockMapper.Object, _client.Object); // Action var result = await handler.Handle(query, _cancellationToken); // Assert Assert.Equal("Product C", result[0].Name); Assert.Equal("Product B", result[1].Name); Assert.Equal("Product A", result[2].Name); }
public void Execute_CorrectPagination_ReturnsProducts() { //Arrange Seed(_context); var query = new GetProductsQuery { PageIndex = 0, PageSize = 25 }; var logger = new Mock <ILogger <GetProductsQueryHandler> >(); var config = new Mock <IConfiguration>(); var validator = new Mock <AbstractValidator <GetProductsQuery> >(); validator.Setup(x => x.Validate(It.IsAny <ValidationContext <GetProductsQuery> >())).Returns(new ValidationResult()); var handler = new GetProductsQueryHandler(_context, config.Object, logger.Object, validator.Object); //Act var result = handler.Handle(query); var mockedDbCount = _context.Products.Count(); //Assert Assert.AreEqual(mockedDbCount, result.Count); }