Example #1
0
        public void LoadAll_EmptyFile_ReturnEmptyRows(ExcelSettings settings, int rowsNum)
        {
            // arrange
            ExcelDataImport importer = new ExcelDataImport(settings);

            // act
            var rows = importer.LoadAll();

            // assert
            Assert.AreEqual(rowsNum, rows.Count());
        }
Example #2
0
        public void GetHeaders_FileDoesNotExist_ThrowFileNotFoundException(ExcelSettings settings)
        {
            // arrange
            ExcelDataImport importer = new ExcelDataImport(settings);

            // act
            TestDelegate action = () => importer.GetHeaders();

            // assert
            Assert.Throws <FileNotFoundException>(action);
        }
Example #3
0
        public void GetHeaders_EmptyFile_ReturnEmptyFileHeaders(ExcelSettings settings, int headersNum)
        {
            // arrange
            ExcelDataImport importer = new ExcelDataImport(settings);

            // act
            var headers = importer.GetHeaders();

            // assert
            Assert.AreEqual(headersNum, headers.Count());
        }
Example #4
0
        public void GetHeaders_NoHeaders_ReturnGenericHeaders(ExcelSettings settings, IEnumerable <object> validHeaders)
        {
            // arrange
            ExcelDataImport importer = new ExcelDataImport(settings);

            // act
            var headers = importer.GetHeaders();

            // assert
            CollectionAssert.AreEqual(validHeaders, headers);
        }
Example #5
0
        static void RunFileImportExamples()
        {
            Console.WriteLine("RunFileImportExamples()");

            ConsoleKeyInfo response = new ConsoleKeyInfo();

            do
            {
                Console.WriteLine();
                Console.WriteLine("[1] = CsvImport1");
                Console.WriteLine("[2] = ExcelImport1");
                Console.WriteLine("[e] = Exit");

                Console.Write("\r\nEnter choice: ");
                response = Console.ReadKey();
                Console.WriteLine("\r\n");

                Stopwatch sw = null;

                switch (response.Key)
                {
                case ConsoleKey.D1:
                    sw = Stopwatch.StartNew();
                    CsvDataImport.CsvImport1(Common.CsvDataPath);
                    break;

                case ConsoleKey.D2:
                    sw = Stopwatch.StartNew();
                    ExcelDataImport.ExcelImport1(Common.ExcelDataPath);
                    break;

                case ConsoleKey.E:
                case ConsoleKey.Escape:
                    break;

                default:
                    Console.WriteLine("Invalid choice.");
                    break;
                }

                if (sw != null && sw.IsRunning)
                {
                    sw.Stop();
                    Common.WriteTime("Import total seconds: ", sw.Elapsed);
                }
            } while (!(response.Key == ConsoleKey.E || response.Key == ConsoleKey.Escape));
        }
Example #6
0
        static void RunLoopedExcelFileImportExamples()
        {
            Console.WriteLine("RunLoopedExcelFileImportExamples()");

            Console.WriteLine("Import started");

            for (int i = 0; i < 5; i++)
            {
                Stopwatch sw = Stopwatch.StartNew();

                ExcelDataImport.ExcelImport1(Common.ExcelDataPath);

                sw.Stop();
                Common.WriteTime(String.Format("Import {0} total seconds: ", i), sw.Elapsed);
            }
            Console.WriteLine("\r\nPress any key to continue.");
            Console.ReadKey(true);
        }
Example #7
0
        public void LoadAll_ValidFile_ReturnRows(ExcelSettings settings, IEnumerable <Row> validRows)
        {
            // arrange
            ExcelDataImport importer = new ExcelDataImport(settings);

            // act
            var rows = importer.LoadAll();

            // assert
            Assert.AreEqual(validRows.Count(), rows.Count());
            var validRowsEnumerator = validRows.GetEnumerator();
            var rowsEnumerator      = rows.GetEnumerator();

            while (validRowsEnumerator.MoveNext() && rowsEnumerator.MoveNext())
            {
                Assert.AreEqual(validRowsEnumerator.Current.Timestamp, rowsEnumerator.Current.Timestamp);
                CollectionAssert.AreEqual(validRowsEnumerator.Current.Samples, rowsEnumerator.Current.Samples);
            }
        }
Example #8
0
        public void Load_ValidFile_ReturnSpecifiedRowsRange(ExcelSettings settings, IEnumerable <Row> validRows, int skip, int take)
        {
            // arrange
            ExcelDataImport importer = new ExcelDataImport(settings);

            // act
            var rows = importer.Load(skip, take);

            // assert
            Assert.AreEqual(validRows.Count(), rows.Count());
            CollectionAssert.AreEqual(validRows, rows, new RowComparer());
            var validRowsEnumerator = validRows.GetEnumerator();
            var rowsEnumerator      = rows.GetEnumerator();

            while (validRowsEnumerator.MoveNext() && rowsEnumerator.MoveNext())
            {
                Assert.AreEqual(validRowsEnumerator.Current.Timestamp, rowsEnumerator.Current.Timestamp);
                CollectionAssert.AreEqual(validRowsEnumerator.Current.Samples, rowsEnumerator.Current.Samples);
            }
        }