public void DataBindingInvokerTest()
        {
            // Create root
            DataBindingTestExample example;
            var root = DataBindingRootsTest.CreateRootWithTest(out example);

            example.testStr = "Teststring";

            // Create invoker
            var parameterizedInvoker = CreateInvoker(root, typeof(DataBindingTestExample).GetMethod("Test3"));
            var parameterLessInvoker = CreateInvoker(root, typeof(DataBindingTestExample).GetMethod("UnitTest"));
            var returningInvoker     = CreateInvoker(root, typeof(DataBindingTestExample).GetMethod("UnitTest2"));

            parameterizedInvoker.SetParameterBinding(0, root, "testStr");

            // Expect debug logging from DataBindingExample.Test3
            LogAssert.Expect(LogType.Log, "Teststring");
            parameterizedInvoker.Invoke();

            // Test parameterless invocation, Test2 method will set testStr to a random float
            Assert.AreEqual("Teststring", example.testStr);
            parameterLessInvoker.Invoke();
            Assert.AreNotEqual("Teststring", example.testStr);
            example.testStr = "Teststring";

            // Test invoker binding to the return value
            Assert.AreEqual(typeof(string), returningInvoker.boundType);
            Assert.AreEqual("Teststring", returningInvoker.boundObject);
        }
        public void DataBindingBranchTest()
        {
            // Create root
            DataBindingTestExample example;
            var root = DataBindingRootsTest.CreateRootWithTest(out example);

            // Create branch
            var branch = CreateBranch(root, "nest");

            Assert.AreEqual(example.nest, branch.boundObject);
            Assert.AreEqual(typeof(DataBindingTestExample.Nest), branch.boundType);
        }
        public void DataBindingCollectionLeafTest()
        {
            // Create root
            DataBindingTestExample example;
            var root = DataBindingRootsTest.CreateRootWithTest(out example);

            // Create collection leaf
            var collectionLeaf = CreateCollectionLeaf(root, "nestArray", CreateCollectionElementPrefab());

            Assert.AreEqual(typeof(List <DataBindingTestExample.Nest>), collectionLeaf.boundType);
            Assert.AreEqual(typeof(DataBindingTestExample.Nest), collectionLeaf.elementPrefab.boundType);

            // Set up test data
            example.nestArray.Clear();
            example.nestArray.Add(new DataBindingTestExample.Nest()
            {
                testNumber = 13371,
                testStr    = "lol"
            });
            example.nestArray.Add(new DataBindingTestExample.Nest()
            {
                testNumber = 13372,
                testStr    = "lol2"
            });

            // Update collection leaf
            collectionLeaf.UpdateBinding();

            // Initialize child leaves
            foreach (var element in collectionLeaf.GetComponentsInChildren <DataBindingCollectionElement>(true))
            {
                // Awake leaves
                foreach (var leaf in element.GetComponentsInChildren <UnityTK.DataBinding.DataBinding>(true))
                {
                    leaf.Awake();
                }

                // Update element
                element.UpdateBinding();
            }

            var elements = collectionLeaf.GetComponentsInChildren <DataBindingCollectionElement>();

            Assert.AreEqual(2, elements.Length);
            Assert.AreEqual(example.nestArray[0], elements[0].boundObject);
            Assert.AreEqual(example.nestArray[1], elements[1].boundObject);
            Assert.AreEqual(example.nestArray[0].testStr, elements[0].GetComponentInChildren <Text>().text);
            Assert.AreEqual(example.nestArray[1].testStr, elements[1].GetComponentInChildren <Text>().text);
        }
        public void DataBindingGenericTemplatedLeafTest()
        {
            // Create root
            DataBindingTestExample example;
            var root = DataBindingRootsTest.CreateRootWithTest(out example);

            // Create branch
            var branch = DataBindingNodesTest.CreateBranch(root, "nest");

            // Create leaf on branch
            example.nest.testNumber = 1337;
            Text text;
            var  leafOnBranch = CreateUITextGenericTemplatedLeaf(branch, "testNumber", out text);

            // Type and bound object check
            Assert.AreEqual("1337", leafOnBranch.boundObject);
            Assert.AreEqual(typeof(object), leafOnBranch.boundType);             // Strings are being handled as objects in the leaves.

            // Update the binding
            leafOnBranch.UpdateBinding();

            // Check if leaf wrote text property
            Assert.AreEqual("1337", text.text);

            // Create leaf on root
            example.testStr = "test";
            var leafOnRoot = CreateUITextGenericTemplatedLeaf(root, "testStr", out text);

            // Type and bound object check
            Assert.AreEqual("test", leafOnRoot.boundObject);
            Assert.AreEqual(typeof(object), leafOnRoot.boundType);             // Strings are being handled as objects in the leaves.

            // Update the binding
            leafOnRoot.UpdateBinding();

            // Check if leaf wrote text property
            Assert.AreEqual("test", text.text);
        }