示例#1
0
        [InlineData(4, 1)] //2.7
        public void TC2_3To2_7True(int currentLoans, int countToBorrow)
        {
            //Arrange
            var lc = new LoanLogic(null, null, null);

            for (var i = 1; i <= currentLoans; i++)
            {
                PersonCurrentNoLoans.Card.Loans.Add(new Loan
                {
                    IsActive = true,
                    Copies   = new List <Copy>
                    {
                        new Copy {
                            Barcode = i, IsAvailable = false
                        }
                    }
                });
            }

            //Act
            var result = lc.CanBorrow(PersonCurrentNoLoans.Card, countToBorrow);

            //Assert
            Assert.True(result);
        }
        public void MakePayment_Pass_PaymentCorrect()
        {
            // Arrange
            Repository repo           = new Repository();
            var        mockRepository = new Mock <ILoanModelDAL>();

            PaymentModel pay = new PaymentModel();

            pay.LoanID        = 1;
            pay.PaymentAmount = 75;

            LoanModel loan = new LoanModel();

            loan.LoanID = 1;
            loan.Amount = 100;

            int id = 1;

            // tell the mock that when LoanSelectByID is called,
            // return the specified Loan
            mockRepository.Setup(cr => cr.LoanSelectByID(id)).Returns(loan);

            // pass the mocked instance, not the mock itself, to the category
            // controller using the Object property
            repo.iLoanModelDAL = mockRepository.Object;

            // Act
            LoanLogic loanLogic = new LoanLogic(repo);
            bool      result    = loanLogic.AttemptPayment(pay);

            // Assert
            Assert.IsTrue(result);
        }
示例#3
0
        // TODO -- Load(<Person>) button


        private void generateReportButton_Click(object sender, EventArgs e)
        {
            MessageBox.Show("OPTION SELECTED = " + $"{(formType)calculationTypeSelector.SelectedIndex}");

            formType index = (formType)calculationTypeSelector.SelectedIndex;


            if (ValidateForm(index))
            {
                LoanModel loan = new LoanModel(
                    totalAmountValue.Text,
                    aprValue.Text,
                    calculationTypeValue.Text);

                // TODO --- Add loan to List<Loans> for <Person>

                decimal totalInterestPaid = (loan.LoanAmount * ((decimal)loan.Apr / 100));
                minimumMonthlyPaymentValue.Text = LoanLogic.calculateMinimumPayment(loan).ToString();
                totalInterestPaidValue.Text     = totalInterestPaid.ToString();
                totalAmountPaidValue.Text       = (loan.LoanAmount + totalInterestPaid).ToString();
                minimumMonthlyPaymentLabel.Text = "Minimum Monthly Payment:";

                MakeCalculationsVisible();

                // TODO -- MAKE TEST CONNECTION
            }

            else
            {
                MessageBox.Show("This from has invalid information. Please check for valid input.");
            }
        }
示例#4
0
        public ActionResult MakePayment(PaymentModel pay)
        {
            LoanLogic loanLogic = new LoanLogic(repo);

            ViewBag.PaymentResult = loanLogic.AttemptPayment(pay);

            return(View(pay));
        }
示例#5
0
        public void TC4_1_False()
        {
            //Arrange
            var lc = new LoanLogic(null, null, null);

            //Act
            var result = lc.IsCardExpired(Person.Card);

            //Assert
            Assert.False(result);
        }
示例#6
0
        //Code adapted from Art of Unit Testing
        public ActionResult LogAnalyzer()
        {
            LoanLogic loanLogic = new LoanLogic(repo);

            string fileName = string.Format("{0}", "hmm.foo");

            //bool original = loanLogic.IsValidLogFileName(fileName);
            bool refactored = loanLogic.IsValidLogFileNameREFACTORED(fileName);


            return(View());
        }
示例#7
0
        public void TC4_1_True()
        {
            //Arrange
            var lc = new LoanLogic(null, null, null);

            Person.Card.Expires = DateTime.Now.AddDays(-1);

            //Act
            var result = lc.IsCardExpired(Person.Card);

            //Assert
            Assert.True(result);
        }
示例#8
0
        public void TC5_1(bool type, int addDays)
        {
            //Arrange
            var lc = new LoanLogic(null, null, null);

            Person.IsProfessor = type;
            var expectedDueDate = DateTime.Now.AddDays(addDays).Date;

            //Act
            var calculatedDueDate = lc.CalculateDueDate(Person, Lib.Library);

            //Assert
            Assert.Equal(expectedDueDate, calculatedDueDate.Date);
        }
        public void LogAnalyzer_ValidFileName_Pass()
        {
            // Arrange
            IFileExtensionManager manager   = new AlwaysValidFakeExtensionManager();
            LoanLogic             loanLogic = new LoanLogic(manager);

            string foo    = "kung.foo";
            bool   result = false;

            // Act
            result = loanLogic.IsValidLogFileNameREFACTORED(foo);

            // Assert
            Assert.IsTrue(result);
        }
        public void CalculatePayment_ThrowError_Fail()
        {
            // Arrange
            Repository repo           = new Repository();
            var        mockRepository = new Mock <ILoanModelDAL>();

            PaymentModel pay = null;

            try
            {
                LoanLogic loanLogic = new LoanLogic(repo);
                bool      result    = loanLogic.CalculatePayment(pay);
                Assert.Fail("no exception thrown");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message == "TestError");
            }
        }
示例#11
0
        public void TC1_4()
        {
            //Arrange
            var loanRepos = new Mock <ILoanRepos <Loan> >();
            var cardRepos = new Mock <ICardRepos <Card> >();
            var userRepos = new Mock <IUserRepos <Person> >();

            loanRepos.Setup(x => x.CheckForStatusOnCopy(It.IsAny <Copy>())).Returns(true);
            loanRepos.Setup(x => x.Create(It.IsAny <Loan>())).Returns((Loan loan) => loan);
            cardRepos.Setup(x => x.Get(It.IsAny <Card>())).Returns(Person.Card);
            userRepos.Setup(x => x.GetUserByCardID(1)).Returns(Person);
            userRepos.Setup(x => x.GetLibrarianById(1)).Returns(Lib);
            var lc = new LoanLogic(loanRepos.Object, cardRepos.Object, userRepos.Object);

            //Act
            var createdLoan = lc.CreateLoan(1, 5, 0, 0, 0, 0, 1);

            //Assert
            Assert.True(createdLoan.StartDate == DateTime.Now.Date);
        }
示例#12
0
        public void TC3_3()
        {
            //Arrange
            Loan loan      = new Loan();
            var  loanRepos = new Mock <ILoanRepos <Loan> >();
            var  cardRepos = new Mock <ICardRepos <Card> >();
            var  userRepos = new Mock <IUserRepos <Person> >();

            loanRepos.Setup(x => x.CheckForStatusOnCopy(It.IsAny <Copy>())).Returns(false);
            loanRepos.Setup(x => x.Create(loan)).Returns(loan);
            cardRepos.Setup(x => x.Get(It.IsAny <Card>())).Returns(Person.Card);
            userRepos.Setup(x => x.GetUserByCardID(1)).Returns(Person);
            userRepos.Setup(x => x.GetLibrarianById(1)).Returns(Lib);
            var lc = new LoanLogic(loanRepos.Object, cardRepos.Object, userRepos.Object);

            //Act
            var createdLoan = lc.CreateLoan(1, 5, 0, 0, 0, 0, 1);

            //Assert
            Assert.NotNull(createdLoan.ErrorMessage);
        }
示例#13
0
 public LoanController()
 {
     loanLogic   = new LoanLogic();
     personLogic = new PersonLogic();
 }