예제 #1
0
        /// <summary><para>Iterates over the <see cref="IDictionary{TKey, TValue}"/> of <see cref="string"/> keys and <see cref="object"/> values in the
        /// <paramref name="dictionaries"/>, mapping their fields to the entity type.</para></summary>
        /// <param name="dictionaries"><para>The <see cref="IDictionary{TKey, TValue}"/> instances of <see cref="string"/> keys and <see cref="object"/> values
        /// to map to the entity type.</para></param>
        /// <param name="columnToMemberMap"><para>The <see cref="IDictionary{TKey, TValue}"/> to map the <see cref="string"/> keys to properties.</para></param>
        /// <returns><para>A yielded instance of the entity type.</para></returns>
        public static IEnumerable <TEntity> ToEntities(IEnumerable <IDictionary <string, object> > dictionaries, IDictionary <string, string> columnToMemberMap)
        {
            IDictionary <string, object> first = dictionaries?.FirstOrDefault();

            if (dictionaries == null)
            {
                throw new ArgumentNullException(nameof(dictionaries));
            }
            if (columnToMemberMap == null)
            {
                throw new ArgumentNullException(nameof(columnToMemberMap));
            }
            if (first == null)
            {
                throw new ArgumentException($"Parameter {nameof(dictionaries)} should have at least 1 value, 0 given.");
            }
            //Get a table definition for the dictionaries then call the data table converter.
            DataTable dataTable = first.AsDataTableDefinition();
            //Converts the sting/string column to member map into a data column/string column to member map.
            Dictionary <DataColumn, string> translatedColumnToMemberMap = new Dictionary <DataColumn, string>();

            foreach (KeyValuePair <string, string> entry in columnToMemberMap)
            {
                translatedColumnToMemberMap.Add(dataTable.Columns[entry.Key], entry.Value);
            }
            return(DataTableConverter <TEntity> .ToEntities(dictionaries.Select(d => DictionaryToDataRow(d, dataTable)), translatedColumnToMemberMap));
        }
예제 #2
0
 public void ArrayDataRowNullColumnToPropertyMap()
 {
     //TODO: Figure out why this test fails even though it should be succeeding - This exception is thrown immediately and
     //manual testing confirms it is being thrown. Like seriously, what the hell is this even doing?
     DataRow[] adr = testTable.Value.Rows.Cast <DataRow>().ToArray();
     Assert.ThrowsException <ArgumentNullException>(() => DataTableConverter <Convertible> .ToEntities(adr, null));
 }
예제 #3
0
        public void NullColumnToPropertyMap()
        {
            //TODO: Figure out why this test fails even though it should be succeeding - This exception is thrown immediately and
            //manual testing confirms it is being thrown. Like seriously, what the hell is this even doing?
            DataTable dt = new DataTable();
            Dictionary <DataColumn, string> nullCtP = null;

            Assert.ThrowsException <ArgumentNullException>(() => DataTableConverter <Convertible> .ToEntities(dt, nullCtP));
        }
예제 #4
0
        /// <summary><para>Iterates over the <see cref="IDictionary{TKey, TValue}"/> of <see cref="string"/> keys and <see cref="object"/> values in the
        /// <paramref name="dictionaries"/>, mapping their fields to the entity type.</para></summary>
        /// <param name="dictionaries"><para>The <see cref="IDictionary{TKey, TValue}"/> instances of <see cref="string"/> keys and <see cref="object"/> values
        /// to map to the entity type.</para></param>
        /// <returns><para>A yielded instance of the entity type.</para></returns>
        public static IEnumerable <TEntity> ToEntities(IEnumerable <IDictionary <string, object> > dictionaries)
        {
            IDictionary <string, object> first = dictionaries?.FirstOrDefault();

            if (dictionaries == null)
            {
                throw new ArgumentNullException(nameof(dictionaries));
            }
            if (first == null)
            {
                throw new ArgumentException($"Parameter {nameof(dictionaries)} should have at least 1 value, 0 given.");
            }
            //Get a table definition for the dictionaries then call the data table converter.
            DataTable dataTable = first.AsDataTableDefinition();

            return(DataTableConverter <TEntity> .ToEntities(dictionaries.Select(d => DictionaryToDataRow(d, dataTable))));
        }
예제 #5
0
 public void NullArrayDataRow()
 {
     DataRow[] adr = null;
     Assert.ThrowsException <ArgumentNullException>(() => DataTableConverter <Convertible> .ToEntities(adr));
 }
예제 #6
0
        public void NullIEnumerableDataRow()
        {
            IEnumerable <DataRow> idr = null;

            Assert.ThrowsException <ArgumentNullException>(() => DataTableConverter <Convertible> .ToEntities(idr));
        }
예제 #7
0
        public void NullDataRowCollection()
        {
            DataRowCollection drc = null;

            Assert.ThrowsException <ArgumentNullException>(() => DataTableConverter <Convertible> .ToEntities(drc));
        }
예제 #8
0
        public void EmptyDataRowCollection()
        {
            DataTable dt = new DataTable();

            Assert.ThrowsException <ArgumentException>(() => DataTableConverter <Convertible> .ToEntities(dt.Rows));
        }
예제 #9
0
        public void NullDataTable()
        {
            DataTable nullDt = null;

            Assert.ThrowsException <ArgumentNullException>(() => DataTableConverter <Convertible> .ToEntities(nullDt));
        }