Exemplo n.º 1
0
        public void CreatingChecksumDigits()
        {
            var accountIdAnalyzer = new AccountAnalyzer();
            var bankId            = ConfigurationManager.AppSettings["BankId"];
            var accountId         = bankId + "0000000000000012";
            var checksum          = accountIdAnalyzer.AppendChecksumDigits(accountId).Substring(0, 2);

            Assert.AreEqual("26", checksum);
        }
        /// <summary>
        /// Generates new account id
        /// </summary>
        /// <param name="container"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public object GenerateId(object container, object document)
        {
            var currentAccountIdConfigKeyValue = DAL.Instance.Configurations.First(config => config.Key == "CurrentAccountId");
            var currentAccountIdAsLong         = long.Parse(currentAccountIdConfigKeyValue.Value);

            currentAccountIdAsLong++;
            var currentAccountIdAsString = currentAccountIdAsLong.ToString();

            while (currentAccountIdAsString.Length < 16)
            {
                currentAccountIdAsString = "0" + currentAccountIdAsString;
            }

            currentAccountIdConfigKeyValue.Value = currentAccountIdAsString;

            DAL.Instance.Configurations.Update(currentAccountIdConfigKeyValue);

            var accountIdWithBankId = ConfigurationManager.AppSettings["BankId"] + currentAccountIdAsString;
            var accountIdAnalyzer   = new AccountAnalyzer();
            var fullAccountId       = accountIdAnalyzer.AppendChecksumDigits(accountIdWithBankId);

            return(fullAccountId);
        }