public void DoNotSyncMailedOrInvoicedItemsFromEbay() { using (MyDataContext.Default = new MyDataContext(Effort.EntityConnectionFactory.CreateTransient("name=MyDataContext"))) { this.InitializeDatabase(); TransactionType ebaySale = CreateEbaySale(); var ebaySyncer = new EbaySalesSyncer(); ebaySyncer.SyncToSale(ebaySale); var sale = MyDataContext.Default.Sales.First(); // Items which are shipped shouldn't be synced again sale.DateOfPayment = DateTime.Now; MyDataContext.Default.SaveChanges(); Mailing.CreateFromUnsentSales(); ebaySale.Buyer.BuyerInfo.ShippingAddress.Name = "New Name"; ebaySyncer.SyncToSale(ebaySale); Assert.AreNotSame("New Name", sale.InvoiceName); // Items which are invoiced shouldn't be synced again Invoice.CreateFromUnbilledSales(); ebaySale.Buyer.BuyerInfo.ShippingAddress.Name = "New Name"; ebaySyncer.SyncToSale(ebaySale); Assert.AreNotSame("New Name", sale.InvoiceName); } }
public void TestEbayShippingCosts() { using (MyDataContext.Default = new MyDataContext(Effort.EntityConnectionFactory.CreateTransient("name=MyDataContext"))) { this.InitializeDatabase(); var ebaySale = CreateEbaySale(); var ebaySyncer = new EbaySalesSyncer(); // Without containing order ebaySyncer.SyncToSale(ebaySale); var sale = MyDataContext.Default.Sales.FirstOrDefault(); Assert.AreEqual(5, sale.ShippingPrice); // Add another sale without containing order and without converted amount ebaySale.ShippingDetails.SellingManagerSalesRecordNumber = 1910; ebaySale.ConvertedAmountPaid.Value = 0; ebaySyncer.SyncToSale(ebaySale); sale = MyDataContext.Default.Sales.Where(runner => runner.SourceId == "1910").FirstOrDefault(); Assert.AreEqual(10, sale.ShippingPrice); // With containing order ebaySale.ShippingDetails.SellingManagerSalesRecordNumber = 1895; ebaySale.ContainingOrder = CreateOrderType(); ebaySyncer.SyncToSale(ebaySale); sale = MyDataContext.Default.Sales.Where(runner => runner.SourceId == "1911").FirstOrDefault(); Assert.AreEqual(4, sale.ShippingPrice); } }
public void SyncEbayWithSpecialEbayArticleNumber() { using (MyDataContext.Default = new MyDataContext(Effort.EntityConnectionFactory.CreateTransient("name=MyDataContext"))) { String ebayArticleNumber = "wi_131843106366_0"; this.InitializeDatabase(); MyDataContext.Default.Articles.First().EbayArticleNumber = ebayArticleNumber; MyDataContext.Default.SaveChanges(); TransactionType ebaySale = CreateEbaySale(); ebaySale.Item.SKU = ebayArticleNumber; var ebaySyncer = new EbaySalesSyncer(); ebaySyncer.SyncToSale(ebaySale); var sale = MyDataContext.Default.Sales.First(); Assert.AreEqual(MyDataContext.Default.Articles.First(), sale.SaleItems.First().Article); } }
public void DoNotSyncCanceldOrChangedItemsFromEbay() { using (MyDataContext.Default = new MyDataContext(Effort.EntityConnectionFactory.CreateTransient("name=MyDataContext"))) { this.InitializeDatabase(); TransactionType ebaySale = CreateEbaySale(); var ebaySyncer = new EbaySalesSyncer(); ebaySyncer.SyncToSale(ebaySale); var sale = MyDataContext.Default.Sales.First(); // Canceled items shouldn't be synced sale = MyDataContext.Default.Sales.First(); sale.Invoice = null; sale.Mailing = null; foreach (var item in sale.SaleItems) { item.CancelDate = DateTime.Now; } MyDataContext.Default.SaveChanges(); ebaySale.Buyer.BuyerInfo.ShippingAddress.Name = "New Name"; ebaySyncer.SyncToSale(ebaySale); Assert.AreNotSame("New Name", sale.InvoiceName); foreach (var item in sale.SaleItems) { item.CancelDate = null; } // Items which have been changed manually shouldn't be synced either sale = MyDataContext.Default.Sales.First(); sale.ManuallyChanged = true; MyDataContext.Default.SaveChanges(); ebaySale.Buyer.BuyerInfo.ShippingAddress.Name = "New Name"; ebaySyncer.SyncToSale(ebaySale); Assert.AreNotSame("New Name", sale.InvoiceName); } }
public void DoNotChangeStockAmountWhenSaleItemWasAlreadySyncedBefore() { using (MyDataContext.Default = new MyDataContext(Effort.EntityConnectionFactory.CreateTransient("name=MyDataContext"))) { this.InitializeDatabase(); TransactionType ebaySale = CreateEbaySale(); var ebaySyncer = new EbaySalesSyncer(); ebaySyncer.SyncToSale(ebaySale); Assert.AreEqual(90, MyDataContext.Default.Articles.First().AmountOnStock); // Sync existing sale item but in another sale, TransactionType anotherEbaySale = CreateEbaySale(); anotherEbaySale.ContainingOrder = CreateOrderType(); ebaySyncer.SyncToSale(anotherEbaySale); Assert.AreEqual(90, MyDataContext.Default.Articles.First().AmountOnStock); } }
public void SyncEbayTransactionToSale() { using (MyDataContext.Default = new MyDataContext(Effort.EntityConnectionFactory.CreateTransient("name=MyDataContext"))) { this.InitializeDatabase(); TransactionType ebaySale = CreateEbaySale(); var ebaySyncer = new EbaySalesSyncer(); ebaySyncer.SyncToSale(ebaySale); var sale = MyDataContext.Default.Sales.First(); Assert.AreEqual("1239817", sale.SourceId); Assert.AreEqual("komakommander", sale.EbayName); Assert.AreEqual("Tobias Mundt", sale.NameOfBuyer); Assert.AreEqual("0049 171 1234567", sale.PhoneNumber); Assert.AreEqual("*****@*****.**", sale.EMailAddress); Assert.AreEqual(new DateTime(2015, 08, 25, 14, 59, 00), sale.DateOfSale); Assert.AreEqual("Tobias Mundt", sale.InvoiceName); Assert.AreEqual("street1", sale.InvoiceStreet1); Assert.AreEqual("street2", sale.InvoiceStreet2); Assert.AreEqual("city", sale.InvoiceCity); Assert.AreEqual("stateOrProvince", sale.InvoiceRegion); Assert.AreEqual("postalCode", sale.InvoicePostcode); Assert.AreEqual("countryName", sale.InvoiceCountry); Assert.AreEqual("Tobias Mundt", sale.ShippingName); Assert.AreEqual("street1", sale.ShippingStreet1); Assert.AreEqual("street2", sale.ShippingStreet2); Assert.AreEqual("city", sale.ShippingCity); Assert.AreEqual("stateOrProvince", sale.ShippingRegion); Assert.AreEqual("postalCode", sale.ShippingPostcode); Assert.AreEqual("countryName", sale.ShippingCountry); Assert.AreEqual(5, sale.ShippingPrice); var saleItem = sale.SaleItems.First(); Assert.AreEqual(1239817, saleItem.EbaySalesRecordNumber); Assert.AreEqual("descDe", saleItem.ExternalArticleName); Assert.AreEqual("external", saleItem.ExternalArticleNumber); Assert.AreEqual("art001", saleItem.InternalArticleNumber); Assert.AreEqual(10.0m, saleItem.Amount); Assert.AreEqual(19.0m, saleItem.TaxRate); Assert.AreEqual(13.0m, saleItem.SinglePriceGross); Assert.AreEqual("TestOrderLine", saleItem.EbayOrderLineItemID); Assert.AreEqual(90, MyDataContext.Default.Articles.First().AmountOnStock); // Item is already synced, so no new entry should be create ebaySyncer.SyncToSale(ebaySale); var noOfSales = MyDataContext.Default.Sales.Count(); var noOfSaleItems = MyDataContext.Default.SaleItems.Count(); Assert.AreEqual(noOfSales, MyDataContext.Default.Sales.Count()); Assert.AreEqual(noOfSaleItems, MyDataContext.Default.SaleItems.Count()); // Add another sale, also private method GetStringFromTransaction is tested here ebaySale.Buyer.BuyerInfo.ShippingAddress.Phone = "invalid request"; ebaySale.ShippingDetails.SellingManagerSalesRecordNumber = 1910; ebaySyncer.SyncToSale(ebaySale); sale = MyDataContext.Default.Sales.Where(runner => runner.SourceId == "1910").FirstOrDefault(); Assert.AreEqual("1910", sale.SourceId); Assert.AreEqual(String.Empty, sale.PhoneNumber); Assert.AreEqual(80, MyDataContext.Default.Articles.First().AmountOnStock); } }
static void Main(String[] args) { MyDataContext.Default = new MyDataContext(); try { ShopperConfiguration.Default = ShopperConfigurationReader.FromWebConfig(); System.Diagnostics.Trace.Listeners.Add(new Models.Syncer.SyncerTraceListener()); System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.ConsoleTraceListener()); System.Diagnostics.Trace.AutoFlush = true; if (args.Contains(SyncProcessRemote.SyncTypes.Stock.ToString())) { StockSyncer syncer = new StockSyncer(); syncer.PerformInMutex(() => { System.Diagnostics.Trace.WriteLine("Stock sync started..."); syncer.SyncStock(); System.Diagnostics.Trace.WriteLine("Stock sync finished!"); }); } if (args.Contains(SyncProcessRemote.SyncTypes.TrackingNumber.ToString())) { TrackingNumberSyncer syncer = new TrackingNumberSyncer(); syncer.PerformInMutex(() => { System.Diagnostics.Trace.WriteLine("TrackingNumber sync started..."); syncer.SyncTrackingNumbersWithEbay(); System.Diagnostics.Trace.WriteLine("TrackingNumber sync finished!"); }); } if (args.Contains(SyncProcessRemote.SyncTypes.Sales.ToString())) { SalesSyncer syncer = new SalesSyncer(); syncer.PerformInMutex(() => { System.Diagnostics.Trace.WriteLine("Sales sync started..."); DateTime from = DateTime.Now.Date.AddDays(ShopperConfiguration.Default.ImportDaysBack * -1); DateTime until = DateTime.Now.Date.AddDays(1); System.Diagnostics.Trace.WriteLine("Loading Magento transactions..."); try { var magentoItems = MagentoController.LoadMagentoTransactions(from); var magentoSyncer = new MagentoSalesSyncer(); magentoSyncer.Import(magentoItems); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Magento could's not be synced: " + ex.Message); } try { System.Diagnostics.Trace.WriteLine("Loading ebay transactions..."); var ebayItems = EbayController.LoadEbayTransactions(from, until); System.Diagnostics.Trace.WriteLine("Ebay transactions loaded!"); var ebaySyncer = new EbaySalesSyncer(); ebaySyncer.Import(ebayItems); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Ebay could's not be synced: " + ex.Message); } System.Diagnostics.Trace.WriteLine("Sales sync finished!"); }); } if (args.Contains(SyncProcessRemote.SyncTypes.Articles.ToString())) { var products = EbayController.LoadEbaySellingManagerProducts(); EbayController.ReviseSellingManagerTemplates(products); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.DeepParse()); } }