Esempio n. 1
0
        public void SyncItemsFromSample(SupplieroasisApi api)
        {
            var coreApi         = new Mock <ISupplieroasisCoreApi>(MockBehavior.Strict);
            var asinsWithErrors = new List <string>();

            coreApi.Setup(p => p.GetItems()).Returns(() =>
            {
                using (var sr = new StringReader(File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files/OverstockSampleResponses/overstock_get_inventory_response.xml"))))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(GetInventoryResponse));
                    return(CallResult <GetInventoryResponse> .Success((GetInventoryResponse)serializer.Deserialize(sr)));
                }
            });
            api.OverrideCoreApi(coreApi.Object);

            var itemService = new SupplierOasisItemsSync(_log, _time, _dbFactory);

            itemService.ReadItemsInfo(api);
        }
Esempio n. 2
0
        public void SyncOrders(SupplieroasisApi api)
        {
            var coreApi         = new Mock <ISupplieroasisCoreApi>(MockBehavior.Strict);
            var asinsWithErrors = new List <string>();

            coreApi.Setup(p => p.GetOrders(It.IsAny <DateTime>(), It.IsAny <DateTime>())).Returns((DateTime d1, DateTime d2) =>
            {
                using (var sr = new StringReader(File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files/OverstockSampleResponses/overstock_get_orders_response.xml"))))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(GetOrdersResponse));
                    return(CallResult <GetOrdersResponse> .Success((GetOrdersResponse)serializer.Deserialize(sr)));
                }
            });
            api.OverrideCoreApi(coreApi.Object);

            var syncInfo = new DbSyncInformer(_dbFactory,
                                              _log,
                                              _time,
                                              SyncType.Orders,
                                              api.MarketplaceId,
                                              api.Market,
                                              String.Empty);
            var settings             = new SettingsService(_dbFactory);
            var dbFactory            = new DbFactory();
            var quantityManager      = new QuantityManager(_log, _time);
            var priceService         = new PriceService(dbFactory);
            var companyAddressList   = new CompanyAddressService(_company, null);
            var serviceFactory       = new ServiceFactory();
            var addressCheckServices = serviceFactory.GetAddressCheckServices(_log,
                                                                              _time,
                                                                              dbFactory,
                                                                              _company.AddressProviderInfoList);
            var addressService = new AddressService(addressCheckServices,
                                                    companyAddressList.GetReturnAddress(MarketIdentifier.Empty()),
                                                    companyAddressList.GetPickupAddress(MarketIdentifier.Empty()));

            var rateProviders = serviceFactory.GetShipmentProviders(_log,
                                                                    _time,
                                                                    dbFactory,
                                                                    _weightService,
                                                                    _company.ShipmentProviderInfoList,
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    null);

            var stampsRateProvider  = rateProviders.FirstOrDefault(r => r.Type == ShipmentProviderType.Stamps);
            var orderHistoryService = new OrderHistoryService(_log, _time, _dbFactory);
            var validatorService    = new OrderValidatorService(_log,
                                                                _dbFactory,
                                                                _emailService,
                                                                settings,
                                                                orderHistoryService,
                                                                _actionService,
                                                                priceService,
                                                                _htmlScraper,
                                                                addressService,
                                                                companyAddressList.GetReturnAddress(MarketIdentifier.Empty()),
                                                                stampsRateProvider,
                                                                _time,
                                                                _company);

            var actionService = new SystemActionService(_log, _time);
            var cacheService  = new CacheService(_log, _time, actionService, quantityManager);

            using (var db = _dbFactory.GetRWDb())
            {
                //if (!syncInfo.IsSyncInProgress())
                {
                    try
                    {
                        syncInfo.SyncBegin(null);

                        var orderSyncFactory = new OrderSyncFactory();
                        var synchronizer     = orderSyncFactory.GetForMarket(api,
                                                                             _log,
                                                                             _company,
                                                                             settings,
                                                                             syncInfo,
                                                                             rateProviders,
                                                                             quantityManager,
                                                                             _emailService,
                                                                             validatorService,
                                                                             orderHistoryService,
                                                                             cacheService,
                                                                             _actionService,
                                                                             companyAddressList,
                                                                             _time,
                                                                             _weightService,
                                                                             _messageService);

                        //if (!String.IsNullOrEmpty(orderNumber))
                        //    synchronizer.ProcessSpecifiedOrder(db, orderNumber);
                        //else
                        synchronizer.Sync(Core.Models.Orders.OrderSyncModes.Full, null);
                    }
                    finally
                    {
                        syncInfo.SyncEnd();
                    }
                }
            }
        }