コード例 #1
0
        public void ParentSelectorPasses()
        {
            #region Consturct Enviroment
            //Model Hierarchy
            // - root: #main type=RecieverModel
            //   - reciever: #main type=RecieverModel
            //   - noneReciever: #main type=NoneRecieverModel
            //     - model: #main type=Model
            //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 model1 = new Model()
            {
                Name = "model", 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 => reciever
                //selector: Parent, "", ""
                //result => root
                var selector   = new ModelViewSelector(ModelRelationShip.Parent, "", "");
                var enumerable = selector.GetEnumerable(recieverModel, binderMapInstance);

                var errorMessage = "Parentを取得できるようにしてください。";
                Assert.AreEqual(1, enumerable.Count(), errorMessage);
                Assert.AreSame(root, enumerable.First(), errorMessage);
            }

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

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

            {//ParentがnullなModelのParentを指定した時のテスト2
                //search root model => model
                //selector: Parent, "root", ""
                //result => root, noneReciever
                var selector   = new ModelViewSelector(ModelRelationShip.Parent, "#main", "");
                var enumerable = selector.GetEnumerable(model1, binderMapInstance);

                var errorMessage = "親指定のSelectorの時、クエリパスを指定した時はBinderInstanceMapのRootModelをクエリルートにし、検索対象のModelの親Modelのみを検索してください。";
                AssertionUtils.AssertEnumerableByUnordered(new object[] {
                    root, noneRecieverModel
                }, enumerable, errorMessage);
            }

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

                var errorMessage = "Viewを指定した時はModelにバインドされているViewを取得できるようにしてください。";
                AssertionUtils.AssertEnumerableByUnordered(
                    binderMapInstance[root].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever)
                    , enumerable
                    , errorMessage);
            }

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

                var errorMessage = "バインドされているModelがIEventHandlerを継承していない場合でも取得できるようにしてください";
                AssertionUtils.AssertEnumerableByUnordered(
                    binderMapInstance[noneRecieverModel].ViewObjects
                    .Where(_v => _v.UseBindInfo.ID.MainID == viewReciever)
                    , enumerable
                    , errorMessage);
            }

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

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

            {//QueryPathとViewIdentityを指定した時のテスト
                //search root model => model
                //selector: Parent, "root", "reciever"
                //result => root
                var selector   = new ModelViewSelector(ModelRelationShip.Parent, "#main", viewReciever);
                var enumerable = selector.GetEnumerable(model1, binderMapInstance);

                var errorMessage  = "親指定のrecieverSelectorの時、クエリパスを指定した時はBinderInstanceMapのRootModelをクエリルートにしてください。";
                var rootViewObj   = binderMapInstance[root].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever).First();
                var parentViewObj = binderMapInstance[noneRecieverModel].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever).First();
                AssertionUtils.AssertEnumerableByUnordered(
                    binderMapInstance[noneRecieverModel].ViewObjects
                    .Concat(binderMapInstance[root].ViewObjects)
                    .Where(_v => _v.UseBindInfo.ID.MainID == viewReciever)
                    , enumerable
                    , errorMessage);
            }
        }
コード例 #2
0
        public void QueryPasses()
        {
            #region Construct Enviroment
            //Model Hierarchy
            // - root: #main type=FookableModel
            //   - reciever: #main type=RecieverModel
            //   - noneReciever: #main type=NoneRecieverModel
            //     - model: #main type=Model
            //
            //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 model1 = new Model()
            {
                Name = "model", 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)
                var selector = new ModelViewSelector(ModelRelationShip.Parent, "", "");

                var enumerable = selector.Query(typeof(RecieverModel), recieverModel, binderMapInstance);

                var errorMessage = "ModelViewSelector#Queryはクエリと一致したModelの中から指定したTypeのものを返すようにしてください。";
                AssertionUtils.AssertEnumerableByUnordered(
                    new object[] { root }
                    , enumerable, errorMessage);
            }
            {//指定した型を持つ時(View)
                var selector = new ModelViewSelector(ModelRelationShip.Parent, "", viewReciever);

                var enumerable = selector.Query(typeof(EventHandlerViewObj), recieverModel, binderMapInstance);

                var errorMessage = "ModelViewSelector#Queryはクエリと一致したModelの中から指定したTypeのものを返すようにしてください。";
                AssertionUtils.AssertEnumerableByUnordered(
                    binderMapInstance.BindInstances[root].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever)
                    , enumerable, errorMessage);
            }
            {//指定したTypeではない時
                var selector = new ModelViewSelector(ModelRelationShip.Parent, "", "");

                var enumerable = selector.Query(typeof(RecieverModel), model1, binderMapInstance);

                var errorMessage = "ModelViewSelector#Queryは指定したTypeではないものは返さないようにしてください。";
                Assert.IsFalse(enumerable.Any(), errorMessage);
            }
            {//指定したTypeではない時(View)
                var selector = new ModelViewSelector(ModelRelationShip.Parent, "", viewReciever);

                var enumerable = selector.Query(typeof(SenderViewObj), model1, binderMapInstance);

                var errorMessage = "ModelViewSelector#Queryはクエリと一致したModelの中から指定したTypeのものを返すようにしてください。";
                Assert.IsFalse(enumerable.Any(), errorMessage);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        public void SelfSelectorPasses()
        {
            #region Construct Enviroment
            //Model Hierarchy
            // - root: #main type=Model
            //   - reciever: #main type=RecieverModel
            //   - noneReciever: #main type=NoneRecieverModel
            //
            //View info
            // #main:
            //   - SenderViewObj: ID=SenderViewObj, InstanceID=SenderViewObj, BinderID=SenderViewObj
            //   - RecieverViewObj: ID=reciever, InstanceID=SenderViewObj, BinderID=SenderViewObj
            var root = new Model()
            {
                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")
            };

            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 => reciever
                //selector: Self, "", ""
                //result => reciever
                var selector   = new ModelViewSelector(ModelRelationShip.Self, "", "");
                var enumerable = selector.GetEnumerable(recieverModel, binderMapInstance);

                var errorMessage = "自身を取得できるようにしてください。";
                Assert.AreEqual(1, enumerable.Count(), errorMessage);
                Assert.AreSame(recieverModel, enumerable.First(), errorMessage);
            }

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

                var errorMessage = "Viewを指定した時はModelにバインドされているViewを取得できるようにしてください。";
                AssertionUtils.AssertEnumerableByUnordered(
                    binderMapInstance[recieverModel].ViewObjects.Where(_v => _v.UseBindInfo.ID.MainID == viewReciever)
                    , enumerable, errorMessage);
            }

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

                var errorMessage = "ViewIdentityが一致していない時は取得できないようにしてください。";
                Assert.IsFalse(enumerable.Any(), errorMessage);
            }
        }
コード例 #5
0
        public void QueryPasses()
        {
            #region Construct Enviroment
            //Model Hierarchy
            // - root: #main type=FookableModel
            //   - reciever: #main type=RecieverModel
            //   - noneReciever: #main type=NoneRecieverModel
            //     - model: #main type=Model
            //
            //View info
            // #main:
            //   - SenderViewObj: ID=SenderViewObj, InstanceID=SenderViewObj, BinderID=SenderViewObj
            //   - EventHandlerViewObj: ID=reciever, InstanceID=SenderViewObj, BinderID=SenderViewObj

            var root = new FookableModel()
            {
                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 model1 = new Model()
            {
                Name = "model", Parent = noneRecieverModel, LogicalID = new ModelIDList("main")
            };

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

            {//None F**k Selector
                var selector = new EventHandlerSelector(ModelRelationShip.Parent, "", "");
                Assert.IsFalse(selector.IsFooking);

                float eventData  = 1.234f;
                var   enumerable = selector.Query(typeof(ITestReciever), recieverModel, binderMapInstance, eventData);

                var errorMessage = "RecieverSelector#Queryは指定したRecieverTypeとEventData、クエリと一致したModelを返すようにしてください。";
                Assert.AreEqual(1, enumerable.Count(), errorMessage);
                var first = enumerable.First();
                Assert.AreEqual(typeof(ITestReciever), first.eventHandlerType, errorMessage);
                Assert.AreSame(root, first.eventHandler, errorMessage);
                Assert.AreEqual(eventData, first.eventData, errorMessage);
            }

            {//F**k Selector!!
                var selector = new EventHandlerSelector(ModelRelationShip.Parent, "", "");
                Assert.IsFalse(selector.IsFooking);

                // set F**k info!!
                selector.FookingRecieverType = typeof(IFookingReciever);
                selector.FookEventData       = 432;
                Assert.IsTrue(selector.IsFooking);

                int eventData  = 123;
                var enumerable = selector.Query(typeof(ITestReciever), recieverModel, binderMapInstance, eventData);

                var errorMessage = "F**k情報が設定されたRecieverSelectorの場合はRecieverSelector#QueryはrecieverTypeを(RecieverSelector#FookingRecieverType)、eventDataを(RecieverSelector#FookEventData)に変換したものを返すようにしてください。";
                Assert.AreEqual(1, enumerable.Count(), errorMessage);
                var first = enumerable.First();
                Assert.AreEqual(typeof(IFookingReciever), first.eventHandlerType, errorMessage);
                Assert.AreSame(root, first.eventHandler, errorMessage);
                Assert.AreEqual(selector.FookEventData, first.eventData, errorMessage);
            }
        }