コード例 #1
0
        public void TestSavingIsValid_TransferIsInvalid()
        {
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(), TimeProvider.Today, null)
            {
                InterestRate = 0.13, Product = _savingsProduct
            };
            SavingBookContract savingTarget = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(), TimeProvider.Today, null)
            {
                InterestRate = 0.13, Product = _savingsProduct, Status = OSavingsStatus.Closed
            };

            _savingServices = new SavingServices(null, null, new User {
                Id = 6
            });

            try
            {
                _savingServices.Transfer(saving, saving, TimeProvider.Today, 99, 0, "transfer", new User(), false);
                Assert.Fail("Saving Contract shouldn't pass validation test before transfer (Saving source = Saving Target).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.SavingsContractForTransferIdenticals, (int)exception.Code);
            }

            try
            {
                _savingServices.Transfer(saving, savingTarget, TimeProvider.Today, 99, 0, "transfer", new User(), false);
                Assert.Fail("Saving Contract shouldn't pass validation test before transfer (Saving Target is Closed).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.CreditTransferAccountInvalid, (int)exception.Code);
            }
        }
コード例 #2
0
        public void TestSavingIsValid_TransferAmountIsInvalid()
        {
            Assert.Ignore();
            SavingBookContract saving = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(), TimeProvider.Today, null)
            {
                Id = 1, InterestRate = 0.13, Product = _savingsProduct
            };
            SavingBookContract savingTarget = new SavingBookContract(ApplicationSettings.GetInstance(""), new User(), TimeProvider.Today, null)
            {
                Id = 2, InterestRate = 0.13, Product = _savingsProduct
            };

            _savingManagerMock = new DynamicMock(typeof(SavingManager));
            _savingServices    = new SavingServices((SavingManager)_savingManagerMock.MockInstance, null, new User {
                Id = 6
            });

            _savingManagerMock.Expect("UpdateAccountsBalance", saving, null);
            _savingManagerMock.Expect("UpdateAccountsBalance", savingTarget, null);

            try
            {
                _savingServices.Transfer(saving, savingTarget, TimeProvider.Today, 99, 0, "transfer", new User(), false);
                Assert.Fail("Saving Contract shouldn't pass validation test before transfer (transfer amount < transfer.min).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.TransferAmountIsInvalid, (int)exception.Code);
            }

            _savingManagerMock.Expect("UpdateAccountsBalance", saving, null);
            _savingManagerMock.Expect("UpdateAccountsBalance", savingTarget, null);

            try
            {
                _savingServices.Transfer(saving, savingTarget, TimeProvider.Today, 301, 0, "transfer", new User(), false);
                Assert.Fail("Saving Contract shouldn't pass validation test before transfer (transfer amount > transfer.max).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.TransferAmountIsInvalid, (int)exception.Code);
            }

            _savingManagerMock.Expect("UpdateAccountsBalance", saving, null);
            _savingManagerMock.Expect("UpdateAccountsBalance", savingTarget, null);

            try
            {
                _savingServices.Transfer(saving, savingTarget, TimeProvider.Today, 200, 0, "transfer", new User(), false);
                Assert.Fail("Saving Contract shouldn't pass validation test before transfer (balance < balance.min).");
            }
            catch (OpenCbsSavingException exception)
            {
                Assert.AreEqual((int)OpenCbsSavingExceptionEnum.BalanceIsInvalid, (int)exception.Code);
            }
        }
コード例 #3
0
        private void BSaveClick(object sender, EventArgs e)
        {
            nudAmount_ValueChanged(sender, e);
            bool pending = cbxPending.Visible && cbxPending.Checked;

            try
            {
                _date = new DateTime(dtpDate.Value.Year, dtpDate.Value.Month, dtpDate.Value.Day, TimeProvider.Now.Hour,
                                     TimeProvider.Now.Minute, TimeProvider.Now.Second);

                SavingServices savingServices = ServicesProvider.GetInstance().GetSavingServices();

                if (_date.Date < TimeProvider.Today.Date)
                {
                    savingServices.PerformBackDateOperations(_date);
                }
                else if (_date.Date > TimeProvider.Today.Date)
                {
                    savingServices.PerformFutureDateOperations(_date);
                }

                if (_saving.HasPendingEvents())
                {
                    if (!savingServices.AllowOperationsDuringPendingDeposit())
                    {
                        return;
                    }
                }

                if ((_flatFees.HasValue && updAmountFees.Value != _flatFees) || (_rateFees.HasValue && updAmountFees.Value != (decimal)(_rateFees * 100)))
                {
                    if (!savingServices.AllowSettingSavingsOperationsFeesManually())
                    {
                        return;
                    }
                }

                switch (_bookingDirection)
                {
                case OSavingsOperation.Credit:
                {
                    var paymentMethod = (PaymentMethod)cbSavingsMethod.SelectedItem;

                    OSavingsMethods savingsMethod = (OSavingsMethods)Enum.Parse(typeof(OSavingsMethods), paymentMethod.Name);
                    if (_saving is SavingBookContract)
                    {
                        if (savingsMethod == OSavingsMethods.Cheque)
                        {
                            ((SavingBookContract)_saving).ChequeDepositFees = updAmountFees.Value;
                        }
                        else
                        {
                            ((SavingBookContract)_saving).DepositFees = updAmountFees.Value;
                        }
                    }

                    savingServices.Deposit(_saving, _date, _amount, _description, User.CurrentUser, pending,
                                           savingsMethod, paymentMethod, null, Teller.CurrentTeller, _chequeNumberTextBox.Text);
                    _saving.Status = OSavingsStatus.Active;
                    savingServices.UpdateStatus(_saving);
                    break;
                }

                case OSavingsOperation.Debit:
                {
                    var paymentMethod = (PaymentMethod)cbSavingsMethod.SelectedItem;
                    if (_saving is SavingBookContract)
                    {
                        if (_flatFees.HasValue)
                        {
                            ((SavingBookContract)_saving).FlatWithdrawFees = updAmountFees.Value;
                        }
                        else
                        {
                            ((SavingBookContract)_saving).RateWithdrawFees = (double)(updAmountFees.Value / 100);
                        }
                    }

                    savingServices.Withdraw(_saving, _date, _amount, _description, User.CurrentUser,
                                            Teller.CurrentTeller, paymentMethod, _chequeNumberTextBox.Text);
                    break;
                }

                case OSavingsOperation.Transfer:
                {
                    if (_saving is SavingBookContract)
                    {
                        if (_flatFees.HasValue)
                        {
                            ((SavingBookContract)_saving).FlatTransferFees = updAmountFees.Value;
                        }
                        else
                        {
                            ((SavingBookContract)_saving).RateTransferFees = (double)(updAmountFees.Value / 100);
                        }
                    }
                    decimal fee = nudTotalAmount.Value - nudAmount.Value;
                    savingServices.Transfer(_saving, _savingTarget, _date, _amount, fee, _description,
                                            User.CurrentUser, false);
                    break;
                }

                case OSavingsOperation.SpecialOperation:
                {
                    OSavingsMethods savingsMethod =
                        (OSavingsMethods)
                        Enum.Parse(typeof(OSavingsMethods), cbSavingsMethod.SelectedValue.ToString());
                    if (cbBookings.SelectedItem != null)
                    {
                        Booking booking = (Booking)cbBookings.SelectedItem;
                        booking.Branch = _saving.Branch;
                        savingServices.SpecialOperation(_saving, _date, _amount, _description, User.CurrentUser,
                                                        savingsMethod, rbxCredit.Checked, booking);
                        break;
                    }
                    throw new OpenCbsSavingException(OpenCbsSavingExceptionEnum.TransactionInvalid);
                }
                }

                Close();
            }
            catch (Exception ex)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }
        }