Пример #1
0
        public void Given_Customer_Should_BeAbleToWithdraw()
        {
            var repositoryMock = new Mock<IAccountRepository>();
            var serviceMock = new Mock<IAccountService>();
            var accountId = 123;
            var password = "******";
            var someAccountObj = new Account() { Id = accountId, Password = password };

            var amountToDeposit = 10000M;

            repositoryMock
                .Setup(it => it.DecrementBalance(It.IsAny<int>(), It.IsAny<decimal>()))
                .Returns(CompletedTask);

            repositoryMock.Setup(it => it.CheckPassword(It.IsAny<int>(), It.IsAny<String>()))
                .ReturnsAsync(true);

            serviceMock
                .Setup(it => it.Withdraw(It.IsAny<int>(), It.IsAny<String>(), It.IsAny<decimal>()))
                .ReturnsAsync(true);

            var service = new AccountService(repositoryMock.Object, null);

            var result = service.Withdraw(accountId, password, amountToDeposit).Result;

            result.Should().Be.True();
        }
Пример #2
0
 public async Task<int> InsertAccount(Account newAccount)
 {
     using (var context = new BaseContext())
     {
         context.Accounts.Add(newAccount);
         await context.SaveChangesAsync();
         return newAccount.Id;
     }
 }
Пример #3
0
 public Task<int> CreateNewAccount(string customerName, string initialPassword)
 {
     if (ValidateName(customerName) == false)
     {
         throw new InvalidCustomerNameException();
     }
     if (ValidatePassword(initialPassword) == false)
     {
         throw new InvalidPasswordException();
     }
     var newCustomer = _customerService.CreateCustomer(customerName);
     var newAccount = new Account() { Balance = 0.0M, Customer = newCustomer, Password = initialPassword };
     return _repository.InsertAccount(newAccount);
 }
Пример #4
0
        public void Given_NewUser_ShouldCreateAnAccount()
        {
            var newAccountId = 123;
            var newCustomerId = 321;
            var newCustomerInstance = new Customer(){Id = newCustomerId};
            var someAccountObj = new Account() { Customer = new Customer() { Id = newCustomerId } };

            _repositoryMock
                .Setup( it=>it.InsertAccount(It.IsAny<Account>()))
                .ReturnsAsync(newAccountId);

            _customerServiceMock.Setup(it => it.CreateCustomer(It.IsAny<String>()))
                .Returns(newCustomerInstance);

            var service =  new AccountService(_repositoryMock.Object, _customerServiceMock.Object);

            var result = service.CreateNewAccount(newCustomerName, customerInitialPassword).Result;

            result.Should().Be.EqualTo(newAccountId);
        }