Example #1
0
        private static bool OrdinalPosition <TErrorCode>(ErrorRecords <TErrorCode> errorRecords, IEnumerable <int> ordinalPositions)
            where TErrorCode : struct, Enum
        {
            var result = errorRecords.Select(x => x.OrdinalPosition).Where(y => ordinalPositions.Contains(y)).Distinct();

            return(result.Count() == ordinalPositions.Distinct().Count());
        }
Example #2
0
        private static bool ErrorCode <TErrorCode>(ErrorRecords <TErrorCode> errorRecords, IEnumerable <TErrorCode> errorCodes)
            where TErrorCode : struct, Enum
        {
            var result = errorRecords.SelectMany(x => x.Errors.Select(y => y.ErrorCode)).Where(z => errorCodes.Contains(z)).Distinct();

            return(result.Count() == errorCodes.Distinct().Count());
        }
Example #3
0
        public static void NotContainsOrdinalPosition <TErrorCode>(ErrorRecords <TErrorCode> errorRecords, IEnumerable <int> ordinalPositions)
            where TErrorCode : struct, Enum
        {
            var result = OrdinalPosition(errorRecords, ordinalPositions);

            Assert.False(result, "Result does contain the ordinal position.");
        }
Example #4
0
        public static void NotContainsErrorCode <TErrorCode>(ErrorRecords <TErrorCode> errorRecords, IEnumerable <TErrorCode> errorCodes)
            where TErrorCode : struct, Enum
        {
            var result = ErrorCode(errorRecords, errorCodes);

            Assert.False(result, "Result contains the error code.");
        }
Example #5
0
        /// <summary>
        /// Imports the CSV record and returns a list of objects
        /// </summary>
        /// <returns></returns>
        public override Dictionary <string, List <EntityClass> > Import()
        {
            string recordData;

            string[]    dataElements;
            EntityClass fileRecord;

            // Category, Data
            Dictionary <string, List <EntityClass> > theDictionary = new Dictionary <string, List <EntityClass> >();

            StreamReader streamReader = File.OpenText(base.FileName);

            while (!streamReader.EndOfStream)
            {
                // Read in a line of the record data
                recordData = streamReader.ReadLine();

                // Filtering is enabled
                if (this.FilterFunction != null)
                {
                    bool matchesFilteringCriteria = this.FilterFunction.Invoke((T)(object)recordData);
                    if (!matchesFilteringCriteria)
                    {
                        continue;
                    }
                }

                try
                {
                    // Split the record data based on the column delimiter
                    dataElements =
                        recordData.Split(
                            ImportFileSettings.FieldDelimiter.ToCharArray());

                    // Populate the record data elements into the object
                    // and add it to the list
                    fileRecord = new EntityClass();

                    // For every data elements we find
                    for (int i = 0; i < dataElements.Length; i++)
                    {
                        ReflectionHelper.SetPropertyValue(
                            fileRecord,
                            dataElements[i],
                            i);
                    }

                    string category = "NONE";
                    if (this.CategoryProperty != null)
                    {
                        category = this.CategoryProperty.GetValue(fileRecord, null).ToString();
                    }

                    // If this category have not existed, create it
                    // Otherwise, add this item to the list
                    List <EntityClass> theList = null;
                    if (!theDictionary.TryGetValue(category, out theList))
                    {
                        theList = new List <EntityClass>();
                        theDictionary.Add(category, theList);
                    }

                    theList.Add(fileRecord);
                }
                catch (FieldValidationException)
                {
                    ErrorRecords.Add(recordData);
                }
            }

            streamReader.Close();
            return(theDictionary);
        }
Example #6
0
 public static void NotContainsOrdinalPosition <TErrorCode>(ErrorRecords <TErrorCode> errorRecords, int ordinalPosition, params int[] ordinalPositions)
     where TErrorCode : struct, Enum
 {
     NotContainsOrdinalPosition(errorRecords, ordinalPositions.Prepend(ordinalPosition));
 }
Example #7
0
 public static void NotContainsErrorCode <TErrorCode>(ErrorRecords <TErrorCode> errorRecords, TErrorCode errorCode, params TErrorCode[] errorCodes)
     where TErrorCode : struct, Enum
 {
     NotContainsErrorCode(errorRecords, errorCodes.Prepend(errorCode));
 }