-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathCanMapParameterBodyFromChildReferenceWithoutMemberExpression.cs
More file actions
53 lines (45 loc) · 1.59 KB
/
CanMapParameterBodyFromChildReferenceWithoutMemberExpression.cs
File metadata and controls
53 lines (45 loc) · 1.59 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Xunit;
namespace AutoMapper.Extensions.ExpressionMapping.UnitTests
{
public class CanMapParameterBodyFromChildReferenceWithoutMemberExpression
{
[Fact]
public void Can_map_parameter_body_from_child_reference_without_member_expression()
{
// Arrange
var config = ConfigurationHelper.GetMapperConfiguration(c =>
{
c.CreateMap<TestCategory, TestProductDTO>()
.ForMember(p => p.Brand, c => c.MapFrom(p => EF.Property<int>(p, "BrandId"))); ;
c.CreateMap<TestProduct, TestProductDTO>()
.IncludeMembers(p => p.Category);
});
config.AssertConfigurationIsValid();
var mapper = config.CreateMapper();
var products = new List<TestProduct>() {
new TestProduct { }
}.AsQueryable();
//Act
Expression<Func<TestProductDTO, bool>> expr = x => x.Brand == 2;
var mappedExpression = mapper.MapExpression<Expression<Func<TestProduct, bool>>>(expr);
//Assert
Assert.Equal("x => (Property(x.Category, \"BrandId\") == 2)", mappedExpression.ToString());
}
public class TestCategory
{
// Has FK BrandId
}
public class TestProduct
{
public TestCategory Category { get; set; }
}
public class TestProductDTO
{
public int Brand { get; set; }
}
}
}