/// <summary> /// Sorts the names in the given file /// outputs sorted names into a file named "sorted-names-list.txt". /// </summary> /// <param name="inputFilename">The file to sort.</param> private static void SortNames(string inputFilename) { try { var delimiter = " "; var outputFilename = "sorted-names-list.txt"; var reader = new PersonFileReader(inputFilename); var parser = new PersonFileParser(delimiter); var writer = new PersonFileWriter(outputFilename); var sorter = new PersonSorter(new PersonNameComparer()); var validator = new PersonValidator(); var processor = new PersonProcessor(reader, parser, writer, validator, sorter); var sortedList = processor.Process(); foreach (var person in sortedList) { System.Console.WriteLine(person.ToString()); } } catch (Exception ex) { System.Console.WriteLine(ex.Message); } }
public void Given_List_With_OneName_Return_OneName() { var sorter = new PersonSorter(new PersonNameComparer()); var list = new List <PersonDTO>(); list.Add(new PersonDTO("one", "A")); var sortedList = sorter.Sort(list); Assert.AreEqual("A", sortedList.First().LastName); }
public void Is_List_Sorted_By_LastName() { var sorter = new PersonSorter(new PersonNameComparer()); var list = new List <PersonDTO>(); list.Add(new PersonDTO("two", "B")); list.Add(new PersonDTO("one", "A")); list.Add(new PersonDTO("four", "D")); list.Add(new PersonDTO("three", "C")); var sortedList = sorter.Sort(list); Assert.AreEqual("A", sortedList.First().LastName); }
public void Is_File_Processed_Successfully() { // Arrange var inputFilename = "./unsorted-names-list.txt"; var outputFilename = "sorted-names-list.txt"; var delimiter = ""; var reader = new PersonFileReader(inputFilename); var parser = new PersonFileParser(delimiter); var writer = new PersonFileWriter(outputFilename); var sorter = new PersonSorter(new PersonNameComparer()); var validator = new PersonValidator(); var processor = new PersonProcessor(reader, parser, writer, validator, sorter); // Act var sortedList = processor.Process(); // Assert Assert.IsTrue(true); }
public void ReadShouldReadLinesUntilQuitCommand(params string[] input) { // Arrange var reader = new Mock <IReader>(); reader.SetupSequence(r => r.ReadLine()) .Returns(input[0]) .Returns(input[1]) .Returns(input[2]) .Returns(input[3]) .Returns(input[4]); var sut = new PersonSorter(); // Act sut.Read(reader.Object); // Assert reader.Verify(r => r.ReadLine(), Times.Exactly(4)); }
public void SortByNameLengthAndExcludeMinAge(params string[] input) { // Arrange var reader = new Mock <IReader>(); var writer = new Mock <IWriter>(); reader.SetupSequence(r => r.ReadLine()) .Returns(input[0]) .Returns(input[1]) .Returns(input[2]) .Returns(input[3]); var sut = new PersonSorter(); // Act sut.Read(reader.Object); sut.Sort(); sut.Write(writer.Object); // Assert //writer.Verify(r => r.WriteLine, Times.Exactly(4)); }