コード例 #1
0
        /// <summary>
        /// Runs all of the column validators against the string provided in <paramref name="toCheck"/>.
        /// </summary>
        /// <param name="toCheck">The row of data to validate</param>
        /// <returns>True if the row has passed validation else false.</returns>
        public bool IsValid(string toCheck)
        {
            bool isValid = true;

            string[] parts         = ColumnSplitter.Split(toCheck, _columnSeperator);
            int[]    columnIndexes = CalculateColumnStartIndexes(parts);

            for (int currentColumn = 0; currentColumn < parts.Length; currentColumn++)
            {
                if (currentColumn < _columns.Length)
                {
                    string elemToCheck = parts[currentColumn].Trim().Replace("\"", "");
                    bool   result      = _columns[currentColumn].IsValid(elemToCheck);

                    IList <ValidationError> newErrors = _columns[currentColumn].GetErrors();
                    _errorInformation.Errors.AddRange(newErrors);

                    // set validation character error location for all errors
                    // on this column to the first character in the column
                    for (int i = 0; i < newErrors.Count; i++)
                    {
                        newErrors[i].AtCharacter = columnIndexes[currentColumn];
                        newErrors[i].Column      = currentColumn + 1; // zero based index
                    }

                    isValid = isValid & result;
                }
            }

            AddRowDetailsToErrors(toCheck);

            return(isValid);
        }
コード例 #2
0
        public void Split_WhenOnlyOneColmn_ReturnsSingleResult()
        {
            const string INPUT     = "just a string";
            const string SEPERATOR = ",";

            string[] result = ColumnSplitter.Split(INPUT, SEPERATOR);

            Assert.AreEqual(result.Length, 1);
            Assert.AreEqual(result[0], INPUT);
        }
コード例 #3
0
        public void Split_WhenUsingQuotedStringMultipleTimes_IgnoresSeperator()
        {
            const string INPUT     = "\"just, a string\",seperated,string,\"just, a string\",\"just, a string\"";
            const string SEPERATOR = ",";

            string[] result = ColumnSplitter.Split(INPUT, SEPERATOR);

            Assert.AreEqual(result.Length, 5);
            Assert.AreEqual("\"just, a string\"", result[0]);
            Assert.AreEqual("seperated", result[1]);
        }
コード例 #4
0
        public void Split_WhenUsingMultiCharSeperators_IsCorrect()
        {
            const string INPUT     = "just a string##seperated";
            const string SEPERATOR = "##";

            string[] result = ColumnSplitter.Split(INPUT, SEPERATOR);

            Assert.AreEqual(result.Length, 2);
            Assert.AreEqual(result[0], "just a string");
            Assert.AreEqual(result[1], "seperated");
        }
コード例 #5
0
        public void Split_WhenTwoColmns_ReturnsTwoResults()
        {
            const string INPUT     = "just a string,seperated";
            const string SEPERATOR = ",";

            string[] result = ColumnSplitter.Split(INPUT, SEPERATOR);

            Assert.AreEqual(result.Length, 2);
            Assert.AreEqual(result[0], "just a string");
            Assert.AreEqual(result[1], "seperated");
        }
コード例 #6
0
 /// <summary>
 /// The get header.
 /// </summary>
 /// <param name="toCheck">The to check.</param>
 /// <returns>The result.</returns>
 public string[] GetHeader(string toCheck)
 {
     return(ColumnSplitter.Split(toCheck, _columnSeperator));
 }