示例#1
0
 private void ImportAsciiData(AsciiSettings asciiSettings)
 {
     dataImport = new AsciiDataImport(asciiSettings);
     Headers    = dataImport.GetHeaders();
     rows       = dataImport.LoadAll();
     RowsView   = CreateDataView();
 }
        public void Load_InvalidDateTimeFormat_ThrowsException(AsciiSettings InvalidDateTimeFormatAsciiSettings, int rows)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(InvalidDateTimeFormatAsciiSettings);

            // act
            TestDelegate action = () => asciiImport.Load(0, rows).ToList();

            // assert
            Assert.Throws <FormatException>(action, "Expected exception was not thrown.");
        }
        public void Load_ColumnDelimiterAsElementofDateTimeFormat_ThrowsException(AsciiSettings ColumnDelimiterAsElementofDateTimeFormatAsciiSettings, int rows)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(ColumnDelimiterAsElementofDateTimeFormatAsciiSettings);

            // act
            TestDelegate action = () => asciiImport.Load(0, rows).ToList();

            // assert
            Assert.Throws <ArgumentException>(action, "Expected exception was not thrown.");
        }
        public void GetHeaders_EmptyFileAndUseFirstRowAsHeaders_ReturnEmptyHeaders(AsciiSettings EmptyFilesAsciiSettings, int rowsNum)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(EmptyFilesAsciiSettings);

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

            // assert
            Assert.AreEqual(rowsNum, headers.Count(), "The returned headers are not empty.");
        }
        // [ExpectedException(typeof(FileNotFoundException), "Expected exception was not thrown.")]
        public void LoadAll_FileDoesNotExist_ThrowsException(AsciiSettings NotExisitngFileAsciiSettings)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(NotExisitngFileAsciiSettings);

            // act
            TestDelegate action = () => asciiImport.LoadAll();

            // assert
            Assert.Throws <FileNotFoundException>(action);
        }
        public void LoadAll_SamplesFileWithEmptyLines_SkipEmptyLines(AsciiSettings SamplesWithEmptyLinesAsciiSettings, int rowsWithoutEmpyLinesNum)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(SamplesWithEmptyLinesAsciiSettings);

            // act
            var rows = asciiImport.LoadAll().ToList();

            // assert
            Assert.AreEqual(rowsWithoutEmpyLinesNum, rows.Count);
        }
        public void GetHeaders_FileDoesNotExist_ThrowsException(AsciiSettings NotExisitngFileAsciiSettings)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(NotExisitngFileAsciiSettings);

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

            // assert
            Assert.Throws <FileNotFoundException>(action, "Expected exception was not thrown.");
        }
        public void LoadAll_EmptyFile_ReturnEmpty(AsciiSettings EmptyFilesAsciiSettings, int rowsNum)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(EmptyFilesAsciiSettings);

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

            // assert
            Assert.AreEqual(rowsNum, rows.Count());
        }
        public void GetHeaders_FirstRowAsHeaders_ReturnHeadersFromFirstRow(AsciiSettings ValidAsciiSettings, IEnumerable <object> validHeaders)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(ValidAsciiSettings);

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

            // assert
            CollectionAssert.AreEqual(validHeaders, headers);
            Assert.AreEqual(validHeaders.Count(), headers.Count());
        }
        public void GetHeaders_FileWithoutHeadersinFirstRow_ReturnGenericHeaders(AsciiSettings GenericHeadersAsciiSettings, IEnumerable <object> genericHeaders)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(GenericHeadersAsciiSettings);

            // act
            var headers = asciiImport.GetHeaders().ToList();

            // assert
            CollectionAssert.AreEqual(genericHeaders, headers);
            Assert.AreEqual(genericHeaders.Count(), headers.Count());
        }
        public void Load_SkipAllRows_ReturnEmpty(AsciiSettings SkipAllRowsAsciiSettings, int skip, int take)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(SkipAllRowsAsciiSettings);
            string          failInfo    = "Returned collection are invalid.";

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

            // assert
            Assert.AreEqual(0, rows.Count(), failInfo);
        }
        public void Load_ValidFile_ReturnSpecificRowsRangeFromFile(AsciiSettings ReturnSpecificRowsRangeFromFile, int rowsNum)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(ReturnSpecificRowsRangeFromFile);

            // act
            var rows = asciiImport.Load(0, rowsNum);

            // assert
            Assert.AreEqual(rowsNum, rows.Count());
            //Check if all rows have the same columns number
            Assert.AreEqual(1, rows.GroupBy(arg => arg.Samples.Count()).Count());
        }
        public void Load_ValidColumnDelimiter_ReturnValidRows(AsciiSettings ColumnDelimitersAsciiSettings, int rowsNum, int columnsNum)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(ColumnDelimitersAsciiSettings);

            // act
            var rows = asciiImport.Load(0, rowsNum);

            // assert
            Assert.AreEqual(rowsNum, rows.Count());
            Assert.AreEqual(1, rows.GroupBy(arg => arg.Samples.Count()).Count());
            Assert.AreEqual(columnsNum, rows.ElementAt(0).Samples.Count());
        }
示例#14
0
        private void LoadCustomData(string parameter)
        {
            AsciiSettings asciiSettings = new AsciiSettings()
            {
                ColumnDelimiter     = ";",
                DateTimeFormat      = parameter == "long" ? "yyyy-MM-dd HH:mm:ss" : "dd.MM.yyyy HH:mm:ss",
                FileName            = parameter == "long" ? "longValidSamples.csv" : "shortValidSamples.csv",
                NumberDelimiter     = ",",
                SkipFirstRowsNum    = 1,
                UseFirstRowAsHeader = true
            };

            ImportAsciiData(asciiSettings);
        }
        public void LoadAll_ValidFile_ReturnAllRowsFromFile(AsciiSettings ValidAsciiSettings, IEnumerable <object> validHeaders)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(ValidAsciiSettings);
            int             headersNum, samplesNum;

            // act
            var rows = asciiImport.LoadAll();
            var headers = asciiImport.GetHeaders();

            samplesNum = rows.First().Samples.Count();
            headersNum = headers.Count() - 1; // Timestamp is not sample

            CollectionAssert.AreEqual(validHeaders, headers);

            // assert
            Assert.AreEqual(1, rows.GroupBy(arg => arg.Samples.Count()).Count(), "Rows have a different number of columns.");
            Assert.AreEqual(samplesNum, headersNum, "The number of samples" + samplesNum + "is different from the number of headers" + headersNum);
        }
 public ImportAsciiSettingsDialogViewModel()
 {
     AsciiSettings = new AsciiSettings();
 }
        public void Load_SettingsWithColumnDelimiterTheSameAsNumberDelimiter_ThrowsException(AsciiSettings ColumnDelimiterTheSameAsNumberDelimiterAsciiSettings, int rows)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(ColumnDelimiterTheSameAsNumberDelimiterAsciiSettings);

            // act
            TestDelegate action = () => asciiImport.Load(0, rows);

            // assert
            Assert.Throws <ArgumentException>(action, "Expected exception was not thrown.");
        }
        public void Load_FileWithColumnDelimiterTheSameAsNumberDelimiter_ThrowsException(AsciiSettings FileWithColumnDelimiterTheSameAsNumberDelimiterAsciiSettings, int rows)
        {
            // arrange
            AsciiDataImport asciiImport = new AsciiDataImport(FileWithColumnDelimiterTheSameAsNumberDelimiterAsciiSettings);

            // act
            TestDelegate action = () => asciiImport.Load(0, rows).ToList().ForEach(arg => arg.Samples.ToList());

            // assert
            Assert.Throws <ArgumentException>(action, "Expected exception was not thrown.");
        }