Esempio n. 1
0
        public int GetOrCreateBitcoinWithdrawAccount(Guid sessionId, string currencyId, string receiveAddress)
        {
            using (var context = this.GetContext())
            {
                var userId = this.VerifySession(sessionId);

                using (var scope = new TransactionScope())
                {
                    var account =
                        context.Accounts.Where(
                            x =>
                            x.BitcoinWithdrawAccount != null && x.CurrencyId == currencyId
                            && x.BitcoinWithdrawAccount.ReceiveAddress == receiveAddress
                            && x.Users.Any(u => u.UserId == userId && u.CanDeposit)).FirstOrDefault();

                    if (account == null)
                    {
                        account = new Account
                            {
                                AccountType = "BitcoinWithdraw",
                                AnyCanDeposit = false,
                                CurrencyId = currencyId,
                                DisplayName = null,
                                BitcoinWithdrawAccount = new BitcoinWithdrawAccount
                                    {
                                        ReceiveAddress = receiveAddress
                                    },
                                Users =
                                    new List<AccountUser>
                                        {
                                            new AccountUser { UserId = userId, CanDeposit = true, CanWithdraw = false }
                                        }
                            };

                        context.Accounts.Add(account);
                        context.SaveChanges();
                    }

                    scope.Complete();

                    return account.AccountId;
                }
            }
        }
Esempio n. 2
0
        public void GetAccountDoesNotThrowException()
        {
            // Arrange
            var sessionId = Guid.NewGuid();
            var accountId = 1;
            var userId = 3;
            var displayName = default(string);
            var currencyId = "BTC";

            var mockContext = new Mock<IOliveContext>();
            mockContext.Setup(c => c.VerifySession(sessionId)).Returns(userId);

            var mockDbSet = new Mock<DataAccess.Tests.MockDbSet<Account>>();
            mockDbSet.CallBase = true;
            var account = new Account
                { AccountId = accountId, AccountType = "Current", CurrencyId = currencyId, DisplayName = displayName };
            mockDbSet.Object.Add(account);
            mockDbSet.Setup(db => db.Find(accountId)).Returns(account);

            mockContext.SetupGet(c => c.Accounts).Returns(mockDbSet.Object);
            this.container.RegisterInstance(mockContext.Object);

            var service = this.GetMockClientService();
            Mock.Get(service).Setup(s => s.UserCanViewAccount(userId, accountId)).Returns(true);

            // Act
            service.GetAccount(sessionId, accountId);

            // Assert
            mockContext.VerifyGet(c => c.Accounts, Times.Once());
            mockContext.Verify(c => c.VerifySession(sessionId), Times.Once());
            Mock.Get(service).Verify(s => s.UserCanViewAccount(userId, accountId), Times.Once());
        }