Exemple #1
0
        public void ShouldCreateNewWithASpecifiedMapper()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <PublicField <int> >()
                .To <PublicCtorStruct <string> >()
                .Map(ctx => ctx.Source.Value * 2)
                .ToCtor <string>();

                var source = new PublicField <int> {
                    Value = 20
                };
                var result = source.MapUsing(mapper).ToANew <PublicCtorStruct <string> >();

                result.Value.ShouldBe("40");
            }
        }
Exemple #2
0
        public void ShouldOverwriteWithASpecifiedMapper()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <PublicField <int> >()
                .Over <PublicProperty <string> >()
                .Map(ctx => ctx.Source.Value + 10)
                .To(pf => pf.Value);

                var source = new PublicField <int> {
                    Value = 20
                };
                var target = new PublicProperty <string>();

                source.MapUsing(mapper).Over(target);

                target.Value.ShouldBe("30");
            }
        }
Exemple #3
0
        public void ShouldMergeWithASpecifiedMapper()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .From <PublicField <int> >()
                .OnTo <PublicField <string> >()
                .Map(ctx => ctx.Source.Value / 2)
                .To(pf => pf.Value);

                var source = new PublicField <int> {
                    Value = 20
                };
                var target = new PublicField <string>();

                source.MapUsing(mapper).OnTo(target);

                target.Value.ShouldBe("10");
            }
        }