-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathCanMapExpressionWithLocalExpressionConstant.cs
More file actions
49 lines (44 loc) · 1.55 KB
/
CanMapExpressionWithLocalExpressionConstant.cs
File metadata and controls
49 lines (44 loc) · 1.55 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Xunit;
namespace AutoMapper.Extensions.ExpressionMapping.UnitTests
{
public class CanMapExpressionWithLocalExpressionConstant
{
[Fact]
public void Map_expression_wchich_includes_local_constant()
{
//Arrange
var config = ConfigurationHelper.GetMapperConfiguration
(
cfg =>
{
cfg.CreateMap<EntityModel, Entity>();
cfg.CreateMap<Entity, EntityModel>();
}
);
config.AssertConfigurationIsValid();
var mapper = config.CreateMapper();
List<Entity> source = [
new Entity { Id = 1 },
new Entity { Id = 3 }
];
//act
Expression<Func<EntityModel, bool>> filter = f => f.Id > 2;
Expression<Func<IQueryable<EntityModel>, IQueryable<EntityModel>>> queryableExpression = q => q.Where(filter);
Expression<Func<IQueryable<Entity>, IQueryable<Entity>>> queryableExpressionMapped = mapper.MapExpression<Expression<Func<IQueryable<Entity>, IQueryable<Entity>>>>(queryableExpression);
//assert
Assert.Equal(1, queryableExpressionMapped.Compile()(source.AsQueryable()).Count());
}
public record Entity
{
public int Id { get; init; }
}
public record EntityModel
{
public int Id { get; init; }
}
}
}