Exemplo n.º 1
0
        public IActionResult PostCredit(string name, decimal creditRequestByUser)
        {
            if (String.IsNullOrWhiteSpace(name) || creditRequestByUser <= 0)
            {
                return(Content("Name or credit request is invalid. Try again."));
            }

            var customers = new List <Customer>();

            customers = GetCustomers();

            if (customers.Count == 0)
            {
                throw new InvalidOperationException("No customers found");
            }

            var foundCustomer = customers.Find(c => c.Nome == name);

            if (foundCustomer is null)
            {
                return(Content("No customer found"));
            }

            var creditRequestObj = new CreditRequest(name, creditRequestByUser);

            // It calculates the credit available based on Customer age and salary - then return a Credit object
            var creditObj = creditRequestObj.GetCredit(foundCustomer);

            return(Ok(creditObj));
        }
Exemplo n.º 2
0
        public void GetCredit_AgeGreaterThan80_ReturnsCredit20PercentOfSalary()
        {
            var customer = new Customer("Charles West", 83, 9126.0M);

            var creditRequest = new CreditRequest("Cristina Pereira", 2500.0M);
            var credit        = creditRequest.GetCredit(customer);

            Assert.AreEqual(1825.2, credit.CreditValueProvided);
        }
Exemplo n.º 3
0
        public void GetCredit_AgeGreaterThan50_ReturnsCredit70PercentOfSalary()
        {
            var customer = new Customer("Cristina Pereira", 54, 4845.0M);

            var creditRequest = new CreditRequest("Cristina Pereira", 2500.0M);
            var credit        = creditRequest.GetCredit(customer);

            Assert.AreEqual(3391.5, credit.CreditValueProvided);
            Assert.LessOrEqual(credit.ValueOfEachParcel, customer.Salario * 20 / 100);
        }
Exemplo n.º 4
0
        public void GetCredit_AgeGreaterThan30_ReturnsCredit80PercentOfSalary()
        {
            var customer = new Customer("Cristina Reeves", 35, 1933.0M);

            var creditRequest = new CreditRequest("Cristina Reeves", 2500.0M);
            var credit        = creditRequest.GetCredit(customer);

            Assert.AreEqual(1739.7, credit.CreditValueProvided);
            Assert.LessOrEqual(credit.ValueOfEachParcel, customer.Salario * 5 / 100);
        }
Exemplo n.º 5
0
        public void GetCredit_AgeGreaterThan20_ReturnsCredit100PercentOfSalary()
        {
            // Arrange
            var customer = new Customer("Andrea Marques", 25, 8236.0M);

            // Act
            var creditRequest = new CreditRequest("Andrea Marques", 2500.0M);
            var credit        = creditRequest.GetCredit(customer);

            // Assert
            Assert.AreEqual(8236.0, credit.CreditValueProvided);
            Assert.LessOrEqual(credit.ValueOfEachParcel, customer.Salario * 40 / 100);
        }