public void ShouldNotCreateDictionaryAsFallbackComplexType()
        {
            var source = new PublicReadOnlyProperty <IDictionary <string, string> >(
                new Dictionary <string, string>());

            var cloned = Mapper.DeepClone(source);

            cloned.ShouldBeNull();
        }
        public void ShouldHandleANullReadOnlyNestedMemberProperty()
        {
            var source = new PublicField <Address> {
                Value = new Address {
                    Line1 = "New value"
                }
            };
            var target = new PublicReadOnlyProperty <Address>(default(Address));
            var result = Mapper.Map(source).Over(target);

            result.Value.ShouldBeNull();
        }
        public void ShouldUseACloneConstructorToPopulateADictionaryConstructorParameter()
        {
            var source = new PublicReadOnlyProperty <IDictionary <string, string> >(
                new Dictionary <string, string> {
                ["Test"] = "Hello!"
            });

            var result = Mapper.Map(source).ToANew <PublicCtor <IDictionary <string, string> > >();

            result.Value.ContainsKey("Test").ShouldBeTrue();
            result.Value["Test"].ShouldBe("Hello!");
        }
Пример #4
0
        public void ShouldNotOverwriteANonNullReadOnlyNestedMemberProperty()
        {
            var source = new PublicField <Address> {
                Value = new Address {
                    Line1 = "Nope"
                }
            };
            var address = new Address {
                Line1 = "Yep"
            };
            var target = new PublicReadOnlyProperty <Address>(address);
            var result = Mapper.Map(source).OnTo(target);

            result.Value.ShouldNotBeNull();
            result.Value.ShouldBeSameAs(address);
            result.Value.Line1.ShouldBe("Yep");
        }
Пример #5
0
        public void ShouldIgnoreAReadOnlyComplexTypeMember()
        {
            using (var mapper = Mapper.CreateNew())
            {
                mapper.WhenMapping
                .To <PublicReadOnlyProperty <Address> >()
                .Ignore(psm => psm.Value);

                var source = new PublicField <Address> {
                    Value = new Address {
                        Line1 = "Use this!"
                    }
                };
                var target = new PublicReadOnlyProperty <Address>(new Address {
                    Line1 = "Ignore this!"
                });

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

                target.Value.Line1.ShouldBe("Ignore this!");
            }
        }