1
1
using System . Collections . Generic ;
2
+ using System . Linq . Dynamic . Core . Exceptions ;
2
3
using System . Linq . Dynamic . Core . Parser ;
3
4
using System . Linq . Expressions ;
4
5
using FluentAssertions ;
@@ -216,9 +217,10 @@ public void ParseTypeAccess_Via_Constructor_DynamicType_To_String(string newExpr
216
217
// Arrange
217
218
var parameter = Expression . Parameter ( typeof ( int ) ) ;
218
219
var parameter2 = Expression . Parameter ( typeof ( int ) ) ;
219
- var returnType = DynamicClassFactory . CreateType ( new List < DynamicProperty > {
220
- new DynamicProperty ( "a" , typeof ( int ) ) ,
221
- new DynamicProperty ( "b" , typeof ( int ) )
220
+ var returnType = DynamicClassFactory . CreateType ( new List < DynamicProperty >
221
+ {
222
+ new ( "a" , typeof ( int ) ) ,
223
+ new ( "b" , typeof ( int ) )
222
224
} ) ;
223
225
224
226
// Act
@@ -228,4 +230,27 @@ public void ParseTypeAccess_Via_Constructor_DynamicType_To_String(string newExpr
228
230
// Assert
229
231
expression . ToString ( ) . Should ( ) . Match ( newExpression2 ) ;
230
232
}
233
+
234
+ [ Fact ]
235
+ public void Parse_NewOperator_When_DisallowNewKeyword_Is_True_Should_Throw_Exception ( )
236
+ {
237
+ // Arrange
238
+ var parameter = Expression . Parameter ( typeof ( int ) ) ;
239
+ var returnType = DynamicClassFactory . CreateType ( new List < DynamicProperty >
240
+ {
241
+ new ( "a" , typeof ( int ) )
242
+ } ) ;
243
+ var config = new ParsingConfig
244
+ {
245
+ DisallowNewKeyword = true
246
+ } ;
247
+
248
+ // Act
249
+ var parser = new ExpressionParser ( new [ ] { parameter } , "new(1 as a)" , new object [ ] { } , config ) ;
250
+
251
+ Action action = ( ) => parser . Parse ( returnType ) ;
252
+
253
+ // Assert
254
+ action . Should ( ) . Throw < ParseException > ( ) . Which . Message . Should ( ) . Be ( Res . NewOperatorIsNotAllowed ) ;
255
+ }
231
256
}
0 commit comments