public void TestSortFile()
        {
            //unittest will construct the input file , then test the file
            //string sFilePath = "c:\\names.txt";
            string sWorkingPath = System.Environment.CurrentDirectory;
            string sFilePath = sWorkingPath + "\\names.txt";
            if (!File.Exists(sFilePath))
            {
                ConstructInputFile(sFilePath);
            }
            Assert.IsTrue(File.Exists(sFilePath));

            //Manual Dependency Injection
            IContentReader provider = new CSVTextReader();
            string sFilepath = sFilePath;
            DataSortingConsumer consumer = new DataSortingConsumer(provider) { path = sFilepath };
            consumer.Process();

            //verification on the order of names
            List<Person> listPersons = consumer.GetSorted();
            String prev = null;
            
            foreach (Person person in listPersons)
            {
                if(prev != null)
                {
                    //assert it is going ascending
                    Assert.IsTrue(person.ToString().CompareTo(prev) >= 0);
                }
                prev = person.ToString();
                
            }
        }
Exemple #2
0
 private CSVTextReader CreateCSVTextReaderFromText(string text)
 {
     var stream = new MemoryStream();
     var bytes = System.Text.Encoding.UTF8.GetBytes(text);
     stream.Write(bytes, 0, bytes.Length);
     stream.Position = 0;
     var reader = new System.IO.StreamReader(stream, System.Text.Encoding.UTF8);
     var target = new CSVTextReader(reader);
     return target;
 }
Exemple #3
0
        public void TestSortFile()
        {
            //unittest will construct the input file , then test the file
            //string sFilePath = "c:\\names.txt";
            string sWorkingPath = System.Environment.CurrentDirectory;
            string sFilePath    = sWorkingPath + "\\names.txt";

            if (!File.Exists(sFilePath))
            {
                ConstructInputFile(sFilePath);
            }
            Assert.IsTrue(File.Exists(sFilePath));

            //Manual Dependency Injection
            IContentReader      provider  = new CSVTextReader();
            string              sFilepath = sFilePath;
            DataSortingConsumer consumer  = new DataSortingConsumer(provider)
            {
                path = sFilepath
            };

            consumer.Process();

            //verification on the order of names
            List <Person> listPersons = consumer.GetSorted();
            String        prev        = null;

            foreach (Person person in listPersons)
            {
                if (prev != null)
                {
                    //assert it is going ascending
                    Assert.IsTrue(person.ToString().CompareTo(prev) >= 0);
                }
                prev = person.ToString();
            }
        }