Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length <= 0 || String.IsNullOrEmpty(args[0]))
            {
                Console.WriteLine("Use: name-sorter <filepath>");
                return;
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("File not found: " + args[0]);
                return;
            }

            IFileController inputFC  = new FileController(args[0]);
            IFileController outputFC = new FileController("./sorted-names-list.txt");
            INameList       nameList = new NameList(inputFC.Read());

            nameList.Sort();

            foreach (var name in nameList.GetAllNames())
            {
                Console.WriteLine(name);
            }
            ;

            outputFC.Write(nameList.GetAllNames());
        }
Ejemplo n.º 2
0
        public void SortBySurname_NoDuplicateSurnamesAlreadySorted_SortedCorrectly()
        {
            // Arrange
            string[] nameArray =
            {
                "Order1 Andrews",
                "Order2 Johnson",
                "Order3 Miles",
                "Order4 Peerson",
                "Order5 Wender"
            };
            INameList nameList = new NameList(nameArray);

            // Act
            nameList.Sort();
            var result = nameList.GetAllNames();

            // Assert
            for (int i = 0; i < nameArray.Length; i++)
            {
                Assert.IsTrue(result[i] == nameArray[i]);
            }
        }
Ejemplo n.º 3
0
        public void SortBySurname_DuplicateSurnames_SortedCorrectly()
        {
            // Arrange
            string[] nameArray =
            {
                "Order2 Johnson",
                "Order3 Miles",
                "Order5 Wender",
                "Order4 Wender",
                "Order1 Andrews"
            };
            INameList nameList = new NameList(nameArray);

            // Act
            nameList.Sort();
            var result = nameList.GetAllNames();

            // Assert
            Assert.IsTrue(result[0] == "Order1 Andrews");
            Assert.IsTrue(result[1] == "Order2 Johnson");
            Assert.IsTrue(result[2] == "Order3 Miles");
            Assert.IsTrue(result[3] == "Order4 Wender");
            Assert.IsTrue(result[4] == "Order5 Wender");
        }