-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathExpressionMappingPropertyFromBaseClass.cs
More file actions
74 lines (65 loc) · 2.03 KB
/
ExpressionMappingPropertyFromBaseClass.cs
File metadata and controls
74 lines (65 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Shouldly;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace AutoMapper.Extensions.ExpressionMapping.UnitTests
{
public class ExpressionMappingPropertyFromBaseClass : AutoMapperSpecBase
{
private List<Entity> _source;
private IQueryable<Entity> entityQuery;
public class BaseDTO
{
public Guid Id { get; set; }
}
public class BaseEntity
{
public Guid Id { get; set; }
}
public class DTO : BaseDTO
{
public string Name { get; set; }
}
public class Entity : BaseEntity
{
public string Name { get; set; }
}
protected override MapperConfiguration Configuration
{
get
{
var config = ConfigurationHelper.GetMapperConfiguration(cfg =>
{
cfg.AddExpressionMapping();
// issue #1886
cfg.CreateMap<Entity, DTO>();
cfg.CreateMap<DTO, Entity>();
});
return config;
}
}
protected override void Because_of()
{
//Arrange
var guid = Guid.NewGuid();
var entity = new Entity { Id = guid, Name = "Sofia" };
_source = new List<Entity> { entity };
// Act
Expression<Func<DTO, bool>> dtoQueryExpression = r => r.Id == guid;
var entityQueryExpression = Mapper.Map<Expression<Func<Entity, bool>>>(dtoQueryExpression);
entityQuery = _source.AsQueryable().Where(entityQueryExpression);
}
[Fact]
[Description("Fix for issue #1886")]
public void Should_support_propertypath_expressions_with_properties_from_assignable_types()
{
// Assert
entityQuery.ToList().Count().ShouldBe(1);
}
}
}