Exemplo n.º 1
0
        public void ChildViewIDPasses()
        {
            #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 Model()
            {
                Name = "root", LogicalID = new ModelIDList("main")
            };
            var recieverModel = new Model()
            {
                Name = "reciever", Parent = root, LogicalID = new ModelIDList("main")
            };
            var noneRecieverModel = new Model()
            {
                Name = "noneReciever", Parent = root, LogicalID = new ModelIDList("main")
            };
            var model1 = new Model()
            {
                Name = "model", Parent = noneRecieverModel, LogicalID = new ModelIDList("main")
            };

            string viewID      = "viewObj";
            var    viewCreator = new DefaultViewInstanceCreator(
                (typeof(ChildViewIDPassesViewObject), new EmptyModelViewParamBinder())
                );
            var binderMap = new ModelViewBinderMap(viewCreator,
                                                   new ModelViewBinder("#main", null,
                                                                       new ModelViewBinder.BindInfo(viewID, typeof(ChildViewIDPassesViewObject))
                                                                       ));
            var binderMapInstance = binderMap.CreateBinderInstaceMap();
            binderMapInstance.RootModel = root;
            #endregion


            {//Case Success childViewID
                var selector = new ModelViewSelector(
                    ModelRelationShip.Self
                    , ""
                    , ViewIdentity.Create(viewID, ChildViewIDPassesViewObject.CHILD_ID));
                var enumerable = selector.Query <EmptyViewObject>(root, binderMapInstance);

                var rootViewObjs = binderMapInstance[root].QueryViews(viewID);
                AssertionUtils.AssertEnumerableByUnordered(
                    rootViewObjs
                    .Select(_v => _v.QueryChild <EmptyViewObject>(ChildViewIDPassesViewObject.CHILD_ID))
                    .Where(_v => _v != null)
                    , enumerable
                    , $"");
            }

            {//Case Success nested childViewID
                var queryViewID = ViewIdentity.Create(
                    viewID
                    , ChildViewIDPassesViewObject.NEST_CHILD_ID
                    , ChildViewIDPassesViewObject.NestChildView.CHILD_APPLE_ID);
                var selector   = new ModelViewSelector(ModelRelationShip.Self, "", queryViewID);
                var enumerable = selector.Query <ChildViewIDPassesViewObject.NestChildView.Apple>(root, binderMapInstance);

                var rootViewObjs = binderMapInstance[root].QueryViews(queryViewID)
                                   .OfType <ChildViewIDPassesViewObject.NestChildView.Apple>();
                AssertionUtils.AssertEnumerableByUnordered(
                    rootViewObjs
                    //.Select(_v => _v.QueryChild<ChildViewIDPassesViewObject.NestChildView.Apple>(childViewID.Split('.')))
                    , enumerable
                    , $"Failed to query '{queryViewID}'...");
            }

            {//Case Invalid childViewID
                var selector   = new ModelViewSelector(ModelRelationShip.Self, "", $"{viewID}.invalidID");
                var enumerable = selector.Query <EmptyViewObject>(root, binderMapInstance);

                Assert.IsFalse(enumerable.Any());
            }
        }
Exemplo n.º 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);
            }
        }