-
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.
Handling local constant expression. (#181)
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 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
49 changes: 49 additions & 0 deletions
49
...per.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithLocalExpressionConstant.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,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 = new MapperConfiguration | ||
( | ||
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; } | ||
} | ||
} | ||
} |