Ejemplo n.º 1
0
        public void PrintFileTest()
        {
            //create a file that we will try to read using the component
            var printFile = new PrintUtil
            {
                ForceCreation = true,
                OutputColumns = new List <string>(),
                PrintFileName = TxtTestFileName,
                PrintList     = "#"
            };

            printFile.OutputColumns.Add("#");
            printFile.PrintFile();

            //check if file exists
            Assert.IsTrue(File.Exists(printFile.PrintFileName));

            //read the contents of the file
            using (var streamReader = new StreamReader(printFile.PrintFileName))
            {
                var stream = streamReader.ReadLine();
                Assert.AreEqual("#", stream, "File was not Printed successfully");
            }

            //clean up now
            File.Delete(printFile.PrintFileName);
            Assert.IsFalse(File.Exists(printFile.PrintFileName));
        }
Ejemplo n.º 2
0
        public void ReadCsvFileTest()
        {
            //create a file that we will try to read using the component
            var printFile = new PrintUtil
            {
                ForceCreation = true,
                OutputColumns = new List <string>(),
                PrintFileName = TxtTestFileName,
                PrintList     = "1234"
            };

            printFile.OutputColumns.Add("#");
            printFile.PrintFile();

            //check if file exists
            Assert.IsTrue(File.Exists(printFile.PrintFileName));

            //check if this file can be read
            Assert.IsTrue(ReadUtil.ReadCsvFile(printFile.PrintFileName).Count > 0);

            //check if the file was loaded with all records
            Assert.IsTrue(ReadUtil.ReadCsvFile(printFile.PrintFileName).Count == 4);

            //clean up now
            File.Delete(printFile.PrintFileName);
            Assert.IsFalse(File.Exists(printFile.PrintFileName));
        }
Ejemplo n.º 3
0
        public void Print(PrintOptions optName)
        {
            //initialize the Print Utility
            var printer = new PrintUtil
            {
                ForceCreation = true,
                PrintFileName = PrintFileName,
                OutputColumns = new List <string>()
            };

            //switch Print View - use linq to order and sort the raw data into various file formats
            switch (optName)
            {
            case PrintOptions.Frequency:
                printer.OutputColumns.Add("LastName"); printer.OutputColumns.Add("Frequency");
                printer.PrintList = Records.GroupBy(
                    l => l.LastName,
                    l => l.LastName,
                    (key, g) => new { LastName = key, Frequency = g.Count() }).OrderByDescending(l => l.Frequency);
                break;

            case PrintOptions.AddressSort:
                printer.OutputColumns.Add("Address");
                printer.PrintList = Records.OrderBy(a => a.StreetName);
                break;

            case PrintOptions.NameList:
                printer.OutputColumns.Add("FirstName"); printer.OutputColumns.Add("LastName");
                printer.PrintList = Records.OrderByDescending(o => o.LastName).Select(p => new ContactInfo {
                    FirstName = p.FirstName, LastName = p.LastName
                }).ToList();
                break;

            case PrintOptions.Default:
                printer.OutputColumns.Add("FirstName"); printer.OutputColumns.Add("LastName");
                printer.OutputColumns.Add("Address"); printer.OutputColumns.Add("PhoneNumber");
                printer.PrintList = Records;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(optName), optName, null);
            }
            //call Generic Print based on View
            if (printer.PrintFile())
            {
                Process.Start("notepad.exe", printer.PrintFileName);
            }
        }