public void ValidationForOrderFailTest_TestsIfValidationOfFundsFailsAsExpected_VerifiesThroughTheResponseReturned()
        {
            var mockFundsRepository                = new MockFundsRepository();
            var mockBalanceRepository              = new MockBalanceRepository();
            var mockFeeCalculationService          = new MockFeeCalculationService();
            var mockWithdrawFeesRepository         = new MockWithdrawFeesRepository();
            var mockWithdrawIdGeneratorService     = new MockWithdrawIdGeneratorService();
            var depositLimitEvaluationService      = new DepositLimitEvaluationService();
            var mockLedgerRepository               = new MockLedgerRepository();
            var mockDepositLimitRepository         = new MockDepositLimitRepository();
            var mockWithdrawLimitEvaluationService = new WithdrawLimitEvaluationService();
            var mockWithdrawLimitRepository        = new MockWithdrawLimitRepository();
            var mockTierLevelRetrievalService      = new MockTierLevelRetrievalService();
            var mockWithdrawRepository             = new MockWithdrawRepository();
            var tierValidationService              = new TierValidationService();
            var mockBboRetrievalService            = new MockBboRetrievalService();
            var mockLimitsConfigurationService     = new LimitsConfigurationService(mockDepositLimitRepository,
                                                                                    depositLimitEvaluationService, mockWithdrawLimitRepository, mockWithdrawLimitEvaluationService, mockBboRetrievalService);
            TransactionService transactionService = new TransactionService(mockFundsRepository, new MockLedgerGeneratorService(),
                                                                           mockLimitsConfigurationService);
            FundsValidationService fundsValidationService = new FundsValidationService(transactionService,
                                                                                       mockFundsRepository, mockBalanceRepository, mockFeeCalculationService, mockWithdrawFeesRepository,
                                                                                       mockWithdrawIdGeneratorService, mockLedgerRepository, depositLimitEvaluationService,
                                                                                       mockDepositLimitRepository, mockWithdrawLimitEvaluationService, mockWithdrawLimitRepository,
                                                                                       mockTierLevelRetrievalService, mockWithdrawRepository, tierValidationService, mockLimitsConfigurationService);

            bool validateFundsForOrder = fundsValidationService.ValidateFundsForOrder(new AccountId(123),
                                                                                      new Currency("XBT", true), new Currency("USD"), 300, 101, "buy", "order123");

            Assert.IsFalse(validateFundsForOrder);
        }
        public void WithdrawFailTest_TestsIfWithdrawValidationisReturnedTrueWhenSufficientBalanceIsNotAvailable_VerifiesThroughReturnedValue()
        {
            var mockFundsRepository                = new MockFundsRepository();
            var mockBalanceRepository              = new MockBalanceRepository();
            var mockFeeCalculationService          = new MockFeeCalculationService();
            var mockWithdrawFeesRepository         = new MockWithdrawFeesRepository();
            var mockWithdrawIdGeneratorService     = new MockWithdrawIdGeneratorService();
            var depositLimitEvaluationService      = new DepositLimitEvaluationService();
            var mockLedgerRepository               = new MockLedgerRepository();
            var mockDepositLimitRepository         = new MockDepositLimitRepository();
            var mockWithdrawLimitEvaluationService = new WithdrawLimitEvaluationService();
            var mockWithdrawLimitRepository        = new MockWithdrawLimitRepository();
            var mockTierLevelRetrievalService      = new MockTierLevelRetrievalService();
            var mockWithdrawRepository             = new MockWithdrawRepository();
            var tierValidationService              = new TierValidationService();
            var mockBboRetrievalService            = new MockBboRetrievalService();
            var mockLimitsConfigurationService     = new LimitsConfigurationService(mockDepositLimitRepository,
                                                                                    depositLimitEvaluationService, mockWithdrawLimitRepository, mockWithdrawLimitEvaluationService, mockBboRetrievalService);
            TransactionService transactionService = new TransactionService(mockFundsRepository, new MockLedgerGeneratorService(),
                                                                           mockLimitsConfigurationService);
            FundsValidationService fundsValidationService = new FundsValidationService(transactionService,
                                                                                       mockFundsRepository, mockBalanceRepository, mockFeeCalculationService, mockWithdrawFeesRepository,
                                                                                       mockWithdrawIdGeneratorService, mockLedgerRepository, depositLimitEvaluationService,
                                                                                       mockDepositLimitRepository, mockWithdrawLimitEvaluationService, mockWithdrawLimitRepository,
                                                                                       mockTierLevelRetrievalService, mockWithdrawRepository, tierValidationService, mockLimitsConfigurationService);
            Balance balance = new Balance(new Currency("XBT", true), new AccountId(123), 100, 100);

            mockBalanceRepository.AddBalance(balance);

            Withdraw withdrawalResponse = fundsValidationService.ValidateFundsForWithdrawal(balance.AccountId, balance.Currency,
                                                                                            100.0002M, new TransactionId("transaction123"), new BitcoinAddress("bitcoinid123"));

            Assert.IsNull(withdrawalResponse);
        }
示例#3
0
        public void DepositConfirmedEventTest_ChecksThatDepositConfirmedEventsAreRaisedHandledProperly_VerifiesThroughRaisedEvents()
        {
            var mockFundsRepository       = new MockFundsRepository();
            var mockWithdrawRepository    = new MockWithdrawRepository();
            var mockBitcoinClientService  = new MockBitcoinClientService();
            var mockLitecoinClientService = new MockLitecoinClientService();
            ClientInteractionService clientInteractionService = new ClientInteractionService(mockFundsRepository, mockWithdrawRepository,
                                                                                             mockBitcoinClientService, mockLitecoinClientService);

            bool             eventFired       = false;
            int              eventCounter     = 0;
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            clientInteractionService.DepositConfirmed +=
                delegate(string currency, int newTransactions)
            {
                eventFired = true;
                eventCounter++;
            };

            // Raise the event twice from both services to see if duplicate invocations don't occur
            mockBitcoinClientService.RaiseDepositConfirmedEvent();
            mockLitecoinClientService.RaiseDepositConfirmedEvent();
            mockBitcoinClientService.RaiseDepositConfirmedEvent();
            mockLitecoinClientService.RaiseDepositConfirmedEvent();
            manualResetEvent.WaitOne(3000);
            Assert.IsTrue(eventFired);
            Assert.AreEqual(4, eventCounter);
        }
示例#4
0
        public void CancelWithdrawTest_ChecksThatWithdrawEventIsSubmittedAsExpectedToTheCoinClientService_VerifiesThroughVariablesValues()
        {
            var mockFundsRepository       = new MockFundsRepository();
            var mockWithdrawRepository    = new MockWithdrawRepository();
            var mockBitcoinClientService  = new MockBitcoinClientService();
            var mockLitecoinClientService = new MockLitecoinClientService();
            ClientInteractionService clientInteractionService = new ClientInteractionService(mockFundsRepository, mockWithdrawRepository,
                                                                                             mockBitcoinClientService, mockLitecoinClientService);

            Withdraw withdraw = new Withdraw(new Currency("BTC", true), "123", DateTime.Now, WithdrawType.Bitcoin, 0.4m,
                                             0.001m, TransactionStatus.Pending,
                                             new AccountId(123), new BitcoinAddress("bitcoin123"));

            bool             eventFired       = false;
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            Withdraw         withdraw2        = null;

            clientInteractionService.WithdrawExecuted += delegate(Withdraw receivedWithdraw)
            {
                eventFired = true;
                withdraw2  = receivedWithdraw;
                manualResetEvent.Set();
            };
            bool commitWithdraw = clientInteractionService.CommitWithdraw(withdraw);

            Assert.IsTrue(commitWithdraw);
            clientInteractionService.CancelWithdraw(withdraw.WithdrawId);
            manualResetEvent.WaitOne(Convert.ToInt16(clientInteractionService.WithdrawSubmissionInterval));

            Assert.IsFalse(eventFired);
            Assert.IsNull(withdraw2);
        }
示例#5
0
        public void CommitWithdrawFailTest_ChecksThatWithdrawEventIsSubmittedAsExpectedToTheCoinClientService_VerifiesThroughVariablesValues()
        {
            var mockFundsRepository       = new MockFundsRepository();
            var mockWithdrawRepository    = new MockWithdrawRepository();
            var mockBitcoinClientService  = new MockBitcoinClientService();
            var mockLitecoinClientService = new MockLitecoinClientService();
            ClientInteractionService clientInteractionService = new ClientInteractionService(mockFundsRepository, mockWithdrawRepository,
                                                                                             mockBitcoinClientService, mockLitecoinClientService);

            Withdraw withdraw = null;

            clientInteractionService.CommitWithdraw(withdraw);
        }
示例#6
0
        public void NewAddressForLtcTest_ChecksThatNewAddressIsCreatedAndReturnedProperly_VerifiesThroughRaisedEvents()
        {
            var mockFundsRepository       = new MockFundsRepository();
            var mockWithdrawRepository    = new MockWithdrawRepository();
            var mockBitcoinClientService  = new MockBitcoinClientService();
            var mockLitecoinClientService = new MockLitecoinClientService();
            ClientInteractionService clientInteractionService = new ClientInteractionService(mockFundsRepository, mockWithdrawRepository,
                                                                                             mockBitcoinClientService, mockLitecoinClientService);

            string newAddress = clientInteractionService.GenerateNewAddress("LTC");

            Assert.IsTrue(!string.IsNullOrEmpty(newAddress));
        }
        public void WithdrawConfirmedTest_TestIfWithdrawalConfirmationExecutesAsExpected_TestsThroughReturnedValue()
        {
            var mockFundsRepository                = new MockFundsRepository();
            var mockBalanceRepository              = new MockBalanceRepository();
            var mockFeeCalculationService          = new MockFeeCalculationService();
            var mockWithdrawFeesRepository         = new MockWithdrawFeesRepository();
            var mockWithdrawIdGeneratorService     = new MockWithdrawIdGeneratorService();
            var depositLimitEvaluationService      = new DepositLimitEvaluationService();
            var mockLedgerRepository               = new MockLedgerRepository();
            var mockDepositLimitRepository         = new MockDepositLimitRepository();
            var mockWithdrawLimitEvaluationService = new WithdrawLimitEvaluationService();
            var mockWithdrawLimitRepository        = new MockWithdrawLimitRepository();
            var mockTierLevelRetrievalService      = new MockTierLevelRetrievalService();
            var mockWithdrawRepository             = new MockWithdrawRepository();
            var tierValidationService              = new TierValidationService();
            var mockBboRetrievalService            = new MockBboRetrievalService();
            var mockLimitsConfigurationService     = new LimitsConfigurationService(mockDepositLimitRepository,
                                                                                    depositLimitEvaluationService, mockWithdrawLimitRepository, mockWithdrawLimitEvaluationService, mockBboRetrievalService);
            TransactionService transactionService = new TransactionService(mockFundsRepository, new MockLedgerGeneratorService(),
                                                                           mockLimitsConfigurationService);
            FundsValidationService fundsValidationService = new FundsValidationService(transactionService,
                                                                                       mockFundsRepository, mockBalanceRepository, mockFeeCalculationService, mockWithdrawFeesRepository,
                                                                                       mockWithdrawIdGeneratorService, mockLedgerRepository, depositLimitEvaluationService,
                                                                                       mockDepositLimitRepository, mockWithdrawLimitEvaluationService, mockWithdrawLimitRepository,
                                                                                       mockTierLevelRetrievalService, mockWithdrawRepository, tierValidationService, mockLimitsConfigurationService);
            Withdraw withdraw = new Withdraw(new Currency("XBT", true), "123", DateTime.Now, WithdrawType.Bitcoin, 0.4m,
                                             0.001m, TransactionStatus.Pending,
                                             new AccountId(123), new BitcoinAddress("bitcoin123"));

            Balance balance = new Balance(withdraw.Currency, withdraw.AccountId, 400, 800);

            mockBalanceRepository.AddBalance(balance);

            Withdraw withdrawalResponse = fundsValidationService.ValidateFundsForWithdrawal(withdraw.AccountId,
                                                                                            withdraw.Currency, withdraw.Amount, withdraw.TransactionId, withdraw.BitcoinAddress);

            Assert.IsNotNull(withdrawalResponse);
            bool withdrawalExecuted = fundsValidationService.WithdrawalExecuted(withdrawalResponse);

            Assert.IsTrue(withdrawalExecuted);

            Assert.AreEqual(5, mockFundsRepository.GetNumberOfObjects());
        }
        public void DepositAmountTest_TestsIfDepositTransactionProceedsAsExpected_VerifiesThroughReturnedValue()
        {
            var mockDepositIdGeneratorService      = new MockDepositIdGeneratorService();
            var mockDepositRepository              = new MockDepositRepository();
            var mockFundsRepository                = new MockFundsRepository();
            var mockBalanceRepository              = new MockBalanceRepository();
            var mockFeeCalculationService          = new MockFeeCalculationService();
            var mockWithdrawFeesRepository         = new MockWithdrawFeesRepository();
            var mockWithdrawIdGeneratorService     = new MockWithdrawIdGeneratorService();
            var depositLimitEvaluationService      = new DepositLimitEvaluationService();
            var mockLedgerRepository               = new MockLedgerRepository();
            var mockDepositLimitRepository         = new MockDepositLimitRepository();
            var mockWithdrawLimitEvaluationService = new WithdrawLimitEvaluationService();
            var mockWithdrawLimitRepository        = new MockWithdrawLimitRepository();
            var mockTierLevelRetrievalService      = new MockTierLevelRetrievalService();
            var mockWithdrawRepository             = new MockWithdrawRepository();
            var tierValidationService              = new TierValidationService();
            var mockBboRetrievalService            = new MockBboRetrievalService();
            var mockLimitsConfigurationService     = new LimitsConfigurationService(mockDepositLimitRepository,
                                                                                    depositLimitEvaluationService, mockWithdrawLimitRepository, mockWithdrawLimitEvaluationService, mockBboRetrievalService);
            TransactionService transactionService = new TransactionService(mockFundsRepository, new MockLedgerGeneratorService(),
                                                                           mockLimitsConfigurationService);
            FundsValidationService fundsValidationService = new FundsValidationService(transactionService,
                                                                                       mockFundsRepository, mockBalanceRepository, mockFeeCalculationService, mockWithdrawFeesRepository,
                                                                                       mockWithdrawIdGeneratorService, mockLedgerRepository, depositLimitEvaluationService,
                                                                                       mockDepositLimitRepository, mockWithdrawLimitEvaluationService, mockWithdrawLimitRepository,
                                                                                       mockTierLevelRetrievalService, mockWithdrawRepository, tierValidationService, mockLimitsConfigurationService);
            Balance balance = new Balance(new Currency("XBT", true), new AccountId(123), 100, 100);

            mockBalanceRepository.AddBalance(balance);

            Deposit deposit = new Deposit(balance.Currency, mockDepositIdGeneratorService.GenerateId(), DateTime.Now,
                                          DepositType.Default, 1.5m, 0, TransactionStatus.Pending, balance.AccountId, new TransactionId("123"),
                                          new BitcoinAddress("123"));

            deposit.IncrementConfirmations(7);
            mockDepositRepository.Save(deposit);
            bool response = fundsValidationService.DepositConfirmed(deposit);

            Assert.IsTrue(response);
            // 3 Object: 1 = Balance, 2 = Deposit, 3 = Ledger
            Assert.AreEqual(3, mockFundsRepository.GetNumberOfObjects());
        }