private void Act(StatementModel testData) { var subject = new Mapper_TransactionSetDto_StatementModel( new FakeLogger(), new Mapper_TransactionDto_Transaction( new InMemoryAccountTypeRepository(), new BucketBucketRepoAlwaysFind(), new InMemoryTransactionTypeRepository())); Result = subject.ToDto(testData); }
partial void ToModelPostprocessing(TransactionSetDto dto, ref StatementModel model) { model.LoadTransactions(dto.Transactions.Select(t => this.transactionMapper.ToModel(t))); }
// ReSharper disable once RedundantAssignment partial void ModelFactory(TransactionSetDto dto, ref StatementModel model) { model = new StatementModel(this.logger); }
partial void ToDtoPostprocessing(ref TransactionSetDto dto, StatementModel model) { var transactions10 = model.AllTransactions.Select(this.transactionMapper.ToDto).ToList(); dto.Transactions = transactions10; }
private TransactionSetDto CreateTransactionSet(string fileName, List<string> allLines, List<TransactionDto> transactions) { string header = allLines[0]; if (string.IsNullOrWhiteSpace(header)) { throw new FileFormatException("The Budget Analyser file does not have a valid header row."); } string[] headerSplit = header.Split(','); var transactionSet = new TransactionSetDto { Checksum = this.importUtilities.SafeArrayFetchLong(headerSplit, 3), FileName = fileName, LastImport = this.importUtilities.SafeArrayFetchDate(headerSplit, 4), Transactions = transactions, VersionHash = this.importUtilities.SafeArrayFetchString(headerSplit, 1), }; return transactionSet; }
private void ValidateChecksumIntegrity(TransactionSetDto transactionSet) { long calcTxnCheckSum = CalculateTransactionCheckSum(transactionSet); // Ignore a checksum of 1, this is used as a special case to bypass transaction checksum test. Useful for manual manipulation of the statement csv. if (transactionSet.Checksum > 1 && transactionSet.Checksum != calcTxnCheckSum) { this.logger.LogError( () => this.logger.Format("BudgetAnalyser statement file being loaded has an incorrect checksum of: {0}, transactions calculate to: {1}", transactionSet.Checksum, calcTxnCheckSum)); throw new StatementModelChecksumException( calcTxnCheckSum.ToString(CultureInfo.InvariantCulture), string.Format( CultureInfo.CurrentCulture, "The statement being loaded, does not match the internal checksum. {0} {1}", calcTxnCheckSum, transactionSet.Checksum)); } }
private static void WriteHeader(StreamWriter writer, TransactionSetDto setDto) { writer.WriteLine("VersionHash,{0},TransactionCheckSum,{1},{2}", setDto.VersionHash, setDto.Checksum, setDto.LastImport.ToString("O", CultureInfo.InvariantCulture)); }
private static long CalculateTransactionCheckSum(TransactionSetDto setDto) { long txnCheckSum = 37; // prime unchecked { txnCheckSum *= 397; // also prime foreach (TransactionDto txn in setDto.Transactions) { txnCheckSum += (long)txn.Amount * 100; txnCheckSum *= 829; } } return txnCheckSum; }
partial void ToModelPostprocessing(TransactionSetDto dto, ref StatementModel model) { model.LoadTransactions(dto.Transactions.Select(t => this.transactionMapper.ToModel(t))); }
partial void ToDtoPostprocessing(ref TransactionSetDto dto, StatementModel model) { var transactions10 = model.AllTransactions.Select(this.transactionMapper.ToDto).ToList(); dto.Transactions = transactions10; }
// ReSharper disable once RedundantAssignment partial void ModelFactory(TransactionSetDto dto, ref StatementModel model) { model = new StatementModel(this.logger); }