public void GivenAValidFileInput_WhenCallingFileReader_ThenDataIsAddedToRepositoryForEachPersonReturned() { // Arrange var expectedPeopleList = GetListOfPeopleFromFile(_fileLocation + InputFile); // Act _fileHandling.FileReader(_fileLocation + InputFile); // Assert foreach (var person in expectedPeopleList) { _mockPersonRepository.Verify(x => x.Add(It.Is <Person>(p => p.FirstName == person.FirstName && p.LastName == person.LastName)), Times.Once); } }
public void Run() { _consoleWrapper.WriteLine("**********************************************************************"); _consoleWrapper.WriteLine(""); _consoleWrapper.WriteLine(" Welcome to SortApplication. "); _consoleWrapper.WriteLine(""); _consoleWrapper.WriteLine(" Please type the word 'exit' when you want to stop the application."); _consoleWrapper.WriteLine(""); _consoleWrapper.WriteLine(" * For sorting a file specify a file name and sorting option, 'asc'."); _consoleWrapper.WriteLine(" -asc for ascending sorting"); _consoleWrapper.WriteLine(" -desc for descending sorting"); _consoleWrapper.WriteLine(" Example: fileName.txt -asc"); _consoleWrapper.WriteLine(""); while (true) // Loop indefinitely { _consoleWrapper.WriteLine("**********************************************************************"); _consoleWrapper.WriteLine(""); _consoleWrapper.WriteLine("Enter file name: "); _consoleWrapper.WriteLine(""); string userInput = _consoleWrapper.ReadLine(); if (userInput == "exit") { return; } var values = userInput.Split('-').Select(p => p.Trim()).ToList(); string fileName = values[0]; SortingOptions option = SortingOptions.Asc; if (values.Count > 1 && values[1].ToLowerInvariant() == SortingOptions.Desc.ToString().ToLowerInvariant()) { option = SortingOptions.Desc; } _consoleWrapper.WriteLine(""); if (!File.Exists(values[0])) { _consoleWrapper.WriteLine("The file '" + fileName + "' does not exist."); } else { try { _fileHandling.FileReader(fileName); _fileHandling.FileWriter(OutputFileName, option); _consoleWrapper.WriteLine("Finished: created '" + OutputFileName + "' that contains the sorted list."); } catch (Exception ex) { _consoleWrapper.WriteLine("An error occurred while processing the name list. Please, check the log file for more information."); _logger.WriteLog("An exception occurred in method 'Run' from 'AppLogic'", ex); } } _consoleWrapper.WriteLine(""); _consoleWrapper.WriteLine(""); } }