2 using System
.Collections
.Generic
;
4 using System
.Reflection
;
6 using System
.Linq
.Expressions
;
7 using Microsoft
.CSharp
.RuntimeBinder
;
8 using System
.Runtime
.CompilerServices
;
15 class AssertDynamicObject
: DynamicMetaObject
17 DynamicObjectMock mock
;
19 public AssertDynamicObject (DynamicObjectMock mock
, Expression parameter
)
20 : base (parameter
, BindingRestrictions
.Empty
, mock
)
25 DynamicMetaObject
GetFakeMetaObject (object value)
27 Type t
= value == null ? typeof (object) : value.GetType ();
28 var v
= Expression
.Variable (t
);
29 Expression e
= Expression
.Block (new[] { v }
, Expression
.Default (t
));
31 Expression restr
= Expression
.Constant (true);
32 return new DynamicMetaObject (e
, BindingRestrictions
.GetExpressionRestriction (restr
));
35 public override DynamicMetaObject
BindBinaryOperation (BinaryOperationBinder binder
, DynamicMetaObject arg
)
37 if (mock
.BinaryOperation
== null)
38 throw new ApplicationException ("Unexpected BindBinaryOperation");
40 mock
.BinaryOperation (binder
, arg
.Value
);
42 return GetFakeMetaObject (new object ());
45 public override DynamicMetaObject
BindConvert (ConvertBinder binder
)
47 if (mock
.ConvertOperation
== null)
48 throw new ApplicationException ("Unexpected BindConvert");
50 var r
= mock
.ConvertOperation (binder
);
52 return GetFakeMetaObject (r
);
55 public override DynamicMetaObject
BindGetIndex (GetIndexBinder binder
, DynamicMetaObject
[] indexes
)
57 if (mock
.GetIndexOperation
== null)
58 throw new ApplicationException ("Unexpected TryGetIndex");
60 mock
.GetIndexOperation (binder
, indexes
.Select (l
=> l
.Value
).ToArray ());
62 return GetFakeMetaObject (new object ());
65 public override DynamicMetaObject
BindGetMember (GetMemberBinder binder
)
67 if (mock
.GetMemberOperation
== null)
68 throw new ApplicationException ("Unexpected BindGetMember");
70 mock
.GetMemberOperation (binder
);
72 return GetFakeMetaObject (new object ());
75 public override DynamicMetaObject
BindInvoke (InvokeBinder binder
, DynamicMetaObject
[] args
)
77 if (mock
.InvokeOperation
== null)
78 throw new ApplicationException ("Unexpected BindInvoke");
80 mock
.InvokeOperation (binder
, args
.Select (l
=> l
.Value
).ToArray ());
82 return GetFakeMetaObject (new object ());
85 public override DynamicMetaObject
BindInvokeMember (InvokeMemberBinder binder
, DynamicMetaObject
[] args
)
87 if (mock
.InvokeMemberOperation
== null)
88 throw new ApplicationException ("Unexpected BindInvokeMember");
90 mock
.InvokeMemberOperation (binder
, args
.Select (l
=> l
.Value
).ToArray ());
92 return GetFakeMetaObject (new object ());
95 public override DynamicMetaObject
BindSetIndex (SetIndexBinder binder
, DynamicMetaObject
[] indexes
, DynamicMetaObject
value)
97 if (mock
.SetIndexOperation
== null)
98 throw new ApplicationException ("Unexpected TrySetIndex");
100 mock
.SetIndexOperation (binder
, indexes
.Select (l
=> l
.Value
).ToArray (), value.Value
);
102 return GetFakeMetaObject (new object ());
105 public override DynamicMetaObject
BindSetMember (SetMemberBinder binder
, DynamicMetaObject
value)
107 if (mock
.SetMemberOperation
== null)
108 throw new ApplicationException ("Unexpected BindSetMember");
110 mock
.SetMemberOperation (binder
, value.Value
);
112 return GetFakeMetaObject (new object ());
115 public override DynamicMetaObject
BindUnaryOperation (UnaryOperationBinder binder
)
117 if (mock
.UnaryOperation
== null)
118 throw new ApplicationException ("Unexpected BindUnaryOperation");
120 var r
= mock
.UnaryOperation (binder
);
122 return GetFakeMetaObject (r
);
127 class DynamicObjectMock
: DynamicObject
129 public int HitCounter
;
131 public DynamicObjectMock ()
135 public override DynamicMetaObject
GetMetaObject (System
.Linq
.Expressions
.Expression parameter
)
138 return new AssertDynamicObject (this, parameter
);
141 public Action
<BinaryOperationBinder
, object> BinaryOperation
;
142 public Func
<ConvertBinder
, object> ConvertOperation
;
143 public Action
<GetIndexBinder
, object[]> GetIndexOperation
;
144 public Action
<GetMemberBinder
> GetMemberOperation
;
145 public Action
<InvokeBinder
, object[]> InvokeOperation
;
146 public Action
<InvokeMemberBinder
, object[]> InvokeMemberOperation
;
147 public Action
<SetIndexBinder
, object[], object> SetIndexOperation
;
148 public Action
<SetMemberBinder
, object> SetMemberOperation
;
149 public Func
<UnaryOperationBinder
, object> UnaryOperation
;
151 // Dynamic arguments methods
152 public DynamicObjectMock (int i
)
156 public void DMethod (int a
)
160 public static void DStaticMethod (object t
)
164 public int this[int i
] {
173 class Tester
: DynamicObjectMock
175 static readonly int field
= 7;
181 public Tester (dynamic d
)
185 static void Assert
<T
> (T expected
, T
value, string name
)
187 if (!EqualityComparer
<T
>.Default
.Equals (expected
, value)) {
188 if (!string.IsNullOrEmpty (name
))
190 throw new ApplicationException (name
+ "Expected " + expected
+ " != " + value);
194 static void Assert
<T
> (IList
<T
> expected
, IList
<T
> value, string name
)
196 if (expected
== null) {
198 throw new ApplicationException (name
+ ": Both arrays expected to be null");
202 if (expected
.Count
!= value.Count
)
203 throw new ApplicationException (name
+ ": Array length does not match " + expected
.Count
+ " != " + value.Count
);
205 for (int i
= 0; i
< expected
.Count
; ++i
) {
206 if (!EqualityComparer
<T
>.Default
.Equals (expected
[i
], value[i
]))
207 throw new ApplicationException (name
+ ": Index " + i
+ ": " + expected
[i
] + " != " + value[i
]);
211 static FieldInfo flags
= typeof (CSharpArgumentInfo
).GetField ("flags", BindingFlags
.NonPublic
| BindingFlags
.Instance
);
213 static void AssertArgument (CallSiteBinder obj
, CSharpArgumentInfo
[] expected
, string name
)
215 var ai
= obj
.GetType ().GetField ("argumentInfo", BindingFlags
.NonPublic
| BindingFlags
.Instance
);
216 IList
<CSharpArgumentInfo
> values
= (IList
<CSharpArgumentInfo
>) ai
.GetValue (obj
);
217 if (values
.Count
!= expected
.Length
)
218 throw new ApplicationException (name
+ ": Array length does not match " + values
.Count
+ " != " + expected
.Length
);
220 for (int i
= 0; i
< expected
.Length
; i
++)
222 Assert (flags
.GetValue (expected
[i
]), flags
.GetValue (values
[i
]), "flags");
226 #pragma warning disable 168, 169, 219
228 void BinaryAdd_1 (dynamic d
, DynamicObjectMock mock
)
230 mock
.BinaryOperation
= (binder
, arg
) => {
231 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
232 AssertArgument (binder
, new[] {
233 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
234 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
237 Assert (arg
, 1, "arg");
243 void BinaryAdd_2 (dynamic d
, DynamicObjectMock mock
)
245 mock
.BinaryOperation
= (binder
, arg
) => {
246 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
247 AssertArgument (binder
, new[] {
248 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
249 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
252 Assert (arg
, null, "arg");
259 void BinaryAdd_3 (dynamic d
, DynamicObjectMock mock
)
261 mock
.BinaryOperation
= (binder
, arg
) => {
262 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
263 AssertArgument (binder
, new[] {
264 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
265 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null)
268 Assert (arg
, Enum
.A
, "arg");
274 void BinaryAdd_4 (dynamic d
, DynamicObjectMock mock
)
276 mock
.BinaryOperation
= (binder
, arg
) => {
277 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
278 AssertArgument (binder
, new[] {
279 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
280 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
283 Assert (arg
, 7, "arg");
286 d
= d
+ Tester
.field
;
289 void BinaryAddChecked_1 (dynamic d
, DynamicObjectMock mock
)
291 mock
.BinaryOperation
= (binder
, arg
) => {
292 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
293 AssertArgument (binder
, new[] {
294 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
295 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
| CSharpArgumentInfoFlags
.Constant
, null) },
298 Assert (arg
, 3, "arg");
304 void BinaryAddChecked_2 (dynamic d
, DynamicObjectMock mock
)
306 mock
.BinaryOperation
= (binder
, arg
) => {
307 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
308 AssertArgument (binder
, new[] {
309 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
310 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
| CSharpArgumentInfoFlags
.Constant
, null) },
313 Assert (arg
, 3, "arg");
324 void BinaryAddAssign_1 (dynamic d
, DynamicObjectMock mock
)
326 mock
.BinaryOperation
= (binder
, arg
) => {
327 Assert (binder
.Operation
, ExpressionType
.AddAssign
, "Operation");
328 AssertArgument (binder
, new[] {
329 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
330 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
333 Assert (arg
, 1, "arg");
339 void BinaryAddAssignChecked_1 (dynamic d
, DynamicObjectMock mock
)
341 mock
.BinaryOperation
= (binder
, arg
) => {
342 Assert (binder
.Operation
, ExpressionType
.AddAssign
, "Operation");
343 AssertArgument (binder
, new[] {
344 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
345 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
348 Assert (arg
, 1, "arg");
356 void BinaryAnd_1 (dynamic d
, DynamicObjectMock mock
)
358 mock
.BinaryOperation
= (binder
, arg
) => {
359 Assert (binder
.Operation
, ExpressionType
.And
, "Operation");
360 AssertArgument (binder
, new[] {
361 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
362 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
365 Assert (arg
, 1, "arg");
371 void BinaryAndAssign_1 (dynamic d
, DynamicObjectMock mock
)
373 mock
.BinaryOperation
= (binder
, arg
) => {
374 Assert (binder
.Operation
, ExpressionType
.AndAssign
, "Operation");
375 AssertArgument (binder
, new[] {
376 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
377 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
380 Assert (arg
, 1, "arg");
386 void BinaryDivide_1 (dynamic d
, DynamicObjectMock mock
)
388 mock
.BinaryOperation
= (binder
, arg
) => {
389 Assert (binder
.Operation
, ExpressionType
.Divide
, "Operation");
390 AssertArgument (binder
, new[] {
391 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
392 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
395 Assert (arg
, 1, "arg");
401 void BinaryDivideAssign_1 (dynamic d
, DynamicObjectMock mock
)
403 mock
.BinaryOperation
= (binder
, arg
) => {
404 Assert (binder
.Operation
, ExpressionType
.DivideAssign
, "Operation");
405 AssertArgument (binder
, new[] {
406 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
407 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
410 Assert (arg
, 1, "arg");
416 void BinaryEqual_1 (dynamic d
, DynamicObjectMock mock
)
418 mock
.BinaryOperation
= (binder
, arg
) => {
419 Assert (binder
.Operation
, ExpressionType
.Equal
, "Operation");
420 AssertArgument (binder
, new[] {
421 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
422 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
425 Assert (arg
, 1, "arg");
431 void BinaryExclusiveOr_1 (dynamic d
, DynamicObjectMock mock
)
433 mock
.BinaryOperation
= (binder
, arg
) => {
434 Assert (binder
.Operation
, ExpressionType
.ExclusiveOr
, "Operation");
435 AssertArgument (binder
, new[] {
436 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
437 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
440 Assert (arg
, 1, "arg");
446 void BinaryExclusiveOrAssign_1 (dynamic d
, DynamicObjectMock mock
)
448 mock
.BinaryOperation
= (binder
, arg
) => {
449 Assert (binder
.Operation
, ExpressionType
.ExclusiveOrAssign
, "Operation");
450 AssertArgument (binder
, new[] {
451 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
452 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
455 Assert (arg
, 1, "arg");
461 void BinaryGreaterThan_1 (dynamic d
, DynamicObjectMock mock
)
463 mock
.BinaryOperation
= (binder
, arg
) => {
464 Assert (binder
.Operation
, ExpressionType
.GreaterThan
, "Operation");
465 AssertArgument (binder
, new[] {
466 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
467 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
470 Assert (arg
, 1, "arg");
476 void BinaryGreaterThanOrEqual_1 (dynamic d
, DynamicObjectMock mock
)
478 mock
.BinaryOperation
= (binder
, arg
) => {
479 Assert (binder
.Operation
, ExpressionType
.GreaterThanOrEqual
, "Operation");
480 AssertArgument (binder
, new[] {
481 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
482 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
485 Assert (arg
, 1, "arg");
491 void BinaryLeftShift_1 (dynamic d
, DynamicObjectMock mock
)
493 mock
.BinaryOperation
= (binder
, arg
) => {
494 Assert (binder
.Operation
, ExpressionType
.LeftShift
, "Operation");
495 AssertArgument (binder
, new[] {
496 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
497 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
500 Assert (arg
, 1, "arg");
506 void BinaryLeftShiftAssign_1 (dynamic d
, DynamicObjectMock mock
)
508 mock
.BinaryOperation
= (binder
, arg
) => {
509 Assert (binder
.Operation
, ExpressionType
.LeftShiftAssign
, "Operation");
510 AssertArgument (binder
, new[] {
511 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
512 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
515 Assert (arg
, 1, "arg");
521 void BinaryLessThan_1 (dynamic d
, DynamicObjectMock mock
)
523 mock
.BinaryOperation
= (binder
, arg
) => {
524 Assert (binder
.Operation
, ExpressionType
.LessThan
, "Operation");
525 AssertArgument (binder
, new[] {
526 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
527 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
530 Assert (arg
, 1, "arg");
536 void BinaryLessThanOrEqual_1 (dynamic d
, DynamicObjectMock mock
)
538 mock
.BinaryOperation
= (binder
, arg
) => {
539 Assert (binder
.Operation
, ExpressionType
.LessThanOrEqual
, "Operation");
540 AssertArgument (binder
, new[] {
541 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
542 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
545 Assert (arg
, 1, "arg");
551 void BinaryModulo_1 (dynamic d
, DynamicObjectMock mock
)
553 mock
.BinaryOperation
= (binder
, arg
) => {
554 Assert (binder
.Operation
, ExpressionType
.Modulo
, "Operation");
555 AssertArgument (binder
, new[] {
556 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
557 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
560 Assert (arg
, 1, "arg");
566 void BinaryModuloAssign_1 (dynamic d
, DynamicObjectMock mock
)
568 mock
.BinaryOperation
= (binder
, arg
) => {
569 Assert (binder
.Operation
, ExpressionType
.ModuloAssign
, "Operation");
570 AssertArgument (binder
, new[] {
571 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
572 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
575 Assert (arg
, 1, "arg");
581 void BinaryMultiply_1 (dynamic d
, DynamicObjectMock mock
)
583 mock
.BinaryOperation
= (binder
, arg
) => {
584 Assert (binder
.Operation
, ExpressionType
.Multiply
, "Operation");
585 AssertArgument (binder
, new[] {
586 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
587 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
590 Assert (arg
, 1, "arg");
596 void BinaryMultiplyAssign_1 (dynamic d
, DynamicObjectMock mock
)
598 mock
.BinaryOperation
= (binder
, arg
) => {
599 Assert (binder
.Operation
, ExpressionType
.MultiplyAssign
, "Operation");
600 AssertArgument (binder
, new[] {
601 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
602 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
605 Assert (arg
, 1, "arg");
611 void BinaryNotEqual_1 (dynamic d
, DynamicObjectMock mock
)
613 mock
.BinaryOperation
= (binder
, arg
) => {
614 Assert (binder
.Operation
, ExpressionType
.NotEqual
, "Operation");
615 AssertArgument (binder
, new[] {
616 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
617 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
620 Assert (arg
, 4, "arg");
626 void BinaryOr_1 (dynamic d
, DynamicObjectMock mock
)
628 mock
.BinaryOperation
= (binder
, arg
) => {
629 Assert (binder
.Operation
, ExpressionType
.Or
, "Operation");
630 AssertArgument (binder
, new[] {
631 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
632 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
635 Assert (arg
, 2, "arg");
641 void BinaryOrAssign_1 (dynamic d
, DynamicObjectMock mock
)
643 mock
.BinaryOperation
= (binder
, arg
) => {
644 Assert (binder
.Operation
, ExpressionType
.OrAssign
, "Operation");
645 AssertArgument (binder
, new[] {
646 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
647 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
650 Assert (arg
, 2, "arg");
656 void BinaryRightShift_1 (dynamic d
, DynamicObjectMock mock
)
658 mock
.BinaryOperation
= (binder
, arg
) => {
659 Assert (binder
.Operation
, ExpressionType
.RightShift
, "Operation");
660 AssertArgument (binder
, new[] {
661 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
662 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
665 Assert (arg
, 1, "arg");
671 void BinaryRightShiftAssign_1 (dynamic d
, DynamicObjectMock mock
)
673 mock
.BinaryOperation
= (binder
, arg
) => {
674 Assert (binder
.Operation
, ExpressionType
.RightShiftAssign
, "Operation");
675 AssertArgument (binder
, new[] {
676 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
677 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
680 Assert (arg
, 1, "arg");
686 void BinarySubtract_1 (dynamic d
, DynamicObjectMock mock
)
688 mock
.BinaryOperation
= (binder
, arg
) => {
689 Assert (binder
.Operation
, ExpressionType
.Subtract
, "Operation");
690 AssertArgument (binder
, new[] {
691 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
692 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
695 Assert (arg
, 1, "arg");
701 void BinarySubtractAssign_1 (dynamic d
, DynamicObjectMock mock
)
703 mock
.BinaryOperation
= (binder
, arg
) => {
704 Assert (binder
.Operation
, ExpressionType
.SubtractAssign
, "Operation");
705 AssertArgument (binder
, new[] {
706 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
707 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
710 Assert (arg
, 1, "arg");
716 void Convert_1 (dynamic d
, DynamicObjectMock mock
)
718 mock
.ConvertOperation
= (binder
) => {
719 Assert (binder
.Explicit
, true, "Explicit");
720 Assert (binder
.Type
, typeof (byte), "Type");
727 void Convert_2 (dynamic d
, DynamicObjectMock mock
)
729 mock
.ConvertOperation
= (binder
) => {
730 Assert (binder
.Explicit
, false, "Explicit");
731 Assert (binder
.Type
, typeof (int), "Type");
735 object[] o
= new object [2];
739 void Convert_3 (dynamic d
, DynamicObjectMock mock
)
741 mock
.ConvertOperation
= (binder
) => {
742 Assert (binder
.Explicit
, true, "Explicit");
743 // Assert (binder.IsChecked, true, "IsChecked");
744 Assert (binder
.Type
, typeof (byte), "Type");
748 object b
= checked((byte) d
);
751 void Convert_4 (dynamic d
, DynamicObjectMock mock
)
753 mock
.ConvertOperation
= (binder
) => {
754 Assert (binder
.Explicit
, false, "Explicit");
755 Assert (binder
.Type
, typeof (int), "Type");
762 void GetIndex_1 (dynamic d
, DynamicObjectMock mock
)
764 mock
.GetIndexOperation
= (binder
, args
) => {
765 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
766 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
767 AssertArgument (binder
, new[] {
768 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
769 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
772 Assert ((IList
<object>)args
, new object[] { 0 }
, "args");
778 void GetIndex_2 (dynamic d
, DynamicObjectMock mock
)
780 mock
.GetIndexOperation
= (binder
, args
) => {
781 Assert (binder
.CallInfo
, new CallInfo (2, new string[0]), "CallInfo");
782 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
783 AssertArgument (binder
, new[] {
784 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
785 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
786 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
789 Assert ((IList
<object>) args
, new object[] { 2, 3 }
, "args");
796 void GetIndex_3 (dynamic d
, DynamicObjectMock mock
)
798 mock
.GetIndexOperation
= (binder
, args
) => {
799 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
800 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
801 AssertArgument (binder
, new[] {
802 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
803 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null) },
806 Assert ((IList
<object>) args
, new object[] { d }
, "args");
812 void GetMember_1 (dynamic d
, DynamicObjectMock mock
)
814 mock
.GetMemberOperation
= (binder
) => {
815 Assert (binder
.Name
, "Foo", "Name");
816 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
817 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
818 AssertArgument (binder
, new[] {
819 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null) },
826 void Invoke_1 (dynamic d
, DynamicObjectMock mock
)
828 mock
.InvokeOperation
= (binder
, args
) => {
829 Assert (binder
.CallInfo
, new CallInfo (2, new string[0]), "CallInfo");
830 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
831 AssertArgument (binder
, new[] {
832 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
833 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
834 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null)
837 Assert ((IList
<object>) args
, new object[] { "foo", null }
, "args");
843 void Invoke_2 (dynamic d
, DynamicObjectMock mock
)
845 mock
.InvokeOperation
= (binder
, args
) => {
846 Assert (binder
.CallInfo
, new CallInfo (0, new string[0]), "CallInfo");
847 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
848 AssertArgument (binder
, new[] {
849 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null) },
852 Assert ((IList
<object>) args
, new object[0], "args");
858 void Invoke_3 (dynamic d
, DynamicObjectMock mock
)
862 Assert (true, false, "No hook expected to be hit");
863 } catch (RuntimeBinderException
) {
867 void Invoke_4 (dynamic d
, DynamicObjectMock mock
)
869 mock
.InvokeOperation
= (binder
, args
) => {
870 Assert (binder
.CallInfo
, new CallInfo (2, new string[] { "name" }
), "CallInfo");
871 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
872 AssertArgument (binder
, new[] {
873 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
874 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
875 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.NamedArgument
| CSharpArgumentInfoFlags
.UseCompileTimeType
, "name")
878 Assert ((IList
<object>) args
, new object[] { typeof (bool), -1 }
, "args");
881 d (typeof (bool), name
:-1);
884 void Invoke_5 (dynamic d
, DynamicObjectMock mock
)
886 mock
.InvokeOperation
= (binder
, args
) => {
887 Assert (binder
.CallInfo
, new CallInfo (2, new string[] { "name" }
), "CallInfo");
888 AssertArgument (binder
, new[] {
889 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
890 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
891 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.NamedArgument
| CSharpArgumentInfoFlags
.UseCompileTimeType
, "name")
894 Assert ((IList
<object>) args
, new object[] { typeof (bool), -1 }
, "args");
897 Action
<object> a
= (i
) => {};
901 void InvokeMember_1 (dynamic d
, DynamicObjectMock mock
)
903 mock
.InvokeMemberOperation
= (binder
, args
) => {
904 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
905 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
906 AssertArgument (binder
, new[] {
907 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
908 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null)},
911 // Assert (binder.Flags, CSharpCallFlags.None, "Flags");
912 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
913 // Assert (binder.TypeArguments, new Type[0], "TypeArguments");
915 Assert ((IList
<object>) args
, new object[] { 'a' }
, "args");
921 void InvokeMember_2 (dynamic d
, DynamicObjectMock mock
)
923 mock
.InvokeMemberOperation
= (binder
, args
) => {
924 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
925 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
926 AssertArgument (binder
, new[] {
927 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
928 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)},
931 // Assert (binder.Flags, CSharpCallFlags.None, "Flags");
932 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
933 // Assert (binder.TypeArguments, new Type[0], "TypeArguments");
935 Assert ((IList
<object>) args
, new object[] { mock }
, "args");
941 void InvokeMember_3 (dynamic d
, DynamicObjectMock mock
)
943 mock
.InvokeMemberOperation
= (binder
, args
) => {
944 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
945 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
946 AssertArgument (binder
, new[] {
947 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
948 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.IsRef
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
951 // Assert (binder.Flags, CSharpCallFlags.None, "Flags");
952 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
953 // Assert (binder.TypeArguments, new Type[0], "TypeArguments");
955 Assert ((IList
<object>) args
, new object[] { 9 }
, "args");
962 void InvokeMember_4 (dynamic d
, DynamicObjectMock mock
)
964 mock
.InvokeMemberOperation
= (binder
, args
) => {
965 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
966 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
967 AssertArgument (binder
, new[] {
968 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
969 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.IsOut
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
972 // Assert (binder.Flags, CSharpCallFlags.None, "Flags");
973 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
974 // Assert (binder.TypeArguments, new Type[0], "TypeArguments");
976 Assert ((IList
<object>) args
, new object[] { 0 }
, "args");
983 void InvokeMember_5 (dynamic d
, DynamicObjectMock mock
)
985 DynamicObjectMock
.DStaticMethod (d
);
988 void InvokeMember_6 (dynamic d
, DynamicObjectMock mock
)
990 InvokeMemberOperation
= (binder
, args
) => {
991 Assert (binder
.CallInfo
, new CallInfo (2, new string[0]), "CallInfo");
992 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
993 AssertArgument (binder
, new[] {
994 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
995 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
996 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
| CSharpArgumentInfoFlags
.Constant
, null),
998 // Assert (binder.Flags, CSharpCallFlags.SimpleNameCall, "Flags");
999 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
1000 // Assert (binder.TypeArguments, Type.EmptyTypes, "TypeArguments");
1002 Assert ((IList
<object>) args
, new object[] { d, null }
, "args");
1005 InvokeMember_5 (d
, null);
1008 void InvokeMember_7 (dynamic d
, DynamicObjectMock mock
)
1010 mock
.InvokeMemberOperation
= (binder
, args
) => {
1011 Assert (binder
.CallInfo
, new CallInfo (0, new string[0]), "CallInfo");
1012 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
1013 AssertArgument (binder
, new[] {
1014 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1016 // Assert (binder.Flags, CSharpCallFlags.None, "Flags");
1017 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
1018 // Assert (binder.TypeArguments, new Type[] { typeof (object) }, "TypeArguments");
1020 Assert ((IList
<object>) args
, new object[0], "args");
1026 void SetIndex_1 (dynamic d
, DynamicObjectMock mock
)
1028 mock
.SetIndexOperation
= (binder
, args
, value) => {
1029 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
1030 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
1031 AssertArgument (binder
, new[] {
1032 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
1033 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
1034 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null)},
1037 Assert ((IList
<object>) args
, new object[] { 0 }
, "args");
1038 Assert (value, 2m
, "value");
1044 void SetIndex_2 (dynamic d
, DynamicObjectMock mock
)
1046 mock
.SetIndexOperation
= (binder
, args
, value) => {
1047 Assert (binder
.CallInfo
, new CallInfo (2, new string[0]), "CallInfo");
1048 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
1049 AssertArgument (binder
, new[] {
1050 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
1051 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
1052 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
1053 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null)
1056 Assert ((IList
<object>) args
, new object[] { 2, 3 }
, "args");
1057 Assert (value, -8, "value");
1064 void SetIndex_3 (dynamic d
, DynamicObjectMock mock
)
1066 mock
.SetIndexOperation
= (binder
, args
, value) => {
1067 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
1068 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
1069 AssertArgument (binder
, new[] {
1070 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
1071 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
1072 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
, null)
1075 Assert ((IList
<object>) args
, new object[] { d }
, "args");
1076 Assert (value, this, "value");
1082 void SetMember_1 (dynamic d
, DynamicObjectMock mock
)
1084 const double d_const
= 2.4;
1086 mock
.SetMemberOperation
= (binder
, value) => {
1087 Assert (binder
.Name
, "Foo", "Name");
1088 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
1089 // Assert (binder.CallingContext, typeof (Tester), "CallingContext");
1090 AssertArgument (binder
, new[] {
1091 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
1092 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.UseCompileTimeType
| CSharpArgumentInfoFlags
.Constant
, null) // CSC bug?
1095 Assert (value, d_const
, "value");
1101 void UnaryPlus_1 (dynamic d
, DynamicObjectMock mock
)
1103 mock
.UnaryOperation
= (binder
) => {
1104 Assert (binder
.Operation
, ExpressionType
.UnaryPlus
, "Operation");
1105 AssertArgument (binder
, new[] {
1106 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1115 void UnaryMinus_1 (dynamic d
, DynamicObjectMock mock
)
1117 mock
.UnaryOperation
= (binder
) => {
1118 Assert (binder
.Operation
, ExpressionType
.Negate
, "Operation");
1119 AssertArgument (binder
, new[] {
1120 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1129 void UnaryNot_1 (dynamic d
, DynamicObjectMock mock
)
1131 mock
.UnaryOperation
= (binder
) => {
1132 Assert (binder
.Operation
, ExpressionType
.Not
, "Operation");
1133 AssertArgument (binder
, new[] {
1134 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1143 void UnaryOnesComplement_1 (dynamic d
, DynamicObjectMock mock
)
1145 mock
.UnaryOperation
= (binder
) => {
1146 Assert (binder
.Operation
, ExpressionType
.OnesComplement
, "Operation");
1147 AssertArgument (binder
, new[] {
1148 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1157 void UnaryDecrement_1 (dynamic d
, DynamicObjectMock mock
)
1159 mock
.UnaryOperation
= (binder
) => {
1160 Assert (binder
.Operation
, ExpressionType
.Decrement
, "Operation");
1161 AssertArgument (binder
, new[] {
1162 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1171 void UnaryDecrement_2 (dynamic d
, DynamicObjectMock mock
)
1173 mock
.UnaryOperation
= (binder
) => {
1174 Assert (binder
.Operation
, ExpressionType
.Decrement
, "Operation");
1175 AssertArgument (binder
, new[] {
1176 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1179 return new object ();
1185 void UnaryIncrement_1 (dynamic d
, DynamicObjectMock mock
)
1187 mock
.UnaryOperation
= (binder
) => {
1188 Assert (binder
.Operation
, ExpressionType
.Increment
, "Operation");
1189 AssertArgument (binder
, new[] {
1190 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1199 void UnaryIncrement_2 (dynamic d
, DynamicObjectMock mock
)
1201 mock
.UnaryOperation
= (binder
) => {
1202 Assert (binder
.Operation
, ExpressionType
.Increment
, "Operation");
1203 AssertArgument (binder
, new[] {
1204 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1207 return new object ();
1213 void UnaryIsFalse_1 (dynamic d
, DynamicObjectMock mock
)
1215 mock
.UnaryOperation
= (binder
) => {
1216 Assert (binder
.Operation
, ExpressionType
.IsFalse
, "Operation");
1217 AssertArgument (binder
, new[] {
1218 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1224 mock
.BinaryOperation
= (binder
, arg
) => {
1225 Assert (binder
.Operation
, ExpressionType
.Equal
, "Operation");
1226 AssertArgument (binder
, new[] {
1227 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
1228 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
1231 Assert (arg
, null, "arg");
1234 object x
= d
== null;
1237 void UnaryIsFalse_2 (dynamic d
, DynamicObjectMock mock
)
1239 mock
.UnaryOperation
= (binder
) => {
1240 Assert (binder
.Operation
, ExpressionType
.IsFalse
, "Operation");
1241 AssertArgument (binder
, new[] {
1242 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1248 mock
.BinaryOperation
= (binder
, arg
) => {
1249 Assert (binder
.Operation
, ExpressionType
.NotEqual
, "Operation");
1250 AssertArgument (binder
, new[] {
1251 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
1252 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
1255 Assert (arg
, null, "arg");
1258 object x
= d
!= null;
1261 void UnaryIsFalse_3 (dynamic d
, DynamicObjectMock mock
)
1263 mock
.UnaryOperation
= (binder
) => {
1264 Assert (binder
.Operation
, ExpressionType
.IsFalse
, "Operation");
1265 AssertArgument (binder
, new[] {
1266 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1272 mock
.BinaryOperation
= (binder
, arg
) => {
1273 Assert (binder
.Operation
, ExpressionType
.And
, "Operation");
1274 AssertArgument (binder
, new[] {
1275 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
1276 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
1279 Assert (arg
, null, "arg");
1282 object x
= d
&& null;
1285 void UnaryIsTrue_1 (dynamic d
, DynamicObjectMock mock
)
1287 mock
.UnaryOperation
= (binder
) => {
1288 Assert (binder
.Operation
, ExpressionType
.IsTrue
, "Operation");
1289 AssertArgument (binder
, new[] {
1290 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1296 object g
= d
? 1 :4;
1299 void UnaryIsTrue_2 (dynamic d
, DynamicObjectMock mock
)
1301 mock
.UnaryOperation
= (binder
) => {
1302 Assert (binder
.Operation
, ExpressionType
.IsTrue
, "Operation");
1303 AssertArgument (binder
, new[] {
1304 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null)
1310 mock
.BinaryOperation
= (binder
, arg
) => {
1311 Assert (binder
.Operation
, ExpressionType
.Or
, "Operation");
1312 AssertArgument (binder
, new[] {
1313 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.None
, null),
1314 CSharpArgumentInfo
.Create (CSharpArgumentInfoFlags
.Constant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
1317 Assert (arg
, null, "arg");
1320 object x
= d
|| null;
1323 #pragma warning restore 168, 169, 219
1325 static bool RunTest (MethodInfo test
)
1327 Console
.Write ("Running test {0, -25}", test
.Name
);
1329 var d
= new DynamicObjectMock ();
1330 test
.Invoke (new Tester (), new [] { d, d }
);
1331 if (d
.HitCounter
< 1)
1332 Assert (true, false, "HitCounter");
1334 Console
.WriteLine ("OK");
1336 } catch (Exception e
) {
1337 Console
.WriteLine ("FAILED");
1338 Console
.WriteLine (e
.ToString ());
1343 public static int Main ()
1345 var tests
= from test
in typeof (Tester
).GetMethods (BindingFlags
.Instance
| BindingFlags
.NonPublic
| BindingFlags
.DeclaredOnly
)
1346 where test
.GetParameters ().Length
== 2
1348 select RunTest (test
);
1350 int failures
= tests
.Count (a
=> !a
);
1351 Console
.WriteLine (failures
+ " tests failed");