コード例 #1
0
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/>
        /// </summary>
        /// <param name="text"><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/></param>
        /// <returns><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.ERPModule.Services.ISalesAppService"/></returns>
        public List <ProductDTO> FindProducts(string text)
        {
            //create the specification ( howto find products for any string )
            var spec = ProductSpecifications.ProductFullText(text);

            //recover products
            var products = _productRepository.AllMatching(spec);

            //adapt results
            return(products.ProjectedAsCollection <ProductDTO>());
        }
コード例 #2
0
        public void ProductFullTextSpecificationEmptyDataReturnTrueSpecification()
        {
            //Arrange
            string productData = string.Empty;

            //Act
            var specification = ProductSpecifications.ProductFullText(productData);

            //Assert
            Assert.NotNull(specification);
            Assert.IsType <TrueSpecification <Product> >(specification);
        }
コード例 #3
0
        public void ProductFullTextSpecificationNonEmptyDataReturnAndSpecification()
        {
            //Arrange
            string productData = "the product title or product description data";

            //Act
            var specification = ProductSpecifications.ProductFullText(productData);

            //Assert
            Assert.NotNull(specification);
            Assert.IsType <AndSpecification <Product> >(specification);
        }
コード例 #4
0
        public void ProductFullTextSpecificationNullDataReturnTrueSpecification()
        {
            //Arrange
            string productData = null;

            //Act
            var specification = ProductSpecifications.ProductFullText(productData);

            //Assert
            Assert.IsNotNull(specification);
            Assert.IsInstanceOfType(specification, typeof(TrueSpecification <Product>));
        }
コード例 #5
0
        public void ProductFullTextSpecificationNonEmptyDataReturnAndSpecification()
        {
            //Arrange
            var productData = "the product title or product description data";

            //Act
            var specification = ProductSpecifications.ProductFullText(productData);

            //Assert
            Assert.IsNotNull(specification);
            Assert.IsInstanceOfType(specification, typeof(AndSpecification <Product>));
        }
コード例 #6
0
        public void ProductRepositoryAllMatchingMethodReturnEntitiesWithSatisfiedCriteria()
        {
            //Arrange
            IProductRepository productRepository = new ProductRepository(fixture.unitOfWork, fixture.productLogger);

            var spec = ProductSpecifications.ProductFullText("book");

            //Act
            var result = productRepository.AllMatching(spec);

            //Assert
            Assert.NotNull(result.All(p => p.Title.Contains("book") || p.Description.Contains("book")));
        }
コード例 #7
0
        public async Task <ActionResult <ProductDto> > GetProduct(Guid id)
        {
            var spec = new ProductSpecifications(id);

            var product = await _productsRepo.GetEntityWithSpec(spec);

            if (product == null)
            {
                return(NotFound(new ApiResponse(404)));
            }

            return(_mapper.Map <Product, ProductDto>(product));
        }
コード例 #8
0
        public async Task <ActionResult <IReadOnlyList <Pagination <ProductDto> > > > GetProducts([FromQuery] ProductSpecParams productParams)
        {
            var spec = new ProductSpecifications(productParams);

            var products = await _productsRepo.ListAsync(spec);

            var countSpec = new ProductCountSpecification(productParams);

            var totalItems = await _productsRepo.CountAsync(countSpec);

            var data = _mapper.Map <IReadOnlyList <Product>, IReadOnlyList <ProductDto> >(products);

            return(Ok(new Pagination <ProductDto>(productParams.PageIndex, productParams.PageSize, totalItems, data)));
        }
コード例 #9
0
        public ProductIsValidToImportValidator(
            DomainModelValidatorBaseSpecifications <Product> domainModelValidatorBaseSpecifications,
            ProductSpecifications productSpecifications
            )
            : base(domainModelValidatorBaseSpecifications)
        {
            AddSpecification(domainModelValidatorBaseSpecifications.DomainModelMustHaveIdSpecification);
            AddSpecificationsForTenantInfo();
            AddSpecificationsForCreationInfo();
            AddSpecificationsForActivationInfo();

            AddSpecification(productSpecifications.ProductMustHaveCodeSpecification);
            AddSpecification(productSpecifications.ProductMustHaveCodeWithValidLengthSpecification);
            AddSpecification(productSpecifications.ProductMustHaveDescriptionWithValidLengthSpecification);
            AddSpecification(productSpecifications.ProductMustHaveNameSpecification);
            AddSpecification(productSpecifications.ProductMustHaveNameWithValidLengthSpecification);
        }