Пример #1
0
        public void PerformTransfer_Invoke_Test()
        {
            //Arrange

            IBankingManagementService bankTransfersService = IoCFactory.Instance.CurrentContainer.Resolve <IBankingManagementService>();
            IBankingManagementService bankAccountService   = IoCFactory.Instance.CurrentContainer.Resolve <IBankingManagementService>();

            string  bankAccountFrom = "BAC0000001";
            string  bankAcccountTo  = "BAC0000002";
            decimal amount          = 10M;
            decimal actualBanlance  = 0M;

            //Act

            //find actual balance in to account
            actualBanlance = bankAccountService.FindBankAccountByNumber(bankAcccountTo).Balance;

            bankTransfersService.PerformTransfer(bankAccountFrom, bankAcccountTo, amount);


            //Assert

            //check balance
            decimal balance = bankAccountService.FindBankAccounts(bankAcccountTo, null).SingleOrDefault().Balance;


            Assert.AreEqual(actualBanlance + amount, balance);
        }
Пример #2
0
        public void PerformTransfer_Invoke_LockedAccountThrowNewInvalidOperationException_Test()
        {
            //Arrange
            IBankingManagementService bankTransfersService = IoCFactory.Instance.CurrentContainer.Resolve <IBankingManagementService>();
            string  bankAccountFrom = "BAC0000003";//bankAccount is locked
            string  bankAcccountTo  = "BAC0000002";
            decimal amount          = 10M;

            //Act
            bankTransfersService.PerformTransfer(bankAccountFrom, bankAcccountTo, amount);
        }
Пример #3
0
        public void PerformTransfer_Invoke_InvalidAmountThrowNewInvalidOperationException_Test()
        {
            //Arrange
            IBankingManagementService bankTransfersService = IoCFactory.Instance.CurrentContainer.Resolve <IBankingManagementService>();
            string  bankAccountFrom = "BAC0000001";
            string  bankAcccountTo  = "BAC0000002";
            decimal amount          = 1000000000000M; //account one not have sufficient money

            //Act
            bankTransfersService.PerformTransfer(bankAccountFrom, bankAcccountTo, amount);
        }
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/>
        /// </summary>
        /// <param name="transferInformation"><see cref="Microsoft.Samples.NLayerApp.DistributedServices.MainModule.IMainModuleService"/></param>
        public void PerformBankTransfer(TransferInformation transferInformation)
        {
            try
            {
                using (IBankingManagementService bankingManagement = IoCFactory.Instance.CurrentContainer.Resolve <IBankingManagementService>())
                {
                    bankingManagement.PerformTransfer(transferInformation.OriginAccountNumber,
                                                      transferInformation.DestinationAccountNumber,
                                                      transferInformation.Amount);
                }
            }
            catch (InvalidOperationException ex)
            {
                //trace data for internal health system and return specific FaultException here!
                //Log and throw is a knowed anti-pattern but in this point ( entry point for clients this is admited!)

                //log exception for manage health system
                ITraceManager traceManager = IoCFactory.Instance.CurrentContainer.Resolve <ITraceManager>();
                traceManager.TraceError(ex.Message);

                //propagate bussines exception to client
                ServiceError detailedError = new ServiceError()
                {
                    ErrorMessage = Resources.Messages.exception_InvalidBankAccountForTransfer
                };

                throw new FaultException <ServiceError>(detailedError);
            }
            catch (ArgumentException ex)
            {
                //trace data for internal health system and return specific FaultException here!
                //Log and throw is a knowed anti-pattern but in this point ( entry point for clients this is admited!)

                //log exception for manage health system
                ITraceManager traceManager = IoCFactory.Instance.CurrentContainer.Resolve <ITraceManager>();
                traceManager.TraceError(ex.Message);

                //propagate bussines exception to client
                ServiceError detailedError = new ServiceError()
                {
                    ErrorMessage = Resources.Messages.exception_InvalidArguments
                };

                throw new FaultException <ServiceError>(detailedError);
            }
        }
Пример #5
0
 public ActionResult TransferMoney(string sourceAccount, string destinationAccount, decimal amount)
 {
     _BankingService.PerformTransfer(sourceAccount, destinationAccount, amount);
     return(RedirectToAction("TransferMoney"));
 }