Esempio n. 1
0
        public void Fail_Null_CreditCard()
        {
            var calculator = new SimpleInterestCalculator(CardRepo);

            var nullCards =
                new Person
            {
                Wallets =
                    new List <Wallet>
                {
                    new Wallet
                    {
                        Cards =
                            new List <CreditCard>
                        {
                            null,
                        },
                    }
                },
            };

            Assert.Throws(
                Is.TypeOf <ArgumentException>()
                .And.Message.EqualTo("Cannot have null credit cards"),
                () =>
            {
                var calculation = calculator.Calculate(nullCards);
            });
        }
Esempio n. 2
0
        public void Fail_Missing_InterestRate()
        {
            var calculator = new SimpleInterestCalculator(CardRepo_Incomplete);

            var person =
                new Person
            {
                Wallets =
                    new List <Wallet>
                {
                    new Wallet
                    {
                        Cards =
                            new List <CreditCard>
                        {
                            CreditCardType.MasterCard,
                        },
                    }
                },
            };

            Assert.Throws(
                Is.TypeOf <ArgumentException>()
                .And.Message.EqualTo("Interest rate(s) do not exist for: MasterCard"),
                () =>
            {
                var calculation = calculator.Calculate(person);
            });
        }
Esempio n. 3
0
        public void Calculate_ForPerson(int personId, decimal interestRate)
        {
            var person = GetPerson(personId);

            var calculation = SimpleInterestCalculator.Calculate(person);

            Assert.AreEqual(calculation, interestRate);
        }
Esempio n. 4
0
        public void Calculate_ByWallet_(int walletId, decimal interestRate)
        {
            var wallet = GetWallet(Person1, walletId);

            Assert.IsNotNull(wallet);

            var calculation = SimpleInterestCalculator.Calculate(wallet);

            Assert.AreEqual(calculation, interestRate);
        }
Esempio n. 5
0
        public IActionResult Index(SimpleInterestCalculator model)
        {
            SetViewBagValues();
            if (!ModelState.IsValid)
            {
                return(View());
            }

            model.TotalAccrued = model.CalculateAccruedAmount();
            return(View(model));
        }
Esempio n. 6
0
        public void Fail_Null_Resolvers()
        {
            var calculator = new SimpleInterestCalculator(CardRepo);

            Assert.Throws(
                Is.TypeOf <ArgumentNullException>()
                .And.Message.EqualTo("Value cannot be null. (Parameter 'resolvers')"),
                () =>
            {
                var calculation = calculator.Calculate(null);
            });
        }
Esempio n. 7
0
        public void Calculate_ByCard_(CreditCardType cardType, decimal interestRate)
        {
            Assert.IsNotNull(Wallet1);
            Assert.AreNotEqual(cardType, CreditCardType.Unknown);

            var creditCard = GetCard(Wallet1, cardType);

            Assert.IsNotNull(creditCard);

            var calculation = SimpleInterestCalculator.Calculate(creditCard);

            Assert.AreEqual(calculation, interestRate);
        }
Esempio n. 8
0
        public void Fail_Null_CardRepo()
        {
            var calculator = new SimpleInterestCalculator(null);

            var validData = TestDataFactory.GetData(1).people.ToArray();

            Assert.Throws(
                Is.TypeOf <NullReferenceException>()
                .And.Message.EqualTo("CardRepo is null"),
                () =>
            {
                var calculation = calculator.Calculate(validData);
            });
        }
        public void SimpleInterestCalculator_CalculateInterestGivesZeroNewPrincipal()
        {
            // Arrange
            var startingPrincipal = 100.0;
            var rate     = 0.15;
            var expected = 0.0;
            var target   = new SimpleInterestCalculator();
            PrincipalInterestBalance result;
            double actual;

            // Act
            result = target.CalculateInterest(startingPrincipal, rate, 1);
            actual = result.Principal;

            // Assert
            Assert.AreEqual(expected, actual, 0.0000001);
        }
Esempio n. 10
0
        public void Calculate_ForPerson()
        {
            var calculation = SimpleInterestCalculator.Calculate(Person1);

            Assert.AreEqual(calculation, 16.0M);
        }