예제 #1
0
        public void BankAccountService_Tests()
        {
            IEnumerable <BankAccount> accs = CustomMapper <BankAccountDTO, BankAccount> .Map(_bankAccounts);

            IRepository <BankAccount> repository = new BankAccountMemoryRepository();

            foreach (var item in accs)
            {
                repository.Create(item);
            }
            IUnitOfWork         unitOfWork = new UnitOfWork(repository);
            IBankAccountService service    = new BankAccountService(unitOfWork);

            BankAccountDTO bankAccount = service.Get(8);

            service.Deposit(bankAccount.Id, 200m);

            Assert.AreEqual(8, bankAccount.Id);
            bankAccount = service.Get(8);
            Assert.AreEqual(700.50m, bankAccount.Balance);
            Assert.AreEqual(20, bankAccount.BonusPoints);

            service.Withdraw(8, 500.50m);
            bankAccount = service.Get(8);
            Assert.AreEqual(200m, bankAccount.Balance);
        }
예제 #2
0
        public bool ObjectExists(BankAccountDTO bankAccount)
        {
            var objectExists = false;
            var iDbContext   = DbContextUtil.GetDbContextInstance();

            try
            {
                var catRepository = new Repository <BankAccountDTO>(iDbContext);
                var catExists     = catRepository
                                    .Query()
                                    .Filter(bp => bp.BankName == bankAccount.BankName && bp.AccountNumber == bankAccount.AccountNumber && bp.Id != bankAccount.Id)
                                    .Get()
                                    .FirstOrDefault();
                if (catExists != null)
                {
                    objectExists = true;
                }
            }
            finally
            {
                iDbContext.Dispose();
            }

            return(objectExists);
        }
        /// <summary>
        /// gets a bank account from a file
        /// </summary>
        /// <param name="iban">IBAN to find</param>
        /// <returns>account with specified <paramref name="iban"/></returns>
        public BankAccountDTO GetByIban(string iban)
        {
            BankAccountDTO account;

            var stream = new FileStream(path, FileMode.Open);

            using (var reader = new BinaryReader(stream))
            {
                while (reader.ReadString() != iban)
                {
                    reader.ReadString();
                    reader.ReadDecimal();
                    reader.ReadSingle();
                    reader.ReadString();
                }

                var owner   = reader.ReadString();
                var balance = reader.ReadDecimal();
                var bonus   = reader.ReadSingle();
                var type    = reader.ReadString();
                account = new BankAccountDTO(
                    iban,
                    new AccountOwnerDTO(owner, owner, owner),
                    balance,
                    bonus,
                    (BankAccountDTO.AccountType)Enum.Parse(typeof(BankAccountDTO.AccountType), type));
            }

            return(account);
        }
예제 #4
0
 public TransactionView(int bankAccountId, IBankAccountFunctions bankAccountFunctions)
 {
     InitializeComponent();
     _bankAccountId        = bankAccountId;
     _bankAccountFunctions = bankAccountFunctions;
     _details = _bankAccountFunctions.ViewAccountDetails(_bankAccountId);
 }
예제 #5
0
        public void AccountTest_ThreeAccounts_ToWithdrayMoneyFromAccount_Moq(int id, string name, string surname, decimal amount, int bonus, AccountTypeDTO accountType)
        {
            // Arrange
            Mock <IBonus> mockWithraw       = new Mock <IBonus>();
            Mock <IBonus> mockReplenishment = new Mock <IBonus>();

            // Act
            mockWithraw.Setup(m => m.GetBonusPoints(It.IsAny <BankAccountDTO>(), It.IsAny <decimal>()))
            .Returns <BankAccountDTO, decimal>((account, balance) => account.BonusPointToWithdraw);

            mockReplenishment.Setup(m => m.GetBonusPoints(It.IsAny <BankAccountDTO>(), It.IsAny <decimal>()))
            .Returns <BankAccountDTO, decimal>((account, balance) => account.BonusPointToReplenishment);

            IBankAccountFactory bankAccount = new BankAccountFactory()
            {
                Withdraw      = mockWithraw.Object,
                Replenishment = mockReplenishment.Object
            };

            BankAccountDTO accountDTO = bankAccount.GetAccount(id, name, surname, amount, bonus, accountType);

            accountDTO.ReplenishmentMoney(100500);
            accountDTO.WithdrawMoney(100500);

            // Assert
            Assert.AreEqual(0, accountDTO.Amount);
        }
예제 #6
0
        public void Test_Idempotency()
        {
            string key = DateTime.Now.Ticks.ToString();

            PayOutBankWireDTO payOut = null;

            // create bankwire
            try
            {
                WalletDTO      wallet  = this.GetJohnsWallet();
                UserNaturalDTO user    = this.GetJohn();
                BankAccountDTO account = this.GetJohnsAccount();

                PayOutBankWirePostDTO payOutPost = new PayOutBankWirePostDTO(user.Id, wallet.Id, new Money {
                    Amount = 10, Currency = CurrencyIso.EUR
                }, new Money {
                    Amount = 5, Currency = CurrencyIso.EUR
                }, account.Id, "Johns bank wire ref");
                payOutPost.Tag            = "DefaultTag";
                payOutPost.CreditedUserId = user.Id;

                payOut = this.Api.PayOuts.CreateBankWire(key, payOutPost);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            Assert.IsNotNull(payOut);


            // test existing key
            IdempotencyResponseDTO result = null;

            try
            {
                result = this.Api.Idempotency.Get(key);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }

            Assert.IsNotNull(result);


            // test not existing key
            result = null;
            try
            {
                result = this.Api.Idempotency.Get(key + "_no");

                // expect a response error
                Assert.Fail();
            }
            catch (Exception ex)
            {
                /* catch block intentionally left empty */
            }
        }
예제 #7
0
 public void Delete(BankAccountDTO account)
 {
     if (!storage.Remove(account))
     {
         throw new ApplicationException($"account with IBAN {account.IBAN} was not removed");
     }
 }
예제 #8
0
        public async Task Test_Idempotency_PayoutsBankwireCreate()
        {
            string    key    = DateTime.Now.Ticks.ToString();
            WalletDTO wallet = await this.GetJohnsWallet();

            UserNaturalDTO user = await this.GetJohn();

            BankAccountDTO account = await this.GetJohnsAccount();

            PayOutBankWirePostDTO payOut = new PayOutBankWirePostDTO(user.Id, wallet.Id,
                                                                     new Money {
                Amount = 10, Currency = CurrencyIso.EUR
            }, new Money {
                Amount = 5, Currency = CurrencyIso.EUR
            },
                                                                     account.Id, "Johns bank wire ref");

            payOut.Tag            = "DefaultTag";
            payOut.CreditedUserId = user.Id;
            await Api.PayOuts.CreateBankWire(key, payOut);

            var result = await Api.Idempotency.Get(key);

            Assert.IsInstanceOf <PayOutBankWireDTO>(result.Resource);
        }
예제 #9
0
        public void AddBankAccountThrowInvalidOperationExceptionWhenCustomerNotExist()
        {
            //Arrange
            var bankAccountRepository = new Mock <IBankAccountRepository>();
            var customerRepository    = new Mock <ICustomerRepository>();

            customerRepository
            .Setup(x => x.Get(It.IsAny <Guid>()))
            .Returns((Guid guid) => null);

            IBankTransferService transferService = new BankTransferService();

            var dto = new BankAccountDTO()
            {
                CustomerId = Guid.NewGuid()
            };

            Mock <ILogger <BankAppService> > _mockLogger = new Mock <ILogger <BankAppService> >();

            IBankAppService bankingService = new BankAppService(bankAccountRepository.Object, customerRepository.Object, transferService, _mockLogger.Object);

            Exception ex = Assert.Throws <InvalidOperationException>(() =>
            {
                //Act
                bankingService.AddBankAccount(dto);
            }
                                                                     );

            Assert.IsType(typeof(InvalidOperationException), ex);
        }
예제 #10
0
        public BankAccountDTO UpdateBankAccount(BankAccountDTO bankAccountDTO)
        {
            if (bankAccountDTO == null || bankAccountDTO.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(_resources.GetStringResource(LocalizationKeys.Application.warning_CannotAddNullBankAccountOrInvalidCustomer));
            }

            //check if exists the customer for this bank account
            var associatedBankAccount = _bankAccountRepository.Get(bankAccountDTO.Id);
            var associatedCustomer    = _customerRepository.Get(bankAccountDTO.CustomerId);

            if (associatedBankAccount != null) // if the customer exist
            {
                associatedCustomer.FirstName = bankAccountDTO.CustomerFirstName;
                associatedCustomer.LastName  = bankAccountDTO.CustomerLastName;
                //save bank account
                SaveBankAccount(associatedBankAccount, associatedCustomer);

                return(associatedBankAccount.ProjectedAs <BankAccountDTO>());
            }
            else //the customer for this bank account not exist, cannot create a new bank account
            {
                throw new InvalidOperationException(_resources.GetStringResource(LocalizationKeys.Application.warning_CannotCreateBankAccountForNonExistingCustomer));
            }
        }
        public void Test_Users_CreateBankAccount_US()
        {
            try
            {
                UserNaturalDTO       john    = TestHelper.GetJohn();
                BankAccountUsPostDTO account = new BankAccountUsPostDTO(john.FirstName + " " + john.LastName, john.Address, "234234234234", "234334789");

                BankAccountDTO createAccount = _objectToTest.CreateBankAccountUs(john.Id, account).Result;

                Assert.True(createAccount.Id.Length > 0);
                Assert.True(createAccount.UserId == (john.Id));
                Assert.True(createAccount.Type == BankAccountType.US);
                Assert.True(((BankAccountUsDTO)createAccount).AccountNumber == "234234234234");
                Assert.True(((BankAccountUsDTO)createAccount).ABA == "234334789");
                Assert.True(((BankAccountUsDTO)createAccount).DepositAccountType == DepositAccountType.CHECKING);

                account.DepositAccountType = DepositAccountType.SAVINGS;
                BankAccountDTO createAccountSavings = _objectToTest.CreateBankAccountUs(john.Id, account).Result;

                Assert.True(createAccountSavings.Id.Length > 0);
                Assert.True(createAccountSavings.UserId == (john.Id));
                Assert.True(createAccountSavings.Type == BankAccountType.US);
                Assert.True(((BankAccountUsDTO)createAccountSavings).AccountNumber == "234234234234");
                Assert.True(((BankAccountUsDTO)createAccountSavings).ABA == "234334789");
                Assert.True(((BankAccountUsDTO)createAccountSavings).DepositAccountType == DepositAccountType.SAVINGS);
            }
            catch (Exception ex)
            {
                Assert.True(false, ex.Message);
            }
        }
        public void Test_Users_UpdateBankAccount()
        {
            try
            {
                UserNaturalDTO     john    = TestHelper.GetJohn();
                BankAccountIbanDTO account = TestHelper.GetJohnsAccount();

                Assert.True(account.Id.Length > 0);
                Assert.True(account.UserId == (john.Id));
                Assert.True(account.Active);

                // disactivate bank account
                DisactivateBankAccountPutDTO disactivateBankAccount = new DisactivateBankAccountPutDTO();
                disactivateBankAccount.Active = false;

                BankAccountDTO result = _objectToTest.UpdateBankAccount(john.Id, disactivateBankAccount, account.Id).Result;

                Assert.NotNull(result);
                Assert.True(account.Id == result.Id);
                Assert.False(result.Active);
            }
            catch (Exception ex)
            {
                Assert.True(false, ex.Message);
            }
        }
예제 #13
0
        public void WithdrawAccount(BankAccount account, decimal withdraw)
        {
            account.Withdraw(withdraw);
            BankAccountDTO accToUpdate = AccountMapper.AccountToDTO(account);

            _repository.UpdateAccount(accToUpdate);
        }
예제 #14
0
        private IEnumerable <BankAccountDTO> LoadStorage()
        {
            var result = new List <BankAccountDTO>();

            using (var currentFileStream = new FileStream(_storagePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read))
            {
                using (var currentBinaryReader = new BinaryReader(currentFileStream))
                {
                    while (currentBinaryReader.BaseStream.Position != currentBinaryReader.BaseStream.Length)
                    {
                        var accountId      = currentBinaryReader.ReadInt32();
                        var ammount        = currentBinaryReader.ReadDecimal();
                        var bonus          = currentBinaryReader.ReadInt32();
                        var isClosed       = currentBinaryReader.ReadBoolean();
                        var ownerFirstName = currentBinaryReader.ReadString();
                        var ownerLastName  = currentBinaryReader.ReadString();
                        BankAccountTypesDTO bankAccountType = (BankAccountTypesDTO)currentBinaryReader.ReadInt32();
                        var bonusRate         = currentBinaryReader.ReadInt32();
                        var loadedBankAccount = new BankAccountDTO(accountId, ownerFirstName, ownerLastName, ammount, bonus, isClosed, bankAccountType, bonusRate);
                        result.Add(loadedBankAccount);
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// removes a bank account from a file
        /// </summary>
        /// <param name="iban">IBAN of an account to remove</param>
        /// <returns>account balance</returns>
        public void Delete(BankAccountDTO account)
        {
            var stream = new FileStream(path, FileMode.Open);

            using (var reader = new BinaryReader(stream))
            {
                while (reader.ReadString() != account.IBAN)
                {
                    reader.ReadString();
                    reader.ReadDecimal();
                    reader.ReadSingle();
                    reader.ReadString();
                }

                var owner   = reader.ReadString();
                var balance = reader.ReadDecimal();
                reader.ReadSingle();
                var type = reader.ReadString();

                var    offset = (account.IBAN.Length + 1) + (owner.Length + 1) + sizeof(decimal) + sizeof(float) + (type.Length + 1);
                byte[] array  = new byte[stream.Length - stream.Position];
                stream.Read(array, 0, array.Length);

                using (var writer = new BinaryWriter(reader.BaseStream))
                {
                    writer.Seek(-(array.Length + offset), SeekOrigin.Current);
                    writer.Write(array);
                    stream.SetLength(stream.Position);
                }
            }
        }
예제 #16
0
        static void Main(string[] args)
        {
            IKernel             kernel      = new StandardKernel(new NinjectServiceModule("xml"));
            IBankAccountService bankService = kernel.Get <IBankAccountService>();
            BankAccountDTO      acc1        = new BankAccountDTO
            {
                FirstName   = "Test",
                SecondName  = "Name",
                Balance     = 3000.50m,
                BonusPoints = 25,
                Type        = AccountTypeDTO.Gold,
                IsOpened    = true
            };
            BankAccountDTO acc2 = new BankAccountDTO
            {
                FirstName   = "James",
                SecondName  = "Doe",
                Balance     = 13040.50m,
                BonusPoints = 60,
                Type        = AccountTypeDTO.Platinum,
                IsOpened    = true
            };
            BankAccountDTO acc3 = new BankAccountDTO
            {
                FirstName   = "Steve",
                SecondName  = "McQueen",
                Balance     = 500.50m,
                BonusPoints = 10,
                Type        = AccountTypeDTO.Base,
                IsOpened    = true
            };
            BankAccountDTO acc4 = new BankAccountDTO
            {
                FirstName   = "Alice",
                SecondName  = "Cooper",
                Balance     = 500.50m,
                BonusPoints = 10,
                Type        = AccountTypeDTO.Base,
                IsOpened    = false
            };

            //bankService.CreateNew(acc1);
            //bankService.CreateNew(acc2);
            //bankService.CreateNew(acc3);
            //bankService.CreateNew(acc4);

            List <BankAccountDTO> bankAccounts = bankService.GetAll().ToList();

            bankAccounts.ForEach(Console.WriteLine);

            Console.WriteLine();
            //bankService.Close(4);
            Console.WriteLine(bankService.Get(4));

            Console.WriteLine();
            //bankService.Deposit(1, 999.43m);
            bankService.Withdraw(1, 230.40m);
            Console.WriteLine(bankService.Get(1));
        }
 internal static BankAccount ToBankAccount(this BankAccountDTO accountDTO) =>
 (BankAccount)Activator.CreateInstance(
     GetBankAccountType(accountDTO.AccountType),
     accountDTO.IBAN,
     accountDTO.OwnersId,
     accountDTO.Balance,
     accountDTO.BonusPoints,
     accountDTO.IsClosed);
        public void Update(BankAccountDTO account)
        {
            var acc = context.BankAccountSet.Find(account.IBAN);

            acc.AccountType = account.Type.ToString();
            acc.Balance     = account.Balance;
            acc.BonusPoints = account.BonusPoints;
            acc.Status      = account.Status.ToString();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="VMPerformTransfer"/> class.
 /// </summary>
 /// <param name="source">The source account to perform a transfer from.</param>
 public VMPerformTransfer(BankAccountDTO source)
 {
     if (!DesignTimeHelper.IsDesignTime)
     {
         GetBankAccounts();
         BankAccountSource = source;
         RefreshBankAccountsStatus();
     }
 }
예제 #20
0
파일: Reference.cs 프로젝트: unicloud/FRP
 public static BankAccountDTO CreateBankAccountDTO(int bankAccountId, bool isCurrent, global::System.DateTime createDate, global::System.DateTime updateDate, int supplierId)
 {
     BankAccountDTO bankAccountDTO = new BankAccountDTO();
     bankAccountDTO.BankAccountId = bankAccountId;
     bankAccountDTO.IsCurrent = isCurrent;
     bankAccountDTO.CreateDate = createDate;
     bankAccountDTO.UpdateDate = updateDate;
     bankAccountDTO.SupplierId = supplierId;
     return bankAccountDTO;
 }
예제 #21
0
파일: Reference.cs 프로젝트: unicloud/FRP
 public static BankAccountDTO CreateBankAccountDTO(int bankAccountId, bool isCurrent, int supplierId)
 {
     BankAccountDTO bankAccountDTO = new BankAccountDTO();
     bankAccountDTO.BankAccountId = bankAccountId;
     bankAccountDTO.IsCurrent = isCurrent;
     bankAccountDTO.SupplierId = supplierId;
     return bankAccountDTO;
 }
예제 #22
0
      private void AddExecute(BankAccountDTO selected)
      {
         if (selected == null) { return; }

         ((MainPage) App.Current.RootVisual).PerformTransfer.DataContext = new VmPerformTransfer(selected);
         VisualStateManager.GoToState(((MainPage) App.Current.RootVisual), "ToAddTransfer", true);
      }