Esempio n. 1
0
        public void GetMethodDelegate_should_return_delegate_if_value_overload_exists()
        {
            // Arrange
            var target = new ClassWithNonPublicMethod();

            // Act
            var actual = typeof(ClassWithNonPublicMethod).GetMethodDelegate("Add", new Type[] { typeof(double), typeof(double) });

            // Assert
            Assert.IsNotNull(actual);
            Assert.LessOrEqual(Math.Abs(2.2 - (double)actual(target, new object[] { 1.1, 1.1 })), 0.001);
        }
Esempio n. 2
0
        public void GetMemberDelegate_should_return_method_delegate_if_condition_for_its_method_is_passed()
        {
            // Arrange
            var target = new ClassWithNonPublicMethod();

            // Act
            var actual = typeof(ClassWithNonPublicMethod).GetMemberDelegate("Add", new Type[] { typeof(double), typeof(double) });

            // Assert
            Assert.IsNotNull(actual);
            Assert.LessOrEqual(Math.Abs(2.2 - (double)actual(target, new object[] { 1.1, 1.1 })), 0.001);
        }
Esempio n. 3
0
 bool TryParse(string s, out ClassWithNonPublicMethod result)
 {
     if (s == typeof(ClassWithNonPublicMethod).Name)
     {
         result = new ClassWithNonPublicMethod();
         return(true);
     }
     else
     {
         result = null;
         return(false);
     }
 }
Esempio n. 4
0
        public void GetMethodDelegate_should_return_delegate_if_value_ByRef_overload_exists()
        {
            // Arrange
            var target = new ClassWithNonPublicMethod();

            // Act
            var actual = typeof(ClassWithNonPublicMethod).GetMethodDelegate("Add", new Type[] { typeof(double), typeof(double), typeof(double).MakeByRefType() });

            // Assert
            Assert.IsNotNull(actual);
            var args = new object[] { 1.1, 2.2, 0.0 };

            actual(target, args);
            Assert.LessOrEqual(Math.Abs(3.3 - (double)args[2]), 0.001);
        }
Esempio n. 5
0
        public void GetMethodDelegate_should_return_delegate_if_overload_exists()
        {
            // Arrange
            var target = new ClassWithNonPublicMethod();

            // Act
            var actual = typeof(ClassWithNonPublicMethod).GetMethodDelegate("TryParse", new Type[] { typeof(string), typeof(ClassWithNonPublicMethod).MakeByRefType() });

            // Assert
            Assert.IsNotNull(actual);

            var args = new object[] { };

            args = new object[] { "failed", null };
            Assert.IsFalse((bool)actual(target, args));
            Assert.IsNull(args[1]);

            args = new object[] { "ClassWithNonPublicMethod", null };
            Assert.IsTrue((bool)actual(target, args));
            Assert.IsNotNull(args[1]);
        }