static void Main(string[] args) { string filePath = "Examples/CSV/Santander.csv"; CSVImporter importer = new CSVImporter(new System.IO.FileInfo(filePath)); List <Transaction> transactions = SantanderCSVParser.Parse(importer).ToList(); Console.WriteLine($"Found {transactions.Count} transactions"); string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string fullPath = Path.Combine(path, "SQLite", "budjit.db"); var builder = new DbContextOptionsBuilder <BudjitContext>().UseSqlite($"DataSource={fullPath}"); BudjitContext context = new BudjitContext(builder.Options); context.Database.Migrate(); ITransactionsRepository repo = new TransactionRepository(context); repo.Create(transactions); List <Transaction> databaseTransactions = repo.GetAll().ToList(); int count = 1; foreach (Transaction trans in databaseTransactions) { Console.WriteLine($"{count} - {trans.Description}"); count++; } Console.ReadLine(); }
public void ShouldParseCSV_ForValidCSV() { var mockImporter = new Mock <IImporter>(); mockImporter.Setup(x => x.Import()).Returns(validCsvData); var importer = mockImporter.Object; SantanderCSVParser parser = new SantanderCSVParser(importer); List <Transaction> result = parser.Parse().ToList(); Assert.AreEqual(1, result.Count); AssertTransactionValues(new DateTime(2017, 10, 18), " CARD PAYMENT TO FAKE COMPANY", " CARD PAYMENT TO FAKE COMPANY", -1.95m, 1337.03m, result.First()); }
public void ShouldParseCSV_ForValidCSVWithMultipleTransactions() { var mockImporter = new Mock <IImporter>(); mockImporter.Setup(x => x.Import()).Returns(validMultipleCsvData); var importer = mockImporter.Object; SantanderCSVParser parser = new SantanderCSVParser(importer); Transaction[] result = parser.Parse().ToArray(); Assert.AreEqual(2, result.Length); AssertTransactionValues(new DateTime(2017, 10, 18), " CARD PAYMENT TO FAKE COMPANY", " CARD PAYMENT TO FAKE COMPANY", -1.95m, 1337.03m, result[0]); AssertTransactionValues(new DateTime(2017, 10, 18), " CARD PAYMENT TO FAKE COMPANY 2", " CARD PAYMENT TO FAKE COMPANY 2", 10.30m, -123.45m, result[1]); }
public async Task <IActionResult> Upload(IFormFile file) { var filePath = Path.GetTempFileName(); if (file.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(stream); } //Default to Santander CSV importing. IImporter importer = new CSVImporter(new FileInfo(filePath)); IImportParser parser = new SantanderCSVParser(importer); IEnumerable <Transaction> data; try { data = parser.Parse(); transactionsRepository.Create(data); return(Ok()); } catch (ParsingException e) { return(StatusCode(500, e.Message)); } catch (Exception e) { return(StatusCode(500, e.Message)); } } else { return(BadRequest("File is empty")); } }