-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from AutoMapper/Issue85
Fix for Issue 85: Missing type map configuration or unsupported mapping
- Loading branch information
Showing
6 changed files
with
50 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ShouldOnlyMapExistingTypeMaps.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using Xunit; | ||
|
||
namespace AutoMapper.Extensions.ExpressionMapping.UnitTests | ||
{ | ||
public class ShouldOnlyMapExistingTypeMaps | ||
{ | ||
[Fact] | ||
public void Issue85() | ||
{ | ||
var config = new MapperConfiguration(cfg => | ||
{ | ||
cfg.AddExpressionMapping(); | ||
|
||
cfg.CreateMap<Source, SourceDto>() | ||
.ForMember(o => o.Items, config => config.MapFrom(p => p.Items.Select(s => s.Name))); | ||
|
||
cfg.CreateMap<SourceDto, Source>() | ||
.ForMember(o => o.Items, config => config.MapFrom(p => p.Items.Select(s => new SubSource { Name = s }))); | ||
}); | ||
|
||
var mapper = config.CreateMapper(); | ||
|
||
Expression<Func<Source, bool>> expression1 = o => string.Equals("item1", "item2"); | ||
var mapped1 = mapper.MapExpression<Expression<Func<SourceDto, bool>>>(expression1); | ||
|
||
Expression<Func<SourceDto, bool>> expression2 = o => string.Equals("item1", "item2"); | ||
var mapped2 = mapper.MapExpression<Expression<Func<Source, bool>>>(expression2); | ||
|
||
Assert.NotNull(mapped1); | ||
Assert.NotNull(mapped2); | ||
} | ||
|
||
public class Source { public ICollection<SubSource> Items { get; set; } } | ||
|
||
public class SubSource { public int ID { get; set; } public string Name { get; set; } } | ||
|
||
public class SourceDto { public string[] Items { get; set; } } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters