SafeMapper icon indicating copy to clipboard operation
SafeMapper copied to clipboard

Can't map items from diferent levels

Open marconsilva opened this issue 9 years ago • 1 comments

I've created 2 tests that reproduce the issue, basically I can't map properties from diferente depths in the classes. Here are the 2 tests that fail and illustrate the issue:

    [TestMethod]
    public void SafeMapper_CreateMap_PersonToPersonPortugueseWithComplexTypeDiferentLevelsMapping()
    {
        SafeMap.CreateMap<Person, PersonPortuguese>(
            cfg =>
            {
                cfg.Map(x => x.StreetName, x => x.Morada.NomeDaRua);
            });

        var person = new Person
        {
            StreetName = "Microsoft Street",
        };
        var result = SafeMap.Convert<Person, PersonPortuguese>(person);

        Assert.AreEqual(person.StreetName, result.Morada.NomeDaRua);
    }

    [TestMethod]
    public void SafeMapper_CreateMap_PersonPortugueseToPersonWithComplexTypeDiferentLevelsMapping()
    {
        SafeMap.CreateMap<PersonPortuguese, Person>(
            cfg =>
            {
                cfg.Map(x => x.Morada.NomeDaRua, x => x.StreetName);
            });


        var person = new PersonPortuguese
        {
            Morada = new AddressPortuguese()
            {
                NumeroDePorta = 12,
                NomeDaRua = "Microsoft Street",
                CodigoPostal = "1234-567"
            }
        };
        var result = SafeMap.Convert<PersonPortuguese, Person>(person);

        Assert.AreEqual(person.Morada.NomeDaRua, result.StreetName);
    }

    public class PersonPortuguese
    {
            public AddressPortuguese Morada { get; set; }
    }
    public class Person
    {
            public string StreetName { get; set; }
    }
    public sealed class Address
    {
            public string StreetName { get; set; }
            public int DoorNumber { get; set; }
            public string ZipCode { get; set; }
    }

marconsilva avatar Nov 19 '15 18:11 marconsilva

This is actually a feature that is not implemented yet. I have plans to implement this in the future. Thanks for the unit tests, I can use them when I implement this.

unger avatar Jan 21 '16 12:01 unger