public void Init()
        {
            _gatewayProviderService = PreTestDataWorker.GatewayProviderService;
            _storeSettingService = PreTestDataWorker.StoreSettingService;
            _shipCountryService = PreTestDataWorker.ShipCountryService;

            _merchelloContext = new MerchelloContext(new ServiceContext(new PetaPocoUnitOfWorkProvider()),
                new CacheHelper(new NullCacheProvider(),
                    new NullCacheProvider(),
                    new NullCacheProvider()));

            _catalog = PreTestDataWorker.WarehouseService.GetDefaultWarehouse().WarehouseCatalogs.FirstOrDefault();

            PreTestDataWorker.DeleteAllShipCountries();
            var country = _storeSettingService.GetCountryByCode("US");
            var shipCountry = new ShipCountry(_catalog.Key, country);
            _shipCountryService.Save(shipCountry);

            var shippingProvider =
               (FixedRateShippingGatewayProvider) _merchelloContext.Gateways.Shipping.CreateInstance(Core.Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey);
            Assert.NotNull(shippingProvider);

            var resource = shippingProvider.ListResourcesOffered().FirstOrDefault();
            var gatewayShipMethod = shippingProvider.CreateShippingGatewayMethod(resource, shipCountry, "Ground");
            shippingProvider.SaveShippingGatewayMethod(gatewayShipMethod);
        }
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            // assert we have our defaults setup
            var dtos = PreTestDataWorker.Database.Query<WarehouseDto>("SELECT * FROM merchWarehouse");
            var catalogs = PreTestDataWorker.Database.Query<WarehouseCatalogDto>("SELECT * FROM merchWarehouseCatalog");

            if (!dtos.Any() || !catalogs.Any())
            {
                Assert.Ignore("Warehouse defaults are not installed.");
            }

            // TODO : This is only going to be the case for the initial Merchello release
            Catalog = PreTestDataWorker.WarehouseService.GetDefaultWarehouse().WarehouseCatalogs.FirstOrDefault();

            if (Catalog == null)
            {
                Assert.Ignore("Warehouse Catalog is null");
            }

            GatewayProviderService = PreTestDataWorker.GatewayProviderService;
            StoreSettingService = PreTestDataWorker.StoreSettingService;
            ShipCountryService = PreTestDataWorker.ShipCountryService;

            PreTestDataWorker.DeleteAllShipCountries();
            const string countryCode = "US";

            var us = StoreSettingService.GetCountryByCode(countryCode);
            var shipCountry = new ShipCountry(Catalog.Key, us);
            ShipCountryService.Save(shipCountry);

            var dk = StoreSettingService.GetCountryByCode("DK");
            ShipCountryService.Save(new ShipCountry(Catalog.Key, dk));
        }
        /// <summary>
        /// Maps a <see cref="WarehouseCatalogDisplay"/> to a <see cref="IWarehouseCatalog"/>.
        /// </summary>
        /// <param name="catalog">
        /// The catalog.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <returns>
        /// The <see cref="WarehouseCatalog"/>.
        /// </returns>
        internal static IWarehouseCatalog ToWarehouseCatalog(this WarehouseCatalogDisplay catalog, IWarehouseCatalog destination)
        {
            if (!catalog.Key.Equals(Guid.Empty)) destination.Key = catalog.Key;

            destination.Name = catalog.Name;
            destination.Description = catalog.Description;

            return destination;
        }
        public DbPreTestDataWorker(ServiceContext serviceContext)
        {
            this.SqlSyntaxProvider = serviceContext.SqlSyntax;

            var uowProvider = new PetaPocoUnitOfWorkProvider(new Mock<ILogger>().Object);

            Database = uowProvider.GetUnitOfWork().Database;

            _serviceContext = serviceContext;

            WarehouseCatalog = new WarehouseCatalog(Constants.DefaultKeys.Warehouse.DefaultWarehouseKey)
            {
                Key = Constants.DefaultKeys.Warehouse.DefaultWarehouseCatalogKey
            };
        }
        public DbPreTestDataWorker(ServiceContext serviceContext)
        {
            var syntax = (DbSyntax)Enum.Parse(typeof (DbSyntax), ConfigurationManager.AppSettings["syntax"]);
            // sets up the Umbraco SqlSyntaxProvider Singleton
            SqlSyntaxProviderTestHelper.EstablishSqlSyntax(syntax);

            var uowProvider = new PetaPocoUnitOfWorkProvider();

            Database = uowProvider.GetUnitOfWork().Database;

            _serviceContext = serviceContext;

            WarehouseCatalog = new WarehouseCatalog(Constants.DefaultKeys.Warehouse.DefaultWarehouseKey)
            {
                Key = Constants.DefaultKeys.Warehouse.DefaultWarehouseCatalogKey
            };
        }
        public DbPreTestDataWorker()
        {
            var syntax = (DbSyntax)Enum.Parse(typeof(DbSyntax), ConfigurationManager.AppSettings["syntax"]);

            // sets up the Umbraco SqlSyntaxProvider Singleton OBSOLETE
            SqlSyntaxProviderTestHelper.EstablishSqlSyntax(syntax);

            this.SqlSyntaxProvider = SqlSyntaxProviderTestHelper.SqlSyntaxProvider(syntax);

            var uowProvider = new PetaPocoUnitOfWorkProvider(new Mock<ILogger>().Object);

            Database = uowProvider.GetUnitOfWork().Database;
            TestLogger = Logger.CreateWithDefaultLog4NetConfiguration();
            _serviceContext = new ServiceContext(new RepositoryFactory(), new PetaPocoUnitOfWorkProvider(TestLogger), TestLogger, new TransientMessageFactory());

            WarehouseCatalog = new WarehouseCatalog(Constants.DefaultKeys.Warehouse.DefaultWarehouseKey)
            {
                Key = Constants.DefaultKeys.Warehouse.DefaultWarehouseCatalogKey
            };
        }
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            var warehouseService = PreTestDataWorker.WarehouseService;
            _warehouse = warehouseService.GetDefaultWarehouse();

            _warehouseCatalog = _warehouse.DefaultCatalog();

            var key = Constants.ProviderKeys.Shipping.FixedRateShippingProviderKey;
            _fixedRateProvider = (FixedRateShippingGatewayProvider)MerchelloContext.Gateways.Shipping.ResolveByKey(key);

            var shipCountryService = PreTestDataWorker.ShipCountryService;
            _shipCountry = shipCountryService.GetShipCountryByCountryCode(_warehouseCatalog.Key, "US");
        }
        /// <summary>
        /// Saves a single <see cref="IWarehouseCatalog"/>.
        /// </summary>
        /// <param name="warehouseCatalog">
        /// The warehouse catalog.
        /// </param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        public void Save(IWarehouseCatalog warehouseCatalog, bool raiseEvents = true)
        {
            if (raiseEvents)
            if (Saving.IsRaisedEventCancelled(new SaveEventArgs<IWarehouseCatalog>(warehouseCatalog), this))
            {
                ((WarehouseCatalog)warehouseCatalog).WasCancelled = true;
                return;
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateWarehouseCatalogRepository(uow))
                {
                    repository.AddOrUpdate(warehouseCatalog);
                    uow.Commit();
                }
            }

            if (raiseEvents) Saved.RaiseEvent(new SaveEventArgs<IWarehouseCatalog>(warehouseCatalog), this);
        }
        /// <summary>
        /// Removes variants from catalog inventory.
        /// </summary>
        /// <param name="catalog">
        /// The catalog.
        /// </param>
        private void RemoveVariantsFromCatalogInventoryBeforeDeleting(IWarehouseCatalog catalog)
        {
            var variants =
                _productVariantService.GetByWarehouseKey(catalog.WarehouseKey)
                    .Where(pv => pv.CatalogInventories.Any(inv => inv.CatalogKey == catalog.Key)).ToArray();

            if (!variants.Any()) return;

            foreach (var variant in variants)
            {
                variant.RemoveFromCatalogInventory(catalog);
            }

            _productVariantService.Save(variants);
        }
Exemple #10
0
 /// <summary>
 /// Saves a single <see cref="IWarehouseCatalog"/>.
 /// </summary>
 /// <param name="warehouseCatalog">
 /// The warehouse catalog.
 /// </param>
 public void Save(IWarehouseCatalog warehouseCatalog)
 {
     _warehouseCatalogService.Save(warehouseCatalog);
 }
        /// <summary>
        /// Deletes a single instance of a <see cref="IWarehouseCatalog"/>.
        /// </summary>
        /// <param name="warehouseCatalog">
        /// The warehouse catalog.
        /// </param>
        /// <param name="raiseEvents">
        /// The raise events.
        /// </param>
        public void Delete(IWarehouseCatalog warehouseCatalog, bool raiseEvents = true)
        {
            if (warehouseCatalog.Key == Core.Constants.DefaultKeys.Warehouse.DefaultWarehouseCatalogKey) return;

            if (raiseEvents)
            if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs<IWarehouseCatalog>(warehouseCatalog), this))
            {
                ((WarehouseCatalog)warehouseCatalog).WasCancelled = true;
                return;
            }

            RemoveVariantsFromCatalogInventoryBeforeDeleting(warehouseCatalog);

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateWarehouseCatalogRepository(uow))
                {
                    repository.Delete(warehouseCatalog);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            Deleted.RaiseEvent(new DeleteEventArgs<IWarehouseCatalog>(warehouseCatalog), this);
        }
Exemple #12
0
 /// <summary>
 /// Associates a product variant with a warehouse
 /// </summary>
 /// <param name="productVariant">The <see cref="IProductVariant"/></param>
 /// <param name="catalog">The <see cref="IWarehouseCatalog"/></param>
 public static void AddToCatalogInventory(this IProductVariant productVariant, IWarehouseCatalog catalog)
 {
     productVariant.AddToCatalogInventory(catalog.Key);
 }
        public void Init()
        {
            var warehouseService = PreTestDataWorker.WarehouseService;
            _warehouse = warehouseService.GetDefaultWarehouse();

            _warehouseCatalog = _warehouse.DefaultCatalog();
        }
Exemple #14
0
        /// <summary>
        /// Removes a product varaint from a catalog inventory.
        /// </summary>
        /// <param name="productVariant">
        /// The product variant.
        /// </param>
        /// <param name="catalog">
        /// The catalog.
        /// </param>
        public static void RemoveFromCatalogInventory(this IProductVariant productVariant, IWarehouseCatalog catalog)
        {
            if (productVariant.CatalogInventories.All(inv => inv.CatalogKey != catalog.Key)) return;

            productVariant.RemoveFromCatalogInventory(catalog.Key);
        }
Exemple #15
0
 /// <summary>
 /// Associates a product with a warehouse catalog
 /// </summary>
 /// <param name="product">The <see cref="IProduct"/></param>
 /// <param name="catalog">The <see cref="IWarehouseCatalog"/></param>
 public static void AddToCatalogInventory(this IProduct product, IWarehouseCatalog catalog)
 {
     ((Product)product).MasterVariant.AddToCatalogInventory(catalog);
 }
Exemple #16
0
 /// <summary>
 /// Deletes a single <see cref="IWarehouseCatalog"/>.
 /// </summary>
 /// <param name="warehouseCatalog">
 /// The warehouse catalog.
 /// </param>
 /// <remarks>
 /// Cannot delete the default catalog in the default warehouse
 /// </remarks>
 public void Delete(IWarehouseCatalog warehouseCatalog)
 {
     _warehouseCatalogService.Delete(warehouseCatalog);
 }
        internal static IWarehouseCatalog ToWarehouseCatalog(this WarehouseCatalogDisplay warehouseCatalogDisplay, IWarehouseCatalog destination)
        {
            if (warehouseCatalogDisplay.Key != Guid.Empty)
            {
                destination.Key = warehouseCatalogDisplay.Key;
            }
            destination.Name = warehouseCatalogDisplay.Name;
            destination.Description = warehouseCatalogDisplay.Description;

            return destination;
        }
Exemple #18
0
        public void FixtureInit()
        {
            // assert we have our defaults setup
            var dtos = PreTestDataWorker.Database.Query<WarehouseDto>("SELECT * FROM merchWarehouse");
            var catalogs = PreTestDataWorker.Database.Query<WarehouseCatalogDto>("SELECT * FROM merchWarehouseCatalog");

            if (!dtos.Any() || !catalogs.Any())
            {
                Assert.Ignore("Warehouse defaults are not installed.");
            }

            // TODO : This is only going to be the case for the initial Merchello release
            _catalog = PreTestDataWorker.WarehouseService.GetDefaultWarehouse().WarehouseCatalogs.FirstOrDefault();

            if (_catalog == null)
            {
                Assert.Ignore("Warehouse Catalog is null");
            }

            _storeSettingService = PreTestDataWorker.StoreSettingService;
            _shipCountryService = PreTestDataWorker.ShipCountryService;
        }
Exemple #19
0
        /// <summary>
        /// Removes a product varaint from a catalog inventory.
        /// </summary>
        /// <param name="productVariant">
        /// The product variant.
        /// </param>
        /// <param name="catalog">
        /// The catalog.
        /// </param>
        internal static void RemoveFromCatalogInventory(this IProductVariant productVariant, IWarehouseCatalog catalog)
        {
            if (productVariant.CatalogInventories.All(inv => inv.CatalogKey != catalog.Key)) return;

            ((CatalogInventoryCollection)productVariant.CatalogInventories).RemoveAt(productVariant.CatalogInventories.FindIndex(x => x.CatalogKey == catalog.Key));
        }
 /// <summary>
 /// Associates a product variant with a warehouse
 /// </summary>
 /// <param name="productVariant"></param>
 /// <param name="catalog"><see cref="IWarehouseCatalog"/></param>
 internal static void AddToCatalogInventory(this IProductVariant productVariant, IWarehouseCatalog catalog)
 {
     ((CatalogInventoryCollection)productVariant.CatalogInventories).Add(new CatalogInventory(catalog.Key, productVariant.Key));
 }