Ejemplo n.º 1
0
        public void MapDataTableToList_ShouldThrowException_WhenNullFoundForNonNullableProperty()
        {
            // SimpleClassWithAttirbute has name "MyColumnName" (type int), but NullValueDataTable has "MyColumnName" which contains DBNull.Value and null.

            DALMap <SimpleClassWithAttribute> dALMap = new DALMap <SimpleClassWithAttribute>();
            List <SimpleClassWithAttribute>   SimpleClassWithAttirbuteList = dALMap.Map(NullValueDataTable);
        }
Ejemplo n.º 2
0
        public void MapDataTableToList_ShouldThrowException_WhenRequiredPropertyNotMapped()
        {
            // SimpleClassWithAttirbute has name "MyColumnName" (required by default), but SimpleDataTable has "Property".

            DALMap <SimpleClassWithAttribute> dALMap = new DALMap <SimpleClassWithAttribute>();
            List <SimpleClassWithAttribute>   SimpleClassWithAttirbuteList = dALMap.Map(SimpleDataTable);
        }
Ejemplo n.º 3
0
        public void DAL_ShouldGetSPResults_NoParameters()
        {
            DBResult result = dAL.ExecuteStoredProcedure("TestSP_Get_NoParam", null);

            DALMap <Store> storeMapper = new DALMap <Store>();
            List <Store>   stores      = storeMapper.Map(result.DataTable);

            Assert.IsTrue(stores.Any());
        }
Ejemplo n.º 4
0
        public void MapDataTableToList_ShouldReturnList_WhenNullFoundForNullableProperty()
        {
            // SimpleClassWithNullableAttribute has name "MyColumnName" (type int?), and NullValueDataTable has "MyColumnName" which contains DBNull.Value and null.

            DALMap <SimpleClassWithNullableAttribute> dALMap     = new DALMap <SimpleClassWithNullableAttribute>();
            List <SimpleClassWithNullableAttribute>   mappedList = dALMap.Map(NullValueDataTable);

            Assert.AreEqual(3, mappedList.Count);
        }
Ejemplo n.º 5
0
        public void MapDataTableToList_ShouldThrowException_WhenDataTypeDoesntMatch()
        {
            DataTable MyDataTable = new DataTable();

            MyDataTable.Columns.Add("MyColumnName", typeof(int));
            MyDataTable.Columns.Add("MySecondColumnName", typeof(char));
            MyDataTable.Rows.Add(new object[] { 1, 'x' });
            MyDataTable.Rows.Add(new object[] { 2, 'x' });

            // ExampleClass has name "MySecondColumnName" (type double), but MyDataTable has "MySecondColumnName" (type char).

            DALMap <ExampleClass1> dALMap     = new DALMap <ExampleClass1>();
            List <ExampleClass1>   mappedList = dALMap.Map(MyDataTable);
        }
Ejemplo n.º 6
0
        public void MapDataTableToList_ShouldReturnList_WhenNameAndTypeMatch()
        {
            DataTable MyDataTable = new DataTable();

            MyDataTable.Columns.Add("MyColumnName", typeof(int));
            MyDataTable.Rows.Add(new object[] { 1 });
            MyDataTable.Rows.Add(new object[] { 2 });

            // SimpleClassWithAttirbute has name "MyColumnName", and MyDataTable has "MyColumnName".

            DALMap <SimpleClassWithAttribute> dALMap     = new DALMap <SimpleClassWithAttribute>();
            List <SimpleClassWithAttribute>   mappedList = dALMap.Map(MyDataTable);

            Assert.AreEqual(2, mappedList.Count);
        }
Ejemplo n.º 7
0
        public void MapDataTableToList_ShouldGetFirstMatchingNameOnly()
        {
            DataTable MyDataTable = new DataTable();

            MyDataTable.Columns.Add("MyColumnName", typeof(int));
            MyDataTable.Columns.Add("SearchName3", typeof(string));     // Ignore this
            MyDataTable.Columns.Add("SearchName2", typeof(string));     // Find this
            MyDataTable.Rows.Add(new object[] { 1, 10, -1 });
            MyDataTable.Rows.Add(new object[] { 2, 11, -1 });

            DALMap <ExampleClass2> dALMap     = new DALMap <ExampleClass2>();
            List <ExampleClass2>   mappedList = dALMap.Map(MyDataTable);

            Assert.AreEqual(2, mappedList.Count);
            Assert.AreEqual("11", mappedList[1].PropertyWithManyNames);
        }
Ejemplo n.º 8
0
        public void MapDataTableToList_ShouldReturnList_WhenDataDoesImplicitConversion()
        {
            DataTable MyDataTable = new DataTable();

            MyDataTable.Columns.Add("MyColumnName", typeof(int));
            MyDataTable.Columns.Add("MySecondColumnName", typeof(int));
            MyDataTable.Rows.Add(new object[] { 1, -1 });
            MyDataTable.Rows.Add(new object[] { 2, -1 });

            // ExampleClass has name "MySecondColumnName" (type double), and MyDataTable has "MySecondColumnName" (type int). Implicit conversion: int -> double.

            DALMap <ExampleClass1> dALMap     = new DALMap <ExampleClass1>();
            List <ExampleClass1>   mappedList = dALMap.Map(MyDataTable);

            Assert.AreEqual(2, mappedList.Count);
        }
Ejemplo n.º 9
0
        public void DAL_ShouldGetSPResults_OneParameter()
        {
            // SP TestSP_Get_OneParam requires 1 parameter.
            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter("InputParam", SqlDbType.Int)
                {
                    Value = 2
                }
            };

            DBResult result = dAL.ExecuteStoredProcedure("TestSP_Get_OneParam", sqlParameters);

            DALMap <Store> storeMapper = new DALMap <Store>();
            List <Store>   stores      = storeMapper.Map(result.DataTable);

            Assert.IsTrue(stores.Any());
        }
Ejemplo n.º 10
0
        public void MapDataTableToList_ShouldReturnList_WhenGivenExtraColumns()
        {
            DataTable MyDataTable = new DataTable();

            MyDataTable.Columns.Add("MyColumnName", typeof(int));
            MyDataTable.Columns.Add("MySecondColumnName", typeof(int));
            MyDataTable.Columns.Add("IrrelevantColumn", typeof(bool));
            MyDataTable.Rows.Add(new object[] { 1, 10, false });
            MyDataTable.Rows.Add(new object[] { 2, 11, false });
            MyDataTable.Rows.Add(new object[] { 3, 12, false });

            // ExampleClass has extra unmapped property "Property".
            // MyDataTable has extra unmapped column "IrrelevantColumn".

            DALMap <ExampleClass1> dALMap     = new DALMap <ExampleClass1>();
            List <ExampleClass1>   mappedList = dALMap.Map(MyDataTable);

            Assert.AreEqual(3, mappedList.Count);
        }
Ejemplo n.º 11
0
 public void MapDataTableToList_ShouldReturnEmpty_WhenNoPropertiesToMap()
 {
     DALMap <SimpleClass> dALMap          = new DALMap <SimpleClass>();
     List <SimpleClass>   SimpleClassList = dALMap.Map(SimpleDataTable);
 }
Ejemplo n.º 12
0
 public void MapDataTableToList_ShouldReturnEmpty_WhenNoRecordsInDataTable()
 {
     DALMap <SimpleClassWithAttribute> dALMap = new DALMap <SimpleClassWithAttribute>();
     List <SimpleClassWithAttribute>   simpleClassWithAttributeList = dALMap.Map(EmptyDataTable);
 }
Ejemplo n.º 13
0
 public void MapDataTableToList_ShouldThrowException_WhenGivenUninitializedDataTable()
 {
     DALMap <SimpleClass> dALMap   = new DALMap <SimpleClass>();
     List <SimpleClass>   testList = dALMap.Map(UninitializedDataTable);
 }
Ejemplo n.º 14
0
 public void MapDataTableToList_ShouldThrowException_WhenGivenNull()
 {
     DALMap <SimpleClass> dALMap   = new DALMap <SimpleClass>();
     List <SimpleClass>   testList = dALMap.Map(null);
 }
Ejemplo n.º 15
0
        public void MapDataTableToList_ShouldReturnEmpty_WhenNoMatchingColumnsFound()
        {
            // SimpleClassWithOptionalAttirbute has name "MyColumnName" (IsRequired = false), but SimpleDataTable has "Property".

            DALMap <SimpleClassWithOptionalAttribute> dALMap = new DALMap <SimpleClassWithOptionalAttribute>();
            List <SimpleClassWithOptionalAttribute>   SimpleClassWithOptionalAttirbuteFalseList = dALMap.Map(SimpleDataTable);

            Assert.AreEqual(0, SimpleClassWithOptionalAttirbuteFalseList.Count);
        }