Ejemplo n.º 1
0
        public PriceCalculationDomainService(
            //IWorkContext workContext,
            IStoreContext storeContext,
            DiscountDomainService discountService,
            CategoryDomainService categoryService,
            ManufacturerDomainService manufacturerService,
            IProductAttributeParser productAttributeParser,
            ProductDomainService productService,
            ICacheManager cacheManager
            , SettingDomainService settingDomainService
            //ShoppingCartSettings shoppingCartSettings,
            //CatalogSettings catalogSettings
            )
        {
            //this._workContext = workContext;
            this._storeContext           = storeContext;
            this._discountService        = discountService;
            this._categoryService        = categoryService;
            this._manufacturerService    = manufacturerService;
            this._productAttributeParser = productAttributeParser;
            this._productService         = productService;
            this._cacheManager           = cacheManager;

            //this._shoppingCartSettings = shoppingCartSettings;
            //this._catalogSettings = catalogSettings;
            _settingDomainService = settingDomainService;
        }
        public void GetAllProducts_WhenCollectionIsNotEmpty_ShouldReturn3()
        {
            // Arrange
            var testCollection = new List <Product>()
            {
                new Product()
                {
                    Name = "Guasha"
                },
                new Product()
                {
                    Name = "GiftBox"
                },
                new Product()
                {
                    Name = "Tree"
                }
            };
            var mockRepository = new Mock <IProductRepository>();

            mockRepository.Setup(p => p.GetAllProducts())
            .Returns(testCollection);
            var service = new ProductDomainService(mockRepository.Object);

            // Act
            var check = service.GetAllProducts();

            // Assert
            var result = Assert.IsType <List <Product> >(check);

            Assert.Equal(3, result.Count);
        }
        public void DeleteProduct_WhenNotExist()
        {
            // Arrange
            var  mockRepository = new Mock <IProductRepository>();
            Guid testId         = Guid.NewGuid();

            mockRepository.Setup(p => p.DeleteProduct(testId))
            .Throws <Exception>();
            var services = new ProductDomainService(mockRepository.Object);

            // Act & Assert
            Assert.Throws <Exception>(() => services.DeleteProduct(testId));
        }
        public void GetProductById_WhenNotExist_ThrowException()
        {
            // Arrange
            var  mockRepository = new Mock <IProductRepository>();
            Guid testId         = Guid.NewGuid();

            mockRepository.Setup(p => p.GetProductById(testId))
            .Throws <Exception>();
            var service = new ProductDomainService(mockRepository.Object);

            // Act & Assert
            Assert.Throws <Exception>(() => service.GetProductById(testId));
        }
        public void UpdateProduct_WhenNotExist()
        {
            // Arrange
            var  mockRepository = new Mock <IProductRepository>();
            Guid testId         = Guid.NewGuid();

            mockRepository.Setup(p => p.UpdateProduct(testId, It.IsAny <Product>()))
            .Throws <Exception>();
            var service = new ProductDomainService(mockRepository.Object);

            // Act & Assert
            Assert.Throws <Exception>(() => service.UpdateProduct(testId, new Product()
            {
                Name = "Guasha"
            }));
        }
        public void GetAllProducts_WhenCollectionEmpty()
        {
            // Arrange
            var mockRepository = new Mock <IProductRepository>();

            mockRepository.Setup(p => p.GetAllProducts())
            .Returns(new List <Product>());
            var service = new ProductDomainService(mockRepository.Object);

            // Act
            var check = service.GetAllProducts();

            // Assert
            var result = Assert.IsType <List <Product> >(check);

            Assert.Empty(result);
        }
Ejemplo n.º 7
0
        public ProductAppService(ProductDomainService productDomainService
                                 , ShippingDomainServie shippingDomainServie
                                 , VendorDomainService vendorDomainService
                                 , SettingDomainService settingDomainService
                                 , ProductTemplateDomainService productTemplateService
                                 , PictureDomainService pictureDomainService
                                 , CurrencyDomainService currencyDomainService
                                 , TaxDomainService taxDomainService
                                 , PriceCalculationDomainService priceCalculationDomainService
                                 , IPriceFormatter priceFormatter
                                 , IProductAttributeParser productAttributeParser
                                 , ProductAttributeDomainService productAttributeDomainService
                                 , DownloadDomainService downloadDomainService
                                 , ManufacturerDomainService manufacturerDomainService
                                 , SpecificationAttributeDomainService specificationAttributeDomainService

                                 , IVendorTest vendorTest
                                 , IStoreContext storeContext
                                 , ICacheManager cacheManager)
        {
            _productDomainService          = productDomainService;
            _shippingDomainServie          = shippingDomainServie;
            _vendorDomainService           = vendorDomainService;
            _settingDomainService          = settingDomainService;
            _productTemplateService        = productTemplateService;
            _pictureDomainService          = pictureDomainService;
            _currencyDomainService         = currencyDomainService;
            _taxDomainService              = taxDomainService;
            _priceCalculationDomainService = priceCalculationDomainService;
            _priceFormatter                      = priceFormatter;
            _productAttributeParser              = productAttributeParser;
            _productAttributeDomainService       = productAttributeDomainService;
            _downloadDomainService               = downloadDomainService;
            _manufacturerDomainService           = manufacturerDomainService;
            _specificationAttributeDomainService = specificationAttributeDomainService;

            _vendorTest        = vendorTest;
            _storeContext      = storeContext;
            this._cacheManager = cacheManager;

            var a = 5;
        }
        public void CreateValidProduct()
        {
            // Arrange
            var mockRepository = new Mock <IProductRepository>();
            var testProduct    = new Product()
            {
                Name = "Guasha"
            };

            mockRepository.Setup(p => p.CreateProduct(testProduct))
            .Returns(() => testProduct);
            var service = new ProductDomainService(mockRepository.Object);

            // Act
            var check = service.CreateProduct(testProduct);

            // Assert
            var result = Assert.IsType <Product>(check);

            Assert.Equal(testProduct.Name, result.Name);
        }
        public void GetProductById_WhenExist()
        {
            // Arrange
            var  mockRepository = new Mock <IProductRepository>();
            Guid testId         = Guid.NewGuid();

            mockRepository.Setup(p => p.GetProductById(testId))
            .Returns(new Product()
            {
                Id   = testId,
                Name = "Guasha"
            });
            var services = new ProductDomainService(mockRepository.Object);

            // Act
            var check = services.GetProductById(testId);

            // Assert
            var result = Assert.IsType <Product>(check);

            Assert.Equal(testId, result.Id);
        }
Ejemplo n.º 10
0
        public void DeleteProduct_WhenExists()
        {
            // Arrange
            var mockRepository = new Mock <IProductRepository>();
            var testProduct    = new Product()
            {
                Id   = Guid.NewGuid(),
                Name = "Guasha"
            };

            mockRepository.Setup(p => p.DeleteProduct(testProduct.Id))
            .Returns(testProduct);
            var services = new ProductDomainService(mockRepository.Object);

            // Act
            var check = services.DeleteProduct(testProduct.Id);

            // Assert
            var result = Assert.IsType <Product>(check);

            Assert.Equal(testProduct.Id, result.Id);
            Assert.Equal(testProduct.Name, result.Name);
        }
Ejemplo n.º 11
0
        public void UpdateProduct_WhenExist()
        {
            // Arrange
            var  mockRepository = new Mock <IProductRepository>();
            Guid testId         = Guid.NewGuid();
            var  testProduct    = new Product()
            {
                Id   = testId,
                Name = "Guasha"
            };

            mockRepository.Setup(p => p.UpdateProduct(testId, It.IsAny <Product>()))
            .Returns(() => testProduct);
            var service = new ProductDomainService(mockRepository.Object);

            // Act
            var check = service.UpdateProduct(testId, testProduct);

            // Assert
            var result = Assert.IsType <Product>(check);

            Assert.Equal(testId, result.Id);
            Assert.Equal(testProduct.Name, result.Name);
        }
        public async Task Queryable_Should_Allow_Composition()
        {
            // Arrange
            var comparer  = new MyProductComparer();
            var expected1 = new MyProduct {
                Id = 1, Name = "Chai", Price = 18.00m, Category = "Beverages"
            };
            var expected2 = new MyProduct {
                Id = 2, Name = "Chang", Price = 19.00m, Category = "Beverages"
            };

            var repository = new TrackableRepository <Product>(_fixture.Context);

            var productDomainService = new ProductDomainService(repository, _mapper);
            // Act

            var query = productDomainService.Queryable();

            var products = await query
                           .Include(p => p.Category)
                           .Take(2)
                           .Where(p => p.UnitPrice > 15)
                           .Select(p => new MyProduct
            {
                Id       = p.ProductId,
                Name     = p.ProductName,
                Price    = p.UnitPrice,
                Category = p.Category.CategoryName
            })
                           .ToListAsync();

            // Assert
            Assert.Collection(products,
                              p => Assert.Equal(expected1, p, comparer),
                              p => Assert.Equal(expected2, p, comparer));
        }
Ejemplo n.º 13
0
 public ProductAppService(ProductDomainService productDomainService)
 {
     _productDomainService = productDomainService;
 }
Ejemplo n.º 14
0
 public ActivateProductHandler(IProductRepository productRepository, ProductDomainService productDomainService)
 {
     _productRepository    = productRepository;
     _productDomainService = productDomainService;
 }
 public CreateProductDraftHandler(IProductRepository productRepository, ProductDomainService productDomainService)
 {
     _productRepository    = productRepository;
     _productDomainService = productDomainService;
 }
Ejemplo n.º 16
0
 public ProductService(ProductDomainService ProductService)
 {
     _productService = ProductService;
 }
 public DiscontinueProductHandler(IProductRepository productRepository, ProductDomainService productDomainService)
 {
     _productRepository    = productRepository;
     _productDomainService = productDomainService;
 }