Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions AgileMapper.UnitTests/Configuration/WhenConfiguringDataSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,5 +860,40 @@ public void ShouldRestrictConfigurationApplicationByMappingRuleSet()
overwriteResult.Value.ShouldBe(source.Value);
}
}

// See https://github.com/agileobjects/AgileMapper/issues/14
[Fact]
public void ShouldAllowIdAndIdentifierConfiguration()
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<PublicTwoFields<int, int>>()
.To<IdTester>()
.Map((ptf, id) => ptf.Value1)
.To(id => id.ClassId)
.And
.Map((ptf, id) => ptf.Value2)
.To(id => id.ClassIdentifier);

var source = new PublicTwoFields<int, int>
{
Value1 = 123,
Value2 = 987
};

var result = mapper.Map(source).ToANew<IdTester>();

result.ClassId.ShouldBe(123);
result.ClassIdentifier.ShouldBe(987);
}
}

private class IdTester
{
public int ClassId { get; set; }

public int ClassIdentifier { get; set; }
}
}
}
5 changes: 4 additions & 1 deletion AgileMapper/Configuration/UserConfiguredItemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ public virtual bool ConflictsWith(UserConfiguredItemBase otherConfiguredItem)

if (ConfigInfo.HasCompatibleTypes(otherConfiguredItem.ConfigInfo))
{
return TargetMember.Matches(otherConfiguredItem.TargetMember);
return MembersConflict(otherConfiguredItem.TargetMember);
}

return false;
}

protected virtual bool MembersConflict(QualifiedMember otherMember)
=> TargetMember.Matches(otherMember);

protected bool SourceAndTargetTypesAreTheSame(UserConfiguredItemBase otherConfiguredItem)
{
return ConfigInfo.HasSameSourceTypeAs(otherConfiguredItem.ConfigInfo) &&
Expand Down
4 changes: 4 additions & 0 deletions AgileMapper/DataSources/ConfiguredDataSourceFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace AgileObjects.AgileMapper.DataSources
{
using System.Linq;
using System.Linq.Expressions;
using Configuration;
using Members;
Expand Down Expand Up @@ -48,6 +49,9 @@ public override bool ConflictsWith(UserConfiguredItemBase otherConfiguredItem)
return _dataSourceLambda.IsSameAs(otherDataSource._dataSourceLambda);
}

protected override bool MembersConflict(QualifiedMember otherMember)
=> TargetMember.LeafMember.Equals(otherMember.LeafMember);

public IConfiguredDataSource Create(IMemberMapperData mapperData)
{
var configuredCondition = GetConditionOrNull(mapperData);
Expand Down