コード例 #1
0
        public void EmptyFileTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser);
            var testLocation = @"C:\Development\Evolution\Evolution\Evolution.Tests\Evolution.ShopifyImportServiceTests\TestData\Empty";
            var files        = Directory.GetFiles(testLocation);

            ShopifyImportService.ShopifyImportService service = new ShopifyImportService.ShopifyImportService(db);

            // It is expected that this test will fail in code as the XML files are empty - one is completly empty, the other only has a <Data> node.
            // This test will catch the failed attat at processing the file and return a true value
            bool errored        = false;
            int  expectedErrors = 3;
            int  actual         = 0;

            ShopifyImportTempModel.Data file = null;
            foreach (var xmlFile in files)
            {
                try {
                    file = service.ProcessXml(xmlFile, testCompany.AccountName);
                } catch {
                    errored = true;
                }
                actual++;
                Assert.IsTrue(errored == true, "Error: Call to 'ProcessXml' should have cause an exception but none was thrown");
            }
            Assert.IsTrue(expectedErrors == actual, $"Error: number of files found where {actual} when {expectedErrors} were expected");
        }
コード例 #2
0
        public void MissingOrderLinesTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser);
            var testLocation = @"C:\Development\Evolution\Evolution\Evolution.Tests\Evolution.ShopifyImportServiceTests\TestData\MissingOrderLines";
            var xmlFile      = Directory.GetFiles(testLocation);
            var taskUser     = GetTaskUser();
            Dictionary <string, string> configDetails = new Dictionary <string, string> {
                { "StoreId", "Companysydney" },
                { "CustomerName", "AAA Company.com.au Sales" },
                { "BrandCategory", "Company" },
                { "DataSource", "OrderHive" }
            };

            ShopifyImportService.ShopifyImportService service = new ShopifyImportService.ShopifyImportService(db);
            bool errored = false;

            // It is expected that this test will fail in code as there is no header in the xml file
            // This test will catch the failed attempt at mapping the file to the TEMP model and return a true value
            try {
                var fileData = service.ProcessXml(xmlFile[0], testCompany.AccountName);
                service.MapOrderToTemp(testCompany.AccountName, configDetails, fileData.Order[0], taskUser);
            } catch {
                errored = true;
            }
            Assert.IsTrue(errored == true, "Error: Call to 'MapOrderToTemp' should have caused an exception but none was thrown");
        }
コード例 #3
0
        public void GetShopifyTempTableDataTest()
        {
            var testUser     = GetTestUser();
            var testCompany  = GetTestCompany(testUser);
            var testLocation = @"C:\Development\Evolution\Evolution\Evolution.Tests\Evolution.ShopifyImportServiceTests\TestData";
            var xmlFile      = Directory.GetFiles(testLocation);
            var taskUser     = GetTaskUser();
            Dictionary <string, string> configDetails = new Dictionary <string, string> {
                { "StoreId", "1" },
                { "CustomerName", "AAA Company.com.au Sales" },
                { "BrandCategory", "Company" },
                { "DataSource", "OrderHive" }
            };

            ShopifyImportService.ShopifyImportService service = new ShopifyImportService.ShopifyImportService(db);

            foreach (var fileName in xmlFile)
            {
                int expectedOrders;
                int actualOrders;
                int expectedItems = 0;
                int actualItems   = 0;

                var orders = service.ProcessXml(fileName, testCompany.AccountName);
                expectedOrders = orders.Order.Length;

                List <ShopifyImportHeaderTemp> sitmList = new List <ShopifyImportHeaderTemp>();
                foreach (var order in orders.Order)
                {
                    expectedItems += order.SalesOrderItems.Length;

                    var shopifyTemp = service.MapOrderToTemp(testCompany.AccountName, configDetails, order, taskUser);
                    sitmList.Add(shopifyTemp);
                }
                service.SaveDataToTempTables(sitmList);

                // Get data from TEMP tables
                sitmList     = service.GetShopifyTempTableData();
                actualOrders = sitmList.Count;
                foreach (var order in sitmList)
                {
                    actualItems += order.ShopifyImportDetailTemps.Count;
                }

                Assert.AreEqual(expectedOrders, actualOrders, $"Error: {expectedOrders} order were expected for file {fileName}, when {actualOrders} were retrieved from the databse");
                Assert.AreEqual(expectedItems, actualItems, $"Error: {expectedItems} items were expected for file {fileName}, when {actualItems} were retrieved from the database");
            }
        }
コード例 #4
0
        public override int DoProcessing(string[] args)
        {
            var shopifyImportService = new ShopifyImportService.ShopifyImportService(_db);

            DataTransferService.DataTransferService dts = new DataTransferService.DataTransferService(_db);

            int    i           = 1;
            var    profileName = GetTaskParameter($"DataTransfer{1}", "");
            var    taskUser    = GetTaskUser();
            string errorMsg    = "";

            var config = dts.FindDataTransferConfigurationModel(profileName);

            if (config == null)
            {
                TaskService.WriteTaskLog(this.Task, $"Error: Failed to find Data Transfer configuration '{profileName}' !");
            }
            else
            {
                string fileLoc = config.TargetFolder;
                while (!string.IsNullOrEmpty(fileLoc))
                {
                    string   businessName = GetTaskParameter($"BusinessName{i}", "");
                    string[] files        = null;
                    try {
                        files = Directory.GetFiles(fileLoc);
                    } catch (Exception ex) {
                        TaskService.WriteTaskLog(this.Task, $"Error: There was a problem getting files from '{fileLoc}'\r\n" + ex, LogSeverity.Severe);
                    }

                    if (files.Length > 0 && files != null)
                    {
                        foreach (string fileName in files)
                        {
                            // Process File
                            TaskService.WriteTaskLog(this.Task, $"Success: Processing file '{fileName}'", LogSeverity.Normal);
                            ShopifyImportTempModel.Data shopifyTempModel = null;
                            try {
                                shopifyTempModel = shopifyImportService.ProcessXml(fileName, businessName);
                            } catch (Exception ex) {
                                TaskService.WriteTaskLog(this.Task, $"Error: Could not process file '{fileName}'\r\n" + ex, LogSeverity.Severe);
                                //MoveFileToErrorFolder(dts, config, fileName);
                            }

                            if (shopifyTempModel != null)
                            {
                                List <ShopifyImportHeaderTemp> sihtList = new List <ShopifyImportHeaderTemp>();

                                // Map each order to TEMP
                                foreach (var order in shopifyTempModel.Order)
                                {
                                    try {
                                        Dictionary <string, string> configDetails = LookupConfigDetails(order.StoreName);
                                        if (configDetails.Count > 0)
                                        {
                                            ShopifyImportHeaderTemp siht = new ShopifyImportHeaderTemp();
                                            siht = shopifyImportService.MapOrderToTemp(businessName, configDetails, order, taskUser);
                                            sihtList.Add(siht);
                                        }
                                        else
                                        {
                                            TaskService.WriteTaskLog(this.Task, $"Error: Configuration Setting are not setup", LogSeverity.Severe);
                                        }
                                    } catch (Exception ex) {
                                        TaskService.WriteTaskLog(this.Task, $"Error: Could not map order (#{order.OrderNumber}) details to temp table\r\n" + ex, LogSeverity.Severe);
                                        //MoveFileToErrorFolder(dts, config, fileName);
                                        break;
                                    }
                                }

                                if (sihtList.Count > 0 && sihtList.Count == shopifyTempModel.Order.Length)   // AND COUNT = THE ACTUAL NUMBER OF ORDERS IN THE XML FILE
                                // Save temp to db
                                {
                                    try {
                                        shopifyImportService.SaveDataToTempTables(sihtList);
                                        TaskService.WriteTaskLog(this.Task, $"Success: Saved '{fileName}' temp table", LogSeverity.Normal);

                                        // Get Temp table data
                                        try {
                                            sihtList = shopifyImportService.GetShopifyTempTableData();
                                            if (sihtList.Count > 0)
                                            {
                                                try {
                                                    // CopyTempDataToSalesModel
                                                    List <SalesOrderHeader> orders = shopifyImportService.CopyTempDataToSalesModel(sihtList, businessName);
                                                    if (orders.Count > 0)
                                                    {
                                                        if (shopifyImportService.SaveSalesOrders(orders))
                                                        {
                                                            TaskService.WriteTaskLog(this.Task, $"Success: Data Saved to Sales tables", LogSeverity.Normal);

                                                            // Move file to Archive folder
                                                            if (dts.MoveToArchive(config, fileName, ref errorMsg))
                                                            {
                                                                TaskService.WriteTaskLog(this.Task, $"Failed to move to Archive folder\r\n{errorMsg}", LogSeverity.Severe);
                                                            }
                                                            else
                                                            {
                                                                TaskService.WriteTaskLog(this.Task, $"Successfully moved file '{fileName}' to Archive folder", LogSeverity.Normal);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            // Move file to Error folder
                                                            MoveFileToErrorFolder(dts, config, fileName);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        TaskService.WriteTaskLog(this.Task, $"Error: Could not retrieve any orders from the temp table/s", LogSeverity.Severe);
                                                        MoveFileToErrorFolder(dts, config, fileName);
                                                    }
                                                } catch (Exception ex) {
                                                    TaskService.WriteTaskLog(this.Task, $"Error: Could not copy data to sales table/s\r\n" + ex, LogSeverity.Severe);
                                                    MoveFileToErrorFolder(dts, config, fileName);
                                                }
                                            }
                                        } catch (Exception ex) {
                                            TaskService.WriteTaskLog(this.Task, $"Error: Failed to get temp data from database\r\n" + ex, LogSeverity.Severe);
                                            MoveFileToErrorFolder(dts, config, fileName);
                                        }
                                    } catch (Exception ex) {
                                        TaskService.WriteTaskLog(this.Task, $"Error: Failed to save data to the temp table/s\r\n" + ex, LogSeverity.Severe);
                                        MoveFileToErrorFolder(dts, config, fileName);
                                    }
                                }
                            }
                            else
                            {
                                TaskService.WriteTaskLog(this.Task, $"Error: The file '{fileName}' was empty", LogSeverity.Severe);
                                MoveFileToErrorFolder(dts, config, fileName);
                            }
                            MoveFileToErrorFolder(dts, config, fileName);
                        }
                    }
                    else
                    {
                        TaskService.WriteTaskLog(this.Task, $"INFO: There were no files to process.'", LogSeverity.Normal);
                    }
                    i++;
                    profileName = GetTaskParameter($"DataTransfer{i}", "");
                    config      = dts.FindDataTransferConfigurationModel(profileName);
                    fileLoc     = (config != null) ? config.TargetFolder : "";
                }
            }
            return(0);
        }