public void Basic_Usage()
        {
            string fullFileNamme = @"c:\temp\testdata.txt";

            FileParser parser = new FileParser();
            Sorter sorter = new Sorter();

            IList<Person> people = parser.ParseFile(fullFileNamme);

            IList<Person> sorted1 = sorter.Sort(people, SortOutputFormat.Output1);
            IList<Person> sorted2 = sorter.Sort(people, SortOutputFormat.Output2);
            IList<Person> sorted3 = sorter.Sort(people, SortOutputFormat.Output3);

            // Verify Output1 - Sorted by Gender
            Assert.IsTrue(sorted1[0].FirstName == "Jackie" && sorted1[0].LastName == "Anderson" && sorted1[0].Gender == "Female");
            Assert.IsTrue(sorted1[1].FirstName == "Beth" && sorted1[1].LastName == "Smith" && sorted1[1].Gender == "Female");
            Assert.IsTrue(sorted1[2].FirstName == "Jack" && sorted1[2].LastName == "Anderson" && sorted1[2].Gender == "Male");

            // Verify Output2 - Sorted by Birthdate ASC
            Assert.IsTrue(sorted2[0].FirstName == "Jackie" && sorted2[0].LastName == "Anderson");
            Assert.IsTrue(sorted2[1].FirstName == "Joe" && sorted2[1].LastName == "Smith");
            Assert.IsTrue(sorted2[2].FirstName == "Beth" && sorted2[2].LastName == "Smith");

            // Verify Output3 - Sorted by Lastname DESC
            Assert.IsTrue(sorted3[0].LastName == "Smith");
            Assert.IsTrue(sorted3[1].LastName == "Smith");
            Assert.IsTrue(sorted3[2].LastName == "Smith");
            Assert.IsTrue(sorted3[3].LastName == "Black");
            Assert.IsTrue(sorted3[4].LastName == "Black");
            Assert.IsTrue(sorted3[5].LastName == "Black");
            Assert.IsTrue(sorted3[6].LastName == "Black");
            Assert.IsTrue(sorted3[7].LastName == "Anderson");
            Assert.IsTrue(sorted3[8].LastName == "Anderson");
            Assert.IsTrue(sorted3[9].LastName == "Anderson");
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // The Length property is used to obtain the length of the array.
            // Notice that Length is a read-only property:
            Output("Number of command line parameters = {0}", args.Length);

            try
            {
                _format = (SortOutputFormat)Convert.ToInt32(args[1]);
                _fileName = args[0].ToString().Trim();
                Output("Input - Filename: {0} Sort Format: {1}", _fileName, _format.ToString());

            }
            catch(Exception)
            {
                Output("ERROR: Please provide valid arguments ex: c:\temp\testdata.txt 1");
                PauseExit();
            }

            // Create the Worker classes - These contain all the implementation code.
            FileParser parser = new FileParser();
            Sorter sorter = new Sorter();

            // Parse People from file
            IList<Person> people = parser.ParseFile(_fileName);

            // Sort People
            IList<Person> sorted = sorter.Sort(people, _format);

            // Display People
            Output(people);

            // Call REST Api
            CallRestApi();

            // Wait for Press any Key
            PauseExit();
        }