Esempio n. 1
0
        public void BadFilename__Exception()
        {
            // arrange
            var service = new FullnameCollectionService();

            // act
            var collection = service.LoadFromFile("BadFileName.bad");

            // assert
            // Exception should be thrown
        }
Esempio n. 2
0
        public void Null__Exception()
        {
            // arrange
            var service = new FullnameCollectionService();

            // act
            var collection = service.LoadFromFile(null);

            // assert
            // Exception should be thrown
        }
Esempio n. 3
0
        public void LastEntry__OK()
        {
            // arrange
            var service    = new FullnameCollectionService();
            var collection = service.LoadFromFile(TestFilepath);

            // act
            collection = service.SortByLastnameGivenname(collection);

            // assert
            //  make sure first entry is "zulu zulu zulu zulu"
            string bottomEntry = collection.Last().ToString();

            Assert.IsTrue(bottomEntry == HIGHEST);
        }
Esempio n. 4
0
        public void FirstEntry__OK()
        {
            // arrange
            var service    = new FullnameCollectionService();
            var collection = service.LoadFromFile(TestFilepath);

            // act
            collection = service.SortByLastnameGivenname(collection);

            // assert
            //  make sure first entry is "alpha alpha alpha alpha"
            string topEntry = collection.First().ToString();

            Assert.IsTrue(topEntry == LOWEST);
        }
Esempio n. 5
0
        public void WriteToFile__OK()
        {
            // arrange
            var service    = new FullnameCollectionService();
            var collection = service.LoadFromFile(TestInputFilepath);

            if (new System.IO.FileInfo(TestOutputFilepath).Exists)
            {
                System.IO.File.Delete(TestOutputFilepath);
            }

            // act
            service.WriteToFile(collection, TestOutputFilepath);

            // assert
            //  make sure first entry is "alpha alpha alpha alpha"
            // test out was created
            Assert.IsTrue(new System.IO.FileInfo(TestOutputFilepath).Exists);
            // test it has content.
            Assert.IsTrue(new System.IO.FileInfo(TestOutputFilepath).Length > 30);
        }
Esempio n. 6
0
        /// <summary>
        /// Reads a file containing names (one name per line) Sorts them and outputs to new file and to the console.
        /// </summary>
        /// <param name="args">args[0] should be the name of the file to read</param>
        /// <returns></returns>
        static int Main(string[] args)
        {
            if (args.Length != 1 || args[0] == "/?" || args[0].Length == 0)
            {
                Usage();
                return(-2);
            }

            var inputFilepath = args[0];  //

            var service = new FullnameCollectionService();

            // Load the data
            var allNames = service.LoadFromFile(args[0]);

            // sort the data
            allNames = service.SortByLastnameGivenname(allNames);

            // output the data
            service.WriteToStream(allNames, Console.Out);
            service.WriteToFile(allNames, OutputPath);

            return(0);
        }