Exemplo n.º 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();
        }
Exemplo n.º 2
0
        public void Given_InvalidUserName_ShouldThrow()
        {
            var service = new AccountService(_repositoryMock.Object, _customerServiceMock.Object);

            Executing.This(() => service.CreateNewAccount(newInvalidCustomerName, customerInitialPassword))
                .Should().Throw<InvalidCustomerNameException>();
        }
Exemplo n.º 3
0
        public void Given_InvalidPassword_ShouldThrow_InvalidPasswordException()
        {
            var service = new AccountService(_repositoryMock.Object, _customerServiceMock.Object);

            Executing.This(() => service.CreateNewAccount(newCustomerName, invalidPassowrd))
                .Should().Throw<InvalidPasswordException>();
        }
Exemplo n.º 4
0
        public void Setup()
        {
            _repositoryMock = new Mock<IAccountRepository>();
            _invalidPassword = String.Empty;
            _invalidAccount = default(int);
            _amountToDeposit = default(decimal);

            _repositoryMock.Setup(it => it.CheckPassword(It.IsAny<int>(), It.IsAny<String>())).ReturnsAsync(false);
            _service = new AccountService(_repositoryMock.Object, null);
        }
Exemplo n.º 5
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);
        }