Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int loanTerm = 36;
            int numberOfPaymentsPerYear = 12;

            var fileReader = new FileReader();

            var inputIsValid = new InputValidator(fileReader).IsInputValid(args);

            if (!inputIsValid)
            {
                Console.WriteLine("The provided filename or the loan amount is invalid!");
                Console.WriteLine("Ex.: cmd> quote.exe [market_file] [loan_amount]");
                Console.WriteLine("Please press a button to exit");
                Console.ReadLine();
                Environment.Exit(1);
            }

            var fileName   = args[0];
            int loanAmount = int.Parse(args[1]);

            LendersManager lendersMgr = new LendersManager(fileReader, new Calculator(), fileName);

            var quote = lendersMgr.GetBestQuote(loanAmount, loanTerm, numberOfPaymentsPerYear);

            quote.Print(Console.Write);

            Console.ReadLine();
        }
Exemplo n.º 2
0
        public void Load_InputFileNotSuccessfullyLoaded_MissingData_Test()
        {
            //Arrange
            var    loanAmount = 1000;
            var    loanTerm   = 36;
            var    numberOfPaymentsPerYear = 12;
            string fileContent             =
                @"Lender,Rate,Available
Bob,0.075,6400
Jane,0.069,480
Fred,0.070,5200
Mary,0.104,1700
John,0.081,3200
Dave,0.074,
Angela,0.069,600";

            fileReaderMock.Setup(foo => foo.ReadLines("test.csv")).Returns(fileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.None));

            var lendersMgr = new LendersManager(fileReaderMock.Object, new Calculator(), "test.csv");

            //Act
            var result = lendersMgr.GetBestQuote(loanAmount, loanTerm, numberOfPaymentsPerYear);

            //Assert
            Assert.AreEqual("Error in the lenders file or the requested loan amount: \n\r Input string was not in a correct format.", result.ErrorMessage);
            Assert.AreEqual(true, result.HasError);
        }
Exemplo n.º 3
0
        public void Load_InputFileHasNoHeader_ThereforeSkippingBestOffer_Test()
        {
            //Arrange
            var    loanAmount = 1000;
            var    loanTerm   = 36;
            var    numberOfPaymentsPerYear = 12;
            string fileContent             =
                @"Bob,0.070,6400
Jane,0.069,480
Fred,0.078,5200
Mary,0.104,1700
John,0.081,3200
Dave,0.074,444
Angela,0.069,600";

            fileReaderMock.Setup(foo => foo.ReadLines("test.csv")).Returns(fileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.None));

            var lendersMgr = new LendersManager(fileReaderMock.Object, new Calculator(), "test.csv");

            //Act
            var result = lendersMgr.GetBestQuote(loanAmount, loanTerm, numberOfPaymentsPerYear);

            //Assert
            Assert.AreEqual(1000, result.LoanAmount);
            Assert.AreEqual(36, result.LoanTerm);
            Assert.AreEqual(31.12, Math.Round(result.MonthlyRepayment, 2));
            Assert.AreEqual(0.078, result.Rate);
        }
Exemplo n.º 4
0
        public void GetBestQuote_NoLenderWasFound_Test()
        {
            //Arrange
            var    loanAmount = 1000;
            var    loanTerm   = 36;
            var    numberOfPaymentsPerYear = 12;
            string fileContent             =
                @"Lender,Rate,Available
Bob,0.075,640
Jane,0.069,480
Fred,0.070,520
Mary,0.104,170
John,0.081,320
Dave,0.074,344
Angela,0.069,600";

            fileReaderMock.Setup(foo => foo.ReadLines("test.csv")).Returns(fileContent.Split(new string[] { Environment.NewLine }, StringSplitOptions.None));

            var lendersMgr = new LendersManager(fileReaderMock.Object, new Calculator(), "test.csv");

            //Act
            var result = lendersMgr.GetBestQuote(loanAmount, loanTerm, numberOfPaymentsPerYear);

            //Assert
            Assert.AreEqual("Error in the lenders file or the requested loan amount: \n\r It is not possible to provide a quote at this time!", result.ErrorMessage);
            Assert.AreEqual(true, result.HasError);
        }