public void TestTryCallWithValuesOnlyAndFixedParameterOrdering()
 {
     var obj = new Elephant();
     obj.TryCallMethodWithValues("Eat",  1, "foo");
     Assert.AreEqual( 4, obj.MethodInvoked );
     obj.TryCallMethodWithValues("Eat",  1.0, "foo", false);
     Assert.AreEqual(5, obj.MethodInvoked);
     obj.TryCallMethodWithValues("Eat",  "foo");
     Assert.AreEqual(2, obj.MethodInvoked);
     obj.TryCallMethodWithValues("Eat",  'f');
     Assert.AreEqual(2, obj.MethodInvoked);
     obj.TryCallMethodWithValues("Eat",  null); // this invokes 1 and not 2 because null implies the params array parameter is null == no arguments
     Assert.AreEqual( 1, obj.MethodInvoked );
     obj.TryCallMethodWithValues("Eat",  1, null);
     Assert.AreEqual( 4, obj.MethodInvoked );
     obj.TryCallMethodWithValues("Eat",  1, null, false);
     Assert.AreEqual(5, obj.MethodInvoked);
     Assert.AreEqual(5, obj.MethodInvoked);
     obj.TryCallMethodWithValues("Accept",  'c');
     Assert.AreEqual(12, obj.MethodInvoked);
     obj.TryCallMethodWithValues("Accept",  "a");
     Assert.AreEqual(12, obj.MethodInvoked);
     obj.TryCallMethodWithValues("AcceptParams");
     Assert.AreEqual(13, obj.MethodInvoked);
     obj.TryCallMethodWithValues("AcceptParams",  null);
     Assert.AreEqual(13, obj.MethodInvoked);
     obj.TryCallMethodWithValues("AcceptParams",  1);
     Assert.AreEqual(13, obj.MethodInvoked);
     obj.TryCallMethodWithValues("AcceptParams",  1, "str");
     Assert.AreEqual(13, obj.MethodInvoked);
 }
Ejemplo n.º 2
0
		public void TestMethodDispatcherWithSingleMethod()
		{
			var obj = new Elephant();
			var dispatcher = new MethodDispatcher();
			dispatcher.AddMethod( typeof(Elephant).Methods( "Eat" ).First() );
			dispatcher.Invoke( obj, true, new {} );
			Assert.AreEqual( 1, obj.MethodInvoked );
		}
Ejemplo n.º 3
0
 public void TestTryCallWithEmptyArgumentShouldInvokeMethod1()
 {
     var obj = new Elephant();
     obj.TryCallMethod( "Eat", true, new { } );
     Assert.AreEqual( 1, obj.MethodInvoked );
     // check that we also work when passing in unused parameters
     obj.TryCallMethod( "Eat", false, new { size=1 } );
     Assert.AreEqual( 1, obj.MethodInvoked );
 }
Ejemplo n.º 4
0
 public void TestTryCallWithCountAndFoodAndIsHayArgumentsShouldInvokeMethod5()
 {
     var obj = new Elephant();
     obj.TryCallMethod( "Eat", true, new { count=2.0, food="hay", isHay=true } );
     Assert.AreEqual( 5, obj.MethodInvoked );
     // try with argument that must be type converted
     obj.TryCallMethod( "Eat", true, new { count=2, food="hay", isHay=true } );
     Assert.AreEqual( 5, obj.MethodInvoked );
 }
Ejemplo n.º 5
0
		public void TestMethodDispatcherWithMultipleMethods()
		{
			var obj = new Elephant();
			var dispatcher = new MethodDispatcher();
			typeof(Elephant).Methods( Flags.InstanceAnyVisibility | Flags.ExcludeBackingMembers ).ForEach( dispatcher.AddMethod );
			dispatcher.Invoke( obj, true, new {} );
			Assert.AreEqual( 1, obj.MethodInvoked );
			dispatcher.Invoke( obj, true, new { count=2.0, food="hay", isHay=true } );
			Assert.AreEqual( 5, obj.MethodInvoked );
			dispatcher.Invoke( obj, true, new { count=2, volume=4 } );
			Assert.AreEqual( 11, obj.MethodInvoked );
		}
Ejemplo n.º 6
0
 public void TestTryCallWithNonMatchShouldThrow()
 {
     var obj = new Elephant();
     obj.TryCallMethod( "Eat", true, new { size=1 } );
 }
Ejemplo n.º 7
0
 public void TestTryCallWithFoodArgumentShouldInvokeMethod2()
 {
     var obj = new Elephant();
     obj.TryCallMethod( "Eat", true, new { food="hay" } );
     Assert.AreEqual( 2, obj.MethodInvoked );
 }
Ejemplo n.º 8
0
 public void TestTryCallWithCountArgumentsShouldInvokeMethod3()
 {
     var obj = new Elephant();
     obj.TryCallMethod( "Eat", true, new { count=2 } );
     Assert.AreEqual( 3, obj.MethodInvoked );
 }
Ejemplo n.º 9
0
 public void TestTryCallWithCountAndFoodArgumentsShouldInvokeMethod4()
 {
     var obj = new Elephant();
     obj.TryCallMethod( "Eat", true, new { count=2, food="hay" } );
     Assert.AreEqual( 4, obj.MethodInvoked );
 }