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);
        }
        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());
        }