コード例 #1
0
        public void TestListOfLinesToListOfLineViewModelMapping()
        {
            IList<CxLine> lines = new CxLineRepository().FindAll<CxLine>();

            // Transform-Map
            IList<CxLineViewModel2> lineViewModels = new List<CxLineViewModel2>();
            lineViewModels = CxLineViewModelMapper.Map(lines).ToList<CxLineViewModel2>();

            Assert.AreEqual(3, lineViewModels.Count);

            for (int i = 0; i < lineViewModels.Count; i++)
            {
                CxLineViewModel2 ds = lineViewModels[i];
                CxLine ts = lines[i];

                Assert.AreEqual(ts.Id, ds.Id);
                Assert.AreEqual(ts.Name, ds.Name);
                Assert.AreEqual(ts.NumberOfSwitches, ds.NumberOfSwitches);

                // Nested Mapping for Location
                Assert.AreEqual(ts.Location.Id, ds.Location.Id);
                Assert.AreEqual(ts.Location.AddressLine1, ds.Location.AddressLine1);
                Assert.AreEqual(ts.Location.City, ds.Location.City);
                Assert.AreEqual(ts.Location.Country, ds.Location.Country);
                Assert.AreEqual(ts.Location.Latitude, ds.Location.Latitude);
                Assert.AreEqual(ts.Location.Longitude, ds.Location.Longitude);
                Assert.AreEqual(ts.Location.PostalCode, ds.Location.PostalCode);
            }
        }
コード例 #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();
            }
        }
コード例 #3
0
        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();
            }
        }