예제 #1
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);
        }
예제 #2
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);
        }
        public void LtcWithdrawTest_TestsThatWithdrawIsSuccessfullySubmittedByTheService_VerifiesByTheRaisedEvent()
        {
            // We will directly create Stub Implemenetations'instances as stubs are mentionedin configuration file in this project,
            // because we do not want the raised event to reach WithdrawApplicationService, so we would not inject services using
            // Spring DI.

            FundsPersistenceRepository fundsPersistenceRepository = new FundsPersistenceRepository();
            IWithdrawRepository        withdrawRepository         = new WithdrawRepository();
            ICoinClientService         bitcoinClientService       = new StubBitcoinClientService();
            ICoinClientService         litecoinClientService      = new StubLitecoinClientService();
            ClientInteractionService   clientInteractionService   = new ClientInteractionService(fundsPersistenceRepository,
                                                                                                 withdrawRepository, bitcoinClientService, litecoinClientService);

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

            clientInteractionService.WithdrawExecuted += delegate(Withdraw incomingWithdraw)
            {
                receivedWithdraw = incomingWithdraw;
                eventFired       = true;
                manualResetEvent.Set();
            };
            AccountId accountId = new AccountId(123);
            Currency  currency  = new Currency(CurrencyConstants.Ltc, true);
            decimal   amount    = 0.02M;
            Withdraw  withdraw  = new Withdraw(currency, "withdrawid123", DateTime.Now, WithdrawType.Litecoin, amount, 0.0001M,
                                               TransactionStatus.Pending, accountId, new BitcoinAddress("bitcoinaddress1"));
            bool commitWithdraw = clientInteractionService.CommitWithdraw(withdraw);

            Assert.IsTrue(commitWithdraw);
            manualResetEvent.WaitOne();

            Assert.IsTrue(eventFired);
            Assert.AreEqual(withdraw.Currency.Name, receivedWithdraw.Currency.Name);
            Assert.AreEqual(withdraw.AccountId.Value, receivedWithdraw.AccountId.Value);
            Assert.AreEqual(withdraw.BitcoinAddress.Value, receivedWithdraw.BitcoinAddress.Value);
            Assert.AreEqual(withdraw.Fee, receivedWithdraw.Fee);
            Assert.AreEqual(TransactionStatus.Pending, receivedWithdraw.Status);
            Assert.IsNotNull(receivedWithdraw.TransactionId);
            Assert.AreEqual(withdraw.Type, receivedWithdraw.Type);
            Assert.AreEqual(withdraw.Amount, receivedWithdraw.Amount);
            Assert.AreEqual(withdraw.WithdrawId, receivedWithdraw.WithdrawId);
        }
        public void BtcDepositConfirmedTest_TestsThatDepositArrivedAndDepositConfirmedEventsAreRaisedFromTheClient_VerifiesByHandlingEvent()
        {
            // We will directly create Stub Implemenetations'instances as stubs are mentionedin configuration file in this project,
            // because we do not want the raised event to reach WithdrawApplicationService, so we would not inject services using
            // Spring DI.

            FundsPersistenceRepository fundsPersistenceRepository = new FundsPersistenceRepository();
            IWithdrawRepository        withdrawRepository         = new WithdrawRepository();
            ICoinClientService         bitcoinClientService       = new StubBitcoinClientService();
            ICoinClientService         litecoinClientService      = new StubLitecoinClientService();
            ClientInteractionService   clientInteractionService   = new ClientInteractionService(fundsPersistenceRepository,
                                                                                                 withdrawRepository, bitcoinClientService, litecoinClientService);

            // Event handling for Deposit Arrived Event
            bool             depositArrivedEventFired = false;
            ManualResetEvent depositManualResetEvent  = new ManualResetEvent(false);
            string           receivedCurrency         = null;

            clientInteractionService.DepositArrived += delegate(string incomingCurrency, List <Tuple <string, string, decimal, string> > arg2)
            {
                depositArrivedEventFired = true;
                receivedCurrency         = incomingCurrency;
            };

            bool   depositConfirmedEventFired = false;
            string receivedTransactionId      = null;

            clientInteractionService.DepositConfirmed += delegate(string arg1, int arg2)
            {
                receivedTransactionId      = arg1;
                depositConfirmedEventFired = true;
                depositManualResetEvent.Set();
            };

            // Event handling for Withdraw Executed Event
            bool             eventFired       = false;
            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            Withdraw         receivedWithdraw = null;

            clientInteractionService.WithdrawExecuted += delegate(Withdraw incomingWithdraw)
            {
                receivedWithdraw = incomingWithdraw;
                eventFired       = true;
                manualResetEvent.Set();
            };
            AccountId accountId = new AccountId(123);
            Currency  currency  = new Currency(CurrencyConstants.Btc, true);
            decimal   amount    = 0.02M;
            Withdraw  withdraw  = new Withdraw(currency, "withdrawid123", DateTime.Now, WithdrawType.Bitcoin, amount, 0.0001M,
                                               TransactionStatus.Pending, accountId, new BitcoinAddress("bitcoinaddress1"));
            bool commitWithdraw = clientInteractionService.CommitWithdraw(withdraw);

            Assert.IsTrue(commitWithdraw);
            manualResetEvent.WaitOne();
            depositManualResetEvent.WaitOne();

            Assert.IsTrue(eventFired);
            Assert.AreEqual(withdraw.Currency.Name, receivedWithdraw.Currency.Name);
            Assert.AreEqual(withdraw.AccountId.Value, receivedWithdraw.AccountId.Value);
            Assert.AreEqual(withdraw.BitcoinAddress.Value, receivedWithdraw.BitcoinAddress.Value);
            Assert.AreEqual(withdraw.Fee, receivedWithdraw.Fee);
            Assert.AreEqual(TransactionStatus.Pending, receivedWithdraw.Status);
            Assert.IsNotNull(receivedWithdraw.TransactionId);
            Assert.AreEqual(withdraw.Type, receivedWithdraw.Type);
            Assert.AreEqual(withdraw.Amount, receivedWithdraw.Amount);
            Assert.AreEqual(withdraw.WithdrawId, receivedWithdraw.WithdrawId);

            Assert.IsTrue(depositArrivedEventFired);
            Assert.AreEqual(CurrencyConstants.Btc, receivedCurrency);

            Assert.IsTrue(depositConfirmedEventFired);
            Assert.AreEqual(receivedWithdraw.TransactionId.Value, receivedTransactionId);
        }