Exemple #1
0
        public IActionResult MappingNest()
        {
            var source = new OuterSource
            {
                Value = 5,
                Inner = new InnerSource {
                    OtherValue = 15
                }
            };
            var destinations = _mapper.Map <OuterSource, OuterDest>(source);

            return(new JsonResult(new { destinations.Value, destinations.Inner.OtherValue }));
        }
Exemple #2
0
        public IActionResult MappingNestedObject()
        {
            var source = new OuterSource
            {
                Value = 5,
                Inner = new InnerSource {
                    OtherValue = 15
                }
            };
            var destination = _mapper.Map <OuterDest>(source);

            return(Ok(destination));
        }
        public void ModelMapperNested()
        {
            var source = new OuterSource
            {
                Value = 5,
                Inner = new InnerSource {
                    OtherValue = 15
                }
            };

            var dest = mapper.Map <OuterSource, OuterDest>(source);

            Assert.AreEqual(dest.Value, 5);
            Assert.IsNotNull(dest.Inner);
            Assert.AreEqual(dest.Inner.OtherValue, 15);
        }
        public void TestIt()
        {
            Mapper.CreateMap<OuterSource, OuterDest>();
            Mapper.CreateMap<InnerSource, InnerDest>();

            Mapper.AssertConfigurationIsValid();

            var source = new OuterSource
                {
                    Value = 5,
                    Inner = new InnerSource {OtherValue = 15}
                };

            var dest = Mapper.Map<OuterDest>(source);

            Console.WriteLine(dest);
        }
			public void Example()
			{
				Mapper.CreateMap<OuterSource, OuterDest>();
				Mapper.CreateMap<InnerSource, InnerDest>();
				Mapper.AssertConfigurationIsValid();

				var source = new OuterSource
					{
						Value = 5,
						Inner = new InnerSource {OtherValue = 15}
					};

				var dest = Mapper.Map<OuterSource, OuterDest>(source);

				dest.Value.ShouldEqual(5);
				dest.Inner.ShouldNotBeNull();
				dest.Inner.OtherValue.ShouldEqual(15);
			}
Exemple #6
0
            public void Example()
            {
                Mapper.CreateMap <OuterSource, OuterDest>();
                Mapper.CreateMap <InnerSource, InnerDest>();
                Mapper.AssertConfigurationIsValid();

                var source = new OuterSource
                {
                    Value = 5,
                    Inner = new InnerSource {
                        OtherValue = 15
                    }
                };

                var dest = Mapper.Map <OuterSource, OuterDest>(source);

                dest.Value.ShouldEqual(5);
                dest.Inner.ShouldNotBeNull();
                dest.Inner.OtherValue.ShouldEqual(15);
            }
Exemple #7
0
			public void Example()
			{
			    var config = new MapperConfiguration(cfg =>
			    {
			        cfg.CreateMap<OuterSource, OuterDest>();
			        cfg.CreateMap<InnerSource, InnerDest>();
			    });
				config.AssertConfigurationIsValid();

				var source = new OuterSource
					{
						Value = 5,
						Inner = new InnerSource {OtherValue = 15}
					};

				var dest = config.CreateMapper().Map<OuterSource, OuterDest>(source);

				dest.Value.ShouldEqual(5);
				dest.Inner.ShouldNotBeNull();
				dest.Inner.OtherValue.ShouldEqual(15);
			}
Exemple #8
0
        public void Nested_Map_Test()
        {
            var configuration = new MapperConfiguration(
                cfg => cfg.AddProfile <AutoMapperProfile>());
            var mapper = new Mapper(configuration);

            configuration.AssertConfigurationIsValid();

            var source = new OuterSource
            {
                Value = 5,
                Inner = new InnerSource {
                    OtherValue = 15
                }
            };

            var dest = mapper.Map <OuterSource, OuterDest>(source);

            Assert.AreEqual(5, dest.Value);
            Assert.IsNotNull(dest.Inner);
            Assert.AreEqual(15, dest.Inner.OtherValue);
        }
Exemple #9
0
            public void Example()
            {
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <OuterSource, OuterDest>();
                    cfg.CreateMap <InnerSource, InnerDest>();
                });

                config.AssertConfigurationIsValid();

                var source = new OuterSource
                {
                    Value = 5,
                    Inner = new InnerSource {
                        OtherValue = 15
                    }
                };

                var dest = config.CreateMapper().Map <OuterSource, OuterDest>(source);

                dest.Value.ShouldBe(5);
                dest.Inner.ShouldNotBeNull();
                dest.Inner.OtherValue.ShouldBe(15);
            }