public void TestPositionService() { var config = new ConfigRoot { Brokers = new List <BrokerConfig> { new BrokerConfig { Broker = Broker.Hpx, Enabled = true }, new BrokerConfig { Broker = Broker.Zb, Enabled = true } } }; var mConfigRepo = new Mock <IConfigStore>(); mConfigRepo.Setup(x => x.Config).Returns(config); var configStore = mConfigRepo.Object; var mBARouter = new Mock <IBrokerAdapterRouter>(); var baRouter = mBARouter.Object; var mTimer = new Mock <ITimer>(); var ps = new BalanceService(configStore, baRouter, mTimer.Object); }
public void NoTelemetryWhenDisabled() { var mockHandler = new Mock <HttpClientHandler> { CallBase = true }; var httpClient = new SystemNetHttpClient( new System.Net.Http.HttpClient(mockHandler.Object), enableTelemetry: false); var stripeClient = new StripeClient("sk_test_123", httpClient: httpClient); mockHandler.Reset(); var fakeServer = FakeServer.ForMockHandler(mockHandler); fakeServer.Delay = TimeSpan.FromMilliseconds(20); var service = new BalanceService(stripeClient); service.Get(); fakeServer.Delay = TimeSpan.FromMilliseconds(40); service.Get(); service.Get(); mockHandler.Protected() .Verify( "SendAsync", Times.Exactly(3), ItExpr.Is <HttpRequestMessage>(m => !m.Headers.Contains("X-Stripe-Client-Telemetry")), ItExpr.IsAny <CancellationToken>()); }
public void BeforeEachTest() { _userBalanceRepositoryMock = new Mock <IUserBalanceRepository>(); _botServiceMock = new Mock <IBotService>(); _sut = new BalanceService(_botServiceMock.Object, _userBalanceRepositoryMock.Object); }
protected WalletDetails GetWalletDetailsCore() { var defaultCsAddress = this.GetAllColdStakingAddressesCore(0, 1).FirstOrDefault()?.Address; long csTotal = 0; long csSpendable = 0; long csStakable = 0; if (defaultCsAddress != null) { var balance = BalanceService.GetBalance(this.metadata.Blocks, this.metadata.SyncedHeight, this.metadata.MemoryPool.Entries, GetOwnAddress, defaultCsAddress); csTotal = balance.Total; csSpendable = balance.Spendable; csStakable = balance.Stakable; } var defaultMsAddress = this.GetAllMultiSigAddressesCore(0, 1).FirstOrDefault()?.Address; long msTotal = 0; long msSpendable = 0; long msStakable = 0; if (defaultMsAddress != null) { var balance = BalanceService.GetBalance(this.metadata.Blocks, this.metadata.SyncedHeight, this.metadata.MemoryPool.Entries, GetOwnAddress, defaultMsAddress); msTotal = balance.Total; msSpendable = balance.Spendable; msStakable = balance.Stakable; } var info = new WalletDetails { WalletName = this.WalletName, WalletFilePath = this.WalletPath, SyncedHeight = this.metadata.SyncedHeight, SyncedHash = this.metadata.SyncedHash, Adresses = this.x1WalletFile.PubKeyHashAddresses.Count, MultiSigAddresses = this.x1WalletFile.MultiSigAddresses.Count, ColdStakingAddresses = this.x1WalletFile.ColdStakingAddresses.Count, MemoryPool = this.metadata.MemoryPool, PassphraseChallenge = this.x1WalletFile.PassphraseChallenge.ToHexString(), DefaultReceiveAddress = this.GetAllPubKeyHashReceiveAddressesCore(0, 1).FirstOrDefault()?.Address, DefaultCSAddress = defaultCsAddress, CSTotal = csTotal, CSSpendable = csSpendable, CSStakable = csStakable, DefaultMSAddress = defaultMsAddress, MSTotal = msTotal, MSSpendable = msSpendable, MSStakable = msStakable }; info.Balance = GetBalanceCore(); return(info); }
public void SetUp() { _accountDataStore = new Mock <IAccountDataStore>(); _accountDataStore.Setup(ads => ads.UpdateAccount(It.IsAny <Account>())); _balanceService = new BalanceService(_accountDataStore.Object); }
public async Task Balance_ShouldAddToEachOtherAsync() { // Arrange var options = BuildContextOptions(); Participant from; Participant to; Currency currency; using (var context = new BorrowBuddyContext(options)) { currency = context.AddCurrency(); from = context.AddParticipant(); to = context.AddParticipant(); context.AddFlow(from, to, currency, 50); context.AddFlow(from, to, currency, 100); } using (var context = new BorrowBuddyContext(options)) { var service = new BalanceService(context); // Act var balance = await service.BalanceAsync(from.Id, to.Id, currency.Code); // Assert Assert.Equal(150, balance); } }
public void Setup() { var mockHttp = new MockHttpMessageHandler(); var client = mockHttp.ToHttpClient(); var stockMarketAPI = new StockMarketAPI(client); var stockMarketData = new StockMarketData(stockMarketAPI); TestHelpers.MockStockData(mockHttp); TestHelpers.MockFondData(mockHttp); TestHelpers.MockBondData(mockHttp); TestHelpers.MockDividendData(mockHttp); TestHelpers.MockCouponsData(mockHttp); var context = TestHelpers.GetMockFinanceDbContext(); TestHelpers.SeedOperations1(context); _financeDataService = new FinanceDataService(context); var assetFactory = new AssetsFactory(_financeDataService, stockMarketData); var balanceService = new BalanceService(_financeDataService); _marketService = new MarketService(_financeDataService, assetFactory, balanceService); _portfolioService = new PortfolioService(_financeDataService, balanceService, assetFactory); }
public BalanceServiceTest( StripeMockFixture stripeMockFixture, MockHttpClientFixture mockHttpClientFixture) : base(stripeMockFixture, mockHttpClientFixture) { this.service = new BalanceService(this.StripeClient); }
public void RetryOnInternalServerError() { this.MockHttpClientFixture.MockHandler.Protected() .SetupSequence <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Returns(Task.FromResult( new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("{}", Encoding.UTF8), })) .Returns(Task.FromResult( new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}", Encoding.UTF8), })) .Throws(new StripeTestException("Unexpected invocation")); var service = new BalanceService(this.StripeClient); var balance = service.Get(); Assert.NotNull(balance); Assert.Equal(1, balance.StripeResponse.NumRetries); }
public void GetBalance_ShouldGiveTheTotalAmountPaidAndPendingEmisAtAGivenEmiNumberWithExtraPaymentsDone() { loanService.Add(new Loan { BankName = "IDIDI", BorrowerName = "Dale", Principal = 5000, NoOfYears = 1, InterestRate = 6 }); paymentService.Add(new Payment { BankName = "IDIDI", BorrowerName = "Dale", Amount = 1000, Emi = 5 }); var balanceService = new BalanceService(loanService, paymentService); var balance = balanceService.GetBalance("IDIDI", "Dale", 6); Assert.Equal(3652, balance.AmountPaid); Assert.Equal(4, balance.PendingEmis); }
static void Main(string[] args) { var globalStorage = GlobalStorage.Instance; IFileService fileService = new FileService(globalStorage); IAllocationService allocationService = new AllocationService(globalStorage); IPromotionService promotionService = new PromotionService(globalStorage); IBalanceService balanceService = new BalanceService(globalStorage); IConsoleService consoleService = new ConsoleService(); consoleService.ShowInitialInformation(); var option = string.Empty; while (option != Commands.exit) { var optionSplit = GetConsoleParameters(); option = optionSplit[0]; try { switch (option) { case Commands.allocate: globalStorage.Teams = allocationService.Allocate(globalStorage.Teams, globalStorage.EmployeesFromFile); consoleService.ShowTeamsAndEmployees(globalStorage.Teams); break; case Commands.balance: globalStorage.Teams = balanceService.BalanceTeams(globalStorage.Teams); consoleService.ShowTeamsAndEmployees(globalStorage.Teams); break; case Commands.load: globalStorage.Teams = fileService.LoadFileTeam(optionSplit.ElementAtOrDefault(1)); globalStorage.EmployeesFromFile = fileService.LoadFileEmployee(optionSplit.ElementAtOrDefault(2)); Console.WriteLine(Messages.MSG002); break; case Commands.promote: promotionService.Promote(optionSplit.ElementAtOrDefault(1)); break; case Commands.showTeams: consoleService.ShowTeamsAndEmployeesDetail(globalStorage.Teams); break; case Commands.exit: break; default: Console.WriteLine(Messages.MSG001); break; } } catch (BusinessException e) { Console.WriteLine(e.Message); } } }
public Handler(IServiceScopeFactory serviceScopeFactory, IMediator mediator) { _mediator = mediator; var serviceScope = serviceScopeFactory.CreateScope(); _balanceService = serviceScope.ServiceProvider.GetService <BalanceService>(); }
public async Task DoNotRetryOnCancel() { var requestCount = 0; this.MockHttpClientFixture.MockHandler.Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Returns <HttpRequestMessage, CancellationToken>(async(_, t) => { requestCount += 1; await Task.Delay(TimeSpan.FromSeconds(1), t).ConfigureAwait(false); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}", Encoding.UTF8), }); }); var service = new BalanceService(this.StripeClient); var source = new CancellationTokenSource(); source.CancelAfter(TimeSpan.FromMilliseconds(10)); await Assert.ThrowsAsync <TaskCanceledException>(async() => await service.GetAsync(null, source.Token)); Assert.Equal(1, requestCount); }
public async Task <IActionResult> GetBalance() { var service = new BalanceService(); Balance balance = await service.GetAsync(); //IsExistingCustomer("*****@*****.**"); return(new OkObjectResult(new { success = "true", bal = balance.Object })); }
public BalanceController(ILog log, BalanceService service, IAddressValidationService addressValidator) { _log = log; _service = service; _addressValidator = addressValidator; }
public Handler(IServiceScopeFactory serviceScopeFactory) { var serviceScope = serviceScopeFactory.CreateScope(); _mediator = serviceScope.ServiceProvider.GetService <IMediator>(); _balanceService = serviceScope.ServiceProvider.GetService <BalanceService>(); _readDb = serviceScope.ServiceProvider.GetService <IReadDbContext>(); }
public Listener(IServiceScopeFactory serviceScopeFactory) { var scope = serviceScopeFactory.CreateScope(); _writeDbContext = scope.ServiceProvider.GetService <IWriteDbContext>(); _mediator = scope.ServiceProvider.GetService <IMediator>(); _balanceService = scope.ServiceProvider.GetService <BalanceService>(); }
public CommandHandler(DiscordShardedClient c, CommandService cs, IServiceProvider s, DatabaseService dbs, BalanceService balanceService) { _client = c; _commandService = cs; _services = s; _databaseService = dbs; _balanceService = balanceService; }
public async Task TestGetBalance() { var service = new BalanceService(MockTokenClaimsAccessor(cjdlqTokenClaims), db); var resp = await service.GetBalance(new AcademyCloud.Expenses.Protos.Balance.GetBalanceRequest { }, TestContext); Assert.Equal(10, resp.Balance); }
public BalanceModel Get(int id) { var service = new BalanceService(); var balance = service.Get(); return(new BalanceModel { availableBalance = balance.Available.First().Amount }); }
public async Task <Balance> GetBalanceFor(string connectedAcctId) { var service = new BalanceService(); RequestOptions ro = new RequestOptions() { StripeAccount = connectedAcctId }; return(await service.GetAsync(ro)); }
public void Setup() { _mockBalanceRepository = new Mock <IBalanceRepository>(); _mockAccountRepository = new Mock <IAccountRepository>(); _mockInterestRepository = new Mock <IInterestRepository>(); _service = new BalanceService(_mockBalanceRepository.Object, _mockInterestRepository.Object, _mockAccountRepository.Object); }
public Balance Check_connected_accounts_balance() { var requestOptions = new RequestOptions(); requestOptions.StripeAccount = ""; var service = new BalanceService(); Balance balance = service.Get(requestOptions); return(balance); }
public async Task BuyProductAsync(BuyProductEventArgs args) { var response = await HttpClient.PostAsync($"api/products/{args.Product.Id}/buy?serverId={args.SelectedServer.Id}", null); switch (response.StatusCode) { case HttpStatusCode.OK: await Swal.FireAsync("OK", $"You successfully bought {args.Product.Title} for ${args.Product.Price}!", SweetAlertIcon.Success); await BalanceService.UpdateBalanceAsync(); break; case HttpStatusCode.NotFound: await Swal.FireAsync("Not Found", "The product you are trying to buy could not be found", SweetAlertIcon.Error); break; case HttpStatusCode.Gone: await Swal.FireAsync("Gone", "The product you are trying to buy is disabled", SweetAlertIcon.Error); break; case HttpStatusCode.Conflict: await Swal.FireAsync("Conflict", "You have already bought maximum amount of this product", SweetAlertIcon.Error); break; case HttpStatusCode.Unauthorized: await Swal.FireAsync("Unauthorized", "You have to sign in to be able to buy", SweetAlertIcon.Error); break; case HttpStatusCode.ServiceUnavailable: await Swal.FireAsync("Service Unavailable", "Failed to communicate with game server, try again later", SweetAlertIcon.Error); break; case HttpStatusCode.InternalServerError: await Swal.FireAsync("Internal Server Error", "Something went wrong, try again later"); break; } await PreviewModal.ToggleModalAsync(); }
public async Task <IActionResult> GetBalance([FromRoute] string userId) { try { StripeConfiguration.ApiKey = ServiceKey; var user = await _accountsRepository.GetByUserId(userId); var service = new BalanceService(); Balance balance = await service.GetAsync(new RequestOptions { StripeAccount = user.StripeUserId }); return(Ok(balance)); } catch (Exception e) { return(BadRequest(new MessageObj(e.Message))); } }
public async Task TelemetryWorksWithConcurrentRequests() { this.MockHttpClientFixture.Reset(); var fakeServer = FakeServer.ForMockHandler(this.MockHttpClientFixture.MockHandler); fakeServer.Delay = TimeSpan.FromMilliseconds(20); var service = new BalanceService(this.StripeClient); // the first 2 requests will not contain telemetry await Task.WhenAll(service.GetAsync(), service.GetAsync()); // the following 2 requests will contain telemetry await Task.WhenAll(service.GetAsync(), service.GetAsync()); this.MockHttpClientFixture.MockHandler.Protected() .Verify( "SendAsync", Times.Exactly(2), ItExpr.Is <HttpRequestMessage>(m => !m.Headers.Contains("X-Stripe-Client-Telemetry")), ItExpr.IsAny <CancellationToken>()); this.MockHttpClientFixture.MockHandler.Protected() .Verify( "SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(m => TelemetryHeaderMatcher( m.Headers, (s) => s == "req_1", (d) => d >= 15)), ItExpr.IsAny <CancellationToken>()); this.MockHttpClientFixture.MockHandler.Protected() .Verify( "SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(m => TelemetryHeaderMatcher( m.Headers, (s) => s == "req_2", (d) => d >= 15)), ItExpr.IsAny <CancellationToken>()); }
public Factory() { DbContext = new DefaultContext(); AccountsService = new AccountsService(DbContext); ClientsService = new ClientsService(DbContext); OpeningsService = new OpeningsService(DbContext); DocumentsService = new DocumentsService(DbContext); ReportsService = new ReportsService(DbContext); DataInitializatorService = new DataInitializatorService(DbContext); ProfitLossService = new ProfitLossService(this); BalanceService = new BalanceService(this); AccountsPrintService = new AccountsPrintService(this); OpeningsPrintService = new OpeningsPrintService(this); DocumentsPrintService = new DocumentsPrintService(this); ReportsPrintService = new ReportsPrintService(this); ProfitLossPrintService = new ProfitAndLossPrintService(this); BalancePrintService = new BalancePrintService(this); }
public void RethrowTimeoutExceptionAfterAllAttempts() { this.MockHttpClientFixture.MockHandler.Protected() .SetupSequence <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Throws(new TaskCanceledException("Timeout 1")) .Throws(new TaskCanceledException("Timeout 2")) .Throws(new TaskCanceledException("Timeout 3")) .Throws(new StripeTestException("Unexpected invocation")); var service = new BalanceService(this.StripeClient); var exception = Assert.Throws <TaskCanceledException>(() => service.Get()); Assert.NotNull(exception); Assert.Equal("Timeout 3", exception.Message); }
public void TelemetryWorks() { this.MockHttpClientFixture.Reset(); var fakeServer = FakeServer.ForMockHandler(this.MockHttpClientFixture.MockHandler); fakeServer.Delay = TimeSpan.FromMilliseconds(20); var service = new BalanceService(this.StripeClient); service.Get(); fakeServer.Delay = TimeSpan.FromMilliseconds(40); service.Get(); service.Get(); this.MockHttpClientFixture.MockHandler.Protected() .Verify( "SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(m => !m.Headers.Contains("X-Stripe-Client-Telemetry")), ItExpr.IsAny <CancellationToken>()); this.MockHttpClientFixture.MockHandler.Protected() .Verify( "SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(m => TelemetryHeaderMatcher( m.Headers, (s) => s == "req_1", (d) => d >= 15)), ItExpr.IsAny <CancellationToken>()); this.MockHttpClientFixture.MockHandler.Protected() .Verify( "SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(m => TelemetryHeaderMatcher( m.Headers, (s) => s == "req_2", (d) => d >= 30)), ItExpr.IsAny <CancellationToken>()); }
public void GetBalance_ShouldGiveTheTotalAmountPaidAndPendingEmisAtAGivenEmiNumber() { loanService.Add(new Loan { BankName = "IDIDI", BorrowerName = "Dale", Principal = 10000, NoOfYears = 5, InterestRate = 4 }); var balanceService = new BalanceService(loanService, paymentService); var balance = balanceService.GetBalance("IDIDI", "Dale", 5); Assert.Equal(1000, balance.AmountPaid); Assert.Equal(55, balance.PendingEmis); }