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