示例#1
0
        public void TestFuncInvokeSuccess()
        {
            var container = ScriptableObject.CreateInstance <MethodContainer>();

            var intFunc = new SerializedFunc <int> {
                MethodContainer = container,
                MethodName      = "IntFunc"
            };
            var intFuncInt = new SerializedFunc <int, int> {
                MethodContainer = container,
                MethodName      = "IntFuncInt"
            };
            var intFuncIntDouble = new SerializedFunc <int, double, int> {
                MethodContainer = container,
                MethodName      = "IntFuncIntDouble"
            };
            var intFuncIntDoubleBool = new SerializedFunc <int, double, bool, int> {
                MethodContainer = container,
                MethodName      = "IntFuncIntDoubleBool"
            };

            Assert.IsTrue(intFunc.CanInvoke);
            Assert.IsTrue(intFuncInt.CanInvoke);
            Assert.IsTrue(intFuncIntDouble.CanInvoke);
            Assert.IsTrue(intFuncIntDoubleBool.CanInvoke);

            Assert.AreEqual(1, intFunc.Invoke());
            Assert.AreEqual(1, intFuncInt.Invoke(1));
            Assert.AreEqual(1, intFuncIntDouble.Invoke(1, 1.0));
            Assert.AreEqual(1, intFuncIntDoubleBool.Invoke(1, 1.0, true));

            Assert.AreEqual(4, container.InvokeCount);
        }
示例#2
0
        public void TestFuncInvokeFail()
        {
            var container = ScriptableObject.CreateInstance <MethodContainer>();

            var func0 = new SerializedFunc <int> {
                MethodContainer = container,
                MethodName      = "Fake"
            };
            var func1 = new SerializedFunc <int, int> {
                MethodContainer = null,
                MethodName      = null,
            };
            var func2 = new SerializedFunc <int, int> {
                MethodContainer = null,
                MethodName      = string.Empty,
            };
            var func3 = new SerializedFunc <int, int> {
                MethodContainer = null,
                MethodName      = "Action",
            };
            var func4 = new SerializedFunc <int, double, int> {
                MethodContainer = container,
                MethodName      = string.Empty
            };
            var func5 = new SerializedFunc <int, double, bool, int> {
                MethodContainer = container,
                MethodName      = null
            };

            Assert.False(func0.CanInvoke);
            Assert.False(func1.CanInvoke);
            Assert.False(func2.CanInvoke);
            Assert.False(func3.CanInvoke);
            Assert.False(func4.CanInvoke);
            Assert.False(func5.CanInvoke);

            Assert.Throws <InvalidOperationException>(() => func0.Invoke());
            Assert.Throws <InvalidOperationException>(() => func1.Invoke(1));
            Assert.Throws <InvalidOperationException>(() => func2.Invoke(1));
            Assert.Throws <InvalidOperationException>(() => func3.Invoke(1));
            Assert.Throws <InvalidOperationException>(() => func4.Invoke(1, 1.0));
            Assert.Throws <InvalidOperationException>(() => func5.Invoke(1, 1.0, true));
        }
        public void TestFuncInvokeFail()
        {
            var container = ScriptableObject.CreateInstance<MethodContainer>();

            var func0 = new SerializedFunc<int> {
                MethodContainer = container,
                MethodName = "Fake"
            };
            var func1 = new SerializedFunc<int, int> {
                MethodContainer = null,
                MethodName = null,
            };
            var func2 = new SerializedFunc<int, int> {
                MethodContainer = null,
                MethodName = string.Empty,
            };
            var func3 = new SerializedFunc<int, int> {
                MethodContainer = null,
                MethodName = "Action",
            };
            var func4 = new SerializedFunc<int, double, int> {
                MethodContainer = container,
                MethodName = string.Empty
            };
            var func5 = new SerializedFunc<int, double, bool, int> {
                MethodContainer = container,
                MethodName = null
            };

            Assert.False(func0.CanInvoke);
            Assert.False(func1.CanInvoke);
            Assert.False(func2.CanInvoke);
            Assert.False(func3.CanInvoke);
            Assert.False(func4.CanInvoke);
            Assert.False(func5.CanInvoke);

            Assert.Throws<InvalidOperationException>(() => func0.Invoke());
            Assert.Throws<InvalidOperationException>(() => func1.Invoke(1));
            Assert.Throws<InvalidOperationException>(() => func2.Invoke(1));
            Assert.Throws<InvalidOperationException>(() => func3.Invoke(1));
            Assert.Throws<InvalidOperationException>(() => func4.Invoke(1, 1.0));
            Assert.Throws<InvalidOperationException>(() => func5.Invoke(1, 1.0, true));
        }
        public void TestFuncInvokeSuccess()
        {
            var container = ScriptableObject.CreateInstance<MethodContainer>();

            var intFunc = new SerializedFunc<int> {
                MethodContainer = container,
                MethodName = "IntFunc"
            };
            var intFuncInt = new SerializedFunc<int, int> {
                MethodContainer = container,
                MethodName = "IntFuncInt"
            };
            var intFuncIntDouble = new SerializedFunc<int, double, int> {
                MethodContainer = container,
                MethodName = "IntFuncIntDouble"
            };
            var intFuncIntDoubleBool = new SerializedFunc<int, double, bool, int> {
                MethodContainer = container,
                MethodName = "IntFuncIntDoubleBool"
            };

            Assert.IsTrue(intFunc.CanInvoke);
            Assert.IsTrue(intFuncInt.CanInvoke);
            Assert.IsTrue(intFuncIntDouble.CanInvoke);
            Assert.IsTrue(intFuncIntDoubleBool.CanInvoke);

            Assert.AreEqual(1, intFunc.Invoke());
            Assert.AreEqual(1, intFuncInt.Invoke(1));
            Assert.AreEqual(1, intFuncIntDouble.Invoke(1, 1.0));
            Assert.AreEqual(1, intFuncIntDoubleBool.Invoke(1, 1.0, true));

            Assert.AreEqual(4, container.InvokeCount);
        }