Example #1
0
        public void GivenNotEnoughMoney_WhenTransfer_ThrowException()
        {
            //arrange
            Account account = new Account()
            {
                Id = 1, UserId = "1", Balance = 0
            };

            _accountRepoMock.Setup(x => x.ReadOne(It.IsAny <Expression <Func <Account, bool> > >()))
            .Returns(account)
            .Verifiable();

            _accountRepoMock.Setup(x => x.Read(It.IsAny <Expression <Func <Account, bool> > >()))
            .Returns((Expression <Func <Account, bool> > expression) =>
            {
                var result = AccountFakeDb.Where(expression);
                return(result);
            })
            .Verifiable();
            _accountRepoMock.Setup(x => x.CommitChanges()).Verifiable();

            _transactionRepoMock.Setup(a => a.Create(It.IsAny <TransactionHistory>())).Verifiable();

            //action
            Exception ex = Assert.Throws <Exception>(() => _accountService.TransferMoney(1, 1000, 2));

            //assert
            Assert.NotNull(ex);
            Assert.NotEmpty(ex.Message);
            Assert.Equal(0, account.Balance);
            _accountRepoMock.Verify(a => a.CommitChanges(), Times.Never);
            _transactionRepoMock.Verify(a => a.Create(It.IsAny <TransactionHistory>()), Times.Never);
            _accountRepoMock.Verify(a => a.ReadOne(It.IsAny <Expression <Func <Account, bool> > >()), Times.Exactly(2));
        }
Example #2
0
        public void GivenUnexistedAccount_WhenCheckExistedAccount_False(int?accountId, string userId, string password = "")
        {
            //arrange
            _accountRepoMock.Setup(a => a.Read(It.IsAny <Expression <Func <Account, bool> > >())).
            Returns((Expression <Func <Account, bool> > expression) =>
            {
                var data = AccountFakeDb.Where(expression);
                return(data);
            });
            //Action

            var result = _accountService.IsAccountExisted(accountId, userId, password);

            //assert
            Assert.Equal(false, result);
        }
Example #3
0
        public void GivenExistedAccountWithoutPassword_WhenCheckExistedAccount_True(int?accountId, string userId, string password = "")
        {
            //arrange
            Account foundEntity = new Account();

            _accountRepoMock.Setup(a => a.Read(It.IsAny <Expression <Func <Account, bool> > >())).
            Returns((Expression <Func <Account, bool> > exp) =>
            {
                var data    = AccountFakeDb.Where(exp);
                foundEntity = AccountFakeDb.First(exp);
                return(data);
            });
            //Action
            var result = _accountService.IsAccountExisted(accountId, userId, password);

            //assert
            Assert.Equal(true, result);
            Assert.True(foundEntity.Id == accountId &&
                        foundEntity.UserId == userId &&
                        foundEntity.Password != password);
        }