2 using System
.Collections
.Generic
;
4 using System
.Reflection
;
6 using System
.Linq
.Expressions
;
7 using Microsoft
.CSharp
.RuntimeBinder
;
14 class AssertDynamicObject
: DynamicMetaObject
16 DynamicObjectMock mock
;
18 public AssertDynamicObject (DynamicObjectMock mock
, Expression parameter
)
19 : base (parameter
, BindingRestrictions
.Empty
, mock
)
24 DynamicMetaObject
GetFakeMetaObject (object value)
26 Type t
= value == null ? typeof (object) : value.GetType ();
27 var v
= Expression
.Variable (t
);
28 Expression e
= Expression
.Block (new[] { v }
, Expression
.Default (t
));
30 Expression restr
= Expression
.Constant (true);
31 return new DynamicMetaObject (e
, BindingRestrictions
.GetExpressionRestriction (restr
));
34 public override DynamicMetaObject
BindBinaryOperation (BinaryOperationBinder binder
, DynamicMetaObject arg
)
36 if (mock
.BinaryOperation
== null)
37 throw new ApplicationException ("Unexpected BindBinaryOperation");
39 mock
.BinaryOperation ((CSharpBinaryOperationBinder
) binder
, arg
.Value
);
41 return GetFakeMetaObject (new object ());
44 public override DynamicMetaObject
BindConvert (ConvertBinder binder
)
46 if (mock
.ConvertOperation
== null)
47 throw new ApplicationException ("Unexpected BindConvert");
49 var r
= mock
.ConvertOperation ((CSharpConvertBinder
) binder
);
51 return GetFakeMetaObject (r
);
54 public override DynamicMetaObject
BindGetIndex (GetIndexBinder binder
, DynamicMetaObject
[] indexes
)
56 if (mock
.GetIndexOperation
== null)
57 throw new ApplicationException ("Unexpected TryGetIndex");
59 mock
.GetIndexOperation ((CSharpGetIndexBinder
) binder
, indexes
.Select (l
=> l
.Value
).ToArray ());
61 return GetFakeMetaObject (new object ());
64 public override DynamicMetaObject
BindGetMember (GetMemberBinder binder
)
66 if (mock
.GetMemberOperation
== null)
67 throw new ApplicationException ("Unexpected BindGetMember");
69 mock
.GetMemberOperation ((CSharpGetMemberBinder
) binder
);
71 return GetFakeMetaObject (new object ());
74 public override DynamicMetaObject
BindInvoke (InvokeBinder binder
, DynamicMetaObject
[] args
)
76 if (mock
.InvokeOperation
== null)
77 throw new ApplicationException ("Unexpected BindInvoke");
79 mock
.InvokeOperation ((CSharpInvokeBinder
) binder
, args
.Select (l
=> l
.Value
).ToArray ());
81 return GetFakeMetaObject (new object ());
84 public override DynamicMetaObject
BindInvokeMember (InvokeMemberBinder binder
, DynamicMetaObject
[] args
)
86 if (mock
.InvokeMemberOperation
== null)
87 throw new ApplicationException ("Unexpected BindInvokeMember");
89 mock
.InvokeMemberOperation ((CSharpInvokeMemberBinder
) binder
, args
.Select (l
=> l
.Value
).ToArray ());
91 return GetFakeMetaObject (new object ());
94 public override DynamicMetaObject
BindSetIndex (SetIndexBinder binder
, DynamicMetaObject
[] indexes
, DynamicMetaObject
value)
96 if (mock
.SetIndexOperation
== null)
97 throw new ApplicationException ("Unexpected TrySetIndex");
99 mock
.SetIndexOperation ((CSharpSetIndexBinder
) binder
, indexes
.Select (l
=> l
.Value
).ToArray (), value.Value
);
101 return GetFakeMetaObject (new object ());
104 public override DynamicMetaObject
BindSetMember (SetMemberBinder binder
, DynamicMetaObject
value)
106 if (mock
.SetMemberOperation
== null)
107 throw new ApplicationException ("Unexpected BindSetMember");
109 mock
.SetMemberOperation ((CSharpSetMemberBinder
) binder
, value.Value
);
111 return GetFakeMetaObject (new object ());
114 public override DynamicMetaObject
BindUnaryOperation (UnaryOperationBinder binder
)
116 if (mock
.UnaryOperation
== null)
117 throw new ApplicationException ("Unexpected BindUnaryOperation");
119 var r
= mock
.UnaryOperation ((CSharpUnaryOperationBinder
) binder
);
121 return GetFakeMetaObject (r
);
126 class DynamicObjectMock
: DynamicObject
128 public int HitCounter
;
130 public DynamicObjectMock ()
134 public override DynamicMetaObject
GetMetaObject (System
.Linq
.Expressions
.Expression parameter
)
137 return new AssertDynamicObject (this, parameter
);
140 public Action
<CSharpBinaryOperationBinder
, object> BinaryOperation
;
141 public Func
<CSharpConvertBinder
, object> ConvertOperation
;
142 public Action
<CSharpGetIndexBinder
, object[]> GetIndexOperation
;
143 public Action
<CSharpGetMemberBinder
> GetMemberOperation
;
144 public Action
<CSharpInvokeBinder
, object[]> InvokeOperation
;
145 public Action
<CSharpInvokeMemberBinder
, object[]> InvokeMemberOperation
;
146 public Action
<CSharpSetIndexBinder
, object[], object> SetIndexOperation
;
147 public Action
<CSharpSetMemberBinder
, object> SetMemberOperation
;
148 public Func
<CSharpUnaryOperationBinder
, object> UnaryOperation
;
150 // Dynamic arguments methods
151 public DynamicObjectMock (int i
)
155 public void DMethod (int a
)
159 public static void DStaticMethod (object t
)
163 public int this[int i
] {
172 class Tester
: DynamicObjectMock
174 static readonly int field
= 7;
180 public Tester (dynamic d
)
184 static void Assert
<T
> (T expected
, T
value, string name
)
186 if (!EqualityComparer
<T
>.Default
.Equals (expected
, value)) {
187 if (!string.IsNullOrEmpty (name
))
189 throw new ApplicationException (name
+ expected
+ " != " + value);
193 static void Assert
<T
> (IList
<T
> expected
, IList
<T
> value, string name
)
195 if (expected
== null) {
197 throw new ApplicationException (name
+ ": Both arrays expected to be null");
201 if (expected
.Count
!= value.Count
)
202 throw new ApplicationException (name
+ ": Array length does not match " + expected
.Count
+ " != " + value.Count
);
204 for (int i
= 0; i
< expected
.Count
; ++i
) {
205 if (!EqualityComparer
<T
>.Default
.Equals (expected
[i
], value[i
]))
206 throw new ApplicationException (name
+ ": Index " + i
+ ": " + expected
[i
] + " != " + value[i
]);
210 #pragma warning disable 168, 169, 219
212 void BinaryAdd_1 (dynamic d
, DynamicObjectMock mock
)
214 mock
.BinaryOperation
= (binder
, arg
) => {
215 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
216 Assert (binder
.IsChecked
, false, "IsChecked");
217 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
218 Assert (binder
.ArgumentInfo
, new [] {
219 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
220 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
223 Assert (arg
, 1, "arg");
229 void BinaryAdd_2 (dynamic d
, DynamicObjectMock mock
)
231 mock
.BinaryOperation
= (binder
, arg
) => {
232 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
233 Assert (binder
.IsChecked
, false, "IsChecked");
234 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
235 Assert (binder
.ArgumentInfo
, new[] {
236 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
237 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
240 Assert (arg
, null, "arg");
247 void BinaryAdd_3 (dynamic d
, DynamicObjectMock mock
)
249 mock
.BinaryOperation
= (binder
, arg
) => {
250 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
251 Assert (binder
.IsChecked
, false, "IsChecked");
252 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
253 Assert (binder
.ArgumentInfo
, new[] {
254 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
255 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
| CSharpArgumentInfoFlags
.LiteralConstant
, null) // CSC bug?
258 Assert (arg
, Enum
.A
, "arg");
264 void BinaryAdd_4 (dynamic d
, DynamicObjectMock mock
)
266 mock
.BinaryOperation
= (binder
, arg
) => {
267 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
268 Assert (binder
.IsChecked
, false, "IsChecked");
269 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
270 Assert (binder
.ArgumentInfo
, new[] {
271 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
272 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
275 Assert (arg
, 7, "arg");
278 d
= d
+ Tester
.field
;
281 void BinaryAddChecked_1 (dynamic d
, DynamicObjectMock mock
)
283 mock
.BinaryOperation
= (binder
, arg
) => {
284 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
285 Assert (binder
.IsChecked
, true, "IsChecked");
286 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
287 Assert (binder
.ArgumentInfo
, new[] {
288 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
289 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
| CSharpArgumentInfoFlags
.LiteralConstant
, null) },
292 Assert (arg
, 3, "arg");
298 void BinaryAddChecked_2 (dynamic d
, DynamicObjectMock mock
)
300 mock
.BinaryOperation
= (binder
, arg
) => {
301 Assert (binder
.Operation
, ExpressionType
.Add
, "Operation");
302 Assert (binder
.IsChecked
, true, "IsChecked");
303 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
304 Assert (binder
.ArgumentInfo
, new[] {
305 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
306 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
| CSharpArgumentInfoFlags
.LiteralConstant
, null) },
309 Assert (arg
, 3, "arg");
320 void BinaryAddAssign_1 (dynamic d
, DynamicObjectMock mock
)
322 mock
.BinaryOperation
= (binder
, arg
) => {
323 Assert (binder
.Operation
, ExpressionType
.AddAssign
, "Operation");
324 Assert (binder
.IsChecked
, false, "IsChecked");
325 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
326 Assert (binder
.ArgumentInfo
, new[] {
327 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
328 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
331 Assert (arg
, 1, "arg");
337 void BinaryAddAssignChecked_1 (dynamic d
, DynamicObjectMock mock
)
339 mock
.BinaryOperation
= (binder
, arg
) => {
340 Assert (binder
.Operation
, ExpressionType
.AddAssign
, "Operation");
341 Assert (binder
.IsChecked
, true, "IsChecked");
342 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
343 Assert (binder
.ArgumentInfo
, new[] {
344 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
345 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| 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 Assert (binder
.IsChecked
, false, "IsChecked");
361 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
362 Assert (binder
.ArgumentInfo
, new[] {
363 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
364 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
367 Assert (arg
, 1, "arg");
373 void BinaryAndAssign_1 (dynamic d
, DynamicObjectMock mock
)
375 mock
.BinaryOperation
= (binder
, arg
) => {
376 Assert (binder
.Operation
, ExpressionType
.AndAssign
, "Operation");
377 Assert (binder
.IsChecked
, false, "IsChecked");
378 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
379 Assert (binder
.ArgumentInfo
, new[] {
380 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
381 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
384 Assert (arg
, 1, "arg");
390 void BinaryDivide_1 (dynamic d
, DynamicObjectMock mock
)
392 mock
.BinaryOperation
= (binder
, arg
) => {
393 Assert (binder
.Operation
, ExpressionType
.Divide
, "Operation");
394 Assert (binder
.IsChecked
, false, "IsChecked");
395 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
396 Assert (binder
.ArgumentInfo
, new[] {
397 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
398 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
401 Assert (arg
, 1, "arg");
407 void BinaryDivideAssign_1 (dynamic d
, DynamicObjectMock mock
)
409 mock
.BinaryOperation
= (binder
, arg
) => {
410 Assert (binder
.Operation
, ExpressionType
.DivideAssign
, "Operation");
411 Assert (binder
.IsChecked
, false, "IsChecked");
412 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
413 Assert (binder
.ArgumentInfo
, new[] {
414 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
415 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
418 Assert (arg
, 1, "arg");
424 void BinaryEqual_1 (dynamic d
, DynamicObjectMock mock
)
426 mock
.BinaryOperation
= (binder
, arg
) => {
427 Assert (binder
.Operation
, ExpressionType
.Equal
, "Operation");
428 Assert (binder
.IsChecked
, false, "IsChecked");
429 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
430 Assert (binder
.ArgumentInfo
, new[] {
431 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
432 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
435 Assert (arg
, 1, "arg");
441 void BinaryExclusiveOr_1 (dynamic d
, DynamicObjectMock mock
)
443 mock
.BinaryOperation
= (binder
, arg
) => {
444 Assert (binder
.Operation
, ExpressionType
.ExclusiveOr
, "Operation");
445 Assert (binder
.IsChecked
, false, "IsChecked");
446 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
447 Assert (binder
.ArgumentInfo
, new[] {
448 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
449 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
452 Assert (arg
, 1, "arg");
458 void BinaryExclusiveOrAssign_1 (dynamic d
, DynamicObjectMock mock
)
460 mock
.BinaryOperation
= (binder
, arg
) => {
461 Assert (binder
.Operation
, ExpressionType
.ExclusiveOrAssign
, "Operation");
462 Assert (binder
.IsChecked
, false, "IsChecked");
463 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
464 Assert (binder
.ArgumentInfo
, new[] {
465 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
466 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
469 Assert (arg
, 1, "arg");
475 void BinaryGreaterThan_1 (dynamic d
, DynamicObjectMock mock
)
477 mock
.BinaryOperation
= (binder
, arg
) => {
478 Assert (binder
.Operation
, ExpressionType
.GreaterThan
, "Operation");
479 Assert (binder
.IsChecked
, false, "IsChecked");
480 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
481 Assert (binder
.ArgumentInfo
, new[] {
482 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
483 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
486 Assert (arg
, 1, "arg");
492 void BinaryGreaterThanOrEqual_1 (dynamic d
, DynamicObjectMock mock
)
494 mock
.BinaryOperation
= (binder
, arg
) => {
495 Assert (binder
.Operation
, ExpressionType
.GreaterThanOrEqual
, "Operation");
496 Assert (binder
.IsChecked
, false, "IsChecked");
497 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
498 Assert (binder
.ArgumentInfo
, new[] {
499 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
500 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
503 Assert (arg
, 1, "arg");
509 void BinaryLeftShift_1 (dynamic d
, DynamicObjectMock mock
)
511 mock
.BinaryOperation
= (binder
, arg
) => {
512 Assert (binder
.Operation
, ExpressionType
.LeftShift
, "Operation");
513 Assert (binder
.IsChecked
, false, "IsChecked");
514 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
515 Assert (binder
.ArgumentInfo
, new[] {
516 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
517 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
520 Assert (arg
, 1, "arg");
526 void BinaryLeftShiftAssign_1 (dynamic d
, DynamicObjectMock mock
)
528 mock
.BinaryOperation
= (binder
, arg
) => {
529 Assert (binder
.Operation
, ExpressionType
.LeftShiftAssign
, "Operation");
530 Assert (binder
.IsChecked
, false, "IsChecked");
531 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
532 Assert (binder
.ArgumentInfo
, new[] {
533 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
534 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
537 Assert (arg
, 1, "arg");
543 void BinaryLessThan_1 (dynamic d
, DynamicObjectMock mock
)
545 mock
.BinaryOperation
= (binder
, arg
) => {
546 Assert (binder
.Operation
, ExpressionType
.LessThan
, "Operation");
547 Assert (binder
.IsChecked
, false, "IsChecked");
548 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
549 Assert (binder
.ArgumentInfo
, new[] {
550 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
551 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
554 Assert (arg
, 1, "arg");
560 void BinaryLessThanOrEqual_1 (dynamic d
, DynamicObjectMock mock
)
562 mock
.BinaryOperation
= (binder
, arg
) => {
563 Assert (binder
.Operation
, ExpressionType
.LessThanOrEqual
, "Operation");
564 Assert (binder
.IsChecked
, false, "IsChecked");
565 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
566 Assert (binder
.ArgumentInfo
, new[] {
567 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
568 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
571 Assert (arg
, 1, "arg");
577 void BinaryModulo_1 (dynamic d
, DynamicObjectMock mock
)
579 mock
.BinaryOperation
= (binder
, arg
) => {
580 Assert (binder
.Operation
, ExpressionType
.Modulo
, "Operation");
581 Assert (binder
.IsChecked
, false, "IsChecked");
582 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
583 Assert (binder
.ArgumentInfo
, new[] {
584 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
585 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
588 Assert (arg
, 1, "arg");
594 void BinaryModuloAssign_1 (dynamic d
, DynamicObjectMock mock
)
596 mock
.BinaryOperation
= (binder
, arg
) => {
597 Assert (binder
.Operation
, ExpressionType
.ModuloAssign
, "Operation");
598 Assert (binder
.IsChecked
, false, "IsChecked");
599 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
600 Assert (binder
.ArgumentInfo
, new[] {
601 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
602 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
605 Assert (arg
, 1, "arg");
611 void BinaryMultiply_1 (dynamic d
, DynamicObjectMock mock
)
613 mock
.BinaryOperation
= (binder
, arg
) => {
614 Assert (binder
.Operation
, ExpressionType
.Multiply
, "Operation");
615 Assert (binder
.IsChecked
, false, "IsChecked");
616 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
617 Assert (binder
.ArgumentInfo
, new[] {
618 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
619 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
622 Assert (arg
, 1, "arg");
628 void BinaryMultiplyAssign_1 (dynamic d
, DynamicObjectMock mock
)
630 mock
.BinaryOperation
= (binder
, arg
) => {
631 Assert (binder
.Operation
, ExpressionType
.MultiplyAssign
, "Operation");
632 Assert (binder
.IsChecked
, false, "IsChecked");
633 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
634 Assert (binder
.ArgumentInfo
, new[] {
635 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
636 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
639 Assert (arg
, 1, "arg");
645 void BinaryNotEqual_1 (dynamic d
, DynamicObjectMock mock
)
647 mock
.BinaryOperation
= (binder
, arg
) => {
648 Assert (binder
.Operation
, ExpressionType
.NotEqual
, "Operation");
649 Assert (binder
.IsChecked
, false, "IsChecked");
650 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
651 Assert (binder
.ArgumentInfo
, new[] {
652 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
653 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
656 Assert (arg
, 4, "arg");
662 void BinaryOr_1 (dynamic d
, DynamicObjectMock mock
)
664 mock
.BinaryOperation
= (binder
, arg
) => {
665 Assert (binder
.Operation
, ExpressionType
.Or
, "Operation");
666 Assert (binder
.IsChecked
, false, "IsChecked");
667 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
668 Assert (binder
.ArgumentInfo
, new[] {
669 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
670 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
673 Assert (arg
, 2, "arg");
679 void BinaryOrAssign_1 (dynamic d
, DynamicObjectMock mock
)
681 mock
.BinaryOperation
= (binder
, arg
) => {
682 Assert (binder
.Operation
, ExpressionType
.OrAssign
, "Operation");
683 Assert (binder
.IsChecked
, false, "IsChecked");
684 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
685 Assert (binder
.ArgumentInfo
, new[] {
686 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
687 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
690 Assert (arg
, 2, "arg");
696 void BinaryRightShift_1 (dynamic d
, DynamicObjectMock mock
)
698 mock
.BinaryOperation
= (binder
, arg
) => {
699 Assert (binder
.Operation
, ExpressionType
.RightShift
, "Operation");
700 Assert (binder
.IsChecked
, false, "IsChecked");
701 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
702 Assert (binder
.ArgumentInfo
, new[] {
703 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
704 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
707 Assert (arg
, 1, "arg");
713 void BinaryRightShiftAssign_1 (dynamic d
, DynamicObjectMock mock
)
715 mock
.BinaryOperation
= (binder
, arg
) => {
716 Assert (binder
.Operation
, ExpressionType
.RightShiftAssign
, "Operation");
717 Assert (binder
.IsChecked
, false, "IsChecked");
718 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
719 Assert (binder
.ArgumentInfo
, new[] {
720 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
721 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
724 Assert (arg
, 1, "arg");
730 void BinarySubtract_1 (dynamic d
, DynamicObjectMock mock
)
732 mock
.BinaryOperation
= (binder
, arg
) => {
733 Assert (binder
.Operation
, ExpressionType
.Subtract
, "Operation");
734 Assert (binder
.IsChecked
, false, "IsChecked");
735 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
736 Assert (binder
.ArgumentInfo
, new[] {
737 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
738 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
741 Assert (arg
, 1, "arg");
747 void BinarySubtractAssign_1 (dynamic d
, DynamicObjectMock mock
)
749 mock
.BinaryOperation
= (binder
, arg
) => {
750 Assert (binder
.Operation
, ExpressionType
.SubtractAssign
, "Operation");
751 Assert (binder
.IsChecked
, false, "IsChecked");
752 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
753 Assert (binder
.ArgumentInfo
, new[] {
754 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
755 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
758 Assert (arg
, 1, "arg");
764 void Convert_1 (dynamic d
, DynamicObjectMock mock
)
766 mock
.ConvertOperation
= (binder
) => {
767 Assert (binder
.Explicit
, true, "Explicit");
768 Assert (binder
.IsChecked
, false, "IsChecked");
769 Assert (binder
.Type
, typeof (byte), "Type");
776 void Convert_2 (dynamic d
, DynamicObjectMock mock
)
778 mock
.ConvertOperation
= (binder
) => {
779 Assert (binder
.Explicit
, false, "Explicit");
780 Assert (binder
.IsChecked
, false, "IsChecked");
781 Assert (binder
.Type
, typeof (int), "Type");
785 object[] o
= new object [2];
789 void Convert_3 (dynamic d
, DynamicObjectMock mock
)
791 mock
.ConvertOperation
= (binder
) => {
792 Assert (binder
.Explicit
, true, "Explicit");
793 Assert (binder
.IsChecked
, true, "IsChecked");
794 Assert (binder
.Type
, typeof (byte), "Type");
798 object b
= checked((byte) d
);
801 void Convert_4 (dynamic d
, DynamicObjectMock mock
)
803 mock
.ConvertOperation
= (binder
) => {
804 Assert (binder
.Explicit
, false, "Explicit");
805 Assert (binder
.IsChecked
, false, "IsChecked");
806 Assert (binder
.Type
, typeof (int), "Type");
813 void GetIndex_1 (dynamic d
, DynamicObjectMock mock
)
815 mock
.GetIndexOperation
= (binder
, args
) => {
816 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
817 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
818 Assert (binder
.ArgumentInfo
, new[] {
819 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
820 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
823 Assert ((IList
<object>)args
, new object[] { 0 }
, "args");
829 void GetIndex_2 (dynamic d
, DynamicObjectMock mock
)
831 mock
.GetIndexOperation
= (binder
, args
) => {
832 Assert (binder
.CallInfo
, new CallInfo (2, new string[0]), "CallInfo");
833 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
834 Assert (binder
.ArgumentInfo
, new[] {
835 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
836 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
837 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
840 Assert ((IList
<object>) args
, new object[] { 2, 3 }
, "args");
847 void GetIndex_3 (dynamic d
, DynamicObjectMock mock
)
849 mock
.GetIndexOperation
= (binder
, args
) => {
850 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
851 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
852 Assert (binder
.ArgumentInfo
, new[] {
853 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
854 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null) },
857 Assert ((IList
<object>) args
, new object[] { d }
, "args");
863 void GetMember_1 (dynamic d
, DynamicObjectMock mock
)
865 mock
.GetMemberOperation
= (binder
) => {
866 Assert (binder
.Name
, "Foo", "Name");
867 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
868 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
869 Assert (binder
.ArgumentInfo
, new[] {
870 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null) },
877 void Invoke_1 (dynamic d
, DynamicObjectMock mock
)
879 mock
.InvokeOperation
= (binder
, args
) => {
880 Assert (binder
.CallInfo
, new CallInfo (2, new string[0]), "CallInfo");
881 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
882 Assert (binder
.ArgumentInfo
, new[] {
883 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
884 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
885 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null)
888 Assert ((IList
<object>) args
, new object[] { "foo", null }
, "args");
894 void Invoke_2 (dynamic d
, DynamicObjectMock mock
)
896 mock
.InvokeOperation
= (binder
, args
) => {
897 Assert (binder
.CallInfo
, new CallInfo (0, new string[0]), "CallInfo");
898 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
899 Assert (binder
.ArgumentInfo
, new[] {
900 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null) },
903 Assert ((IList
<object>) args
, new object[0], "args");
909 void Invoke_3 (dynamic d
, DynamicObjectMock mock
)
913 Assert (true, false, "No hook expected to be hit");
914 } catch (RuntimeBinderException
) {
918 void Invoke_4 (dynamic d
, DynamicObjectMock mock
)
920 mock
.InvokeOperation
= (binder
, args
) => {
921 Assert (binder
.CallInfo
, new CallInfo (2, new string[] { "name" }
), "CallInfo");
922 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
923 Assert (binder
.ArgumentInfo
, new[] {
924 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
925 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
926 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.NamedArgument
| CSharpArgumentInfoFlags
.UseCompileTimeType
| CSharpArgumentInfoFlags
.LiteralConstant
, "name") // CSC bug?
929 Assert ((IList
<object>) args
, new object[] { typeof (bool), -1 }
, "args");
932 d (typeof (bool), name
:-1);
935 void InvokeMember_1 (dynamic d
, DynamicObjectMock mock
)
937 mock
.InvokeMemberOperation
= (binder
, args
) => {
938 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
939 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
940 Assert (binder
.ArgumentInfo
, new[] {
941 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
942 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null)},
945 Assert (binder
.Flags
, CSharpCallFlags
.None
, "Flags");
946 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
947 Assert (binder
.TypeArguments
, new Type
[0], "TypeArguments");
949 Assert ((IList
<object>) args
, new object[] { 'a' }
, "args");
955 void InvokeMember_2 (dynamic d
, DynamicObjectMock mock
)
957 mock
.InvokeMemberOperation
= (binder
, args
) => {
958 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
959 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
960 Assert (binder
.ArgumentInfo
, new[] {
961 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
962 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)},
965 Assert (binder
.Flags
, CSharpCallFlags
.None
, "Flags");
966 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
967 Assert (binder
.TypeArguments
, new Type
[0], "TypeArguments");
969 Assert ((IList
<object>) args
, new object[] { mock }
, "args");
975 void InvokeMember_3 (dynamic d
, DynamicObjectMock mock
)
977 mock
.InvokeMemberOperation
= (binder
, args
) => {
978 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
979 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
980 Assert (binder
.ArgumentInfo
, new[] {
981 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
982 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.IsRef
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
985 Assert (binder
.Flags
, CSharpCallFlags
.None
, "Flags");
986 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
987 Assert (binder
.TypeArguments
, new Type
[0], "TypeArguments");
989 Assert ((IList
<object>) args
, new object[] { 9 }
, "args");
996 void InvokeMember_4 (dynamic d
, DynamicObjectMock mock
)
998 mock
.InvokeMemberOperation
= (binder
, args
) => {
999 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
1000 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
1001 Assert (binder
.ArgumentInfo
, new[] {
1002 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
1003 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.IsOut
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
1006 Assert (binder
.Flags
, CSharpCallFlags
.None
, "Flags");
1007 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
1008 Assert (binder
.TypeArguments
, new Type
[0], "TypeArguments");
1010 Assert ((IList
<object>) args
, new object[] { 0 }
, "args");
1017 void InvokeMember_5 (dynamic d
, DynamicObjectMock mock
)
1019 DynamicObjectMock
.DStaticMethod (d
);
1022 void InvokeMember_6 (dynamic d
, DynamicObjectMock mock
)
1024 InvokeMemberOperation
= (binder
, args
) => {
1025 Assert (binder
.CallInfo
, new CallInfo (2, new string[0]), "CallInfo");
1026 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
1027 Assert (binder
.ArgumentInfo
, new[] {
1028 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
1029 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
1030 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
| CSharpArgumentInfoFlags
.LiteralConstant
, null),
1032 Assert (binder
.Flags
, CSharpCallFlags
.SimpleNameCall
, "Flags");
1033 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
1034 Assert (binder
.TypeArguments
, Type
.EmptyTypes
, "TypeArguments");
1036 Assert ((IList
<object>) args
, new object[] { d, null }
, "args");
1039 InvokeMember_5 (d
, null);
1042 void InvokeMember_7 (dynamic d
, DynamicObjectMock mock
)
1044 mock
.InvokeMemberOperation
= (binder
, args
) => {
1045 Assert (binder
.CallInfo
, new CallInfo (0, new string[0]), "CallInfo");
1046 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
1047 Assert (binder
.ArgumentInfo
, new[] {
1048 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1050 Assert (binder
.Flags
, CSharpCallFlags
.None
, "Flags");
1051 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
1052 Assert (binder
.TypeArguments
, new Type
[] { typeof (object) }
, "TypeArguments");
1054 Assert ((IList
<object>) args
, new object[0], "args");
1060 void SetIndex_1 (dynamic d
, DynamicObjectMock mock
)
1062 mock
.SetIndexOperation
= (binder
, args
, value) => {
1063 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
1064 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
1065 Assert (binder
.ArgumentInfo
, new[] {
1066 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
1067 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
1068 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null)},
1071 Assert ((IList
<object>) args
, new object[] { 0 }
, "args");
1072 Assert (value, 2m
, "value");
1078 void SetIndex_2 (dynamic d
, DynamicObjectMock mock
)
1080 mock
.SetIndexOperation
= (binder
, args
, value) => {
1081 Assert (binder
.CallInfo
, new CallInfo (2, new string[0]), "CallInfo");
1082 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
1083 Assert (binder
.ArgumentInfo
, new[] {
1084 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
1085 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
1086 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
1087 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null)
1090 Assert ((IList
<object>) args
, new object[] { 2, 3 }
, "args");
1091 Assert (value, -8, "value");
1098 void SetIndex_3 (dynamic d
, DynamicObjectMock mock
)
1100 mock
.SetIndexOperation
= (binder
, args
, value) => {
1101 Assert (binder
.CallInfo
, new CallInfo (1, new string[0]), "CallInfo");
1102 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
1103 Assert (binder
.ArgumentInfo
, new[] {
1104 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
, null),
1105 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
1106 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
, null)
1109 Assert ((IList
<object>) args
, new object[] { d }
, "args");
1110 Assert (value, this, "value");
1116 void SetMember_1 (dynamic d
, DynamicObjectMock mock
)
1118 const double d_const
= 2.4;
1120 mock
.SetMemberOperation
= (binder
, value) => {
1121 Assert (binder
.Name
, "Foo", "Name");
1122 Assert (binder
.IgnoreCase
, false, "IgnoreCase");
1123 Assert (binder
.CallingContext
, typeof (Tester
), "CallingContext");
1124 Assert (binder
.ArgumentInfo
, new[] {
1125 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
1126 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.UseCompileTimeType
| CSharpArgumentInfoFlags
.LiteralConstant
, null) // CSC bug?
1129 Assert (value, d_const
, "value");
1135 void UnaryPlus_1 (dynamic d
, DynamicObjectMock mock
)
1137 mock
.UnaryOperation
= (binder
) => {
1138 Assert (binder
.Operation
, ExpressionType
.UnaryPlus
, "Operation");
1139 Assert (binder
.IsChecked
, false, "IsChecked");
1140 Assert (binder
.ArgumentInfo
, new[] {
1141 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1150 void UnaryMinus_1 (dynamic d
, DynamicObjectMock mock
)
1152 mock
.UnaryOperation
= (binder
) => {
1153 Assert (binder
.Operation
, ExpressionType
.Negate
, "Operation");
1154 Assert (binder
.IsChecked
, false, "IsChecked");
1155 Assert (binder
.ArgumentInfo
, new[] {
1156 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1165 void UnaryNot_1 (dynamic d
, DynamicObjectMock mock
)
1167 mock
.UnaryOperation
= (binder
) => {
1168 Assert (binder
.Operation
, ExpressionType
.Not
, "Operation");
1169 Assert (binder
.IsChecked
, false, "IsChecked");
1170 Assert (binder
.ArgumentInfo
, new[] {
1171 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1180 void UnaryOnesComplement_1 (dynamic d
, DynamicObjectMock mock
)
1182 mock
.UnaryOperation
= (binder
) => {
1183 Assert (binder
.Operation
, ExpressionType
.OnesComplement
, "Operation");
1184 Assert (binder
.IsChecked
, false, "IsChecked");
1185 Assert (binder
.ArgumentInfo
, new[] {
1186 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1195 void UnaryDecrement_1 (dynamic d
, DynamicObjectMock mock
)
1197 mock
.UnaryOperation
= (binder
) => {
1198 Assert (binder
.Operation
, ExpressionType
.Decrement
, "Operation");
1199 Assert (binder
.IsChecked
, false, "IsChecked");
1200 Assert (binder
.ArgumentInfo
, new[] {
1201 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1210 void UnaryDecrement_2 (dynamic d
, DynamicObjectMock mock
)
1212 mock
.UnaryOperation
= (binder
) => {
1213 Assert (binder
.Operation
, ExpressionType
.Decrement
, "Operation");
1214 Assert (binder
.IsChecked
, false, "IsChecked");
1215 Assert (binder
.ArgumentInfo
, new[] {
1216 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1219 return new object ();
1225 void UnaryIncrement_1 (dynamic d
, DynamicObjectMock mock
)
1227 mock
.UnaryOperation
= (binder
) => {
1228 Assert (binder
.Operation
, ExpressionType
.Increment
, "Operation");
1229 Assert (binder
.IsChecked
, false, "IsChecked");
1230 Assert (binder
.ArgumentInfo
, new[] {
1231 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1240 void UnaryIncrement_2 (dynamic d
, DynamicObjectMock mock
)
1242 mock
.UnaryOperation
= (binder
) => {
1243 Assert (binder
.Operation
, ExpressionType
.Increment
, "Operation");
1244 Assert (binder
.IsChecked
, false, "IsChecked");
1245 Assert (binder
.ArgumentInfo
, new[] {
1246 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1249 return new object ();
1255 void UnaryIsFalse_1 (dynamic d
, DynamicObjectMock mock
)
1257 mock
.UnaryOperation
= (binder
) => {
1258 Assert (binder
.Operation
, ExpressionType
.IsFalse
, "Operation");
1259 Assert (binder
.IsChecked
, false, "IsChecked");
1260 Assert (binder
.ArgumentInfo
, new[] {
1261 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1267 mock
.BinaryOperation
= (binder
, arg
) => {
1268 Assert (binder
.Operation
, ExpressionType
.Equal
, "Operation");
1269 Assert (binder
.IsChecked
, false, "IsChecked");
1270 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
1271 Assert (binder
.ArgumentInfo
, new[] {
1272 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
1273 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
1276 Assert (arg
, null, "arg");
1279 object x
= d
== null;
1282 void UnaryIsFalse_2 (dynamic d
, DynamicObjectMock mock
)
1284 mock
.UnaryOperation
= (binder
) => {
1285 Assert (binder
.Operation
, ExpressionType
.IsFalse
, "Operation");
1286 Assert (binder
.IsChecked
, false, "IsChecked");
1287 Assert (binder
.ArgumentInfo
, new[] {
1288 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1294 mock
.BinaryOperation
= (binder
, arg
) => {
1295 Assert (binder
.Operation
, ExpressionType
.NotEqual
, "Operation");
1296 Assert (binder
.IsChecked
, false, "IsChecked");
1297 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
1298 Assert (binder
.ArgumentInfo
, new[] {
1299 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
1300 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
1303 Assert (arg
, null, "arg");
1306 object x
= d
!= null;
1309 void UnaryIsFalse_3 (dynamic d
, DynamicObjectMock mock
)
1311 mock
.UnaryOperation
= (binder
) => {
1312 Assert (binder
.Operation
, ExpressionType
.IsFalse
, "Operation");
1313 Assert (binder
.IsChecked
, false, "IsChecked");
1314 Assert (binder
.ArgumentInfo
, new[] {
1315 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1321 mock
.BinaryOperation
= (binder
, arg
) => {
1322 Assert (binder
.Operation
, ExpressionType
.And
, "Operation");
1323 Assert (binder
.IsChecked
, false, "IsChecked");
1324 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
1325 Assert (binder
.ArgumentInfo
, new[] {
1326 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
1327 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
1330 Assert (arg
, null, "arg");
1333 object x
= d
&& null;
1336 void UnaryIsTrue_1 (dynamic d
, DynamicObjectMock mock
)
1338 mock
.UnaryOperation
= (binder
) => {
1339 Assert (binder
.Operation
, ExpressionType
.IsTrue
, "Operation");
1340 Assert (binder
.IsChecked
, false, "IsChecked");
1341 Assert (binder
.ArgumentInfo
, new[] {
1342 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1348 object g
= d
? 1 :4;
1351 void UnaryIsTrue_2 (dynamic d
, DynamicObjectMock mock
)
1353 mock
.UnaryOperation
= (binder
) => {
1354 Assert (binder
.Operation
, ExpressionType
.IsTrue
, "Operation");
1355 Assert (binder
.IsChecked
, false, "IsChecked");
1356 Assert (binder
.ArgumentInfo
, new[] {
1357 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null)
1363 mock
.BinaryOperation
= (binder
, arg
) => {
1364 Assert (binder
.Operation
, ExpressionType
.Or
, "Operation");
1365 Assert (binder
.IsChecked
, false, "IsChecked");
1366 Assert (binder
.IsMemberAccess
, false, "IsMemberAccess");
1367 Assert (binder
.ArgumentInfo
, new[] {
1368 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.None
, null),
1369 new CSharpArgumentInfo (CSharpArgumentInfoFlags
.LiteralConstant
| CSharpArgumentInfoFlags
.UseCompileTimeType
, null) },
1372 Assert (arg
, null, "arg");
1375 object x
= d
|| null;
1378 #pragma warning restore 168, 169, 219
1380 static bool RunTest (MethodInfo test
)
1382 Console
.Write ("Running test {0, -25}", test
.Name
);
1384 var d
= new DynamicObjectMock ();
1385 test
.Invoke (new Tester (), new [] { d, d }
);
1386 if (d
.HitCounter
< 1)
1387 Assert (true, false, "HitCounter");
1389 Console
.WriteLine ("OK");
1391 } catch (Exception e
) {
1392 Console
.WriteLine ("FAILED");
1393 Console
.WriteLine (e
.ToString ());
1398 public static int Main ()
1400 var tests
= from test
in typeof (Tester
).GetMethods (BindingFlags
.Instance
| BindingFlags
.NonPublic
| BindingFlags
.DeclaredOnly
)
1401 where test
.GetParameters ().Length
== 2
1403 select RunTest (test
);
1405 int failures
= tests
.Count (a
=> !a
);
1406 Console
.WriteLine (failures
+ " tests failed");