|
@@ -49,181 +49,125 @@ namespace Luticate2.Auth.Tests.Business.ExpressionConverter
|
49
|
49
|
return new LuExpressionConverterVisitor(GetConverterOptions(), GetServiceProvider());
|
50
|
50
|
}
|
51
|
51
|
|
52
|
|
- [Fact]
|
53
|
|
- public void TestSimpleProperty1()
|
|
52
|
+ public static IEnumerable<object[]> GetTests()
|
54
|
53
|
{
|
55
|
|
- Expression<Func<TestDbo2, Guid>> expDbo = (x => x.TestDbo1.Id);
|
56
|
|
- Expression<Func<TestModel2, Guid>> expModel = (Param_0 => Param_0.test_model1.id);
|
57
|
|
- var converter = GetConverter();
|
58
|
|
- var result = converter.Visit(expDbo);
|
59
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
60
|
|
- }
|
61
|
|
-
|
62
|
|
- [Fact]
|
63
|
|
- public void TestSimpleProperty2()
|
64
|
|
- {
|
65
|
|
- Expression<Func<TestDbo2, bool>> expDbo = (x => x.TestDbo1.Id == Guid.Empty);
|
66
|
|
- Expression<Func<TestModel2, bool>> expModel = (Param_0 => Param_0.test_model1.id == Guid.Empty);
|
67
|
|
- var converter = GetConverter();
|
68
|
|
- var result = converter.Visit(expDbo);
|
69
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
70
|
|
- }
|
71
|
|
-
|
72
|
|
- [Fact]
|
73
|
|
- public void TestSimpleProperty3()
|
74
|
|
- {
|
75
|
|
- Expression<Func<TestDbo2, bool>> expDbo = (x => x.TestDbo1.Name.Length == 2);
|
76
|
|
- Expression<Func<TestModel2, bool>> expModel = (Param_0 => Param_0.test_model1.name.Length == 2);
|
77
|
|
- var converter = GetConverter();
|
78
|
|
- var result = converter.Visit(expDbo);
|
79
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
80
|
|
- }
|
81
|
|
-
|
82
|
|
- [Fact]
|
83
|
|
- public void TestStaticProperty1()
|
84
|
|
- {
|
85
|
|
- Expression<Func<TestDbo2, bool>> expDbo = (x => (x.TestDbo1.Name == "42") == StaticDbo.StaticField);
|
86
|
|
- Expression<Func<TestModel2, bool>> expModel = (Param_0 => (Param_0.test_model1.name == "42") == StaticDbo.StaticField);
|
87
|
|
- var converter = GetConverter();
|
88
|
|
- var result = converter.Visit(expDbo);
|
89
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
90
|
|
- }
|
91
|
|
-
|
92
|
|
- [Fact]
|
93
|
|
- public void TestStaticProperty2()
|
94
|
|
- {
|
95
|
|
- Expression<Func<TestDbo2, bool>> expDbo = (x => (x.TestDbo1.Name == "42") == StaticDbo.StaticProperty);
|
96
|
|
- Expression<Func<TestModel2, bool>> expModel = (Param_0 => (Param_0.test_model1.name == "42") == StaticDbo.StaticProperty);
|
97
|
|
- var converter = GetConverter();
|
98
|
|
- var result = converter.Visit(expDbo);
|
99
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
100
|
|
- }
|
101
|
|
-
|
102
|
|
- [Fact]
|
103
|
|
- public void TestVirtualProperty1()
|
104
|
|
- {
|
105
|
|
- Expression<Func<TestDbo2, string>> expDbo = (x => x.NameVirtual);
|
106
|
|
- Expression<Func<TestModel2, string>> expModel = (Param_0 => Param_0.name == null ? "[no data]" : Param_0.name + " " + Param_0.name);
|
107
|
|
- var converter = GetConverter();
|
108
|
|
- var result = converter.Visit(expDbo);
|
109
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
110
|
|
- }
|
111
|
|
-
|
112
|
|
- [Fact]
|
113
|
|
- public void TestVirtualProperty2()
|
114
|
|
- {
|
115
|
|
- Expression<Func<TestDbo2, string>> expDbo = (x => x.Parent.NameVirtual);
|
116
|
|
- Expression<Func<TestModel2, string>> expModel = (Param_0 => Param_0.parent.name == null ? "[no data]" : Param_0.parent.name + " " + Param_0.parent.name);
|
117
|
|
- var converter = GetConverter();
|
118
|
|
- var result = converter.Visit(expDbo);
|
119
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
120
|
|
- }
|
121
|
|
-
|
122
|
|
- [Fact]
|
123
|
|
- public void TestStaticValue1()
|
124
|
|
- {
|
125
|
|
- Expression<Func<TestDbo2, int>> expDbo = (x => 0);
|
126
|
|
- Expression<Func<TestModel2, int>> expModel = (Param_0 => 0);
|
127
|
|
- var converter = GetConverter();
|
128
|
|
- var result = converter.Visit(expDbo);
|
129
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
130
|
|
- }
|
131
|
|
-
|
132
|
|
- [Fact]
|
133
|
|
- public void TestStaticValue2()
|
134
|
|
- {
|
135
|
|
- Expression<Func<TestDbo2, TestDbo2>> expDbo = (x => x);
|
136
|
|
- Expression<Func<TestModel2, TestModel2>> expModel = (Param_0 => Param_0);
|
137
|
|
- var converter = GetConverter();
|
138
|
|
- var result = converter.Visit(expDbo);
|
139
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
140
|
|
- }
|
141
|
|
-
|
142
|
|
- [Fact]
|
143
|
|
- public void TestStaticValue3()
|
144
|
|
- {
|
145
|
|
- Expression<Func<TestDbo2, bool>> expDbo = (x => StaticDbo.StaticField);
|
146
|
|
- Expression<Func<TestModel2, bool>> expModel = (Param_0 => StaticDbo.StaticField);
|
147
|
|
- var converter = GetConverter();
|
148
|
|
- var result = converter.Visit(expDbo);
|
149
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
150
|
|
- }
|
151
|
|
-
|
152
|
|
- [Fact]
|
153
|
|
- public void TestComplexExpression1()
|
154
|
|
- {
|
155
|
|
- Expression<Func<TestDbo2, int>> expDbo = (x => (x.Name + " " + x.Name).Length);
|
156
|
|
- Expression<Func<TestModel2, int>> expModel = (Param_0 => (Param_0.name + " " + Param_0.name).Length);
|
157
|
|
- var converter = GetConverter();
|
158
|
|
- var result = converter.Visit(expDbo);
|
159
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
160
|
|
- }
|
161
|
|
-
|
162
|
|
- [Fact]
|
163
|
|
- public void TestComplexExpression2()
|
164
|
|
- {
|
165
|
|
- Expression<Func<TestDbo2, int>> expDbo = (x => (x.NameVirtual + " " + x.Name).Length);
|
166
|
|
- Expression<Func<TestModel2, int>> expModel = (Param_0 => ((Param_0.name == null ? "[no data]" : (Param_0.name + " " + Param_0.name)) + " " + Param_0.name).Length);
|
167
|
|
- var converter = GetConverter();
|
168
|
|
- var result = converter.Visit(expDbo);
|
169
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
170
|
|
- }
|
171
|
|
-
|
172
|
|
- [Fact]
|
173
|
|
- public void TestSimpleMethodSimpleArg1()
|
174
|
|
- {
|
175
|
|
- Expression<Func<TestDbo2, bool>> expDbo = (x => x.Name.Contains("s"));
|
176
|
|
- Expression<Func<TestModel2, bool>> expModel = (Param_0 => Param_0.name.Contains("s"));
|
177
|
|
- var converter = GetConverter();
|
178
|
|
- var result = converter.Visit(expDbo);
|
179
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
180
|
|
- }
|
181
|
|
-
|
182
|
|
- [Fact]
|
183
|
|
- public void TestSimpleMethodSimpleArg2()
|
184
|
|
- {
|
185
|
|
- Expression<Func<TestDbo2, bool>> expDbo = (x => x.TestDbo1.Name.Contains("s"));
|
186
|
|
- Expression<Func<TestModel2, bool>> expModel = (Param_0 => Param_0.test_model1.name.Contains("s"));
|
187
|
|
- var converter = GetConverter();
|
188
|
|
- var result = converter.Visit(expDbo);
|
189
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
190
|
|
- }
|
191
|
|
-
|
192
|
|
- [Fact]
|
193
|
|
- public void TestSimpleMethodSimpleArg3()
|
194
|
|
- {
|
195
|
|
- Expression<Func<TestDbo2, string>> expDbo = (x => x.TestDbo1.ToString());
|
196
|
|
- Expression<Func<TestModel2, string>> expModel = (Param_0 => Param_0.test_model1.id + ": " + Param_0.test_model1.name);
|
197
|
|
- var converter = GetConverter();
|
198
|
|
- var result = converter.Visit(expDbo);
|
199
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
200
|
|
- }
|
201
|
|
-
|
202
|
|
- [Fact]
|
203
|
|
- public void TestSimpleMethodAdvArg1()
|
204
|
|
- {
|
205
|
|
- Expression<Func<TestDbo2, bool>> expDbo = (x => x.TestDbo1.Name.Contains(x.Name));
|
206
|
|
- Expression<Func<TestModel2, bool>> expModel = (Param_0 => Param_0.test_model1.name.Contains(Param_0.name));
|
207
|
|
- var converter = GetConverter();
|
208
|
|
- var result = converter.Visit(expDbo);
|
209
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
210
|
|
- }
|
211
|
|
-
|
212
|
|
- [Fact]
|
213
|
|
- public void TestAdvMethodSimpleArg1()
|
214
|
|
- {
|
215
|
|
- Expression<Func<TestDbo1, bool>> expDbo = (x => x.TestDbo2s.Any());
|
216
|
|
- Expression<Func<TestModel1, bool>> expModel = (Param_0 => Param_0.test_model2.Any());
|
217
|
|
- var converter = GetConverter();
|
218
|
|
- var result = converter.Visit(expDbo);
|
219
|
|
- Assert.Equal(expModel.ToString(), result?.ToString());
|
|
54
|
+ return new List<object[]>
|
|
55
|
+ {
|
|
56
|
+ new object[]
|
|
57
|
+ {
|
|
58
|
+ "TestSimpleProperty1",
|
|
59
|
+ (Expression<Func<TestDbo2, Guid>>) (x => x.TestDbo1.Id),
|
|
60
|
+ (Expression<Func<TestModel2, Guid>>) (Param_0 => Param_0.test_model1.id)
|
|
61
|
+ },
|
|
62
|
+ new object[]
|
|
63
|
+ {
|
|
64
|
+ "TestSimpleProperty2",
|
|
65
|
+ (Expression<Func<TestDbo2, bool>>) (x => x.TestDbo1.Id == Guid.Empty),
|
|
66
|
+ (Expression<Func<TestModel2, bool>>) (Param_0 => Param_0.test_model1.id == Guid.Empty)
|
|
67
|
+ },
|
|
68
|
+ new object[]
|
|
69
|
+ {
|
|
70
|
+ "TestSimpleProperty3",
|
|
71
|
+ (Expression<Func<TestDbo2, bool>>) (x => x.TestDbo1.Name.Length == 2),
|
|
72
|
+ (Expression<Func<TestModel2, bool>>) (Param_0 => Param_0.test_model1.name.Length == 2)
|
|
73
|
+ },
|
|
74
|
+ new object[]
|
|
75
|
+ {
|
|
76
|
+ "TestStaticProperty1",
|
|
77
|
+ (Expression<Func<TestDbo2, bool>>) (x => (x.TestDbo1.Name == "42") == StaticDbo.StaticField),
|
|
78
|
+ (Expression<Func<TestModel2, bool>>) (Param_0 => (Param_0.test_model1.name == "42") == StaticDbo.StaticField)
|
|
79
|
+ },
|
|
80
|
+ new object[]
|
|
81
|
+ {
|
|
82
|
+ "TestStaticProperty2",
|
|
83
|
+ (Expression<Func<TestDbo2, bool>>) (x => (x.TestDbo1.Name == "42") == StaticDbo.StaticProperty),
|
|
84
|
+ (Expression<Func<TestModel2, bool>>) (Param_0 => (Param_0.test_model1.name == "42") == StaticDbo.StaticProperty)
|
|
85
|
+ },
|
|
86
|
+ new object[]
|
|
87
|
+ {
|
|
88
|
+ "TestVirtualProperty1",
|
|
89
|
+ (Expression<Func<TestDbo2, string>>) (x => x.NameVirtual),
|
|
90
|
+ (Expression<Func<TestModel2, string>>) (Param_0 => Param_0.name == null ? "[no data]" : Param_0.name + " " + Param_0.name)
|
|
91
|
+ },
|
|
92
|
+ new object[]
|
|
93
|
+ {
|
|
94
|
+ "TestVirtualProperty2",
|
|
95
|
+ (Expression<Func<TestDbo2, string>>) (x => x.Parent.NameVirtual),
|
|
96
|
+ (Expression<Func<TestModel2, string>>) (Param_0 => Param_0.parent.name == null ? "[no data]" : Param_0.parent.name + " " + Param_0.parent.name)
|
|
97
|
+ },
|
|
98
|
+ new object[]
|
|
99
|
+ {
|
|
100
|
+ "TestStaticValue1",
|
|
101
|
+ (Expression<Func<TestDbo2, int>>) (x => 0),
|
|
102
|
+ (Expression<Func<TestModel2, int>>) (Param_0 => 0)
|
|
103
|
+ },
|
|
104
|
+ new object[]
|
|
105
|
+ {
|
|
106
|
+ "TestStaticValue2",
|
|
107
|
+ (Expression<Func<TestDbo2, TestDbo2>>) (x => x),
|
|
108
|
+ (Expression<Func<TestModel2, TestModel2>>) (Param_0 => Param_0)
|
|
109
|
+ },
|
|
110
|
+ new object[]
|
|
111
|
+ {
|
|
112
|
+ "TestStaticValue3",
|
|
113
|
+ (Expression<Func<TestDbo2, bool>>) (x => StaticDbo.StaticField),
|
|
114
|
+ (Expression<Func<TestModel2, bool>>) (Param_0 => StaticDbo.StaticField)
|
|
115
|
+ },
|
|
116
|
+ new object[]
|
|
117
|
+ {
|
|
118
|
+ "TestComplexExpression1",
|
|
119
|
+ (Expression<Func<TestDbo2, int>>) (x => (x.Name + " " + x.Name).Length),
|
|
120
|
+ (Expression<Func<TestModel2, int>>) (Param_0 => (Param_0.name + " " + Param_0.name).Length)
|
|
121
|
+ },
|
|
122
|
+ new object[]
|
|
123
|
+ {
|
|
124
|
+ "TestComplexExpression2",
|
|
125
|
+ (Expression<Func<TestDbo2, int>>) (x => (x.NameVirtual + " " + x.Name).Length),
|
|
126
|
+ (Expression<Func<TestModel2, int>>) (Param_0 => ((Param_0.name == null ? "[no data]" : (Param_0.name + " " + Param_0.name)) + " " + Param_0.name).Length)
|
|
127
|
+ },
|
|
128
|
+ new object[]
|
|
129
|
+ {
|
|
130
|
+ "TestSimpleMethodSimpleArg1",
|
|
131
|
+ (Expression<Func<TestDbo2, bool>>) (x => x.Name.Contains("s")),
|
|
132
|
+ (Expression<Func<TestModel2, bool>>) (Param_0 => Param_0.name.Contains("s"))
|
|
133
|
+ },
|
|
134
|
+ new object[]
|
|
135
|
+ {
|
|
136
|
+ "TestSimpleMethodSimpleArg2",
|
|
137
|
+ (Expression<Func<TestDbo2, bool>>) (x => x.TestDbo1.Name.Contains("s")),
|
|
138
|
+ (Expression<Func<TestModel2, bool>>) (Param_0 => Param_0.test_model1.name.Contains("s"))
|
|
139
|
+ },
|
|
140
|
+ new object[]
|
|
141
|
+ {
|
|
142
|
+ "TestSimpleMethodSimpleArg3",
|
|
143
|
+ (Expression<Func<TestDbo2, string>>) (x => x.TestDbo1.ToString()),
|
|
144
|
+ (Expression<Func<TestModel2, string>>) (Param_0 => Param_0.test_model1.id + ": " + Param_0.test_model1.name)
|
|
145
|
+ },
|
|
146
|
+ new object[]
|
|
147
|
+ {
|
|
148
|
+ "TestSimpleMethodAdvArg1",
|
|
149
|
+ (Expression<Func<TestDbo2, bool>>) (x => x.TestDbo1.Name.Contains(x.Name)),
|
|
150
|
+ (Expression<Func<TestModel2, bool>>) (Param_0 => Param_0.test_model1.name.Contains(Param_0.name))
|
|
151
|
+ },
|
|
152
|
+ new object[]
|
|
153
|
+ {
|
|
154
|
+ "TestAdvMethodSimpleArg1",
|
|
155
|
+ (Expression<Func<TestDbo1, bool>>) (x => x.TestDbo2s.Any()),
|
|
156
|
+ (Expression<Func<TestModel1, bool>>) (Param_0 => Param_0.test_model2.Any())
|
|
157
|
+ },
|
|
158
|
+ new object[]
|
|
159
|
+ {
|
|
160
|
+ "TestAdvMethodAdvArg1",
|
|
161
|
+ (Expression<Func<TestDbo1, bool>>) (x => x.TestDbo2s.Any(y => y.Name.Contains(x.Name + "s"))),
|
|
162
|
+ (Expression<Func<TestModel1, bool>>) (Param_0 => Param_0.test_model2.Any(Param_1 => Param_1.name.Contains(Param_0.name + "s")))
|
|
163
|
+ }
|
|
164
|
+ };
|
220
|
165
|
}
|
221
|
166
|
|
222
|
|
- [Fact]
|
223
|
|
- public void TestAdvMethodAdvArg1()
|
|
167
|
+ [Theory]
|
|
168
|
+ [MemberData(nameof(GetTests))]
|
|
169
|
+ public void Test(string testName, LambdaExpression expDbo, LambdaExpression expModel)
|
224
|
170
|
{
|
225
|
|
- Expression<Func<TestDbo1, bool>> expDbo = (x => x.TestDbo2s.Any(y => y.Name.Contains(x.Name + "s")));
|
226
|
|
- Expression<Func<TestModel1, bool>> expModel = (Param_0 => Param_0.test_model2.Any(Param_1 => Param_1.name.Contains(Param_0.name + "s")));
|
227
|
171
|
var converter = GetConverter();
|
228
|
172
|
var result = converter.Visit(expDbo);
|
229
|
173
|
Assert.Equal(expModel.ToString(), result?.ToString());
|