Example #1
0
        public void Execute_FromAccountLowBalance_NotifyFundsLow()
        {
            // Arrange
            Guid from = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00");

            var fromAccount = new App.Account
            {
                Id   = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00"),
                User = new App.User()
                {
                    Id = new Guid("12223344-5566-7788-99AA-BBCCDDEEFF00"), Name = "Test1", Email = "*****@*****.**"
                },
                Balance   = 500,
                Withdrawn = 50,
                PaidIn    = 50
            };

            _iAccountRepository.Setup(x => x.GetAccountById(from)).Returns(fromAccount);

            // Act
            Assert.DoesNotThrow(() => _withdrawMoney.Execute(from, 50));

            // Assert
            _notificationService.Verify(service => service.NotifyFundslow("*****@*****.**"), Times.Once);
            _iAccountRepository.Verify(service => service.Update(fromAccount), Times.Once);
        }
        public void Execute_ValidDetails_Success()
        {
            // Arrange
            Guid from = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00");
            Guid to   = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF01");

            var fromAccount = new App.Account
            {
                Id   = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00"),
                User = new App.User()
                {
                    Id = new Guid("12223344-5566-7788-99AA-BBCCDDEEFF00"), Name = "Test1", Email = "*****@*****.**"
                },
                Balance   = 500,
                Withdrawn = 50,
                PaidIn    = 50
            };

            var toAccount = new App.Account
            {
                Id   = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF01"),
                User = new App.User()
                {
                    Id = new Guid("12223344-5566-7788-99AA-BBCCDDEEFF01"), Name = "Test1", Email = "*****@*****.**"
                },
                Balance   = 100,
                Withdrawn = 50,
                PaidIn    = 3000
            };

            _iAccountRepository.Setup(x => x.GetAccountById(from)).Returns(fromAccount);
            _iAccountRepository.Setup(x => x.GetAccountById(to)).Returns(toAccount);

            // Act
            Assert.DoesNotThrow(() => _transferMoney.Execute(from, to, 50));

            // Assert

            _iAccountRepository.Verify(service => service.Update(toAccount), Times.Once);
            _iAccountRepository.Verify(service => service.Update(fromAccount), Times.Once);
        }
        public void Execute_ToAccountPaidInLimit_InvalidOperationException()
        {
            // Arrange
            Guid from = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00");
            Guid to   = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF01");

            var fromAccount = new App.Account
            {
                Id   = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00"),
                User = new App.User()
                {
                    Id = new Guid("12223344-5566-7788-99AA-BBCCDDEEFF00"), Name = "Test1", Email = "*****@*****.**"
                },
                Balance   = 500,
                Withdrawn = 50,
                PaidIn    = 50
            };

            var toAccount = new App.Account
            {
                Id   = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF01"),
                User = new App.User()
                {
                    Id = new Guid("12223344-5566-7788-99AA-BBCCDDEEFF01"), Name = "Test1", Email = "*****@*****.**"
                },
                Balance   = 100,
                Withdrawn = 50,
                PaidIn    = 5000
            };

            _iAccountRepository.Setup(x => x.GetAccountById(from)).Returns(fromAccount);
            _iAccountRepository.Setup(x => x.GetAccountById(to)).Returns(toAccount);

            // Act
            Assert.Throws <InvalidOperationException>(() => _transferMoney.Execute(from, to, 50));

            // Assert

            _iAccountRepository.Verify(service => service.Update(null), Times.Never);
        }