Skip to content
This repository

EnumMapper doesn't evaluate nor respect condition #143

Closed
kalebpederson opened this Issue November 04, 2011 · 1 comment

2 participants

Kaleb Pederson Jimmy Bogard
Kaleb Pederson

Here's a testcase started from a SO post:

[Flags] public enum Enum1 { One, Two };
[Flags] public enum Enum2 { Three, Four }

public class EnumTestSource
{
    public IEnumerable<Enum1> Prop1{ get; set; }
    public IEnumerable<Enum2> Prop2{ get; set; }
}

public class EnumTestDest
{
    public Enum1 Prop1 { get; set; }
    public Enum2 Prop2 { get; set; }
}

[TestFixture]
public class EnumMapperTest
{
    [Test]
    public void Mapper_respects_condition()
    {
        var _c1Called = false;
        var _c2Called = false;
        Mapper.CreateMap<EnumTestSource, EnumTestDest>()
            .ForMember(m => m.Prop1, o => { o.Condition(c => { _c1Called = true; return !c.IsSourceValueNull; });
                                            o.MapFrom(f => f.Prop1.Aggregate((current, next) => current | next));
                                        })
            .ForMember(m => m.Prop2, o => { o.Condition(c => { _c2Called = true; return !c.IsSourceValueNull; } );
                                            o.MapFrom(f => f.Prop2.Aggregate((current, next) => current | next));
                                        });
        var src = new EnumTestSource {Prop1 = new[] {Enum1.One}, Prop2 = null};
        var dest = Mapper.Map<EnumTestDest>(src); // will throw
        Assert.IsTrue(_c1Called);
        Assert.IsTrue(_c2Called);
    }
}
Jimmy Bogard
Owner

This one got fixed by an earlier commit.

Jimmy Bogard jbogard closed this December 17, 2011
Jimmy Bogard jbogard referenced this issue from a commit in jbogard/AutoMapper December 17, 2011
Jimmy Bogard Passing condition for an issue, closes #143 e6ec194
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.