Exemplo n.º 1
0
        public void IEnumerable_Passes()
        {
            var node = new TreeNodeHelper <int>();

            node.Children.Add(
                node.CreateNode(10)
                , node.CreateNode(20)
                , node.CreateNode(30));

            node[0].Children.Add(
                node.CreateNode(100)
                , node.CreateNode(200));

            node[2].Children.Add(
                node.CreateNode(100));

            AssertionUtils.AssertEnumerable(
                new TreeNodeHelper <int>[] {
                node,
                node.Children[0], node.Children[0][0], node.Children[0][1],
                node.Children[1],
                node.Children[2], node.Children[2][0]
            }
                , node
                , ""
                );
        }
Exemplo n.º 2
0
        public void BasicUsagePasses()
        {
            var query           = ".style1";
            var layoutValueDict = new ViewLayoutValueDictionary()
                                  .AddValue("key", 100)
                                  .AddValue("key2", 200);
            var layoutValueDict2 = new ViewLayoutValueDictionary()
                                   .AddValue("apple", -100)
                                   .AddValue("orange", -200);

            var layoutOverwriter = new ViewLayoutOverwriter();

            layoutOverwriter
            .Add(new ViewLayoutSelector(query, ""), layoutValueDict)
            .Add(new ViewLayoutSelector($"Model {query}", ""), layoutValueDict2);

            var model = new Model()
            {
                Name = "Model"
            }
            .AddStylingID(query);

            AssertionUtils.AssertEnumerable(
                new ViewLayoutValueDictionary[] {
                layoutValueDict2,
                layoutValueDict,
            }
                , layoutOverwriter.MatchLayoutValueDicts(model, null)
                , "");
        }
Exemplo n.º 3
0
        public void SetParamByIndexPasses()
        {
            var data = new HavingTextResourceData();

            data.ResizeParams(3);
            data.SetParam(0, 100);
            data.SetParam(1, "Apple");
            data.SetParam(2, 1.23f);

            Assert.AreEqual(3, data.ParamCount);
            AssertionUtils.AssertEnumerable(
                new object[]
            {
                100,
                "Apple",
                1.23f,
            },
                data.GetTextResourceParams(),
                "");

            Debug.Log($"Success to Basic SetParam");

            Assert.Throws <UnityEngine.Assertions.AssertionException>(() => {
                data.SetParam(10, 654);
            });
            Debug.Log($"Success to Out of Range Index(over paramCount)");
            Assert.Throws <UnityEngine.Assertions.AssertionException>(() => {
                data.SetParam(-1, 654);
            });
            Debug.Log($"Success to Out of Range Index(minus index)");
        }
Exemplo n.º 4
0
        public void IEnumerable_GetValueEnueramble_Passes()
        {
            var node = new TreeNodeHelper <int>();

            node.Children.Add(
                node.CreateNode(10
                                , node.CreateNode(100)
                                , node.CreateNode(200)
                                )
                , node.CreateNode(20)
                , node.CreateNode(30
                                  , node.CreateNode(100)
                                  )
                );

            AssertionUtils.AssertEnumerable(
                new TreeNodeHelper <int>[] {
                node,
                node.Children[0], node.Children[0][0], node.Children[0][1],
                node.Children[1],
                node.Children[2], node.Children[2][0]
            }.Select(_n => _n.Value)
                , node.GetValueEnumerable()
                , ""
                );
        }
Exemplo n.º 5
0
        public void GetFlagEnumCombinationPasses()
        {
            var flagsEnumerable = IndexCombinationEnumerable.GetFlagEnumCombination(
                TestFlags.A,
                TestFlags.D,
                TestFlags.E
                );

            //foreach(var f in flagsEnumerable)
            //{
            //    Debug.Log($"flags => {f}");
            //}
            AssertionUtils.AssertEnumerable(
                new TestFlags[] {
                TestFlags.A,
                TestFlags.A | TestFlags.D,
                TestFlags.A | TestFlags.D | TestFlags.E,
                TestFlags.A | TestFlags.E,
                TestFlags.D,
                TestFlags.D | TestFlags.E,
                TestFlags.E,
            },
                flagsEnumerable,
                ""
                );
        }
Exemplo n.º 6
0
        public void Children_Property_Passes()
        {
            var node = new TreeNodeHelper <int>();
            {
                node.Children.Add(
                    TreeNodeHelper <int> .Create(100)
                    , TreeNodeHelper <int> .Create(200)
                    , TreeNodeHelper <int> .Create(300));

                AssertionUtils.AssertEnumerable(
                    new int[] {
                    100, 200, 300
                }
                    , node.Children.Select(_c => _c.Value)
                    , ""
                    );
                Assert.IsTrue(node.Children.All(_c => _c.Parent == node));
            }

            {
                node.Children.RemoveAt(1);
                AssertionUtils.AssertEnumerable(
                    new int[] {
                    100, 300
                }
                    , node.Children.Select(_c => _c.Value)
                    , ""
                    );
                Assert.IsTrue(node.Children.All(_c => _c.Parent == node));
            }
        }
Exemplo n.º 7
0
        public void TakeSnapshotPasses()
        {
            var data = new SnapshotData
            {
                value1 = 100,
                value2 = "Test",
            };
            var stackFrame = new StackFrame();

            System.Func <SnapshotData, SnapshotData, bool> validateSnapshot = (correct, got) => correct.AreSame(got);

            //Snapshotの作成のテスト
            DoTakeSnapshot = true;
            var snapshot = TakeOrValid(data, stackFrame, 0, validateSnapshot,
                                       "Failed to Take snapshot...");

            Assert.AreSame(snapshot, LastSnapshot);

            var snapshotFilepath = CreateSnapshotFilepath(stackFrame);

            Assert.AreEqual(snapshot.GetAssetPath(), snapshotFilepath);

            Assert.IsTrue(Hinode.Editors.EditorFileUtils.IsExistAsset(snapshotFilepath), $"don't exist snapshot file... filepath='{snapshotFilepath}'");
            var savedSnapshot = AssetDatabase.LoadAssetAtPath <Snapshot>(snapshotFilepath);

            AssertionUtils.AssertEnumerable(new[] { "snapshot" }, AssetDatabase.GetLabels(savedSnapshot), "想定したラベルが付けられていません。");

            //Snapshotによる検証のテスト
            DoTakeSnapshot = false;
            Assert.DoesNotThrow(() => {
                var snap = TakeOrValid(data, stackFrame, 0, validateSnapshot, "Failed to Take snapshot...");
                Assert.AreSame(snap, LastSnapshot);
            });
            ReserveDeleteAssets(snapshotFilepath);
        }
Exemplo n.º 8
0
        public void ResizeParamsPasses()
        {
            var data = new HavingTextResourceData()
            {
                HavingTextResourceKey = "key1",
            };
            var paramList = new object[]
            {
                100,
                "Apple",
                1.23f,
            };

            data.SetParams(paramList);

            {
                data.ResizeParams(1);
                Assert.AreEqual(1, data.ParamCount);
                AssertionUtils.AssertEnumerable(
                    new object[] { paramList[0] },
                    data.GetTextResourceParams(),
                    "");
            }
            Debug.Log($"Success to Resize paramList(Reduce ParamCount)");

            {
                data.ResizeParams(3);
                Assert.AreEqual(3, data.ParamCount);
                AssertionUtils.AssertEnumerable(
                    new object[] { paramList[0], null, null },
                    data.GetTextResourceParams(),
                    "");
            }
            Debug.Log($"Success to Resize paramList(Increase ParamCount)");
        }
Exemplo n.º 9
0
        public void BasicUsagePasses()
        {
            //foreach(var pair in new IndexCombinationEnumerable(4))
            //{
            //    var log = pair.Select(_i => _i.ToString()).Aggregate((_s, _c) => _s + "," + _c);
            //    Debug.Log(log);
            //}

            AssertionUtils.AssertEnumerable(
                new List <int[]>()
            {
                new int[] { 0 },
                new int[] { 0, 1 },
                new int[] { 0, 1, 2 },
                new int[] { 0, 1, 2, 3 },
                new int[] { 0, 1, 3 },
                new int[] { 0, 2 },
                new int[] { 0, 2, 3 },
                new int[] { 0, 3 },
                new int[] { 1 },
                new int[] { 1, 2 },
                new int[] { 1, 2, 3 },
                new int[] { 1, 3 },
                new int[] { 2 },
                new int[] { 2, 3 },
                new int[] { 3 },
            },
                new IndexCombinationEnumerable(4),
                "",
                (_correct, _got) => {
                var correct = _correct.ToArray();
                var got     = _got.ToArray();
                if (correct.Length != got.Length)
                {
                    Debug.LogWarning($"Not Equal Length... corrent={correct.Length}, got={got.Length}");
                    Logger.LogWarning(Logger.Priority.High, () => {
                        var correctList = correct.Select(_e => _e.ToString()).Aggregate((_s, _c) => _s + "," + _c);
                        var gotList     = got.Select(_e => _e.ToString()).Aggregate((_s, _c) => _s + "," + _c);
                        return($"correct list=> {correctList};{System.Environment.NewLine}got list=>{gotList}");
                    });
                    return(false);
                }
                for (var i = 0; i < correct.Length; ++i)
                {
                    if (correct[i] != got[i])
                    {
                        Debug.LogWarning($"Not Equal element[{i}]... corrent={correct[i]}, got={got[i]}");
                        Logger.LogWarning(Logger.Priority.High, () => {
                            var correctList = correct.Select(_e => _e.ToString()).Aggregate((_s, _c) => _s + "," + _c);
                            var gotList     = got.Select(_e => _e.ToString()).Aggregate((_s, _c) => _s + "," + _c);
                            return($"correct list=> {correctList};{System.Environment.NewLine}got list=>{gotList}");
                        });
                        return(false);
                    }
                }
                return(true);
            }
                );
        }
Exemplo n.º 10
0
        public void IsHighSiblingOrderPasses()
        {
            var notSiblingOrderModel = new Model()
            {
                Name = "notSiblingOrder"
            };
            var siblingOrderModel = new SiblingOrderModel()
            {
                Name = "SiblingOrder", SiblingOrder = 100
            };
            var highestSiblingModelView = new EmptyViewObject()
            {
                UseModel    = siblingOrderModel,
                UseBindInfo = new ModelViewBinder.BindInfo("highest", typeof(EmptyViewObject))
                              .AddViewLayoutValue(BasicViewLayoutName.siblingOrder, 200)
            };
            var siblingModelView = new EmptyViewObject()
            {
                UseModel    = siblingOrderModel,
                UseBindInfo = new ModelViewBinder.BindInfo("siblingModelView", typeof(EmptyViewObject))
                              .AddViewLayoutValue(BasicViewLayoutName.siblingOrder, 100)
            };
            var siblingModel = new EmptyViewObject()
            {
                UseModel    = siblingOrderModel,
                UseBindInfo = new ModelViewBinder.BindInfo("siblingModel", typeof(EmptyViewObject))
            };
            var siblingView = new EmptyViewObject()
            {
                UseModel    = notSiblingOrderModel,
                UseBindInfo = new ModelViewBinder.BindInfo("siblingView", typeof(EmptyViewObject))
                              .AddViewLayoutValue(BasicViewLayoutName.siblingOrder, 100)
            };
            var notSiblingView = new EmptyViewObject()
            {
                UseModel    = notSiblingOrderModel,
                UseBindInfo = new ModelViewBinder.BindInfo("notSibling", typeof(EmptyViewObject))
            };
            var list = new IViewObject[]
            {
                siblingView,
                notSiblingView,
                highestSiblingModelView,
                siblingModelView,
                siblingModel
            };

            AssertionUtils.AssertEnumerable(
                new IViewObject[] {
                highestSiblingModelView,
                siblingModelView,
                siblingModel,
                siblingView,
                notSiblingView,
            }, list.OrderBy(_v => _v, new SiblingOrderViewObjectCompare()),
                $"想定された並び順になっていません");
        }
Exemplo n.º 11
0
        public void ParsePasses()
        {
            var viewID = ViewIdentity.Parse("apple.orange.grape");

            Assert.AreEqual("apple", viewID.MainID);
            Assert.IsTrue(viewID.HasChildIDs);
            AssertionUtils.AssertEnumerable(
                new string[] { "orange", "grape" }
                , viewID.ChildIDs
                , "");
        }
Exemplo n.º 12
0
        public void CreateOnlyMainIdPasses()
        {
            var viewID = ViewIdentity.Create("apple");

            Assert.AreEqual("apple", viewID.MainID);
            Assert.IsFalse(viewID.HasChildIDs);
            AssertionUtils.AssertEnumerable(
                new string[] { }
                , viewID.ChildIDs
                , "");
        }
Exemplo n.º 13
0
        public void OnlyMainIDViewIdentityPasses()
        {
            Assert.IsTrue(typeof(OnlyMainIDViewIdentity).IsSubclassOf(typeof(ViewIdentity)));

            var viewID = OnlyMainIDViewIdentity.Create("apple");

            Assert.AreEqual("apple", viewID.MainID);
            Assert.IsFalse(viewID.HasChildIDs);
            AssertionUtils.AssertEnumerable(
                new string[] { }
                , viewID.ChildIDs
                , "");
        }
Exemplo n.º 14
0
        public void AsEnumerable_Pass()
        {
            int[,] list = new int[, ] {
                { 0, 1, 2, },
                { 3, 4, 5, },
            };

            AssertionUtils.AssertEnumerable(
                Enumerable.Range(0, 6)
                , list.AsEnumerable()
                , ""
                );
        }
Exemplo n.º 15
0
 public void GetClassHierarchyEnumerablePasses()
 {
     AssertionUtils.AssertEnumerable(
         new System.Type[] {
         typeof(ClassHierarchyChild2Class),
         typeof(ClassHierarchyChildClass),
         typeof(ClassHierarchyBaseClass),
         typeof(System.Object),
     }
         , typeof(ClassHierarchyChild2Class).GetClassHierarchyEnumerable()
         , ""
         );
 }
Exemplo n.º 16
0
        public void Copy_Passes()
        {
            int[,] list = new int[, ] {
                { 0, 1, 2, },
                { 3, 4, 5, },
            };

            var copy = list.Copy();

            AssertionUtils.AssertEnumerable(
                list.AsEnumerableWithIndex()
                , copy.AsEnumerableWithIndex()
                , ""
                );
        }
Exemplo n.º 17
0
        public IEnumerator CaptureScreenshotPasses()
        {
            var data = new SnapshotData
            {
                value1 = 100,
                value2 = "Test",
            };
            var stackFrame = new StackFrame();

            System.Func <SnapshotData, SnapshotData, bool> validateSnapshot = (correct, got) => correct.AreSame(got);

            //Snapshotの作成のテスト
            DoTakeSnapshot = true;
            var enumerator = TakeOrValidWithCaptureScreen(data, stackFrame, 0, validateSnapshot,
                                                          "Failed to Take snapshot...");

            while (enumerator.MoveNext())
            {
                yield return(enumerator.Current);
            }
            Assert.IsNotNull(LastSnapshot);

            var snapshotFilepath = CreateSnapshotFilepath(stackFrame);

            Assert.IsTrue(Hinode.Editors.EditorFileUtils.IsExistAsset(snapshotFilepath));
            var savedSnapshot = AssetDatabase.LoadAssetAtPath <Snapshot>(snapshotFilepath);

            Assert.AreEqual(savedSnapshot, LastSnapshot);
            AssertionUtils.AssertEnumerable(new[] { "snapshot" }, AssetDatabase.GetLabels(savedSnapshot), "想定したラベルが付けられていません。");

            //Snapshotによる検証のテスト
            DoTakeSnapshot = false;
            enumerator     = TakeOrValidWithCaptureScreen(data, stackFrame, 0, validateSnapshot, "Failed to Take snapshot...");
            while (enumerator.MoveNext())
            {
                yield return(enumerator.Current);
            }
            Assert.IsNotNull(LastSnapshot);
            var snapshotForTest = LastSnapshot;

            Assert.IsTrue(Hinode.Editors.EditorFileUtils.IsExistAsset(snapshotForTest.ScreenshotFilepath), $"検証用のスクリーンショットはAssetとして保存するようにしてください。assetPath={snapshotForTest.ScreenshotFilepath}");
            Assert.AreEqual(Path.GetDirectoryName(savedSnapshot.GetAssetPath()), Path.GetDirectoryName(snapshotForTest.ScreenshotFilepath), $"検証用のスクリーンショットはSnapshotと同じディレクトリに保存するようにしてください");

            Assert.IsFalse(Hinode.Editors.EditorFileUtils.IsExistAsset(snapshotForTest.ScreenshotFilepathAtTest), $"テスト用のスクリーンショットはAssetとしては保存しないでください. filepath={snapshotForTest.ScreenshotFilepathAtTest}");
            FileAssert.Exists(snapshotForTest.ScreenshotFilepathAtTest, $"テスト用のスクリーンショットはAssetとしては保存しないでください. filepath={snapshotForTest.ScreenshotFilepathAtTest}");
            ReserveDeleteAssets(snapshotForTest.ScreenshotFilepath, snapshotForTest.ScreenshotFilepathAtTest, Path.GetDirectoryName(snapshotFilepath));
        }
Exemplo n.º 18
0
        public IEnumerator GetChildEnumerablePass()
        {
            var corrects = new List <GameObject>();
            var root     = GameObjectExtensions.Create(
                ("root", (Transform)null, new CreateGameObjectParam[] {
                "A",
                "B",
                "C",
            }
                ),
                corrects
                ).transform;

            corrects.RemoveAt(0);
            AssertionUtils.AssertEnumerable(corrects.Select(_g => _g.transform), root.GetChildEnumerable(), "TransformExtensions#GetChildEnumerableの探索順が想定したものになっていません。");
            yield return(null);
        }
Exemplo n.º 19
0
        public void IEnumerable_GetParentEnueramble_Passes()
        {
            var node = new TreeNodeHelper <int>();

            node.Parent               = new TreeNodeHelper <int>(10);
            node.Parent.Parent        = new TreeNodeHelper <int>(100);
            node.Parent.Parent.Parent = new TreeNodeHelper <int>(1000);

            AssertionUtils.AssertEnumerable(
                new TreeNodeHelper <int>[] {
                node.Parent,
                node.Parent.Parent,
                node.Parent.Parent.Parent
            }
                , node.GetParentEnumerable()
                , ""
                );
        }
Exemplo n.º 20
0
        public void SetParamsPasses()
        {
            var data      = new HavingTextResourceData();
            var paramList = new object[]
            {
                100,
                "Apple",
                1.23f,
            };

            data.SetParams(paramList);

            Assert.AreNotSame(paramList, data.GetTextResourceParams());
            Assert.AreEqual(paramList.Length, data.ParamCount);
            AssertionUtils.AssertEnumerable(
                paramList,
                data.GetTextResourceParams(),
                "");
        }
Exemplo n.º 21
0
        public void SafeDynamicInvoke_ReturnValues_Passes()
        {
            var d = new SmartDelegate <ReturnValueDelegate>();

            d.Add(() => 10);
            d.Add(() => 20);
            d.Add(() => 30);

            var returnValues = d.SafeDynamicInvoke(() => "");
            var t            = returnValues.Select(_n => _n.ToString()).Aggregate("", (_s, _c) => _s + _c + ", ");

            Debug.Log($"test -- {t}");
            AssertionUtils.AssertEnumerable(
                new object[] {
                10, 20, 30
            }
                , returnValues
                , ""
                );
        }
Exemplo n.º 22
0
        public IEnumerator InsertPasses()
        {
            yield return(null);

            var parent = new GameObject("parent");
            var binder = new ModelViewBinder.BindInfo(typeof(MonoBehaviourViewObject));

            var child1 = MonoBehaviourViewObject.Create("child1");
            var child2 = MonoBehaviourViewObject.Create("child2");
            var child3 = MonoBehaviourViewObject.Create("child3");

            child1.transform.SetParent(parent.transform);
            child2.transform.SetParent(parent.transform);
            child3.transform.SetParent(parent.transform);

            child1.Bind(new SiblingOrderModel(100), binder, null);
            child2.Bind(new SiblingOrderModel(200), binder, null);
            child3.Bind(new SiblingOrderModel(300), binder, null);

            SiblingOrderViewLayoutAccessor.Insert(parent.transform, child1);
            SiblingOrderViewLayoutAccessor.Insert(parent.transform, child2);
            SiblingOrderViewLayoutAccessor.Insert(parent.transform, child3);

            AssertionUtils.AssertEnumerable(
                new Transform[] {
                child3.transform, child2.transform, child1.transform
            }, parent.transform.GetChildEnumerable(), "");


            var child4 = MonoBehaviourViewObject.Create("child4");

            child4.transform.SetParent(parent.transform);

            child4.Bind(new SiblingOrderModel(150), binder, null);
            SiblingOrderViewLayoutAccessor.Insert(parent.transform, child4);

            AssertionUtils.AssertEnumerable(
                new Transform[] {
                child3.transform, child2.transform, child4.transform, child1.transform
            }, parent.transform.GetChildEnumerable(), "");
        }
Exemplo n.º 23
0
        public void GetMatchEnumerable_Passes()
        {
            var text = "abc def ghi";

            var regex = new Regex(@"\w+");

            AssertionUtils.AssertEnumerable(
                new string[] {
                "abc", "def", "ghi"
            }
                , regex.GetMatchEnumerable(text).Select(_m => _m.ToString())
                , $"Fail..."
                );

            AssertionUtils.AssertEnumerable(
                new string[] {
                "ef", "ghi"
            }
                , regex.GetMatchEnumerable(text, 5).Select(_m => _m.ToString())
                , $"Fail..."
                );
        }
Exemplo n.º 24
0
        public void BasicUsageWithViewObjPasses()
        {
            var query           = ".style1";
            var viewID          = "view1";
            var viewID2         = "view2";
            var layoutValueDict = new ViewLayoutValueDictionary()
                                  .AddValue("key", 100)
                                  .AddValue("key2", 200);
            var layoutValueDict2 = new ViewLayoutValueDictionary()
                                   .AddValue("apple", -100)
                                   .AddValue("orange", -200);

            var layoutValueDict3 = new ViewLayoutValueDictionary()
                                   .AddValue("grape", -100);

            var layoutOverwriter = new ViewLayoutOverwriter();

            layoutOverwriter
            .Add(new ViewLayoutSelector(query, viewID), layoutValueDict)
            .Add(new ViewLayoutSelector($"Model {query}", viewID), layoutValueDict2)
            .Add(new ViewLayoutSelector($"Model {query}", viewID2), layoutValueDict3);

            var model = new Model()
            {
                Name = "Model"
            }
            .AddStylingID(query);
            var viewObj = new EmptyViewObject();

            viewObj.Bind(model, new ModelViewBinder.BindInfo(viewID, typeof(EmptyViewObject)), null);

            AssertionUtils.AssertEnumerable(
                new ViewLayoutValueDictionary[] {
                layoutValueDict2,
                layoutValueDict,
            }
                , layoutOverwriter.MatchLayoutValueDicts(model, viewObj)
                , "");
        }
Exemplo n.º 25
0
        public IEnumerator RemoveRecordedTouch_Passes()
        {
            yield return(null);

            var input = new ReplayableInput();

            input.IsReplaying = true;
            for (int i = 0; i < 3; ++i)
            {
                var t = new Touch()
                {
                    fingerId = i,
                };
                input.SetRecordedTouch(i, t);
            }

            input.RemoveRecordedTouch(1);

            AssertionUtils.AssertEnumerable(
                new int[] { 0, 2 }
                , input.GetTouches().Select(_t => _t.fingerId)
                , "");
        }
Exemplo n.º 26
0
        public void AutoBindOnChangedModelHierarchyPasses()
        {
            var allBinder = new ModelViewBinder("*", null, new ModelViewBinder.BindInfo(typeof(EmptyViewObjClass)));

            var viewInstanceCreator = new DefaultViewInstanceCreator(
                (typeof(EmptyViewObjClass), new EmptyViewObjClass.Binder())
                );
            var binderMap       = new ModelViewBinderMap(viewInstanceCreator, allBinder);
            var bindInstanceMap = new ModelViewBinderInstanceMap(binderMap);

            Assert.IsFalse(bindInstanceMap.EnableAutoBind);

            var root = new Model()
            {
                Name = "root"
            };
            var apple = new Model()
            {
                Name = "apple"
            };
            var orange = new Model()
            {
                Name = "orange"
            };
            var grape = new Model()
            {
                Name = "grape"
            };

            {//自動バインドのルートモデルの設定のテスト
                //RootModelの設定
                // root <- set to RootModel
                bindInstanceMap.RootModel = root;
                Assert.IsTrue(bindInstanceMap.EnableAutoBind, "ModelViewBinderInstaneMap#RootModelを設定した時はEnableAutoBindはtrueになるようにしてください。");
                var errorMessage = "ModelViewBinderInstaneMap#RootModelを設定した時はバインドも行うようにしてください。";
                Assert.AreEqual(1, bindInstanceMap.BindInstances.Count, errorMessage);
                Assert.IsTrue(bindInstanceMap.BindInstances.ContainsKey(root), errorMessage);

                //RootModelをnullにした時
                // root <- unset to RootModel
                bindInstanceMap.RootModel = null;
                Assert.IsFalse(bindInstanceMap.EnableAutoBind, "ModelViewBinderInstaneMap#RootModelをnullにした時はEnableAutoBindはfalseになるようにしてください。");
                errorMessage = "ModelViewBinderInstaneMap#RootModelをnullにした時は既存のバインドを全て削除してください。";
                Assert.AreEqual(0, bindInstanceMap.BindInstances.Count, errorMessage);

                //子を持つModelをRootModelにした時
                // root <- set to RootModel
                //   - apple <- Auto Add
                //     - orange <- Auto Add
                apple.AddChildren(orange);
                root.AddChildren(apple);
                bindInstanceMap.RootModel = root;
                Assert.IsTrue(bindInstanceMap.EnableAutoBind, "ModelViewBinderInstaneMap#RootModelを設定した時はEnableAutoBindはtrueになるようにしてください。");
                errorMessage = "子を持つModelをModelViewBinderInstaneMap#RootModelに設定した時はバインドも行うようにしてください。";
                Assert.AreEqual(3, bindInstanceMap.BindInstances.Count, errorMessage);
                Assert.IsTrue(bindInstanceMap.BindInstances.ContainsKey(root), errorMessage);
                Assert.IsTrue(bindInstanceMap.BindInstances.ContainsKey(apple), errorMessage);
                Assert.IsTrue(bindInstanceMap.BindInstances.ContainsKey(orange), errorMessage);

                bindInstanceMap.RootModel = null;
                root.Parent   = null;
                apple.Parent  = null;
                orange.Parent = null;
                grape.Parent  = null;
            }

            {//自動生成のテスト
                root.ClearChildren();
                apple.ClearChildren();
                orange.ClearChildren();
                grape.ClearChildren();

                // 子Modelの追加
                //   Appleをrootの子に追加
                // root(RootModel)
                //   - apple <- Add
                bindInstanceMap.RootModel = root;
                var count        = bindInstanceMap.BindInstances.Count;
                var errorMessage = "子を追加した時は、それに対してのバインドを自動的に追加してください";

                root.AddChildren(apple);

                Assert.AreEqual(count + 1, bindInstanceMap.BindInstances.Count, errorMessage);
                Assert.IsTrue(bindInstanceMap.BindInstances.ContainsKey(apple), errorMessage);

                // 親子構造を持つModelの追加
                //   grapeを子に持つorangeをrootの子に追加
                // root(RootModel)
                //   - apple
                //   - orange <- Add
                //     - grape <- Auto Add
                count        = bindInstanceMap.BindInstances.Count;
                errorMessage = "親子構造を持つModelを追加した時は、その全てのModelに対してバインドを行うようにしてください";

                grape.Parent  = orange;
                orange.Parent = root;

                Assert.AreEqual(count + 2, bindInstanceMap.BindInstances.Count, errorMessage);
                Assert.IsTrue(bindInstanceMap.BindInstances.ContainsKey(orange), $"Model(orange)がバインドに追加されていません。{errorMessage}");
                Assert.IsTrue(bindInstanceMap.BindInstances.ContainsKey(grape), $"Model(grape)がバインドに追加されていません。{errorMessage}");
            }

            {//自動削除のテスト
                root.ClearChildren();
                apple.ClearChildren();
                orange.ClearChildren();
                grape.ClearChildren();

                // 子Modelの削除
                // BindInstanceMapからappleを削除する
                // root(RootModel)
                //   - apple <- Remove
                //   - orange
                //     - grape
                apple.Parent              = root;
                orange.Parent             = root;
                grape.Parent              = orange;
                bindInstanceMap.RootModel = root;

                var count        = bindInstanceMap.BindInstances.Count;
                var errorMessage = "子が削除された時は、それに関連するバインドも削除してください。";

                root.RemoveChildren(apple);

                Assert.AreEqual(count - 1, bindInstanceMap.BindInstances.Count, errorMessage);
                Assert.IsFalse(bindInstanceMap.BindInstances.ContainsKey(apple), errorMessage);

                //孫を持つModelの削除
                // BindInstanceMapからorangeを削除する
                // root(RootModel)
                //   - apple
                //   - orange <- Remove
                //     - grape <- Auto Remove
                apple.Parent  = root;
                count         = bindInstanceMap.BindInstances.Count;
                errorMessage  = "孫を持つModelを削除した時はそのModel階層以下のModel全てのバインドも削除してください";
                orange.Parent = null;
                Assert.AreEqual(count - 2, bindInstanceMap.BindInstances.Count, $"想定した個数のModelが削除されていません。{errorMessage}");
                Assert.IsFalse(bindInstanceMap.BindInstances.ContainsKey(orange), $"Model(orange)のバインドが削除されていません。{errorMessage}");
                Assert.IsFalse(bindInstanceMap.BindInstances.ContainsKey(grape), $"Model(grape)のバインドが削除されていません。{errorMessage}");

                orange.Parent = root;//後のテストのために元に戻す
            }

            {//ルートModelに親を追加した時のテスト
                // ルートModelに親を追加
                // - rootParent <- Add
                //   - root(RootModel)
                //     - apple
                //     - orange
                //       - grape
                var count             = bindInstanceMap.BindInstances.Count;
                var errorMessage      = "ルートModelに親を設定した時はその親に対してはバインドを行いません。";
                var saveBindInstances = bindInstanceMap.BindInstances.ToArray();
                var rootParent        = new Model()
                {
                    Name = "rootParent"
                };
                root.Parent = rootParent;
                Assert.AreEqual(count, bindInstanceMap.BindInstances.Count, errorMessage);
                AssertionUtils.AssertEnumerable(saveBindInstances, bindInstanceMap.BindInstances, errorMessage);
            }
        }
Exemplo n.º 27
0
        public void ChildSelectorPasses()
        {
            #region Consturct Enviroment
            //Model Hierarchy
            // - root: #main type=RecieverModel
            //   - reciever: #main type=RecieverModel
            //   - noneReciever: #main type=NoneRecieverModel
            //     - reciever2: #main type=RecieverModel
            //View info
            // #main:
            //   - SenderViewObj: ID=SenderViewObj, InstanceID=SenderViewObj, BinderID=SenderViewObj
            //   - RecieverViewObj: ID=reciever, InstanceID=SenderViewObj, BinderID=SenderViewObj
            var root = new RecieverModel()
            {
                Name = "root", LogicalID = new ModelIDList("main")
            };
            var recieverModel = new RecieverModel()
            {
                Name = "reciever", Parent = root, LogicalID = new ModelIDList("main")
            };
            var noneRecieverModel = new NoneRecieverModel()
            {
                Name = "noneReciever", Parent = root, LogicalID = new ModelIDList("main")
            };
            var recieverModel2 = new RecieverModel()
            {
                Name = "reciever2", Parent = noneRecieverModel, LogicalID = new ModelIDList("main")
            };

            string viewReciever = "reciever";
            var    viewCreator  = new DefaultViewInstanceCreator(
                (typeof(SenderViewObj), new SenderViewObj.ParamBinder()),
                (typeof(EventHandlerViewObj), new EventHandlerViewObj.ParamBinder())
                );
            var binderMap = new ModelViewBinderMap(viewCreator,
                                                   new ModelViewBinder("#main", null,
                                                                       new ModelViewBinder.BindInfo(typeof(SenderViewObj)),
                                                                       new ModelViewBinder.BindInfo(viewReciever, typeof(EventHandlerViewObj))
                                                                       ));
            var binderMapInstance = binderMap.CreateBinderInstaceMap();
            binderMapInstance.RootModel = root;
            #endregion

            {//Modelを取得しようとした時のテスト
                //search root model => root
                //selector: Child, "", ""
                //result => reciever, noneReciever
                var selector   = new ModelViewSelector(ModelRelationShip.Child, "", "");
                var enumerable = selector.GetEnumerable(root, binderMapInstance);

                var errorMessage = "IEventHandlerを継承している時は取得できるようにしてください。";
                AssertionUtils.AssertEnumerableByUnordered(new object[] {
                    recieverModel,
                    noneRecieverModel,
                }, enumerable, errorMessage);
            }

            {//Childがない時のModelのChildを指定した時のテスト
                //search root model => reciever
                //selector: Child, "", ""
                //result => (empty)
                var selector   = new ModelViewSelector(ModelRelationShip.Child, "", "");
                var enumerable = selector.GetEnumerable(recieverModel, binderMapInstance);

                var errorMessage = "ChildがないmodelのChildを指定した時は何も取得できないようにしてください。";
                Assert.IsFalse(enumerable.Any(), errorMessage);
            }

            {//QueryPathを指定した時のテスト
                //search root model => root
                //selector: Child, "*", ""
                //result => reciever, reciever2
                var selector     = new ModelViewSelector(ModelRelationShip.Child, "*", "");
                var enumerable   = selector.GetEnumerable(root, binderMapInstance);
                var errorMessage = "QueryPathを指定した時はそれに一致するModel全て取得できるようにしてください";
                AssertionUtils.AssertEnumerableByUnordered(new object[] {
                    recieverModel,
                    noneRecieverModel,
                    recieverModel2,
                }, enumerable, errorMessage);
            }

            {//一致しないQueryPathを指定した時のテスト
                //search root model => root
                //selector: Child, "__invalid", ""
                //result => (empty)
                var selector     = new ModelViewSelector(ModelRelationShip.Child, "__invalid", "");
                var enumerable   = selector.GetEnumerable(root, binderMapInstance);
                var errorMessage = "QueryPathが一致しない時は何も取得できないようにしてください。";
                Assert.IsFalse(enumerable.Any(), errorMessage);
            }

            {//Viewを取得しようとした時のテスト
                //search root model => root
                //selector: Child, "", "reciever"
                //result => RecieverViewObj in reciever, RecieverViewObj in noneReciever
                var selector   = new ModelViewSelector(ModelRelationShip.Child, "", viewReciever);
                var enumerable = selector.GetEnumerable(root, binderMapInstance);

                var errorMessage = "子モデルのViewを指定した時はModelにバインドされていて、かつIEventHandlerを継承しているViewを全て取得できるようにしてください。";
                var viewObj1     = binderMapInstance[recieverModel].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever).First();
                var viewObj2     = binderMapInstance[noneRecieverModel].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever).First();
                AssertionUtils.AssertEnumerableByUnordered(new object[] {
                    viewObj1,
                    viewObj2
                }, enumerable, errorMessage);
            }

            {//Viewを取得しようとした時のテスト(一致しないViewID)
                //search root model => root
                //selector: Child, "", "__invalid"
                //result => (empty)
                var selector   = new ModelViewSelector(ModelRelationShip.Child, "", "__invalid");
                var enumerable = selector.GetEnumerable(root, binderMapInstance);

                var errorMessage = "指定したViewIdentityと一致ない時は何も取得できないようにしてください。";
                Assert.IsFalse(enumerable.Any(), errorMessage);
            }

            {//Viewを取得しようとした時のテスト(クエリパスを指定した時)
                //search root model => root
                //selector: Child, "reciever", "reciever"
                //result => RecieverViewObj in reciever,
                var selector   = new ModelViewSelector(ModelRelationShip.Child, recieverModel.Name, viewReciever);
                var enumerable = selector.GetEnumerable(root, binderMapInstance);

                var errorMessage = "クエリパスを伴う子モデルのViewを指定した時はクエリパスに一致しModelにバインドされていて、かつIEventHandlerを継承しているViewを全て取得できるようにしてください。";
                var viewObj1     = binderMapInstance[recieverModel].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever).First();
                AssertionUtils.AssertEnumerable((new IViewObject[] { viewObj1 }).OfType <IEventHandler>(), enumerable, errorMessage);
            }

            {//Viewを取得しようとした時のテスト(クエリパスを指定し、ViewIDが一致しない時)
                //search root model => root
                //selector: Child, "reciever", "__invalid"
                //result => (empty)
                var selector   = new ModelViewSelector(ModelRelationShip.Child, recieverModel.Name, "__invalid");
                var enumerable = selector.GetEnumerable(root, binderMapInstance);

                var errorMessage = "指定したViewIdentityと一致ない時は何も取得できないようにしてください。";
                Assert.IsFalse(enumerable.Any(), errorMessage);
            }
        }
Exemplo n.º 28
0
        public void GetEnumerableWithTypePasses()
        {
            System.Array arr = Enumerable.Range(0, 5).ToArray();

            AssertionUtils.AssertEnumerable(Enumerable.Range(0, 5), arr.GetEnumerable <int>().Select(_o => (int)_o), "");
        }
Exemplo n.º 29
0
        public void BinderInstanceMapBasicUsagePasses()
        {
            var root = new ModelClass()
            {
                Name = "root"
            };
            var apple = new ModelClass()
            {
                Name = "apple"
            };
            var noneBinderModel = new ModelClass()
            {
                Name = "grape"
            };

            root.AddChildren(apple, noneBinderModel);
            var orange = new ModelClass()
            {
                Name = "orange"
            };

            noneBinderModel.AddChildren(orange);

            var appleBinder = new ModelViewBinder("apple", null,
                                                  new ModelViewBinder.BindInfo(typeof(IntViewObjClass)));
            var orangeBinder = new ModelViewBinder("orange", null,
                                                   new ModelViewBinder.BindInfo(typeof(FloatViewObjClass)));
            var rebindBinder = new ModelViewBinder("Rebind", null,
                                                   new ModelViewBinder.BindInfo(typeof(FloatViewObjClass)));

            Assert.IsFalse(root.DoMatchQueryPath(appleBinder.Query));
            var viewInstanceCreator = new DefaultViewInstanceCreator(
                (typeof(IntViewObjClass), new IntViewObjClass.Binder()),
                (typeof(FloatViewObjClass), new FloatViewObjClass.Binder())
                );
            var binderMap = new ModelViewBinderMap(viewInstanceCreator, appleBinder, orangeBinder, rebindBinder);

            {//BinderInstanceMapのテスト
                var bindInstanceMap = new ModelViewBinderInstanceMap(binderMap);
                Assert.AreSame(binderMap, bindInstanceMap.BinderMap);

                {//BindInstanceMap#Addのテスト
                    Assert.AreEqual(0, bindInstanceMap.BindInstances.Count());
                    bindInstanceMap.Add(false, null, apple, noneBinderModel);
                    //grapeはQueryPathと一致しないので追加されない
                    AssertionUtils.AssertEnumerableByUnordered(new Model[] {
                        apple, orange
                    }, bindInstanceMap.BindInstances.Select(_b => _b.Key), "");

                    //追加された時は合わせてViewのパラメータもModelのものに更新する
                    var appleViewObj = bindInstanceMap[apple].ViewObjects.First(_v => _v is IntViewObjClass) as IntViewObjClass;
                    Assert.AreEqual(apple.IntValue, appleViewObj.IntValue);
                    foreach (var viewObj in bindInstanceMap[apple].ViewObjects)
                    {
                        Assert.AreEqual(bindInstanceMap[apple], viewObj.UseBinderInstance);
                    }
                    Assert.AreSame(bindInstanceMap, bindInstanceMap[apple].UseInstanceMap);

                    var orangeViewObj = bindInstanceMap[orange].ViewObjects.First(_v => _v is FloatViewObjClass) as FloatViewObjClass;
                    Assert.AreEqual(orange.FloatValue, orangeViewObj.FloatValue);
                    foreach (var viewObj in bindInstanceMap[orange].ViewObjects)
                    {
                        Assert.AreEqual(bindInstanceMap[orange], viewObj.UseBinderInstance);
                    }

                    //既に追加されていたら追加しない
                    bindInstanceMap.Add(false, null, apple, orange);
                    AssertionUtils.AssertEnumerableByUnordered(new Model[] {
                        apple, orange
                    }, bindInstanceMap.BindInstances.Select(_b => _b.Key), "同じModelが追加できないようにしてください");
                }

                {//マッチしないModelを追加した時のテスト
                    var empty = new Model()
                    {
                        Name = "__empty"
                    };
                    Assert.DoesNotThrow(() =>
                    {
                        bindInstanceMap.Add(empty);
                        Assert.IsFalse(bindInstanceMap.BindInstances.ContainsKey(empty), "マッチしないModelを追加した時はModelViewBinderInstanceを生成しないようにしてください");
                    }, "マッチしないModelを追加した時でもModelViewBinderInstanceMapから例外を発生させないようにしてください。");
                }

                var appleBindInstance  = bindInstanceMap[apple];
                var orangeBindInstance = bindInstanceMap[orange];
                {//BindInstanceMap#[]のテスト
                    Assert.IsNotNull(appleBindInstance);
                    Assert.AreEqual(apple, appleBindInstance.Model);

                    Assert.IsNotNull(orangeBindInstance);
                    Assert.AreEqual(orange, orangeBindInstance.Model);
                }

                {//BindInstanceMap#UpdateViewObjectsのテスト
                    apple.IntValue    = 234;
                    orange.FloatValue = 2.5432f;
                    bindInstanceMap.UpdateViewObjects();
                    var appleViewObj = appleBindInstance.ViewObjects.First(_v => _v is IntViewObjClass) as IntViewObjClass;
                    Assert.AreEqual(apple.IntValue, appleViewObj.IntValue);
                    var orangeViewObj = orangeBindInstance.ViewObjects.First(_v => _v is FloatViewObjClass) as FloatViewObjClass;
                    Assert.AreEqual(orange.FloatValue, orangeViewObj.FloatValue);
                }

                {//BindInstanceMap#Rebindのテスト
                    apple.Name = "Rebind";
                    var isSuccess = bindInstanceMap.Rebind(apple);
                    Assert.IsTrue(isSuccess, "Rebindに失敗しています");
                    Assert.AreSame(rebindBinder, bindInstanceMap.BindInstances[apple].Binder);
                    Assert.AreSame(bindInstanceMap, bindInstanceMap.BindInstances[apple].UseInstanceMap);
                }
                {
                    // 追加されていないものをRebindした時は何もしない
                    var recordedBindInstances = bindInstanceMap.BindInstances.ToArray();
                    var model = new ModelClass()
                    {
                        Name = "Tmp"
                    };
                    var isSuccess = bindInstanceMap.Rebind(model);
                    Assert.IsFalse(isSuccess, "登録されていないModelの場合はRebindしないようにしてください");
                    AssertionUtils.AssertEnumerable(recordedBindInstances, bindInstanceMap.BindInstances, "ModelViewBinderInstanceMapに追加されていないModelをRebindした時は何もしないようにしてください。");
                }

                {//BindInstanceMap#Removeのテスト
                    bindInstanceMap.Remove(apple, noneBinderModel);
                    Assert.AreEqual(0, bindInstanceMap.BindInstances.Count());
                }

                {//BindInstanceMap#ClearBindInstancesのテスト
                    bindInstanceMap.Add(false, null, apple, orange);
                    bindInstanceMap.ClearBindInstances();
                    Assert.AreEqual(0, bindInstanceMap.BindInstances.Count());
                }
            }
        }
        public IEnumerator ComparerPasses()
        {
            var mainCamera = new GameObject("MainCamera", typeof(Camera)).GetComponent <Camera>();

            mainCamera.tag = "MainCamera";
            mainCamera.transform.position = Vector3.zero;
            var nearestCameraDistance = 10f;
            var middleCameraDistance  = 20f;
            var farestCameraDistance  = 100f;

            var nearestOverlayCanvas = CanvasViewObject.Create("nearestScreenOverlayCanvas")
                                       .gameObject.AddComponent <OnPointerEventControllerMonoBehaivour>();

            nearestOverlayCanvas.RootCanvas.renderMode   = RenderMode.ScreenSpaceOverlay;
            nearestOverlayCanvas.RootCanvas.sortingOrder = 100;

            var overlayCanvas = CanvasViewObject.Create("screenOverlayCanvas")
                                .gameObject.AddComponent <OnPointerEventControllerMonoBehaivour>();

            overlayCanvas.RootCanvas.renderMode = RenderMode.ScreenSpaceOverlay;

            var childInOverlayCanvas = CanvasViewObject.Create("childInScreenOverlayCanvas")
                                       .gameObject.AddComponent <OnPointerEventControllerMonoBehaivour>();

            childInOverlayCanvas.transform.SetParent(overlayCanvas.transform);

            var child2InOverlayCanvas = CanvasViewObject.Create("child2InScreenOverlayCanvas")
                                        .gameObject.AddComponent <OnPointerEventControllerMonoBehaivour>();

            child2InOverlayCanvas.transform.SetParent(overlayCanvas.transform);

            var cameraOverlayCanvas = CanvasViewObject.Create("cameraOverlayCanvas")
                                      .gameObject.AddComponent <OnPointerEventControllerMonoBehaivour>();

            cameraOverlayCanvas.RootCanvas.renderMode    = RenderMode.ScreenSpaceCamera;
            cameraOverlayCanvas.RootCanvas.worldCamera   = mainCamera;
            cameraOverlayCanvas.RootCanvas.planeDistance = nearestCameraDistance;

            var childInCameraOverlayCanvas = CanvasViewObject.Create("childInCameraOverlayCanvas")
                                             .gameObject.AddComponent <OnPointerEventControllerMonoBehaivour>();

            childInCameraOverlayCanvas.transform.SetParent(cameraOverlayCanvas.Transform);

            var worldCanvas = CanvasViewObject.Create("worldCanvas")
                              .gameObject.AddComponent <OnPointerEventControllerMonoBehaivour>();

            worldCanvas.RootCanvas.renderMode  = RenderMode.WorldSpace;
            worldCanvas.RootCanvas.worldCamera = mainCamera;
            worldCanvas.Transform.position     = mainCamera.transform.position
                                                 + mainCamera.transform.forward * middleCameraDistance;

            var childInWorldCanvas = CanvasViewObject.Create("childInWorldCanvas")
                                     .gameObject.AddComponent <OnPointerEventControllerMonoBehaivour>();

            childInWorldCanvas.Transform.SetParent(worldCanvas.Transform);

            var cubeObj3D = GameObject.CreatePrimitive(PrimitiveType.Cube)
                            .AddComponent <OnPointerEventControllerMonoBehaivour>();

            cubeObj3D.Transform.position = mainCamera.transform.position
                                           + mainCamera.transform.forward * farestCameraDistance;
            yield return(null);

            var list = new OnPointerEventControllerMonoBehaivour[]
            {
                childInWorldCanvas,
                cameraOverlayCanvas,
                overlayCanvas,
                worldCanvas,
                childInOverlayCanvas,
                childInCameraOverlayCanvas,
                child2InOverlayCanvas,
                cubeObj3D,
                nearestOverlayCanvas,
            };

            var comparer   = new IOnPointerEventControllerObjectComparer(mainCamera);
            var sortedList = list.OrderBy(_c => _c, comparer);

            Debug.Log($"sorted result -> {sortedList.Select(_o => _o.name).Aggregate("", (_s, _c) => _s + _c + " : ")}");
            AssertionUtils.AssertEnumerable(
                new OnPointerEventControllerMonoBehaivour[] {
                nearestOverlayCanvas,
                child2InOverlayCanvas,
                childInOverlayCanvas,
                overlayCanvas,
                childInCameraOverlayCanvas,
                cameraOverlayCanvas,
                childInWorldCanvas,
                worldCanvas,
                cubeObj3D,
            }, sortedList, "");
        }