public void ShouldReturnStatementsInDescendingDateOrderWhenPrintingBalance() { DateTime today = DateTime.Now; ITransactions transactions = Substitute.For <ITransactions>(); List <AccountStatement> statements = new List <AccountStatement> { new AccountStatement(today.AddDays(2), 100, 200), new AccountStatement(today.AddDays(1), -100, 100), new AccountStatement(today, 200, 200) }; IBalanceRetriever balanceRetriever = Substitute.For <IBalanceRetriever>(); balanceRetriever.GetStatements().Returns(statements); var bankingService = new BankingService(transactions, balanceRetriever); var balance = bankingService.PrintBalance(); var expectedStatements = new List <AccountStatement> { new AccountStatement(today.AddDays(2), 100, 200), new AccountStatement(today.AddDays(1), -100, 100), new AccountStatement(today, 200, 200) }; Check.That(balance.GetAccountStatements()).IsEqualTo(expectedStatements); }
public void RetrievePaymentThrowsHttpExceptionWhenBankingApiCallEncountersAnUnpectedError() { //Arrange var bankDto = new BankRetrievePaymentsRequestDto() { TransactionId = new Guid("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa") }; var httpClient = new HttpClient(this._handler.Object) { BaseAddress = null }; this._bankingService = new BankingService(this._bankingApiConfiguration.Object, httpClient, this._logger.Object); //Act - see assertion. //Assert var ex = Assert.ThrowsAsync <HttpException>(() => this._bankingService.RetrievePayments(bankDto)); Assert.AreEqual(HttpStatusCode.InternalServerError, ex.StatusCode); Assert.AreEqual(Resources.ErrorMessage_BankingApiUnexpectedError, ex.Message); Assert.AreEqual(Resources.ErrorCode_BankingApiUnexpectedError, ex.ErrorCode); //Verify logging took place this._logger.Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Once); }
public ResultSrv <ServiceCallResultSrv <BankingSrv <List <GetDepositInvoiceSrv> > > > GetDepositInvoice() { try { var output = new ResultSrv <ServiceCallResultSrv <BankingSrv <List <GetDepositInvoiceSrv> > > >(); var getDepositInvoiceVo = GetDepositInvoiceVo.ConcreteBuilder .SetServiceCallParameters(internalServiceCallVo) .SetUserName(userName) .SetDepositNumber("") .SetStartDate(DateTime.Now) .SetEndDate(DateTime.Now) .SetFirstIndex(0) .SetCount(10) //.SetSheba("") .SetPrivateKey(xml) .Build(); BankingService.GetDepositInvoice(getDepositInvoiceVo, response => Listener.GetResult(response, out output)); return(output); } catch (PodException podException) { Console.WriteLine( $"-- {podException.Code}-an error has occured : {Environment.NewLine}{podException.Message}"); throw; } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } }
public ResultSrv <ServiceCallResultSrv <BankingSrv <GetShebaInfoSrv> > > GetShebaInfo() { try { var output = new ResultSrv <ServiceCallResultSrv <BankingSrv <GetShebaInfoSrv> > >(); var getShebaInfoVo = GetShebaInfoVo.ConcreteBuilder .SetServiceCallParameters(internalServiceCallVo) .SetUserName(userName) .SetSheba("") .SetPrivateKey(xml) //.SetShenaseVariz("") .Build(); BankingService.GetShebaInfo(getShebaInfoVo, response => Listener.GetResult(response, out output)); return(output); } catch (PodException podException) { Console.WriteLine( $"-- {podException.Code}-an error has occured : {Environment.NewLine}{podException.Message}"); throw; } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } }
public ResultSrv <ServiceCallResultSrv <BankingSrv <List <CoreBatchTransferPayaSrv> > > > PayaService() { try { var output = new ResultSrv <ServiceCallResultSrv <BankingSrv <List <CoreBatchTransferPayaSrv> > > >(); var getDepositInvoiceVo = PayaServiceVo.ConcreteBuilder .SetServiceCallParameters(internalServiceCallVo) .SetUserName(userName) .SetPrivateKey(xml) .SetSourceDepositNumber("") .SetBatchPayaItemInfos(new List <BatchPayaItemInfoVo> { BatchPayaItemInfoVo.ConcreteBuilder.SetBillNumber("12345").SetAmount(100).SetBeneficiaryFullName("تست ۱").SetDescription("تست۱۱").SetDestShebaNumber("").Build(), BatchPayaItemInfoVo.ConcreteBuilder.SetBillNumber("123456").SetAmount(100).SetBeneficiaryFullName("تست ۲").SetDescription("تست۲۲").SetDestShebaNumber("").Build() }) .SetFileUniqueIdentifier("") //.SetTransferMoneyBillNumber("") .Build(); BankingService.PayaService(getDepositInvoiceVo, response => Listener.GetResult(response, out output)); return(output); } catch (PodException podException) { Console.WriteLine( $"-- {podException.Code}-an error has occured : {Environment.NewLine}{podException.Message}"); throw; } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } }
public void ShouldReturnAccountStatementsWithDepositsAndWithdrawsWhenPrintingBalance() { DateTime today = DateTime.Now; var transactions = new Transactions(); IBalanceRetriever balanceRetriever = new BalanceRetriever(transactions); var bankingService = new BankingService(transactions, balanceRetriever); uint depositAmount = 200; bankingService.Deposit(depositAmount, today); uint withDrawAmount = 100; bankingService.Withdraw(withDrawAmount, today.AddDays(1)); bankingService.Deposit(depositAmount, today.AddDays(2)); Balance balance = bankingService.PrintBalance(); var expectedStatements = new List <AccountStatement> { new AccountStatement(today.AddDays(2), 200, 300), new AccountStatement(today.AddDays(1), -100, 100), new AccountStatement(today, 200, 200) }; Check.That(balance.GetAccountStatements()).IsEqualTo(expectedStatements); }
public ResultSrv <ServiceCallResultSrv <BankingSrv <string> > > TransferMoney() { try { var output = new ResultSrv <ServiceCallResultSrv <BankingSrv <string> > >(); var getDepositInvoiceVo = TransferMoneyVo.ConcreteBuilder .SetServiceCallParameters(internalServiceCallVo) .SetUserName(userName) .SetPrivateKey(xml) .SetPaymentId("100") .SetSourceDepositNumber("") .SetDestDepositNumber("") //.SetSourceSheba("") //.SetDestSheba("") .SetAmount(10) .SetSourceComment("تست") .SetDestComment("تست۱") .SetDestFirstName("") .SetDestLastName("") .Build(); BankingService.TransferMoney(getDepositInvoiceVo, response => Listener.GetResult(response, out output)); return(output); } catch (PodException podException) { Console.WriteLine( $"-- {podException.Code}-an error has occured : {Environment.NewLine}{podException.Message}"); throw; } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } }
public ResultSrv <ServiceCallResultSrv <BankingSrv <GetTransferMoneyStateSrv> > > GetTransferState() { try { var output = new ResultSrv <ServiceCallResultSrv <BankingSrv <GetTransferMoneyStateSrv> > >(); var getTransferStateVo = GetTransferStateVo.ConcreteBuilder .SetServiceCallParameters(internalServiceCallVo) .SetUserName(userName) .SetPrivateKey(xml) .SetPaymentId("10") .SetDate(DateTime.Now) .Build(); BankingService.GetTransferState(getTransferStateVo, response => Listener.GetResult(response, out output)); return(output); } catch (PodException podException) { Console.WriteLine( $"-- {podException.Code}-an error has occured : {Environment.NewLine}{podException.Message}"); throw; } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } }
public ResultSrv <ServiceCallResultSrv <BankingSrv <string> > > GetCardInformation() { try { var output = new ResultSrv <ServiceCallResultSrv <BankingSrv <string> > >(); var getCardInformationVo = GetCardInformationVo.ConcreteBuilder .SetServiceCallParameters(internalServiceCallVo) .SetUserName(userName) .SetPrivateKey(xml) .SetSrcCardNumber("") .SetDestCardNumber("") //optional //.SetEmail("") .Build(); BankingService.GetCardInformation(getCardInformationVo, response => Listener.GetResult(response, out output)); return(output); } catch (PodException podException) { Console.WriteLine( $"-- {podException.Code}-an error has occured : {Environment.NewLine}{podException.Message}"); throw; } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } }
public WithdrawResult Withdraw(Guid accountId, double amount) { var policy = _dailyPolicyRespository.GetDailyPolicy(); var account = _accountRepository.GetAccount(accountId); if (account == null) { return(WithdrawResult.AccountNotFound(accountId)); } var bankingService = new BankingService(); var result = bankingService.Withdraw(policy, account, amount, DateTime.Now); if (result.Status == Domain.WithdrawStatus.DailyQuotaReached) { return(WithdrawResult.DailyQuotaReached(result.DailyLimit)); } else if (result.Status == Domain.WithdrawStatus.InsufficientFunds) { return(WithdrawResult.InsufficientFunds(result.AvailableFunds)); } else if (result.Status == Domain.WithdrawStatus.AccountDoesNotAllowWithdrawals) { return(WithdrawResult.AccountCannotWithdraw()); } else { return(WithdrawResult.Success()); } }
public ResultSrv <ServiceCallResultSrv <BankingSrv <string> > > ConvertShebaToDepositNumber() { try { var output = new ResultSrv <ServiceCallResultSrv <BankingSrv <string> > >(); var convertShebaToDepositNumberVo = ConvertShebaToDepositNumberVo.ConcreteBuilder .SetServiceCallParameters(internalServiceCallVo) .SetUserName(userName) .SetPrivateKey(xml) .SetSheba("") .Build(); BankingService.ConvertShebaToDepositNumber(convertShebaToDepositNumberVo, response => Listener.GetResult(response, out output)); return(output); } catch (PodException podException) { Console.WriteLine( $"-- {podException.Code}-an error has occured : {Environment.NewLine}{podException.Message}"); throw; } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } }
public BankingController(ILogger <BankingController> logger, BankingService bankingService, IActionContextAccessor accessor, UserService userService, RecipientService recipientService) { _logger = logger; _bankingService = bankingService; _accessor = accessor; _userService = userService; _recipientService = recipientService; }
public async Task NeftExportBankingDetailsByTypeMethod() { Program.BuildConfiguration(); var data = await BankingService.ExportBankingDetailsByTypeAsync(new TeamHttpContext(MockData.httpContext), MockData.year, MockData.month, Enums.BankingMode.Neft, MockData.Exporttype, MockData.exportPWD).ConfigureAwait(false); string result = data.FileStream.Length > 0 ? "OK" : "ERROR"; Xunit.Assert.Equal("OK", result); }
public async Task NoBankBankingWidgetMethod() { Program.BuildConfiguration(); var data = await BankingService.GetBankingDetailsByTypeAsync(new TeamHttpContext(MockData.httpContext), 0, 5, Enums.BankingMode.NoDetails).ConfigureAwait(false); string result = data.Code == HttpStatusCode.OK ? "OK" : "ERROR"; Xunit.Assert.Equal("OK", result); }
public void ShouldAddWithdrawIntoTransactions() { DateTime today = DateTime.Now; ITransactions transactions = Substitute.For <ITransactions>(); IBalanceRetriever balanceRetriever = Substitute.For <IBalanceRetriever>(); var bankingService = new BankingService(transactions, balanceRetriever); uint withdrawAmount = 200; bankingService.Withdraw(withdrawAmount, today); transactions.Received().Add(Arg.Is <ITransaction>(t => t.GetType() == typeof(Withdraw))); }
public void ShouldReturnNoStatementWhenHavingNoTransaction() { DateTime today = DateTime.Now; ITransactions transactions = Substitute.For <ITransactions>(); List <AccountStatement> noStatements = new List <AccountStatement>(); IBalanceRetriever balanceRetriever = Substitute.For <IBalanceRetriever>(); balanceRetriever.GetStatements().Returns(noStatements); var bankingService = new BankingService(transactions, balanceRetriever); var balance = bankingService.PrintBalance(); Check.That(balance.GetAccountStatements()).IsEmpty(); }
public void BankingServiceTests_Setup() { this._handler = new Mock <HttpMessageHandler>(); this._bankingApiConfiguration = new Mock <IConfiguration>(); this._bankingApiConfiguration.SetupGet(x => x["bankingApi:paymentsEndpointPost"]).Returns("fakeendpointPost"); this._bankingApiConfiguration.SetupGet(x => x["bankingApi:paymentsEndpointGet"]).Returns("fakeendpointGet"); this._logger = new Mock <ILogger <BankingService> >(); var httpClient = new HttpClient(this._handler.Object) { BaseAddress = new Uri("http://fakeapi.com/") }; this._bankingService = new BankingService(this._bankingApiConfiguration.Object, httpClient, this._logger.Object); }
public void ShouldReturnOneStatementWhenHavingOneWithdrawTransaction() { DateTime today = DateTime.Now; ITransactions transactions = Substitute.For <ITransactions>(); List <AccountStatement> statements = new List <AccountStatement> { new AccountStatement(today, -100, -100) }; IBalanceRetriever balanceRetriever = Substitute.For <IBalanceRetriever>(); balanceRetriever.GetStatements().Returns(statements); var bankingService = new BankingService(transactions, balanceRetriever); var balance = bankingService.PrintBalance(); Check.That(balance.GetAccountStatements()) .ContainsExactly(new AccountStatement(today, -100, -100)); }
public ResultSrv <ServiceCallResultSrv <BankingSrv <string> > > CardToCard() { try { var output = new ResultSrv <ServiceCallResultSrv <BankingSrv <string> > >(); var cardToCardVo = CardToCardVo.ConcreteBuilder .SetServiceCallParameters(internalServiceCallVo) .SetUserName(userName) .SetPrivateKey(xml) .SetAmount(10) .SetCvv2("") .SetSrcCardNumber("") .SetPassword("") .SetDestCardNumber("") .SetExpireMonth(0) .SetExpireYear("") .SetAuthorizationCode("0") .SetWithReferenceNumber(false) //optional //.SetCardName("") //.SetSrcComment("tst1") //.SetDestComment("tst2") //.SetEmail("*****@*****.**") .SetExtraData("DeviceId", "UserAgent", "127.0.0.1", PlatformType.ANDROID, "OS", "imei") //.SetOriginalAddress("127.0.0.1") .Build(); BankingService.CardToCard(cardToCardVo, response => Listener.GetResult(response, out output)); return(output); } catch (PodException podException) { Console.WriteLine( $"-- {podException.Code}-an error has occured : {Environment.NewLine}{podException.Message}"); throw; } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } }
public TransferResult Transfer(Guid sourceAccountId, Guid destinationAccountId, double amount, string reason) { var bankingService = new BankingService(); var policy = _dailyPolicyRespository.GetDailyPolicy(); var source = _accountRepository.GetAccount(sourceAccountId); var dest = _accountRepository.GetAccount(destinationAccountId); if (source == null) { return(TransferResult.AccountNotFound(sourceAccountId)); } if (dest == null) { return(TransferResult.AccountNotFound(destinationAccountId)); } var result = bankingService.Transfer(policy, source, dest, amount, reason, DateTime.Now); if (result.Status == Domain.TransferStatus.DailyQuotaReached) { return(TransferResult.DailyQuotaReached(result.DailyLimit)); } else if (result.Status == Domain.TransferStatus.InsufficientFunds) { return(TransferResult.InsufficientFunds(result.AvailableFunds)); } else if (result.Status == Domain.TransferStatus.InvalidReason) { return(TransferResult.InvalidReasonProvided()); } else if (result.Status == Domain.TransferStatus.AccountDoesNotAllowWithdrawals) { return(TransferResult.AccountCannotWithdraw()); } else { return(TransferResult.Success()); } }
public RequestResult ServiceWebMethod(Methods methodToUse, BankingService bs = null) { RequestResult result = new RequestResult(); string URL = APIBaseUrl + Properties.Settings.Default.Service; string json = ""; switch (methodToUse) { case Methods.GET: if (bs != null) { URL += "/" + bs.Id; json = logic.GET(URL); result.BankingBankAccountResult = JsonConvert.DeserializeObject<BankingBankAccount>(json); } else { json = logic.GET(URL); } break; case Methods.POST: json = logic.POST(URL, JsonConvert.SerializeObject(bs)); result.BankingBankAccountResult = JsonConvert.DeserializeObject<BankingBankAccount>(json); break; case Methods.DELETE: URL += "/" + bs.Id; json = logic.DELETE(URL); break; case Methods.PUT: URL += "/" + bs.Id; json = logic.PUT(URL, JsonConvert.SerializeObject(bs)); break; default: break; } result.Status = 0; result.Result = "200 OK"; return result; }
public void ProcessPaymentThrowsHttpExceptionWhenBankingApiCallEncountersAnUnpectedError() { //Arrange var bankDto = new BankProcessPaymentRequestDto() { CardNumber = "5500000000000004", CardHolder = "Test Account", CardType = CardType.MasterCard, ExpirationMonth = DateTime.Now.ToString("MM"), ExpirationYear = DateTime.Now.AddYears(1).ToString("yy"), PaymentAmount = 100.00M, Currency = SupportedCurrencies.GBP, Cvv = "123" }; var httpClient = new HttpClient(this._handler.Object) { BaseAddress = null }; this._bankingService = new BankingService(this._bankingApiConfiguration.Object, httpClient, this._logger.Object); //Act - see assertion. //Assert var ex = Assert.ThrowsAsync <HttpException>(() => this._bankingService.ProcessPayment(bankDto)); Assert.AreEqual(HttpStatusCode.InternalServerError, ex.StatusCode); Assert.AreEqual(Resources.ErrorMessage_BankingApiUnexpectedError, ex.Message); Assert.AreEqual(Resources.ErrorCode_BankingApiUnexpectedError, ex.ErrorCode); //Verify logging took place this._logger.Verify(x => x.Log(LogLevel.Error, It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>()), Times.Once); }
public ResultSrv <ServiceCallResultSrv <BankingSrv <List <CardToCardListSrv> > > > CardToCardList() { try { var output = new ResultSrv <ServiceCallResultSrv <BankingSrv <List <CardToCardListSrv> > > >(); var cardToCardListVo = CardToCardListVo.ConcreteBuilder .SetServiceCallParameters(internalServiceCallVo) .SetUserName(userName) .SetPrivateKey(xml) .SetMinAmount(10) .SetMaxAmount(20) .SetSourceCardNumber("") .SetStartDate(DateTime.Now) .SetEndDate(DateTime.Now) //optional //.SetSourceDepositNumber("") //.SetDestinationCardNumber("") //.SetRefrenceNumber("") //.SetSequenceNumber("") //.SetSourceNote("") //.SetDestinationNote("") .Build(); BankingService.CardToCardList(cardToCardListVo, response => Listener.GetResult(response, out output)); return(output); } catch (PodException podException) { Console.WriteLine( $"-- {podException.Code}-an error has occured : {Environment.NewLine}{podException.Message}"); throw; } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } }
public async Task ShouldProcessPaymentSuccessfully() { // Arrange var paymentRepositoryMock = new Mock <IRepository <Payment> >(); var handlerMock = new Mock <HttpMessageHandler>(); handlerMock.Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(@"{ ""paymentId"": ""aeb9fd74-fb35-4767-82bf-4dbdff7200f9"", ""paymentStatus"": ""Declined""}"), }); var httpClient = new HttpClient(handlerMock.Object) { BaseAddress = new UriBuilder("http://address").Uri }; var service = new BankingService(httpClient, paymentRepositoryMock.Object); // Act var processedPayment = await service.ProcessPaymentAsync(new Payment(), "/endpoint", It.IsAny <CancellationToken>()); // Assert processedPayment.PaymentStatus.Should().Be("Declined"); paymentRepositoryMock.Verify(x => x.ReplaceOneAsync(It.IsAny <Payment>(), It.IsAny <CancellationToken>()), Times.Once()); handlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Post), ItExpr.IsAny <CancellationToken>()); }
public ResultSrv <ServiceCallResultSrv <BankingSrv <List <GetSubmissionChequeSrv> > > > GetSubmissionCheque() { try { var output = new ResultSrv <ServiceCallResultSrv <BankingSrv <List <GetSubmissionChequeSrv> > > >(); var getSubmissionChequeVo = GetSubmissionChequeVo.ConcreteBuilder .SetServiceCallParameters(internalServiceCallVo) .SetUserName(userName) .SetPrivateKey(xml) .SetDeposit("") //optional .SetMinAmount(0) .SetMaxAmount(0) .SetBankCode(BankCode.همه_بانک_ها) .SetChequeStatus(ChequeStatus.همه) .SetChequeNumber("") .SetStartDate(new DateTime(2019, 12, 15)) .SetEndDate(new DateTime(2019, 12, 15)) .SetStartSubmisionDate(new DateTime(2019, 12, 15)) .SetEndSubmitionDate(new DateTime(2019, 12, 15)) .SetRowCount(10) .Build(); BankingService.GetSubmissionCheque(getSubmissionChequeVo, response => Listener.GetResult(response, out output)); return(output); } catch (PodException podException) { Console.WriteLine( $"-- {podException.Code}-an error has occured : {Environment.NewLine}{podException.Message}"); throw; } catch (Exception exception) { Console.WriteLine(exception.Message); throw; } }
public RecipientController(RecipientService recipientService, UserService userService, BankingService bankingService) { _recipentService = recipientService; _userService = userService; _bankingService = bankingService; }