示例#1
0
        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);
        }
示例#2
0
        private static long CalculateTransactionCheckSum(TransactionSetDto setDto)
        {
            long txnCheckSum = 37; // prime

            unchecked
            {
                txnCheckSum *= 397; // also prime
                foreach (var txn in setDto.Transactions)
                {
                    txnCheckSum += (long)txn.Amount * 100;
                    txnCheckSum *= 829;
                }
            }

            return(txnCheckSum);
        }
示例#3
0
        private void ValidateChecksumIntegrity(TransactionSetDto transactionSet)
        {
            var 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(l =>
                                     l.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));
            }
        }
示例#4
0
        private TransactionSetDto CreateTransactionSet(string fileName, List <string> allLines, List <TransactionDto> transactions)
        {
            var header = allLines[0];

            if (string.IsNullOrWhiteSpace(header))
            {
                throw new DataFormatException("The Budget Analyser file does not have a valid header row.");
            }

            string[] headerSplit    = header.Split(',');
            var      transactionSet = new TransactionSetDto
            {
                Checksum     = this.importUtilities.FetchLong(headerSplit, 3),
                StorageKey   = fileName,
                LastImport   = this.importUtilities.FetchDate(headerSplit, 4),
                Transactions = transactions,
                VersionHash  = this.importUtilities.FetchString(headerSplit, 1)
            };

            return(transactionSet);
        }
示例#5
0
 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));
 }