public void CopyValuesFrom_should_copy_source_values_to_result_values()
        {
            CreateStaticMap(map => map.IgnoreMember(x => x.Address));

            var dest = _randomValuesHelper.CreateInstanceWithRandomValues <Dest>();

            var dest2 = dest.CopyValuesFrom(_source);

            Assert.AreSame(dest, dest2);

            _mapTester.IgnoringMember(d => d.Address).AssertMappedValues(_source, dest);
        }
Ejemplo n.º 2
0
        public void ConvertUsing_should_work_as_expected()
        {
            CreateStaticMap(cfg => cfg.CreateMap <Source, Dest>().ConvertUsing(src => new Dest
            {
                Id      = src.Id,
                Name    = src.FullName,
                Address = "Address"
            }));

            var input = _randomValuesHelper.CreateInstanceWithRandomValues <Source>();

            AssertSourceToDestMapping(input, Mapper.Map <Source, Dest>(input));
        }
        public void WithMaximumDepth_should_work()
        {
            var helper = new RandomValuesHelper();

            var result = helper.CreateInstanceWithRandomValues <Depth1>();

            Assert.IsNotNull(result.Depth2.Depth3.Depth4, "No maximum depth");

            result = helper.WithMaximumDepth(3).CreateInstanceWithRandomValues <Depth1>();
            Assert.IsNull(result.Depth2.Depth3.Depth4, $"Maximum depth {helper.MaximumDepth}");

            result = helper.WithMaximumDepth(2).CreateInstanceWithRandomValues <Depth1>();
            Assert.IsNull(result.Depth2.Depth3, $"Maximum depth {helper.MaximumDepth}");

            result = helper.WithMaximumDepth(1).CreateInstanceWithRandomValues <Depth1>();
            Assert.IsNull(result.Depth2, $"Maximum depth {helper.MaximumDepth}");
        }
 public void TestInitialize()
 {
     _randomValuesHelper = new RandomValuesHelper();
     _source             = _randomValuesHelper.CreateInstanceWithRandomValues <Source>();
     _mapTester          = MapTester.ForMap <Source, Dest>();
 }