public void TestIDataReaderToListOfLineDTOMapping()
        {
            IDataReader dr = new CxLineRepository().GetDataReader<CxLine>();
            IList<DxLineDTO> lineDtoList = new List<DxLineDTO>();

            try
            {
                while (dr.Read())
                {
                    var lineDto = new DxLineDTO();
                    lineDto.InjectFrom<ReaderInjection>(dr);

                    lineDtoList.Add(lineDto);
                }

                Assert.IsNotNull(lineDtoList);
                Assert.AreEqual(2, lineDtoList.Count);

                // only get this for validation reasons
                dr = new CxLineRepository().GetDataReader<CxLine>();

                foreach (DxLineDTO s in lineDtoList)
                {
                    dr.Read();

                    Assert.AreEqual(dr[CxLineRepository.FieldNames.Id], s.Id);
                    Assert.AreEqual(dr[CxLineRepository.FieldNames.Name], s.Name);
                    Assert.AreEqual(dr[CxLineRepository.FieldNames.NumberOfSwitches], s.NumberOfSwitches);
                }

                dr.Close();

            }
            finally
            {
                if (!dr.IsClosed)
                    dr.Close();
            }
        }
Example #2
0
        public void TestIDataReaderToListOfLineDTOMapping()
        {
            IDataReader dr = new CxLineRepository().GetDataReader<CxLine>();

            try
            {

                // Transform-Map
                var lineDtos = Mapper.Map<IDataReader, IEnumerable<DxLineDTO>>(dr);

                dr.Close();

                Assert.IsNotNull(lineDtos);
                Assert.AreEqual(2, lineDtos.LongCount<DxLineDTO>());

                // Convert IEnumerable to IList using Linq
                IList<DxLineDTO> lineDtoList = lineDtos.ToList();

                Assert.IsNotNull(lineDtoList);
                Assert.AreEqual(2, lineDtoList.Count);

                // only get this for validation reasons
                dr = new CxLineRepository().GetDataReader<CxLine>();

                foreach (DxLineDTO s in lineDtoList)
                {
                    dr.Read();

                    Assert.AreEqual(dr[CxLineRepository.FieldNames.Id], s.Id);
                    Assert.AreEqual(dr[CxLineRepository.FieldNames.Name], s.Name);
                    Assert.AreEqual(dr[CxLineRepository.FieldNames.NumberOfSwitches], s.NumberOfSwitches);
                }

                dr.Close();

            }
            finally
            {
                if (!dr.IsClosed)
                    dr.Close();
            }
        }