forked from zzzprojects/System.Linq.Dynamic.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpressionParserTests.MemberAccess.cs
More file actions
101 lines (81 loc) · 3.05 KB
/
ExpressionParserTests.MemberAccess.cs
File metadata and controls
101 lines (81 loc) · 3.05 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.Linq.Dynamic.Core.CustomTypeProviders;
using FluentAssertions;
using Xunit;
namespace System.Linq.Dynamic.Core.Tests.Parser
{
partial class ExpressionParserTests
{
[Fact]
public void ParseMemberAccess_DictionaryIndex_On_Dynamic()
{
// Arrange
var products = new ProductDynamic[0].AsQueryable();
// Act
var expression = products.Where("Properties.Name == @0", "First Product").Expression;
// Assert
#if NET461 || NET48
expression.ToString().Should().Be("System.Linq.Dynamic.Core.Tests.Parser.ProductDynamic[].Where(Param_0 => (GetMember Name(Param_0.Properties) == Convert(\"First Product\")))");
#else
expression.ToString().Should().Be("System.Linq.Dynamic.Core.Tests.Parser.ProductDynamic[].Where(Param_0 => ([Dynamic] == Convert(\"First Product\", Object)))");
#endif
}
[Theory]
[InlineData("Prop", "TestProp")]
[InlineData("Field", "TestField")]
[InlineData("Constant", "ConstantField")]
public void Parse_StaticPropertyOrField_In_StaticClass1(string name, string value)
{
// Arrange
var queryable = new int[1].AsQueryable();
// Act
var result = queryable.Select<string>($"{typeof(StaticClassExample)}.{name}").First();
// Assert
Assert.Equal(value, result);
}
[Theory]
[InlineData("Prop", "TestProp")]
[InlineData("Field", "TestField")]
[InlineData("Constant", "ConstantField")]
public void Parse_StaticPropertyOrField_In_NonStaticClass1(string name, string value)
{
// Arrange
var queryable = new int[1].AsQueryable();
// Act
var result = queryable.Select<string>($"new {typeof(NonStaticClassExample)}().{name}").First();
// Assert
Assert.Equal(value, result);
}
[Theory]
[InlineData("Prop", "TestProp")]
[InlineData("Field", "TestField")]
[InlineData("Constant", "ConstantField")]
public void Parse_StaticPropertyOrField_In_NonStaticClass2(string name, string value)
{
// Arrange
var queryable = new[] { new NonStaticClassExample() }.AsQueryable();
// Act
var result = queryable.Select<string>(name).First();
// Assert
Assert.Equal(value, result);
}
}
[DynamicLinqType]
public class StaticClassExample
{
public static string Prop { get; set; } = "TestProp";
public static string Field = "TestField";
public const string Constant = "ConstantField";
}
[DynamicLinqType]
public class NonStaticClassExample
{
public static string Prop { get; set; } = "TestProp";
public static string Field = "TestField";
public const string Constant = "ConstantField";
}
public class ProductDynamic
{
public string ProductId { get; set; }
public dynamic Properties { get; set; }
}
}