public void GivenDataInTheRepositoryAndSortingOptionIsAscending_WhenCallingFileWriter_ThenDataIsWrittenToAFile() { // Arrange var expectedPeopleList = GetListOfPeopleFromFile(_fileLocation + ExpectedSortedByAscending); _mockPersonRepository.Setup(m => m.GetPeopleByNamesAscending()).Returns(expectedPeopleList); // Act _fileHandling.FileWriter(_fileLocation + OutputFile, SortingOptions.Asc); // Assert _mockPersonRepository.Verify(m => m.GetPeopleByNamesAscending()); var actualPeopleList = GetListOfPeopleFromFile(_fileLocation + OutputFile); CollectionAssert.AreEqual(expectedPeopleList.ToList(), actualPeopleList.ToList(), Comparer()); }
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(""); } }