Created
August 19, 2015 22:12
-
-
Save brenovieira/106b904f3899713e090d to your computer and use it in GitHub Desktop.
AutoMapper issue #840 [https://github.com/AutoMapper/AutoMapper/issues/840]
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
using System.Linq; | |
using AutoMapper; | |
using AutoMapper.QueryableExtensions; | |
using Should; | |
using Xunit; | |
namespace UnitTestProject1 | |
{ | |
public class MapAndProjectEnumsTest | |
{ | |
const SourceType SrcType = SourceType.Type2; | |
const DestinationType DestType = DestinationType.Type2; | |
private readonly Source _source = new Source { Type = SrcType }; | |
class Source | |
{ | |
public SourceType Type { get; set; } | |
} | |
enum SourceType | |
{ | |
Type1 = 0, | |
Type2 = 1 | |
} | |
class Destination | |
{ | |
public DestinationType Type { get; set; } | |
} | |
enum DestinationType | |
{ | |
Type1 = 0, | |
Type2 = 1 | |
} | |
[Fact] | |
public void Should_map_and_project_correctly_but_project_fails() | |
{ | |
Mapper.CreateMap<Source, Destination>(); | |
//map | |
var destination = Mapper.Map<Source, Destination>(_source); | |
destination.Type.ShouldEqual(DestType); | |
//project | |
var query = (new Source[] { _source }).AsQueryable(); | |
var destinations = query.ProjectTo<Destination>().ToArray(); | |
destinations[0].Type.ShouldEqual(DestType); | |
} | |
[Fact] | |
public void Should_map_and_project_correctly_but_map_fails() | |
{ | |
Mapper.CreateMap<Source, Destination>(); | |
Mapper.CreateMap<SourceType, DestinationType>().ProjectUsing(s => (DestinationType)s); | |
//map | |
var destination = Mapper.Map<Source, Destination>(_source); | |
destination.Type.ShouldEqual(DestType); | |
//project | |
var query = (new Source[] { _source }).AsQueryable(); | |
var destinations = query.ProjectTo<Destination>().ToArray(); | |
destinations[0].Type.ShouldEqual(DestType); | |
} | |
[Fact] | |
public void Should_map_and_project_correctly() | |
{ | |
Mapper.CreateMap<Source, Destination>(); | |
var m = Mapper.CreateMap<SourceType, DestinationType>(); | |
m.ProjectUsing(s => (DestinationType)s); | |
m.ConvertUsing(s => (DestinationType)s); | |
//map | |
var destination = Mapper.Map<Source, Destination>(_source); | |
destination.Type.ShouldEqual(DestType); | |
//project | |
var query = (new Source[] { _source }).AsQueryable(); | |
var destinations = query.ProjectTo<Destination>().ToArray(); | |
destinations[0].Type.ShouldEqual(DestType); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment