-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
123 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
53 changes: 53 additions & 0 deletions
53
...pressionMapping.UnitTests/CanMapParameterBodyFromChildReferenceWithoutMemberExpression.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,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 = new MapperConfiguration(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 => (Convert(Property(x.Category, \"BrandId\"), Int32) == 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; } | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...pper.Extensions.ExpressionMapping.UnitTests/CanMapParameterBodyWithoutMemberExpression.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,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using Xunit; | ||
|
||
namespace AutoMapper.Extensions.ExpressionMapping.UnitTests | ||
{ | ||
public class CanMapParameterBodyWithoutMemberExpression | ||
{ | ||
[Fact] | ||
public void Can_map_parameter_body_without_member_expression() | ||
{ | ||
// Arrange | ||
var config = new MapperConfiguration(c => | ||
{ | ||
c.CreateMap<TestProduct, TestProductDTO>() | ||
.ForMember(p => p.Brand, c => c.MapFrom(p => EF.Property<int>(p, "BrandId"))); | ||
}); | ||
|
||
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 => (Convert(Property(x, \"BrandId\"), Int32) == 2)", mappedExpression.ToString()); | ||
} | ||
|
||
public class TestProduct | ||
{ | ||
// Empty, has shadow key named BrandId | ||
} | ||
|
||
public class TestProductDTO | ||
{ | ||
public int Brand { get; set; } | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/EF.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,12 @@ | ||
using System; | ||
|
||
namespace AutoMapper.Extensions.ExpressionMapping.UnitTests | ||
{ | ||
internal class EF | ||
{ | ||
internal static object Property<T>(object p, string v) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |