public void Can_write_amounts_containing_commas()
        {
            // Arrange
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load();
            var new_bank_record         = new BankRecord();
            var amount_containing_comma = "£1,234.55";

            new_bank_record.Load(string.Format("01/05/2017^{0}^^POS^Purchase^^^^^", amount_containing_comma));
            csv_file.Records.Add(new_bank_record);

            // Act
            csv_file.Write_to_csv_file("testing");

            // Assert
            var file_io_test_file = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only-testing");
            var new_csv_file      = new CSVFile <BankRecord>(file_io_test_file);

            new_csv_file.Load(
                true,
                ',');

            Assert.AreEqual(1234.55, new_csv_file.Records[5].Unreconciled_amount);
            Assert.AreEqual("\"Purchase\"", new_csv_file.Records[5].Description);
        }
        public void M_WhenRemovingRecordPermanentlyItDoesNotComeBackAfterRefreshingFileContents()
        {
            // Arrange
            var mock_file_io    = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var new_description = "Third record";
            var source_records  = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord {
                    Description = "First record"
                },
                new ExpectedIncomeRecord {
                    Description = "Second record"
                }
            };

            mock_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(source_records);
            var file = new CSVFile <ExpectedIncomeRecord>(mock_file_io.Object);

            file.Load();
            Assert.AreEqual(2, file.Records.Count);

            // Act
            file.Add_record_permanently(new ExpectedIncomeRecord {
                Description = new_description
            });
            file.Populate_records_from_original_file_load();

            // Assert
            Assert.AreEqual(3, file.Records.Count);
            Assert.AreEqual(new_description, file.Records[2].Description);
        }
        public void Can_output_all_records_as_csv_ordered_by_matched_and_then_by_date()
        {
            // Arrange
            const bool doNotOrderByDate = false;
            var        file_io          = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var        csv_file         = new CSVFile <BankRecord>(file_io);

            csv_file.Load(
                true,
                null,
                doNotOrderByDate);
            csv_file.Records[0].Matched = true;
            csv_file.Records[1].Matched = true;
            csv_file.Records[3].Matched = true;

            // Act
            List <string> csv_lines = csv_file.All_records_as_csv();

            // Assert
            Assert.AreEqual("01/03/2017,£350.00,x,ABC,\"ZZZThing2\",,,,,", csv_lines[0]);
            Assert.AreEqual("24/03/2017,£200.12,x,PCL,\"ZZZSpecialDescription001\",,,,,", csv_lines[1]);
            Assert.AreEqual("03/04/2017,£350.00,x,ABC,\"ZZZThing1\",,,,,", csv_lines[2]);
            Assert.AreEqual("01/02/2017,£350.00,,ABC,\"ZZZThing3\",,,,,", csv_lines[3]);
            Assert.AreEqual("01/04/2017,£261.40,,PCL,\"ZZZSpecialDescription005\",,,,,", csv_lines[4]);
        }
        public void Can_write_new_contents_to_csv()
        {
            // Arrange
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load();
            var new_bank_record = new BankRecord();
            // Date, unreconciled amount, type and description are mandatory.
            // string csvLine = String.Format("DATE^UNRECONCILED_AMT^^TYPE^DESCRIPTION^^^^^");
            var todays_date = DateTime.Today.ToString("dd/MM/yyyy");

            new_bank_record.Load(String.Format("{0}^£12.34^^POS^Purchase^^^^^", todays_date));
            csv_file.Records.Add(new_bank_record);

            // Act
            csv_file.Write_to_csv_file("testing");

            // Assert
            var file_io_test_file = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only-testing");
            var new_csv_file      = new CSVFile <BankRecord>(file_io_test_file);

            new_csv_file.Load(
                true,
                ',');
            List <string> csv_lines = new_csv_file.All_records_as_csv();

            Assert.AreEqual("01/02/2017,£350.00,,ABC,\"ZZZThing3\",,,,,", csv_lines[0]);
            Assert.AreEqual("01/03/2017,£350.00,,ABC,\"ZZZThing2\",,,,,", csv_lines[1]);
            Assert.AreEqual("24/03/2017,£200.12,,PCL,\"ZZZSpecialDescription001\",,,,,", csv_lines[2]);
            Assert.AreEqual("01/04/2017,£261.40,,PCL,\"ZZZSpecialDescription005\",,,,,", csv_lines[3]);
            Assert.AreEqual("03/04/2017,£350.00,,ABC,\"ZZZThing1\",,,,,", csv_lines[4]);
            Assert.AreEqual(String.Format("{0},£12.34,,POS,\"Purchase\",,,,,", todays_date), csv_lines[5]);
        }
        public void removeErrors(CSVFile csv)
        {
            int len = csv.rowCount;

            int cols = csv.Data.Count();

            if (errorRows.Count > 0)
            {
                for (int j = 0; j < cols; j++)
                {
                    string[]      oldData  = csv.Data[j].Data.ToArray();
                    List <string> newArray = new List <string>();
                    for (int i = 0; i < len; i++)
                    {
                        if (!errorRows.Contains(i))
                        {
                            if (csv.Data[j].Context.Equals("Time series"))
                            {
                                newArray.Add(csv.Data[j].Data[i].ToString());
                            }
                            else
                            {
                                newArray.Add(oldData[i]);
                            }
                        }
                    }
                    csv.Data[j].Data = newArray;
                }
            }
        }
Exemple #6
0
        public void Can_filter_for_employer_expense_records_only()
        {
            // Arrange
            var mock_expected_income_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var expected_income_csv_file     = new CSVFile <ExpectedIncomeRecord>(mock_expected_income_file_io.Object);
            var expected_description         = "description2";
            var expected_income_records      = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord
                {
                    Description = expected_description,
                    Code        = Codes.Expenses
                },
                new ExpectedIncomeRecord
                {
                    Description = "description1",
                    Code        = "other"
                }
            };

            mock_expected_income_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(expected_income_records);
            expected_income_csv_file.Load();
            var expected_income_file = new ExpectedIncomeFile(expected_income_csv_file);

            // Act
            expected_income_file.Filter_for_employer_expenses_only();

            // Assert
            Assert.AreEqual(1, expected_income_csv_file.Records.Count);
            Assert.AreEqual(expected_description, expected_income_csv_file.Records[0].Description);
        }
        public void ErrorEntity_Write_Test()
        {
            //No assertion for this test case, needs enhancements

            var           csvConfig = new CSVConfiguration();
            List <string> columns   = new List <string>();

            columns.Add("Shipment Origin");
            columns.Add("Shipment Destination");
            columns.Add("Pickup Date");
            columns.Add("Description");

            csvConfig.Columns = columns.ToArray();

            using (var csvFile = new CSVFile <ErrorEntity>("Shipment_Error_Output.csv", csvConfig))
            {
                for (int i = 0; i < 10; i++)
                {
                    var errorEntity = new ErrorEntity();
                    errorEntity.Description      = "test error" + i;
                    errorEntity.EntityProperties = new EntityPropertyCollection();
                    errorEntity.EntityProperties.Add(new EntityProperty {
                        PropertyName = "ShipmentOrigin", PropertyType = typeof(string), PropertyValue = "Origin_" + i
                    });
                    errorEntity.EntityProperties.Add(new EntityProperty {
                        PropertyName = "ShipmentDestination", PropertyType = typeof(string), PropertyValue = "Destination_" + i
                    });
                    errorEntity.EntityProperties.Add(new EntityProperty {
                        PropertyName = "PickupDate", PropertyType = typeof(DateTime), PropertyValue = DateTime.Now
                    });

                    csvFile.Append(errorEntity);
                }
            }
        }
Exemple #8
0
        public void testParse(string input, string[] expectedEntries)
        {
            var csvFile = new CSVFile();

            csvFile.ProcessCSVLines(new string[] { input });
            Assert.AreEqual(expectedEntries.ToList(), csvFile.GetRow(0));
        }
Exemple #9
0
        private List <CSVFile> ReadCSVFiles(GenerationOrLoad generationOrLoad, [NotNull] DirectoryInfo di)
        {
            Info("Reading " + di.FullName);
            string filepattern = "*." + generationOrLoad + ".csv";
            var    csvfiles    = di.GetFiles(filepattern);

            if (csvfiles.Length == 0)
            {
                throw new FlaException("No exported files found in: " + di.FullName + " for file pattern " + filepattern);
            }

            var csvs        = new List <CSVFile>();
            var activeFiles = new List <CSVFile>();

            foreach (var info in csvfiles)
            {
                var cs = new CSVFile(generationOrLoad, info.Name);
                csvs.Add(cs);
                cs.MyThread = ThreadProvider.Get().MakeThreadAndStart(() => { cs.Read(info); }, "CSVProfileVisualizer");
                activeFiles.Add(cs);
                WaitForJoining(activeFiles, 8);
            }

            WaitForJoining(activeFiles, 0);
            if (csvs.Count != csvfiles.Length)
            {
                throw new FlaException("Missing files");
            }

            Info("Read " + csvs.Count + " for " + generationOrLoad);
            return(csvs);
        }
        public void SimpleWrite_Test()
        {
            List <Shipment> outputData = new List <Shipment>();
            List <Shipment> inputData  = new List <Shipment>();

            using (var csvFile = new CSVFile <Shipment>("Shipment_Output.csv"))
            {
                for (int i = 0; i < 10; i++)
                {
                    var shipment = new Shipment()
                    {
                        PickupDate = DateTime.Now, ShipmentOrigin = "Origin-" + i, ShipmentDestination = "Destination" + i
                    };
                    outputData.Add(shipment);
                    csvFile.Append(shipment);
                }
            }
            var csvFileReader = new CSVFileReader <Shipment>("Shipment_Output.csv");

            foreach (Shipment shipment in csvFileReader)
            {
                inputData.Add(shipment);
            }

            Assert.AreEqual(outputData.Count, 10);
            Assert.AreEqual(inputData.Count, 10);
        }
        public void Will_create_new_expenses_record_to_match_balance()
        {
            // Arrange
            var income_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var income_records = new List <ExpectedIncomeRecord>();

            income_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(income_records);
            var income_file = new CSVFile <ExpectedIncomeRecord>(income_file_io.Object);

            income_file.Load();
            var expected_income_file = new ExpectedIncomeFile(income_file);
            var actual_bank_record   = new ActualBankRecord
            {
                Date   = DateTime.Today,
                Amount = 50
            };
            double balance = actual_bank_record.Amount - 10;

            // Act
            expected_income_file.Create_new_expenses_record_to_match_balance(actual_bank_record, balance);

            // Assert
            Assert.AreEqual(1, expected_income_file.File.Records.Count);
            Assert.AreEqual(ReconConsts.UnknownExpense, expected_income_file.File.Records[0].Description);
            Assert.AreEqual(balance, expected_income_file.File.Records[0].Unreconciled_amount);
            Assert.AreEqual(actual_bank_record, expected_income_file.File.Records[0].Match);
            Assert.AreEqual(true, expected_income_file.File.Records[0].Matched);
            Assert.AreEqual(actual_bank_record.Date, expected_income_file.File.Records[0].Date);
            Assert.AreEqual(actual_bank_record.Date, expected_income_file.File.Records[0].Date_paid);
            Assert.AreEqual(actual_bank_record.Amount, expected_income_file.File.Records[0].Total_paid);
            Assert.AreEqual(Codes.Expenses, expected_income_file.File.Records[0].Code);
        }
Exemple #12
0
        /// <summary>
        /// Imports data from the specified csv, automatically determining whether the data contains IPv4 or IPv6 addresses by scanning (up to) the first 1000 rows and looking for any IP address number larger than int.MaxValue.
        /// </summary>
        /// <param name="csvPath"></param>
        /// <param name="bw"></param>
        public void ImportData(string csvPath, BackgroundWorker bw)
        {
            bool isIpv6Data = false;

            using (StreamReader sr = new StreamReader(csvPath))
            {
                IEnumerable <string[]> rows = CSVFile.StreamingRead(sr);
                int i = 0;
                foreach (string[] row in rows)
                {
                    // index 0 (ip_from) is always smaller than index 1 (ip_to), so we only need to look at index 1.
                    if (long.Parse(row[1]) > int.MaxValue)
                    {
                        isIpv6Data = true;
                        break;
                    }
                    else if (i++ > 1000)
                    {
                        break;
                    }
                }
            }
            if (isIpv6Data)
            {
                ImportIPv6Data(csvPath, bw);
            }
            else
            {
                ImportIPv4Data(csvPath, bw);
            }
        }
Exemple #13
0
        public static void ExportToExcel()
        {
            var visitedAttrs = new List <string>();
            var csvFile      = new CSVFile()
            {
                FileName = "Formulas.csv"
            };

            foreach (var en in App.MigEntities)
            {
                foreach (var f in en.Formulas)
                {
                    var bloc = new CSVBloc()
                    {
                        EntityName    = f.SourceEntityName,
                        AttributeName = f.SourceEntityName
                    };

                    csvFile.Blocs.Add(bloc);

                    bloc.AddRow(new string[] { f.Name, f.Type.Value + "", f.Type.Name });
                }
            }

            csvFile.Export();
        }
Exemple #14
0
    public void ReadFile(string filePath)
    {
        FileInfo fi = new FileInfo(filePath);

        if (fi.Extension.ToLower() == ".csv")
        {
            IFileReader fileReader = new CSVFile();
            try
            {
                fileReader.OpenFile(filePath);
                ReadConfigFilesAll(fileReader);
            }
            catch (System.Exception e)
            {
                Debug.LogError("CsvLoader.ReadFile():异常" + e.Message);
            }
            fileReader.Close();

            Debug.Log("CsvLoader.ReadFile():读文件结束,当前 有效记录Count =" + Count);
        }
        else
        {
            Debug.Log("CsvLoader.ReadFile():不支持的文件" + fi.FullName);
        }
    }
        public void Will_append_all_rows_in_csv_file_to_specified_worksheet()
        {
            // Arrange
            var sheet_name = TestSheetNames.Bank;
            var file_io    = new FileIO <BankRecord>(new ExcelSpreadsheetRepoFactory(""), _csvFilePath, "BankIn-formatted-date-only");
            var csv_file   = new CSVFile <BankRecord>(file_io);

            csv_file.Load();
            var initial_last_row_number = _excelSpreadsheet.Last_row_number(sheet_name);

            // Act
            _excelSpreadsheet.Append_csv_file <BankRecord>(sheet_name, csv_file);
            var new_last_row   = _excelSpreadsheet.Read_last_row(sheet_name);
            var new_row_number = _excelSpreadsheet.Last_row_number(sheet_name);

            // Clean up
            for (int count = 1; count <= csv_file.Records.Count; count++)
            {
                _excelSpreadsheet.Remove_last_row(sheet_name);
            }

            // Assert
            var last_record_in_ordered_csv_file = csv_file.Records_ordered_for_spreadsheet()[csv_file.Records.Count - 1];

            Assert.AreEqual(last_record_in_ordered_csv_file.Date, DateTime.FromOADate((double)new_last_row.Read_cell(0)));
            Assert.AreEqual(last_record_in_ordered_csv_file.Unreconciled_amount, (Double)new_last_row.Read_cell(1));
            Assert.AreEqual(last_record_in_ordered_csv_file.Type, (String)new_last_row.Read_cell(3));
            Assert.AreEqual(last_record_in_ordered_csv_file.Description, (String)new_last_row.Read_cell(4));
            Assert.AreEqual(null, new_last_row.Read_cell(5));
            Assert.AreEqual(null, new_last_row.Read_cell(6));
            Assert.AreEqual(initial_last_row_number + csv_file.Records.Count, new_row_number);
        }
        public void Will_mark_last_bank_out_row_when_loading_before_records_are_ordered_in_date_order()
        {
            // Arrange
            string last_row_description = "Last row";
            var    fake_records         = new List <ActualBankRecord>
            {
                new ActualBankRecord {
                    Amount = 10, Date = new DateTime(2020, 1, 4), Description = last_row_description
                },
                new ActualBankRecord {
                    Amount = 10, Date = new DateTime(2020, 1, 4), Description = "This will be the last row when ordered in date order."
                },
                new ActualBankRecord {
                    Amount = 10, Date = new DateTime(2020, 1, 2)
                },
            };
            var mock_actual_bank_file_io = new Mock <IFileIO <ActualBankRecord> >();

            mock_actual_bank_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), It.IsAny <char?>()))
            .Returns(fake_records);
            var actual_bank_file    = new CSVFile <ActualBankRecord>(mock_actual_bank_file_io.Object);
            var actual_bank_in_file = new ActualBankInFile(actual_bank_file);

            // Act
            actual_bank_in_file.Load();

            // Assert
            var last_record = actual_bank_in_file.File.Records.First(x => x.Description == last_row_description);

            Assert.AreEqual(ReconConsts.LastOnlineTransaction, last_record.LastTransactionMarker);
        }
Exemple #17
0
        private FileStatus ProcessPinFile_SmartVista(issuer config)
        {
            //branchCode = batchReference.Substring(0, batchReference.IndexOf('_'));

            //read file
            //IndigoFileLoader.objects.root.ACardsFile cardsFile = null;
            var             cardsFile = new CSVFile(fullFileName, false, false);
            List <string[]> records   = cardsFile.ReadFile();

            //note --- check if ref is null

            //parse records, format contents
            for (int i = 0; i < records.Count; i++)
            {
                var    newRecord = new string[3];
                string record    = records[i][0];
                newRecord[0] = record.Substring(0, 4) + record.Substring(5, 4) + record.Substring(10, 4) +
                               record.Substring(15, 4);
                newRecord[1] =
                    IndigoFileLoader.utility.UtilityClass.HandleUnexpectedCharacters(
                        record.Substring(record.IndexOf('^') + 1, record.LastIndexOf('^') - record.IndexOf('^') - 1)
                        .Replace('/', ' '));
                newRecord[2] = record.Substring(record.LastIndexOf('#') + 1, 16);
                records[i]   = newRecord;
            }

            return(FileStatus.READ);
        }
Exemple #18
0
    static private void CreateSkillStats(StatsHolder statsHolder)
    {
        TextAsset csvText = (TextAsset)AssetDatabase.LoadAssetAtPath(DATABASE_FOLDER + "/CSV/database - skill.csv", typeof(TextAsset));
        CSVFile   csvFile = new CSVFile(csvText.text);

        AssetDatabase.CreateFolder(DATABASE_FOLDER + "/Asset", "Skill");

        int csvCount = csvFile.length;

        for (int i = 0; i < csvCount; i++)
        {
            string id = csvFile.Get <string>(i, "ID");

            if (string.IsNullOrEmpty(id))
            {
                continue;
            }

            SkillStats c_prefab = ScriptableObjectUtility.CreateAsset <SkillStats>(DATABASE_FOLDER + "/Asset/Skill/", "[SkillStat] " + id);
            EditorUtility.SetDirty(c_prefab);

            c_prefab.id    = id;
            c_prefab.label = csvFile.Get <string>(i, "Label");

            c_prefab.parameter_1 = csvFile.Get <float>(i, "Parameter 1");
            c_prefab.parameter_2 = csvFile.Get <float>(i, "Parameter 2");
            c_prefab.parameter_3 = csvFile.Get <float>(i, "Parameter 3");
            c_prefab.parameter_4 = csvFile.Get <float>(i, "Parameter 4");

            statsHolder.stpObjectHolder.Add(c_prefab);
        }
    }
        public async Task <IActionResult> Upload(FileUploadVM model)
        {
            if (ModelState.IsValid)
            {
                string filePath = null;
                string fileName = null;
                if (model.CsvFile != null)
                {
                    string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "data");
                    fileName = model.CsvFile.FileName;
                    filePath = Path.Combine(uploadsFolder, model.CsvFile.FileName);
                    using (Stream fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        await model.CsvFile.CopyToAsync(fileStream);
                    }
                }

                CSVFile csvFile = new CSVFile
                {
                    FilePath = filePath,
                    FileName = fileName
                };
                _fileService.Add(csvFile);
                return(RedirectToAction("details", new { Id = csvFile.Id }));
            }
            return(View());
        }
Exemple #20
0
        public void WhenFinishing_WillReconcileAllRecords()
        {
            // Arrange
            var mock_income_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var desc1  = "desc1";
            var desc2  = "desc2";
            var amount = 10;
            var expected_income_records = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord {
                    Matched = false, Unreconciled_amount = amount, Reconciled_amount = 0, Description = desc1
                },
                new ExpectedIncomeRecord {
                    Matched = true, Unreconciled_amount = amount, Reconciled_amount = 0, Description = desc2
                }
            };

            mock_income_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(expected_income_records);
            var csv_file = new CSVFile <ExpectedIncomeRecord>(mock_income_file_io.Object);

            csv_file.Load();
            var expected_income_file = new ExpectedIncomeFile(csv_file);

            // Act
            expected_income_file.Finish();

            // Assert
            Assert.AreEqual(amount, csv_file.Records[0].Unreconciled_amount);
            Assert.AreEqual(0, csv_file.Records[0].Reconciled_amount);
            Assert.AreEqual(desc1, csv_file.Records[0].Description);
            Assert.AreEqual(0, csv_file.Records[1].Unreconciled_amount);
            Assert.AreEqual(amount, csv_file.Records[1].Reconciled_amount);
            Assert.AreEqual(desc2, csv_file.Records[1].Description);
        }
        public void GetRecordsForCSVFile_HandlesMultipleAmountColumns()
        {
            var testCsv = new CSVFile();

            testCsv.Header = "Account Number,Post Date,Check,Description,Debit,Credit,Status,Balance";
            testCsv.Rows   = new List <string>()
            {
                "\"XXXX1234S2345\",1/1/2020,,\"ID: 1234567890 CO: SOMEBODY ACH Trace Number: 12345856433242\",100.00,,Posted,200.00",
                "\"XXXX1234S2345\",1/1/2020,,\"ID: 2345678901 CO: SOMEBODY ELSE ACH Trace Number: 12456789765345\",,200.00,Posted,400.00"
            };

            var testColumnOptions = new CSVFileColumnOptions()
            {
                DateColumn        = "Post Date",
                AmountColumns     = new Dictionary <string, bool>(),
                CategoryColumn    = "Description",
                DescriptionColumn = "Description",
            };

            testColumnOptions.AmountColumns.Add("Credit", false);
            testColumnOptions.AmountColumns.Add("Debit", true);

            var result = SUT.GetRecordsForCSVFile(testCsv, testColumnOptions, 13);

            Assert.Equal(2, result.Count);
            Assert.Contains(result, x => x.Amount == -100);
            Assert.Contains(result, x => x.Amount == 200);
        }
Exemple #22
0
        public void Will_copy_all_records_to_pending_file()
        {
            // Arrange
            var mock_expected_income_file = new Mock <ICSVFile <ExpectedIncomeRecord> >();
            var expected_income_records   = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord
                {
                    Description = "description1"
                },
                new ExpectedIncomeRecord
                {
                    Description = "description2"
                }
            };

            mock_expected_income_file.Setup(x => x.Records).Returns(expected_income_records);
            var expected_income_file = new ExpectedIncomeFile(mock_expected_income_file.Object);
            var mock_pending_file_io = new Mock <IFileIO <BankRecord> >();

            mock_pending_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(new List <BankRecord>());
            var pending_file = new CSVFile <BankRecord>(mock_pending_file_io.Object);

            pending_file.Load();
            Assert.AreEqual(0, pending_file.Records.Count);

            // Act
            expected_income_file.Copy_to_pending_file(pending_file);

            // Assert
            Assert.AreEqual(2, pending_file.Records.Count);
            Assert.AreEqual(expected_income_file.File.Records[0].Description, pending_file.Records[0].Description);
            Assert.AreEqual(expected_income_file.File.Records[1].Description, pending_file.Records[1].Description);
        }
Exemple #23
0
        public void WhenLoadingPendingData_WillConvertSourceLineSeparatorsAfterLoading()
        {
            // Arrange
            var mock_input_output    = new Mock <IInputOutput>();
            var reconciliate         = new FileLoader(mock_input_output.Object);
            var mock_pending_file_io = new Mock <IFileIO <BankRecord> >();
            var pending_file         = new CSVFile <BankRecord>(mock_pending_file_io.Object);

            mock_pending_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null))
            .Returns(new List <BankRecord> {
                new BankRecord()
            });
            var  loading_info     = new BankAndBankOutLoader().Loading_info();
            bool exception_thrown = false;

            // Act
            try
            {
                reconciliate.Load_pending_data <ActualBankRecord, BankRecord>(
                    mock_pending_file_io.Object,
                    pending_file,
                    loading_info);
            }
            catch (NullReferenceException)
            {
                exception_thrown = true;
            }

            // Assert
            Assert.IsFalse(exception_thrown);
        }
        public void Will_order_records_for_spreadsheet_by_matched_and_then_by_date_with_divider_between()
        {
            // Arrange
            const bool doNotOrderByDate = false;
            var        file_io          = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var        csv_file         = new CSVFile <BankRecord>(file_io);

            csv_file.Load(
                true,
                null,
                doNotOrderByDate);
            csv_file.Records[0].Matched = true;
            csv_file.Records[1].Matched = true;
            csv_file.Records[3].Matched = true;

            // Act
            var records = csv_file.Records_ordered_for_spreadsheet();

            // Assert
            Assert.AreEqual("ZZZThing2", records[0].Description);
            Assert.AreEqual("ZZZSpecialDescription001", records[1].Description);
            Assert.AreEqual("ZZZThing1", records[2].Description);
            Assert.AreEqual(true, records[3].Divider);
            Assert.AreEqual("ZZZThing3", records[4].Description);
            Assert.AreEqual("ZZZSpecialDescription005", records[5].Description);
        }
Exemple #25
0
        protected void PersistEntities <T, U>(Connection connection, Guid projectId, CSVFile file, string dtype = "")
            where T : BaseEntity
            where U : BaseDto
        {
            if (file == null)
            {
                return;
            }

            List <T> entities = new List <T>();
            CSVRow   header   = file.GetHeader();

            foreach (CSVRow row in file.GetValues())
            {
                CSVValue dtypeValue = file.GetValueToColumn(row, "DTYPE");
                if (dtypeValue != null && !string.IsNullOrEmpty(dtype))
                {
                    if (!dtype.Equals(dtypeValue.GetValue()))
                    {
                        continue;
                    }
                }
                entities.Add(CreateEntity <T, U>(file, row, projectId));
            }
            GenericRepository genericRepository = new GenericRepository(connection);

            genericRepository.PersistAsNews <T>(entities);
        }
        public void Can_write_descriptions_containing_commas()
        {
            // Arrange
            var file_io  = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only");
            var csv_file = new CSVFile <BankRecord>(file_io);

            csv_file.Load();
            var new_bank_record = new BankRecord();
            var description_containing_comma = "something, something, something else";

            // Date, unreconciled amount, type and description are mandatory.
            // string csvLine = String.Format("DATE^UNRECONCILED_AMT^^TYPE^DESCRIPTION^^^^^");
            new_bank_record.Load(string.Format("01/05/2017^12.34^^POS^{0}^^^^^", description_containing_comma));
            csv_file.Records.Add(new_bank_record);

            // Act
            csv_file.Write_to_csv_file("testing");

            // Assert
            var file_io_test_file = new FileIO <BankRecord>(new FakeSpreadsheetRepoFactory(), _csv_file_path, "BankIn-formatted-date-only-testing");
            var new_csv_file      = new CSVFile <BankRecord>(file_io_test_file);

            new_csv_file.Load(
                true,
                ',');

            Assert.AreEqual("01/05/2017,£12.34,,POS,\"something, something, something else\",,,,,", new_csv_file.Records[5].Source_line);
        }
Exemple #27
0
        /// <summary>
        /// сохранение результатов расчетов в файл
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonSaveAs_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog();

            sf.InitialDirectory = Vars.Options.LastDirectory;
            sf.Filter           = "Файл MS Excel *.xlsx | *.xlsx";
            sf.Filter          += "|Файл *.csv | *.csv";
            sf.AddExtension     = true;
            sf.FileName         = "Расчёт ВЭК для " + range.Name;
            sf.AddExtension     = true;
            if (sf.ShowDialog(this) == DialogResult.OK)
            {
                Vars.Options.LastDirectory = Path.GetDirectoryName(sf.FileName);
                FileProvider provider;
                switch (Path.GetExtension(sf.FileName))
                {
                case ".csv":
                    provider = new CSVFile();
                    break;

                case ".xlsx":
                    provider = new ExcelFile();
                    break;

                default: throw new Exception("Этот тип файла не реализован");
                }
                provider.SaveEnergyInfo(sf.FileName, range);

                _ = Process.Start(sf.FileName);
            }
        }
        public void M_WillCopyRecordsToAnotherFile()
        {
            // Arrange
            var mock_source_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var source_records      = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord {
                    Description = "First record"
                },
                new ExpectedIncomeRecord {
                    Description = "Second record"
                }
            };

            mock_source_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(source_records);
            var source_file = new CSVFile <ExpectedIncomeRecord>(mock_source_file_io.Object);

            source_file.Load();
            var mock_target_file_io = new Mock <IFileIO <ExpectedIncomeRecord> >();

            mock_target_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(new List <ExpectedIncomeRecord>());
            var target_file = new CSVFile <ExpectedIncomeRecord>(mock_target_file_io.Object);

            target_file.Load();
            Assert.AreEqual(0, target_file.Records.Count);

            // Act
            source_file.Copy_records_to_csv_file(target_file);

            // Assert
            Assert.AreEqual(source_file.Records.Count, target_file.Records.Count);
            Assert.AreEqual(source_file.Records[0].Description, target_file.Records[0].Description);
            Assert.AreEqual(source_file.Records[1].Description, target_file.Records[1].Description);
        }
        protected virtual bool SelectFileCompleted()
        {
            if (string.IsNullOrEmpty(this.Filename.Value))
            {
                SheerResponse.Alert(EcmTexts.Localize("Select a file to attach.", new object[0]), new string[0]);
                return(false);
            }
            string filename = FileUtil.MapPath("/temp/" + FileUtil.GetFileName(this.Filename.Value));

            if (!FileUtil.FileExists(filename))
            {
                SheerResponse.Alert(EcmTexts.Localize("The '{0}' file does not exist.", new object[] { filename }), new string[0]);
                return(false);
            }
            if (!filename.Equals(this.LastFile))
            {
                using (CSVFile file = new CSVFile(filename))
                {
                    List <string> list = file.ReadLine();
                    this.FieldList = list;
                    this.LastFile  = filename;
                    this.InitializeFields();
                }
            }
            return(true);
        }
        public void M_WhenAddingRecordPermanentlyItIsStillThereAfterRefreshingFileContents()
        {
            // Arrange
            var mock_file_io     = new Mock <IFileIO <ExpectedIncomeRecord> >();
            var lost_description = "First record";
            var source_records   = new List <ExpectedIncomeRecord>
            {
                new ExpectedIncomeRecord {
                    Description = lost_description
                },
                new ExpectedIncomeRecord {
                    Description = "Second record"
                }
            };

            mock_file_io.Setup(x => x.Load(It.IsAny <List <string> >(), null)).Returns(source_records);
            var file = new CSVFile <ExpectedIncomeRecord>(mock_file_io.Object);

            file.Load();
            Assert.AreEqual(2, file.Records.Count);

            // Act
            file.Remove_record_permanently(source_records[0]);
            file.Populate_records_from_original_file_load();

            // Assert
            Assert.AreEqual(1, file.Records.Count);
            Assert.IsFalse(file.Records.Any(x => x.Description == lost_description));
        }
Exemple #31
0
    public static void Main()
    {
        modshogun.init_shogun_with_defaults();
        double width = 1.2;

        double[,] traindata_real = Load.load_numbers("../data/fm_train_real.dat");
        double[,] testdata_real = Load.load_numbers("../data/fm_test_real.dat");

        RealFeatures feats_train = new RealFeatures(traindata_real);
        RealFeatures feats_test = new RealFeatures(testdata_real);

        GaussianKernel kernel = new GaussianKernel(feats_train, feats_test, width);
        double[,] km_train = kernel.get_kernel_matrix();
        CSVFile f=new CSVFile("gaussian_train.ascii",'w');
        kernel.save(f);

        kernel.init(feats_train, feats_test);
        double[,] km_test = kernel.get_kernel_matrix();
        CSVFile f_test=new CSVFile("gaussian_train.ascii",'w');
        kernel.save(f_test);

        //  Parse and Display km_train
        Console.Write("km_train:\n");
        int numRows = km_train.GetLength(0);
        int numCols = km_train.GetLength(1);

        for(int i = 0; i < numRows; i++){
            for(int j = 0; j < numCols; j++){
                Console.Write(km_train[i,j] +" ");
            }
            Console.Write("\n");
        }

        //  Parse and Display km_test
        Console.Write("\nkm_test:\n");
        numRows = km_test.GetLength(0);
        numCols = km_test.GetLength(1);

        for(int i = 0; i < numRows; i++){
            for(int j = 0; j < numCols; j++){
                Console.Write(km_test[i,j] +" ");
            }
            Console.Write("\n");
        }

        modshogun.exit_shogun();
    }