Exemplo n.º 1
0
        public void DeleteUser()
        {
            ParamsDelegate deleteUser = new ParamsDelegate(DeleteUserDelegate);

            Assert.IsTrue(ExpectArgumentNull(deleteUser, null), "Null username");
            Assert.IsTrue(ExpectArgumentNull(deleteUser, String.Empty), "Empty username");
        }
Exemplo n.º 2
0
        public void UserExists()
        {
            ParamsDelegate userExists = new ParamsDelegate(UserExistsDelegate);

            Assert.IsTrue(ExpectArgumentNull(userExists, null), "Null username");
            Assert.IsTrue(ExpectArgumentNull(userExists, String.Empty), "Empty username");
        }
Exemplo n.º 3
0
        public void GetUserRoles()
        {
            ParamsDelegate getUserRoles = new ParamsDelegate(GetUserRolesDelegate);

            Assert.IsTrue(ExpectArgumentNull(getUserRoles, null), "Null username");
            Assert.IsTrue(ExpectArgumentNull(getUserRoles, String.Empty), "Empty username");
        }
Exemplo n.º 4
0
        public void GetRoleUsers()
        {
            ParamsDelegate getRoleUsers = new ParamsDelegate(GetRoleUsersDelegate);

            Assert.IsTrue(ExpectArgumentNull(getRoleUsers, null), "Null role");
            Assert.IsTrue(ExpectArgumentNull(getRoleUsers, String.Empty), "Empty role");
        }
Exemplo n.º 5
0
        public void GetPassword()
        {
            ParamsDelegate getPassword = new ParamsDelegate(GetPasswordDelegate);

            Assert.IsTrue(ExpectArgumentNull(getPassword, null), "Null password");
            Assert.IsTrue(ExpectArgumentNull(getPassword, String.Empty), "Empty password");
        }
Exemplo n.º 6
0
        public void CreateRole()
        {
            ParamsDelegate createRole = new ParamsDelegate(CreateRoleDelegate);

            Assert.IsTrue(ExpectArgumentNull(createRole, null), "Null role");
            Assert.IsTrue(ExpectArgumentNull(createRole, String.Empty), "Empty role");
        }
 public void ChangeUserPassword()
 {
     ParamsDelegate changeUserPassword = new ParamsDelegate(ChangeUserPasswordDelegate);
     Assert.IsTrue(ExpectArgumentNull(changeUserPassword, null, new byte[1]), "Null username");
     Assert.IsTrue(ExpectArgumentNull(changeUserPassword, "test", null), "Null password");
     Assert.IsTrue(ExpectArgumentNull(changeUserPassword, String.Empty, new byte[1]), "Empty username");
 }
 public void CreateUser()
 {
     ParamsDelegate createUser = new ParamsDelegate(CreateUserDelegate);
     Assert.IsTrue(ExpectArgumentNull(createUser, null, new byte[1]), "Null username");
     Assert.IsTrue(ExpectArgumentNull(createUser, "test", null), "Null password");
     Assert.IsTrue(ExpectArgumentNull(createUser, String.Empty, new byte[1]), "Empty username");
 }
Exemplo n.º 9
0
        public void GetUserIdFromUsername()
        {
            ParamsDelegate getUserIdFromUsername = new ParamsDelegate(GetUserIdFromUsernameDelegate);

            Assert.IsTrue(ExpectArgumentNull(getUserIdFromUsername, null), "Null username");
            Assert.IsTrue(ExpectArgumentNull(getUserIdFromUsername, String.Empty), "Empty username");
        }
Exemplo n.º 10
0
        public void GetRoleIdFromRoleName()
        {
            ParamsDelegate getRoleIdFromRoleName = new ParamsDelegate(GetRoleIdFromRoleNameDelegate);

            Assert.IsTrue(ExpectArgumentNull(getRoleIdFromRoleName, null), "Null role");
            Assert.IsTrue(ExpectArgumentNull(getRoleIdFromRoleName, String.Empty), "Empty role");
        }
Exemplo n.º 11
0
        public void ChangeUserPassword()
        {
            ParamsDelegate changeUserPassword = new ParamsDelegate(ChangeUserPasswordDelegate);

            Assert.IsTrue(ExpectArgumentNull(changeUserPassword, null, new byte[1]), "Null username");
            Assert.IsTrue(ExpectArgumentNull(changeUserPassword, "test", null), "Null password");
            Assert.IsTrue(ExpectArgumentNull(changeUserPassword, String.Empty, new byte[1]), "Empty username");
        }
Exemplo n.º 12
0
        public void CreateUser()
        {
            ParamsDelegate createUser = new ParamsDelegate(CreateUserDelegate);

            Assert.IsTrue(ExpectArgumentNull(createUser, null, new byte[1]), "Null username");
            Assert.IsTrue(ExpectArgumentNull(createUser, "test", null), "Null password");
            Assert.IsTrue(ExpectArgumentNull(createUser, String.Empty, new byte[1]), "Empty username");
        }
Exemplo n.º 13
0
 public void CreateUserRole()
 {
     ParamsDelegate createUserRole = new ParamsDelegate(CreateUserRoleDelegate);
     Assert.IsTrue(ExpectArgumentNull(createUserRole, null, "test"), "Null username");
     Assert.IsTrue(ExpectArgumentNull(createUserRole, String.Empty, "test"), "Empty username");
     Assert.IsTrue(ExpectArgumentNull(createUserRole, "test", null), "Null role");
     Assert.IsTrue(ExpectArgumentNull(createUserRole, "test", String.Empty), "Empty role");
 }
Exemplo n.º 14
0
        public void MethodCallInvocation_WithParamsArgument_ReturnsTheLastElementOfTheArray()
        {
            ParamsDelegate @delegate = MethodWithParams;
            var            func      = ExecuteLambda <ParamsDelegate>(@delegate);
            string         month     = func(5, Month.Jan.ToString(), Month.Feb.ToString(), Month.Mar.ToString(), Month.Apr.ToString(), Month.May.ToString(), Month.Jun.ToString());

            Assert.AreEqual(month, Month.Jun.ToString());
        }
Exemplo n.º 15
0
        public void DeleteUserRole()
        {
            ParamsDelegate deleteUserRole = new ParamsDelegate(DeleteUserRoleDelegate);

            Assert.IsTrue(ExpectArgumentNull(deleteUserRole, null, "test"), "Null username");
            Assert.IsTrue(ExpectArgumentNull(deleteUserRole, String.Empty, "test"), "Empty username");
            Assert.IsTrue(ExpectArgumentNull(deleteUserRole, "test", null), "Null role");
            Assert.IsTrue(ExpectArgumentNull(deleteUserRole, "test", String.Empty), "Empty role");
        }
Exemplo n.º 16
0
        public void Call_Accepts_One_Or_More_Arguments()
        {
            var fn = new ParamsDelegate((object[] arguments) => arguments.Length);

            Assert.AreEqual(R.Call(fn), 0);
            Assert.AreEqual(R.Call(fn, "x"), 1);
            Assert.AreEqual(R.Call(fn, "x", "y"), 2);
            Assert.AreEqual(R.Call(fn, "x", "y", "z"), 3);
        }
Exemplo n.º 17
0
        public void RenameRole()
        {
            ParamsDelegate renameRole = new ParamsDelegate(RenameRoleDelegate);

            Assert.IsTrue(ExpectArgumentNull(renameRole, null, "test"), "Original role null");
            Assert.IsTrue(ExpectArgumentNull(renameRole, String.Empty, "test"), "Original role empty");
            Assert.IsTrue(ExpectArgumentNull(renameRole, "test", null), "New role null");
            Assert.IsTrue(ExpectArgumentNull(renameRole, "test", String.Empty), "New role empty");
        }
Exemplo n.º 18
0
        /// <summary>
        /// Function which creates a shim for a target method.
        /// The target method is expected to take 1 or more enumerables of various types, and return a single enumerable of another type.
        /// The shim is a lambda expression which takes 1 or more object[,] parameters, and returns a single object[,]
        /// The first row of each array defines the field names, which are mapped to the public properties of the
        /// input and return types.
        /// </summary>
        /// <returns></returns>
        private static LambdaExpression MakeObjectArrayShim(
            LambdaExpression targetMethod,
            IList <ShimParameter> inputShimParameters,
            ShimParameter resultShimParameter)
        {
            var nParams = targetMethod.Parameters.Count;

            var compiledTargetMethod = targetMethod.Compile();

            // create a delegate, object*n -> object
            // (simpler, but probably slower, alternative to building it all out of Expressions)
            ParamsDelegate shimDelegate = inputObjectArray =>
            {
                try
                {
                    if (inputObjectArray.GetLength(0) != nParams)
                    {
                        throw new InvalidOperationException(
                                  $"Expected {nParams} params, received {inputObjectArray.GetLength(0)}");
                    }

                    var targetMethodInputs = new object[nParams];

                    for (int i = 0; i != nParams; ++i)
                    {
                        try
                        {
                            targetMethodInputs[i] = inputShimParameters[i].ConvertShimToTarget(inputObjectArray[i]);
                        }
                        catch (Exception e)
                        {
                            throw new InvalidOperationException($"Failed to convert parameter {i + 1}: {e.Message}");
                        }
                    }

                    var targetMethodResult = compiledTargetMethod.DynamicInvoke(targetMethodInputs);

                    return(resultShimParameter.ConvertTargetToShim(targetMethodResult));
                }
                catch (Exception e)
                {
                    return(new object[, ] {
                        { ExcelError.ExcelErrorValue }, { e.Message }
                    });
                }
            };

            // convert the delegate back to a LambdaExpression
            var args        = targetMethod.Parameters.Select(param => Expression.Parameter(typeof(object))).ToList();
            var paramsParam = Expression.NewArrayInit(typeof(object), args);
            var closure     = Expression.Constant(shimDelegate.Target);
            var call        = Expression.Call(closure, shimDelegate.Method, paramsParam);

            return(Expression.Lambda(call, args));
        }
Exemplo n.º 19
0
        private bool ExpectArgumentNull(ParamsDelegate myMethod, params object[] methodParams)
        {
            bool ret = false;

            try
            {
                if (methodParams == null)
                {
                    myMethod(new object[] { null });
                }
                else
                {
                    myMethod(methodParams);
                }
            }
            catch (ArgumentNullException)
            {
                ret = true;
            }

            return(ret);
        }
Exemplo n.º 20
0
 public void GetRoleUsers()
 {
     ParamsDelegate getRoleUsers = new ParamsDelegate(GetRoleUsersDelegate);
     Assert.IsTrue(ExpectArgumentNull(getRoleUsers, null), "Null role");
     Assert.IsTrue(ExpectArgumentNull(getRoleUsers, String.Empty), "Empty role");
 }
Exemplo n.º 21
0
 extern public static string Call(ParamsDelegate f);
Exemplo n.º 22
0
 public void CreateUserRoleBatch()
 {
     ParamsDelegate createUserRoleBatch = new ParamsDelegate(CreateUserRoleBatchDelegate);
     Assert.IsTrue(ExpectArgumentNull(createUserRoleBatch, null), "Null dataTable");
 }
Exemplo n.º 23
0
 public void UserExists()
 {
     ParamsDelegate userExists = new ParamsDelegate(UserExistsDelegate);
     Assert.IsTrue(ExpectArgumentNull(userExists, null), "Null username");
     Assert.IsTrue(ExpectArgumentNull(userExists, String.Empty), "Empty username");
 }
Exemplo n.º 24
0
        private bool ExpectArgumentNull(ParamsDelegate myMethod, params object[] methodParams)
        {
            bool ret = false;

            try
            {
                if (methodParams == null)
                {
                    myMethod(new object[] {null});
                }
                else
                {
                    myMethod(methodParams);
                }
            }
            catch (ArgumentNullException)
            {
                ret = true;
            }

            return ret;
        }
Exemplo n.º 25
0
 public void GetUserRoles()
 {
     ParamsDelegate getUserRoles = new ParamsDelegate(GetUserRolesDelegate);
     Assert.IsTrue(ExpectArgumentNull(getUserRoles, null), "Null username");
     Assert.IsTrue(ExpectArgumentNull(getUserRoles, String.Empty), "Empty username");
 }
Exemplo n.º 26
0
 public void RenameRole()
 {
     ParamsDelegate renameRole = new ParamsDelegate(RenameRoleDelegate);
     Assert.IsTrue(ExpectArgumentNull(renameRole, null, "test"), "Original role null");
     Assert.IsTrue(ExpectArgumentNull(renameRole, String.Empty, "test"), "Original role empty");
     Assert.IsTrue(ExpectArgumentNull(renameRole, "test", null), "New role null");
     Assert.IsTrue(ExpectArgumentNull(renameRole, "test", String.Empty), "New role empty");
 }
Exemplo n.º 27
0
 public void GetUserIdFromUsername()
 {
     ParamsDelegate getUserIdFromUsername = new ParamsDelegate(GetUserIdFromUsernameDelegate);
     Assert.IsTrue(ExpectArgumentNull(getUserIdFromUsername, null), "Null username");
     Assert.IsTrue(ExpectArgumentNull(getUserIdFromUsername, String.Empty), "Empty username");
 }
Exemplo n.º 28
0
        public void DeleteUserRoleBatch()
        {
            ParamsDelegate deleteUserRoleBatch = new ParamsDelegate(DeleteUserRoleBatchDelegate);

            Assert.IsTrue(ExpectArgumentNull(deleteUserRoleBatch, null), "Null dataTable");
        }
Exemplo n.º 29
0
 public void GetRoleIdFromRoleName()
 {
     ParamsDelegate getRoleIdFromRoleName = new ParamsDelegate(GetRoleIdFromRoleNameDelegate);
     Assert.IsTrue(ExpectArgumentNull(getRoleIdFromRoleName, null), "Null role");
     Assert.IsTrue(ExpectArgumentNull(getRoleIdFromRoleName, String.Empty), "Empty role");
 }
Exemplo n.º 30
0
 public void GetPassword()
 {
     ParamsDelegate getPassword = new ParamsDelegate(GetPasswordDelegate);
     Assert.IsTrue(ExpectArgumentNull(getPassword, null), "Null password");
     Assert.IsTrue(ExpectArgumentNull(getPassword, String.Empty), "Empty password");
 }
Exemplo n.º 31
0
 public void DeleteUser()
 {
     ParamsDelegate deleteUser = new ParamsDelegate(DeleteUserDelegate);
     Assert.IsTrue(ExpectArgumentNull(deleteUser, null), "Null username");
     Assert.IsTrue(ExpectArgumentNull(deleteUser, String.Empty), "Empty username");
 }
Exemplo n.º 32
0
 public void DeleteRole()
 {
     ParamsDelegate deleteRole = new ParamsDelegate(DeleteRoleDelegate);
     Assert.IsTrue(ExpectArgumentNull(deleteRole, null), "Null role");
     Assert.IsTrue(ExpectArgumentNull(deleteRole, String.Empty), "Empty role");
 }
Exemplo n.º 33
0
        private static void Run()
        {
            {
                TestLogger.Log("Testing basic interop...");
                var fso    = new FileSystemObject();
                var drive1 = fso.GetDrive("C:");
                var drive2 = fso.GetDrive("C:");
                TestLogger.Log(drive1.FreeSpace == drive2.FreeSpace);
            }

            {
                TestLogger.Log("Tesing getters...");
                var prop = new PropertyTest();
                prop.Setup();
                TestLogger.Log(prop.X);
            }

            {
                TestLogger.Log("Testing virtuals...");
                var b = new VirtualsBase();
                TestLogger.Log(b.V());
                TestLogger.Log(b.CallV());
                TestLogger.Log(b.U());
                var d = (VirtualsBase) new VirtualsDerived();
                TestLogger.Log(d.V());
                TestLogger.Log(d.CallV());
                TestLogger.Log(d.U());
            }

            {
                TestLogger.Log("Testing JSObject...");
                var obj = new JSObject
                {
                    { "int", 1 },
                    { "string", "two" },
                    { "object", new JSObject {
                          { "inner", 3 }, { "null", null }
                      } }
                };
                TestLogger.Log(obj.GetField <int>("int"));
                TestLogger.Log(obj.GetField <string>("string"));
                TestLogger.Log(obj.GetField <JSObject>("object").GetField <int>("inner"));
            }

            {
                TestLogger.Log("Testing exceptions...");
                var obj = new JSObject {
                    { "int", 1 }, { "string", "two" }
                };
                try
                {
                    // Invalid cast
                    var dummy = obj.GetField <int[]>("int");
                    TestLogger.Log(dummy.ToString());
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
                try
                {
                    // User exception
                    TestException.ThrowFromUnmanaged();
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
                // Managed -> unmanaged exception
                TestException.CatchFromManagedInUnmanaged();
                try
                {
                    // Managed -> unmanaged -> managed exception
                    TestException.ThrowViaUnmanaged();
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
                // Unmanaged -> managed -> unmanaged -> catch
                TestException.CatchViaManagedInUnmanaged();
                try
                {
                    // Unmanaged exception
                    TestException.InvalidJavaScript();
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
            }

            {
                TestLogger.Log("Testing JSArray...");
                var arr = JSArray.FromArray(0, 1, "two", new JSObject {
                    { "value", 3 }
                }, new JSObject {
                    { "value", "four" }
                });
                TestLogger.Log(arr.Length);
                TestLogger.Log(arr[0].ToString());
                TestLogger.Log(arr[1].ToString());
                TestLogger.Log(arr[2].ToString());
                TestLogger.Log(arr[3].GetField <int>("value"));
                TestLogger.Log(arr[4].GetField <string>("value"));
            }

            {
                TestLogger.Log("Testing polymorphic method of higher-kinded type...");
                var t1 = new TestGeneric <int>(1);
                TestLogger.Log(t1.M <string>("two"));
                var obj = new JSObject();
                obj.SetField("f", "field");
                var t2 = new TestGeneric <JSObject>(obj);
                TestLogger.Log(t2.M <int>(3));
                TestLogger.Log(t2.M <JSObject>(obj));
            }

            {
                TestLogger.Log("Testing exported instance methods in base types...");
                var d = new TestGenericDerived <int>();
                d.Value      = new int[] { 1, 2, 3 };
                d.OtherValue = 4;
                TestLogger.Log(d.N());
            }

            {
                TestLogger.Log("Testing delegates...");
                TestLogger.Log(TestDelegate.TestWithDelegate());
                TestLogger.Log
                    (TestDelegate.WithManagedDelegate
                        ((i, obj) =>
                        new JSObject {
                    { "test", i.ToString() + " " + obj.GetField <int>("test").ToString() }
                },
                        new JSObject {
                    { "test", 7 }
                }));
            }

            {
                TestLogger.Log("Testing param arrays...");
                TestLogger.Log(TestParams.JoinA(3, 7, "a", "b", "c"));
                TestLogger.Log(TestParams.TestB());
                ParamsDelegate f = TestParams.JoinA;
                TestLogger.Log(TestParams.Call(f));
                var g = TestParams.GetTestB();
                TestLogger.Log(g(3, 7, "a", "b", "c"));
            }

            {
                TestLogger.Log("Testing proxied object...");
                var p = new ProxiedTest();
                TestLogger.Log(ProxiedBase.TestGlobal);
                TestLogger.Log(p.One);
                TestLogger.Log(p.Two);
                TestLogger.Log(p.Three.GetField <int>("value"));
                TestLogger.Log(p.GetValue());
                p.One   = 11;
                p.Two   = "twenty-two";
                p.Three = new JSObject {
                    { "value", 55 }
                };
#if true
                // BROKEN: Polymorphic delegates
                p.Delegate = i => TestLogger.Log(i);
#endif
                TestLogger.Log(p.One);
                TestLogger.Log(p.Two);
                TestLogger.Log(p.Three.GetField <int>("value"));
#if true
                // BROKEN: Polymorphic delegates
                p.Delegate(7);
#endif
                TestLogger.Log(p.GetValue());
                p.Morph();
                // TODO: Managed Interop will not notice '2' is an int rather than a string
#if false
                try
                {
                    TestLogger.Log(p.Two);
                }
                catch (InvalidCastException e)
                {
                    TestLogger.LogException(e);
                }
#endif
                var obj = JSObject.From(p);
                TestLogger.Log(obj.GetField <int>("two"));
                obj.SetField <int>("one", 111);
                TestLogger.Log(p.One);
                p.One = 1111;
                TestLogger.Log(obj.GetField <int>("one"));
            }

            {
                TestLogger.Log("Testing keyed object...");
                var k = new KeyedTest(1, "two", 3, "four");
                TestLogger.Log(k.I);
                TestLogger.Log(k.S);
                TestLogger.Log(k.X);
                TestLogger.Log(k.Y);
                k.I = 11;
                k.X = 33;
                TestLogger.Log(k.I);
                TestLogger.Log(k.X);
                var k2 = k.Clone();
                TestLogger.Log(k2.I);
                TestLogger.Log(k2.X);
                k.I = 111;
                k.X = 333;
                TestLogger.Log(k2.I);
                TestLogger.Log(k2.X);
                var k3 = k.PassThrough();
                TestLogger.Log(k3.I);
                TestLogger.Log(k3.X);
                k3.I = 1111;
                k3.X = 3333;
                TestLogger.Log(k.I);
                TestLogger.Log(k.X);
                k.Morph();
                try
                {
                    TestLogger.Log(k.X);
                }
                catch (Exception e)
                {
                    TestLogger.LogException(e);
                }
                var obj = JSObject.From(k);
                TestLogger.Log(obj.GetField <string>("x"));
                obj.SetField <int>("x", 1);
                TestLogger.Log(k.X);
            }

            {
                TestLogger.Log("Testing nullable...");
                var ni = new int?(3);
                TestLogger.Log(ni.Value);
                ni = NullableTest.Incr(ni);
                TestLogger.Log(ni.Value);
                var ni2 = default(int?);
                TestLogger.Log(ni2.HasValue);
                ni2 = NullableTest.Incr(ni2);
                TestLogger.Log(ni2.HasValue);
            }

            {
                TestLogger.Log("Testing primitive arrays...");
                var arr  = new int[] { 0, 1, 2, 3, 4, 5 };
                var arr2 = TestArray.WithArray(arr);
                TestLogger.Log(arr[3]);
                TestLogger.Log(arr2.Length);
                TestLogger.Log(arr2[3]);
            }

            {
                TestLogger.Log("Testing normal object...");
                {
                    var l = "left";
                    var r = new Normal {
                        I = 7, S = "nine"
                    };
                    var o  = TestNormal.Right(l, r);
                    var r2 = (Normal)o;
                    TestLogger.Log(r2.I);
                    TestLogger.Log(r2.S);
                }
                {
                    var l = new Normal {
                        I = 7, S = "nine"
                    };
                    var r  = "right";
                    var o  = TestNormal.Right(l, r);
                    var r2 = (string)o;
                    TestLogger.Log(r2);
                }
                {
                    var l  = "left";
                    var r  = 2;
                    var o  = TestNormal.Right(l, r);
                    var r2 = (int)o;
                    TestLogger.Log(r2);
                }
                {
                    var l = new KeyedTest(1, "two", 3, "four");
                    var r = new ProxiedTest();
                    try
                    {
                        var o  = TestNormal.Right(l, r);
                        var r2 = (ProxiedTest)o;
                        TestLogger.Log(r2.One);
                    }
                    catch (Exception e)
                    {
                        TestLogger.LogException(e);
                    }
                }
            }

            {
                TestLogger.Log("Testing default instances bug...");
                var t = new TestDefaultInstance();
                TestLogger.Log(t.X.ToString());
                t.X = 3;
                TestLogger.Log(t.X.ToString());
            }

            TestLogger.Log("Done.");
        }