示例#1
0
        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);
            }
        }
示例#2
0
        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 GetProductsQueryHandlerTests(ITestOutputHelper output)
        {
            _output = output;

            _handler = new GetProductsQueryHandler(Context, Mapper);

            _query = new GetProductsQuery();
        }
        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();
        }
示例#6
0
        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 GetProductsQueryHandlerTest()
 {
     mapper = new Mock <IMapper>();
     searchProductService = new Mock <ISearchProductsService>();
     query        = new GetProductsQuery(new FilteringData());
     queryHandler = new GetProductsQueryHandler(mapper.Object, searchProductService.Object);
     products     = new List <Product> {
         new Product(), new Product()
     };
     productsDto = new List <GetProductsDto> {
         new GetProductsDto(), new GetProductsDto()
     };
 }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }