Example #1
0
        public void NewProductsFromPayamGostarAreInserted()
        {
            var productSyncServiceMock       = new Mock <IProductSyncService>();
            var productServiceMock           = new Mock <IProductService>();
            var pgProductMetaDataServiceMock = new Mock <IPgProductMetaDataService>();
            var productTemplateServiceMock   = new Mock <IProductTemplateService>();
            var logger = new Mock <ILogger>();

            productTemplateServiceMock.Setup(x => x.GetAllProductTemplates())
            .Returns(new List <Nop.Core.Domain.Catalog.ProductTemplate>
            {
                new Nop.Core.Domain.Catalog.ProductTemplate()
                {
                    Id = 1, Name = "Simple product", DisplayOrder = 1, ViewPath = ""
                }
            }
                     );

            productSyncServiceMock.Setup(x => x.GetProductChangesSince(It.IsAny <DateTime>()))
            .Returns(new ProductChanges
            {
                NewProducts = new
                              List <Product>
                {
                    new Product {
                        Code = "1", Name = "test product", UnitPrice = 1000.0M
                    }
                }
            });

            var insertedProductId = 5;

            productServiceMock.Setup(x => x.InsertProduct(It.IsAny <Nop.Core.Domain.Catalog.Product>()))
            .Callback <Nop.Core.Domain.Catalog.Product>(x => x.Id = insertedProductId);

            var productSyncTask = new ProductSyncTask(
                productSyncServiceMock.Object,
                productServiceMock.Object,
                pgProductMetaDataServiceMock.Object,
                productTemplateServiceMock.Object,
                logger.Object);

            productSyncTask.Execute();

            productServiceMock.Verify(x => x.InsertProduct(It.Is <Nop.Core.Domain.Catalog.Product>(product => product.Price == 1000.0M && product.Name == "test product")));
            pgProductMetaDataServiceMock.Verify(x => x.InsertPgProductMetaData(It.Is <PgProductMetaData>(meta => meta.Code == "1" && meta.ProductId == insertedProductId)));
        }
Example #2
0
        public void DeletedProductsFromPayamGostarAreDeleted()
        {
            var productSyncServiceMock       = new Mock <IProductSyncService>();
            var productServiceMock           = new Mock <IProductService>();
            var pgProductMetaDataServiceMock = new Mock <IPgProductMetaDataService>();
            var productTemplateServiceMock   = new Mock <IProductTemplateService>();
            var logger = new Mock <ILogger>();

            productTemplateServiceMock.Setup(x => x.GetAllProductTemplates())
            .Returns(new List <Nop.Core.Domain.Catalog.ProductTemplate>
            {
                new Nop.Core.Domain.Catalog.ProductTemplate()
                {
                    Id = 1, Name = "Simple product", DisplayOrder = 1, ViewPath = ""
                }
            }
                     );

            productSyncServiceMock.Setup(x => x.GetProductChangesSince(It.IsAny <DateTime>()))
            .Returns(new ProductChanges
            {
                NewProducts = null,

                EditedProducts = null,

                DeletedProductCodes = new
                                      List <string>
                {
                    "1"
                }
            });


            var updattedProductId = 5;

            pgProductMetaDataServiceMock.Setup(x => x.GetPgProductMetaDataByCode(It.IsAny <string>())).
            Returns(new PgProductMetaData()
            {
                Id = 1, ProductId = updattedProductId
            });

            productServiceMock.Setup(x => x.GetProductById(It.IsAny <int>())).
            Returns(new Nop.Core.Domain.Catalog.Product()
            {
                Id = updattedProductId
            });

            productServiceMock.Setup(x => x.UpdateProduct(It.IsAny <Nop.Core.Domain.Catalog.Product>()))
            .Callback <Nop.Core.Domain.Catalog.Product>(x => x.Id = updattedProductId);

            var productSyncTask = new ProductSyncTask(
                productSyncServiceMock.Object,
                productServiceMock.Object,
                pgProductMetaDataServiceMock.Object,
                productTemplateServiceMock.Object,
                logger.Object);

            productSyncTask.Execute();

            productServiceMock.Verify(x => x.UpdateProduct(It.Is <Nop.Core.Domain.Catalog.Product>(product => product.Deleted == true)));
        }