public static void Main(string[] args) { var userInterface = new UserInterface(); if (!userInterface.AreInputsValid(args)) { userInterface.DisplayUsageMessage(); } var file = args[0]; var amount = int.Parse(args[1]); var appSettings = new AppSettings(); var marketDataDataAccess = new MarketDataDataAccess(new FileSystem(), appSettings, file); try { var marketData = marketDataDataAccess.ReadAllMarketData(); var loanCalculator = new LoanCalculator(marketData, appSettings, amount); var quote = loanCalculator.Calculate(); userInterface.DisplayQuote(quote); } catch (Exception e) { userInterface.DisplayExceptionMessage(e); } }
public void ReadAllMarketData_WhenFileDoesntExist_ThrowsException() { var fileSystem = new FileSystem(); var marketDataDataAccess = new MarketDataDataAccess(fileSystem, _appSettingsMock.Object, FileName); Action action = () => marketDataDataAccess.ReadAllMarketData(); action.ShouldThrow <FileNotFoundException>(); }
public void ReadAllMarketData_WhenNoData_ThrowsException() { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { FileName, new MockFileData("") } }); var marketDataDataAccess = new MarketDataDataAccess(fileSystem, _appSettingsMock.Object, FileName); Action action = () => marketDataDataAccess.ReadAllMarketData(); action.ShouldThrow <CsvFileEmptyException>().WithMessage("The CSV file is empty."); }
public void ReadAllMarketData_WhenNoLendersExist_ThrowsException() { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { FileName, new MockFileData("Lender,Rate,Available") } }); var marketDataDataAccess = new MarketDataDataAccess(fileSystem, _appSettingsMock.Object, FileName); Action action = () => marketDataDataAccess.ReadAllMarketData(); action .ShouldThrow <CsvFileNoLendersException>() .WithMessage("The CSV file contains no lenders."); }
public void ReadAllMarketData_WhenDataCorrupt_ThrowsException(string problemLines) { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { FileName, new MockFileData("Lender,Rate,Available" + Environment.NewLine + problemLines) } }); var marketDataDataAccess = new MarketDataDataAccess(fileSystem, _appSettingsMock.Object, FileName); Action action = () => marketDataDataAccess.ReadAllMarketData(); action .ShouldThrow <CsvFileCorruptionException>() .WithMessage($"The CSV file is corrupt at this row: '{GetLastLine(problemLines)}'."); }
public void ReadAllMarketData_WhenHeaderCorrupt_ThrowsException(string header) { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { FileName, new MockFileData(header) } }); var marketDataDataAccess = new MarketDataDataAccess(fileSystem, _appSettingsMock.Object, FileName); Action action = () => marketDataDataAccess.ReadAllMarketData(); action .ShouldThrow <CsvHeaderCorruptionException>() .WithMessage($"The header of the CSV file is corrupt: '{header}'."); }
public void ReadAllMarketData_WhenDataExists_LoadsAllData(string lenders) { var fileSystem = new MockFileSystem(new Dictionary <string, MockFileData> { { FileName, new MockFileData("Lender,Rate,Available" + Environment.NewLine + lenders) } }); _expectedLenders.Add(new Lender("Lender 1", 0.015m, 100)); _expectedLenders.Add(new Lender("Lender 2", 0.05m, 1000)); var marketDataDataAccess = new MarketDataDataAccess(fileSystem, _appSettingsMock.Object, FileName); var result = marketDataDataAccess.ReadAllMarketData(); result.ShouldBeEquivalentTo(_expectedLenders); }