Esempio n. 1
0
        // This test method is to validate the engine to fix wrong observation date based on above correct date.
        // Input data is containing 2 wrong observation date. One is invalid date '14/01/1900', another is empty.
        public void ConvertGasQuoteData_WithWrongObservationDate()
        {
            // Arange

            string expectedHeader   = "ObservationDate,Q1_14,Q2_14,Q3_14,Q4_14,Q1_15";
            string expectedDataLine = "13/11/2009,0.6855,0.592,0.575,0.6295,0.7145";
            var    fileLines        = File.ReadAllLines("Data\\WrongObservationDateFile.csv");

            GasQuoteConvertService qcService = new GasQuoteConvertService();

            // Act
            string[] result = qcService.ConvertGasQuoteData(fileLines).Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            // Assert

            Assert.AreEqual(expectedHeader, result[0]);
            Assert.AreEqual(expectedDataLine, result[1]);
        }
Esempio n. 2
0
        // This test method is to validate the engine to fix wrong shorthands based on dates.
        public void GetGasQuoteFromString_WithWrongShorthand()
        {
            // Arange
            string wrongShorthandLine1       = "02/01/2009,,01/07/2010,30/09/2010,0.511";      // empty shorthand
            string wrongShorthandLine2       = "02/01/2009,Q,01/07/2010,30/09/2010,0.511";     // wrong shorthand 'Q'
            string wrongShorthandLine3       = "02/01/2009,Q5_11,01/07/2010,30/09/2010,0.511"; // wrong shorthand 'Q5_11'. Q5 is invalid.
            string expected                  = "Q3_10";
            GasQuoteConvertService qcService = new GasQuoteConvertService();

            // Act
            GasQuote gasQuote1 = qcService.GetGasQuoteFromString(wrongShorthandLine1);
            GasQuote gasQuote2 = qcService.GetGasQuoteFromString(wrongShorthandLine2);
            GasQuote gasQuote3 = qcService.GetGasQuoteFromString(wrongShorthandLine3);

            // Assert

            Assert.AreEqual(expected, gasQuote1.Shorthand);
            Assert.AreEqual(expected, gasQuote2.Shorthand);
            Assert.AreEqual(expected, gasQuote3.Shorthand);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Input the csv file path to convert.");
            string filepath = string.Empty;

            string[] lines = null;
            while (lines == null || lines.Length < 1)
            {
                filepath = Console.ReadLine();
                try
                {
                    lines = File.ReadAllLines(filepath).Skip(1).ToArray();
                }
                catch
                {
                    Console.WriteLine("Invalid csv file. Input file path again.");
                    continue;
                }
                if (lines.Length < 1)
                {
                    Console.WriteLine("No data in file. Input file path again.");
                }
            }

            FileStream   fs;
            StreamWriter sw;
            TextWriter   twOldOut = Console.Out; //  Save old out to set it later.

            try
            {
                if (!Directory.Exists("Log"))
                {
                    Directory.CreateDirectory("Log");
                }
                fs = new FileStream($"Log\\log_{DateTime.Now.ToString("yyyyMMddTHHmmss")}.txt", FileMode.OpenOrCreate, FileAccess.Write);
                sw = new StreamWriter(fs);
            }
            catch (Exception e)
            {
                Console.WriteLine("Cannot open log.txt for writing");
                Console.WriteLine(e.Message);
                return;
            }
            Console.SetOut(sw);     // Set console's out as streamwriter for log.txt.

            Console.WriteLine("Start converting csv file...");
            Console.WriteLine("FilePath : {0}", filepath);
            Console.WriteLine("Timestamp : {0}", DateTime.Now.ToString());
            Console.WriteLine();

            GasQuoteConvertService qcService = new GasQuoteConvertService();
            var outputBuffer = qcService.ConvertGasQuoteData(lines);

            using (StreamWriter file = new StreamWriter("output.csv", false))
            {
                file.Write(outputBuffer);
            }

            Console.WriteLine("Converted successfully....");

            Console.SetOut(twOldOut);   // Set console's out as original.
            sw.Close();
            fs.Close();
            Console.WriteLine("Done");
        }