public void GetHeadingListTest()
        {
            var fiService = new FileImportService.FileImportService(db);
            var headings  = fiService.GetHeadingList("Sale.dat");

            int expected = 10,
                actual   = headings.Count();

            Assert.IsTrue(actual > expected, $"Error: {actual} item(s) were returned when more than {actual} were expected");
        }
Beispiel #2
0
        public void ImportOrdersTest()
        {
            var testUser = GetTestUser();
            //var testCompany = GetTestCompany(testUser, true);
            var testCompany = GetTestCompanyAU();

            List <string> headings = new List <string>();

            headings.Add("ProductCode");
            headings.Add("UnitPrice");
            headings.Add("Quantity");
            headings.Add("SupplierName");

            // Create a temporary file of test data
            string tempFile = Path.GetTempFileName();

            var productList = db.FindProducts()
                              .Where(p => p.PrimarySupplierId != null)
                              .ToList();

            using (var sw = new StreamWriter(tempFile)) {
                // Write a random number of products
                string temp = "";
                for (int i = 0; i < headings.Count(); i++)
                {
                    if (!string.IsNullOrEmpty(temp))
                    {
                        temp += ",";
                    }
                    temp += headings[i];
                }
                sw.WriteLine(temp);

                for (int i = 0; i < 25; i++)
                {
                    int rnd     = RandomInt(0, productList.Count() - 1);
                    var product = productList[rnd];

                    string line = "\"" + product.ItemNumber + "\",";
                    line += RandomInt(1, 25).ToString() + ",";
                    line += rnd.ToString() + ",\"";
                    line += product.Supplier.Name + "\"";
                    sw.WriteLine(line);

                    productList.RemoveAt(rnd);      // So we don't get the same product again
                }
            }

            // Now import the file into the database
            FileImportService.FileImportService fis = new FileImportService.FileImportService(db);

            var error = fis.UploadFile(testCompany, testUser, tempFile, true);

            Assert.IsTrue(!error.IsError, error.Message);

            // Validate the items
            error = PurchasingService.ValidateOrders(testCompany, testUser, headings);
            Assert.IsTrue(!error.IsError, error.Message);

            // Now create orders
            error = PurchasingService.ImportOrders(testCompany, testUser, testCompany.DefaultLocationID.Value, headings);
            Assert.IsTrue(!error.IsError, error.Message);
        }
Beispiel #3
0
        public void ImportSalesTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompanyAU();

            // Use the file import service to load the file into staging tables
            FileImportService.FileImportService fiService = new FileImportService.FileImportService(db);

            string testFile = GetAppSetting("SourceFolder", "") + @"\Evolution.Tests\Evolution.SalesServiceTests\TestData\Sales.csv";
            string fileName = MediaServices.GetTempFolder() + "Sales.csv";
            var    error    = MediaService.MediaService.CopyOrMoveFile(testFile, fileName, FileCopyType.Copy);

            Assert.IsTrue(!error.IsError, error.Message);

            error = fiService.UploadFile(testCompany, testUser, fileName, true);
            Assert.IsTrue(!error.IsError, error.Message);

            // Get the column headings from the first line of the file
            bool   bFirst    = true;
            int    lineCount = 0;
            string firstLine = "";

            using (var sr = new StreamReader(testFile)) {
                string lineText;
                while ((lineText = sr.ReadLine()) != null)
                {
                    if (bFirst)
                    {
                        firstLine = lineText.Replace("\t", ",");
                        bFirst    = false;
                    }
                    else
                    {
                        lineCount++;
                    }
                }
            }
            var headings = firstLine.Split(',')
                           .ToList();

            // Get the data mapping model
            var data     = fiService.GetData(testCompany, testUser);
            int expected = lineCount,
                actual   = data.Lines.Count();

            Assert.IsTrue(expected == actual, $"Error: {actual} line(s) were found when {expected} were expected");

            // Validate the sales records
            error = SalesService.ValidateOrders(testCompany, testUser, headings, "dd/MM/yyyy");
            Assert.IsTrue(!error.IsError, error.Message);

            // Now import the sales
            var soStatus = LookupService.FindSalesOrderHeaderStatusListItemModel()
                           .FirstOrDefault();
            var source = LookupService.FindLOVItemsListItemModel(testCompany, LOVName.OrderSource)
                         .FirstOrDefault();

            error = SalesService.ImportSales(testCompany,
                                             testUser,
                                             Convert.ToInt32(soStatus.Id),
                                             Convert.ToInt32(source.Id),
                                             headings,
                                             testUser.DateFormat,
                                             0);
            Assert.IsTrue(!error.IsError, error.Message);
        }