Skip to content

Can't map items from diferent levels #3

@marconsilva

Description

@marconsilva

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; }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions