private void LoadTransactions(DataSource dataSource) { ITransactionFileReader fileReader = new GenericCsvReader(); using (ITransactionManager trManager = new TransactionsManager(new UnitOfWork(), fileReader)) { trManager.Insert(dataSource, GlobalSettings.GetResourceFilePath(resourceFile)); } }
public void AddTheSameTransactionsAgain() { // Arrange const string resourceFile = "Inquiry_statements.csv"; const string clientId = "1"; const int dataSourceId = 5; const string cultureStr = "en-US"; ITransactionFileReader reader = new GenericCsvReader(); if (reader.Read(GlobalSettings.GetResourceFilePath(resourceFile), new CultureInfo(cultureStr)).Count == 0) { Assert.Inconclusive("Zero transactions read from file"); } var moqTrRepo = new Mock <IRepository <Transaction> >(); var transactions = reader.Read(GlobalSettings.GetResourceFilePath(resourceFile), new CultureInfo(cultureStr)); foreach (var tr in transactions) { tr.DataSourceId = dataSourceId; } moqTrRepo.SetupGet(inst => inst.Set).Returns(transactions.AsQueryable()); var moqDsRepo = new Mock <IRepository <DataSource> >(); moqDsRepo.Setup(inst => inst.GetById(It.Is <int>(id => id == dataSourceId))) .Returns(new DataSource { ClientName = clientId, Id = dataSourceId, Culture = cultureStr }); var moqUnitOfWork = new Mock <IUnitOfWork>(); moqUnitOfWork.SetupGet(inst => inst.DataSourceRepository).Returns(moqDsRepo.Object); moqUnitOfWork.SetupGet(inst => inst.TransactionRepository).Returns(moqTrRepo.Object); var transactionManager = new TransactionsManager(moqUnitOfWork.Object, new GenericCsvReader()); // Act var response = transactionManager.Insert(new DataSource { Id = dataSourceId, ClientName = clientId }, GlobalSettings.GetResourceFilePath(resourceFile)); // Assert moqTrRepo.Verify(inst => inst.Set, Times.AtLeastOnce); moqTrRepo.Verify(inst => inst.Insert(It.IsAny <Transaction>()), Times.Never); moqDsRepo.Verify(inst => inst.GetById(It.Is <int>(id => id == dataSourceId)), Times.AtLeastOnce); Assert.IsTrue(response.Status == ActionResponseCode.Success); }
public IList <Transaction> Read(string fileName, Period period, CultureInfo culture) { var returnValue = new List <Transaction>(); var lines = new List <CsvFileLine>(); using (var sr = new StreamReader(fileName)) { using (var reader = new CsvReader(sr)) { HybridDictionary maps = null; while (reader.Read()) { if (maps == null) { maps = CreateColumnMaps(reader, culture); } var fileLine = GenericCsvReader.CreateFileLine(reader, maps); if ((fileLine.Date != string.Empty) && (lines.Count > 0)) { var transaction = GenericCsvReader.GetTransactionFromLines(lines, culture); if (transaction == null) { returnValue = null; break; } returnValue.Add(transaction); lines.Clear(); } lines.Add(fileLine); } } if ((returnValue != null) && (lines.Count > 0)) { var transaction = GenericCsvReader.GetTransactionFromLines(lines, culture); if (transaction == null) { returnValue = null; } returnValue.Add(transaction); } } return(returnValue); }
public void NoCommaAtStartFile() { // Arrange const string resourceFile = "RO75INGB0000999901728780.csv"; var reader = new GenericCsvReader(); //Act var transactions = reader.Read(GlobalSettings.GetResourceFilePath(resourceFile), new CultureInfo("en-US")); //Assert Assert.IsTrue(transactions.Count == 2); var transaction = transactions[1]; Assert.IsTrue(transaction.TransactionDate == new DateTime(2016, 9, 21)); Assert.IsTrue(transaction.TransactionType == TransactionType.Debit); Assert.IsTrue(transaction.Amount == 70.50m); Assert.IsTrue(transaction.TransactionDetails == "POS purchase"); Assert.IsTrue(transaction.OtherDetails.Contains("043740")); }
public void AddAnEmptyTransactionFile() { // Arrange const string resourceFile = "Tranzactii_pe_perioada_empty.csv"; const string clientId = "1"; const int dataSourceId = 5; const string cultureStr = "ro-RO"; ITransactionFileReader reader = new GenericCsvReader(); var transactions = reader.Read(GlobalSettings.GetResourceFilePath(resourceFile), new CultureInfo(cultureStr)); if (transactions.Count != 0) { Assert.Inconclusive("The transaction file is not empty"); } var moqTrRepo = new Mock <IRepository <Transaction> >(); var moqDsRepo = new Mock <IRepository <DataSource> >(); moqDsRepo.Setup(inst => inst.GetById(It.Is <int>(id => id == dataSourceId))) .Returns(new DataSource { ClientName = clientId, Id = dataSourceId, Culture = cultureStr }); var moqUnitOfWork = new Mock <IUnitOfWork>(); moqUnitOfWork.SetupGet(inst => inst.DataSourceRepository).Returns(moqDsRepo.Object); moqUnitOfWork.SetupGet(inst => inst.TransactionRepository).Returns(moqTrRepo.Object); var transactionManager = new TransactionsManager(moqUnitOfWork.Object, new GenericCsvReader()); // Act var response = transactionManager.Insert(new DataSource { Id = dataSourceId, ClientName = clientId }, GlobalSettings.GetResourceFilePath(resourceFile)); // Assert Assert.IsTrue(response.Status == ActionResponseCode.NoActionPerformed); moqTrRepo.Verify(inst => inst.Insert(It.IsAny <Transaction>()), Times.Never); Assert.IsTrue(response.ActionResponseMessage == Resources.ZeroTransactionsInFile); moqDsRepo.Verify(inst => inst.GetById(It.Is <int>(id => id == dataSourceId)), Times.AtLeastOnce); }