示例#1
0
        public void TestMethodCache()
        {
            var f = new FuncHost("",cacheAsKey: "cache");

            var expect1 = "v1";
            f.Function("hello", () => { return expect1; });

            var result1 = f.Invoke("hello");

            var expect2 = "v2";
            f.Function("hello", () => { return expect2; });
            var result2 = f.Invoke("hello");

            Assert.AreEqual(expect1, result1);
        }
示例#2
0
        public void TestMethod2()
        {
            var f = new FuncHost();

            var functionName = "someFunction";
            f.Function(functionName, () => { return ""; });
            var result = f.Render();

            Assert.IsTrue(result.ToString().Contains(functionName));
        }
示例#3
0
        public void TestMethod1()
        {
            var f = new FuncHost();

            var expect = "yoo";
            f.Function("foo", () => { return expect; });
            var result = f.Invoke("foo");

            Assert.AreEqual(expect, result);
        }
示例#4
0
        public void TestMethodDeserialize()
        {
            var f = new FuncHost();

            var functionName = "someFunction";

            f.Function<Foo>(functionName, (param) => { return param.Name; });

            var result = f.Invoke("someFunction", "{Name:'Jonas'}");

            Assert.AreEqual("Jonas", result.ToString());
        }
示例#5
0
        public void TestMethodDeserializeComplex()
        {
            var f = new FuncHost();

            var functionName = "someFunction";
            var parameter = new Foo { Name = "Jonas" };

            f.Function<dynamic>(functionName, (param) => { return param.Name; });

            var result = f.InvokeAndSerialize("someFunction", "{Name:'Jonas'}");

            Assert.AreEqual("\"" + parameter.Name + "\"", result);
        }
示例#6
0
        public void TestMethodInt()
        {
            var f = new FuncHost();

            var expect = "yoo";
            f.Function<int>("foo", (i) => { return (i+i).ToString(); });
            var result = f.Invoke("foo","100");

            Assert.AreEqual("200", result);
        }
示例#7
0
        public void TestMethodStringParameter()
        {
            var f = new FuncHost();

            var expect = "yoo";
            f.Function("foo", (param) => { return param; });
            var result = f.Invoke("foo", expect);

            Assert.AreEqual(expect, result);
        }
示例#8
0
        public void TestMethodSerialize()
        {
            var f = new FuncHost();

            var expect = "yoo";
            f.Function("foo", () => { return new Foo { Name = expect }; });
            var result = f.InvokeAndSerialize("foo", "");

            Assert.AreEqual("{\"Name\":\"yoo\"}", result);
        }
示例#9
0
        public void TestMethodNoCache()
        {
            var f = new FuncHost("", "");

            var expect = "v1";
            f.Function("hello", () => { return expect; });

            var result1 = f.Invoke("hello");

            expect = "v2";
            f.Function("hello", () => { return expect; });

            var result2 = f.Invoke("hello");

            Assert.AreEqual(expect, result2);
        }