示例#1
0
        public void SendPasses()
        {
            #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 TestSendPassRecieverModel()
            {
                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

            var i = EventHandlerTypeManager.Instance;
            return;

            i.EntryEventHandlerExecuter <ITestSendPassReciever, int>(
                (reciever, sender, eventData) => {
                (reciever as ITestSendPassReciever).Recieve(sender, (int)eventData);
            }
                );
            var selector = new EventHandlerSelector(ModelRelationShip.Child, "", "");

            selector.Send <ITestSendPassReciever>(root, 100, binderMapInstance);

            Assert.AreSame(root, recieverModel.SenderModel);
            Assert.AreEqual(100, recieverModel.RecievedValue);
        }
示例#2
0
        public void DontMatchBinderFailed()
        {
            var         modelID            = "modelID";
            var         interruptModelName = "Interrupt";
            Model       senderModel        = null;
            IViewObject senderViewObject   = null;
            int         senderEventData    = 0;

            System.Type    recieverEventType    = null;
            ControllerInfo senderControllerInfo = null;
            var            eventInterrupter     = new EventInterrupter();

            var binderMap = new ModelViewBinderMap()
            {
                UseEventInterrupter = eventInterrupter
            };
            var binderInstanceMap = binderMap.CreateBinderInstaceMap();

            eventInterrupter.Add(new EventDispatchQuery(modelID, ""),
                                 (_binderInstanceMap, _interruptedData) =>
            {
                senderModel          = _interruptedData.SenderModel;
                senderViewObject     = _interruptedData.SenderViewObj;
                recieverEventType    = _interruptedData.EventType;
                senderEventData      = (int)_interruptedData.SendEventData;
                senderControllerInfo = _interruptedData.SenderControllerInfo;
                var interruptModel   = new Model()
                {
                    Name = interruptModelName
                };
                return(interruptModel, true);
            }
                                 );

            //run Test
            var interruptedData = EventInterruptedData.Create <ITestEventHandler>(
                new Model()
            {
                Name = modelID
            }
                , new EmptyViewObject()
            {
                UseBindInfo = new ModelViewBinder.BindInfo(typeof(EmptyViewObject))
            }
                , 100
                , new ControllerInfo(TestEventName.Test));

            Assert.Throws <UnityEngine.Assertions.AssertionException>(() =>
            {
                eventInterrupter.Interrupt(binderInstanceMap, interruptedData);
            }, "OnEventInterruptCallbackでModelを返した時、ModelViewBinderInstanceMapへ登録が失敗した時は例外を投げるようにしてください");
        }
示例#3
0
        public void ContainsPasses()
        {
            var binderMap = new ModelViewBinderMap(new DefaultViewInstanceCreator(),
                                                   new ModelViewBinder("*", null)
                                                   );

            var binderInstanceMap = binderMap.CreateBinderInstaceMap();

            var model = new Model();

            Assert.IsFalse(binderInstanceMap.Contains(model));
            binderInstanceMap.Add(model);
            Assert.IsTrue(binderInstanceMap.Contains(model));
        }
示例#4
0
        public void ContainsAtDelayPasses()
        {
            var binderMap = new ModelViewBinderMap(new DefaultViewInstanceCreator(),
                                                   new ModelViewBinder("*", null)
                                                   );

            var binderInstanceMap = binderMap.CreateBinderInstaceMap();

            binderInstanceMap.EnabledDelayOperation = true;

            var model = new Model();

            Assert.IsFalse(binderInstanceMap.Contains(model));
            binderInstanceMap.Add(model);
            Assert.IsFalse(binderInstanceMap.Contains(model));

            binderInstanceMap.DoDelayOperations();
            Assert.IsTrue(binderInstanceMap.Contains(model));
        }
示例#5
0
        public void BasicPasses()
        {
            var         modelID            = "modelID";
            var         interruptModelName = "Interrupt";
            Model       senderModel        = null;
            IViewObject senderViewObject   = null;
            int         senderEventData    = 0;

            System.Type    recieverEventType    = null;
            ControllerInfo senderControllerInfo = null;
            var            eventInterrupter     = new EventInterrupter();

            var binderMap = new ModelViewBinderMap(null,
                                                   new ModelViewBinder("*", null))
            {
                UseEventInterrupter = eventInterrupter
            };
            var binderInstanceMap = binderMap.CreateBinderInstaceMap();

            eventInterrupter.Add(new EventDispatchQuery(modelID, ""),
                                 (_binderInstanceMap, _interruptedData) =>
            {
                senderModel          = _interruptedData.SenderModel;
                senderViewObject     = _interruptedData.SenderViewObj;
                recieverEventType    = _interruptedData.EventType;
                senderEventData      = (int)_interruptedData.SendEventData;
                senderControllerInfo = _interruptedData.SenderControllerInfo;
                var interruptModel   = new Model()
                {
                    Name = interruptModelName
                };
                return(interruptModel, false);
            }
                                 );

            //run Test
            var interruptedData = EventInterruptedData.Create <ITestEventHandler>(
                new Model()
            {
                Name = modelID
            }
                , new EmptyViewObject()
                , 100
                , new ControllerInfo(TestEventName.Test));

            interruptedData.SenderViewObj.Bind(interruptedData.SenderModel, new ModelViewBinder.BindInfo(typeof(EmptyViewObject)), null);

            Assert.IsTrue(eventInterrupter.DoMatch(interruptedData));
            var doSendImmediate = eventInterrupter.Interrupt(binderInstanceMap, interruptedData);

            Assert.IsFalse(doSendImmediate, $"設定したコールバックが返すdoSendImmediateと異なります");

            Debug.Log($"Success to EventInterrupter#Interrupt!!");

            {//設定したPredicateが実行されているか確認
                Assert.AreSame(interruptedData.SenderModel, senderModel);
                Assert.AreSame(interruptedData.SenderViewObj, senderViewObject);
                Assert.AreEqual(interruptedData.EventType, recieverEventType);
                Assert.AreEqual(interruptedData.SendEventData, senderEventData);
                Assert.AreSame(interruptedData.SenderControllerInfo, senderControllerInfo);
            }
            Debug.Log($"Success to Check EventInterrupter#Interrupt Callback!!");

            {//自動的にModelをModelViewBinderInstanceMapに登録しているか確認
                Assert.IsTrue(binderInstanceMap.BindInstances.Any(_b => _b.Value.Model.Name == interruptModelName));
                var interruptBinderInstace = binderInstanceMap.BindInstances.Values.First(_b => _b.Model.Name == interruptModelName);

                Assert.IsTrue(interruptBinderInstace.HasEventInterruptedData);
                var holdInterruptedData = interruptBinderInstace.HoldedEventInterruptedData;
                Assert.AreSame(interruptedData.SenderModel, holdInterruptedData.SenderModel);
                Assert.AreSame(interruptedData.SenderViewObj, holdInterruptedData.SenderViewObj);
                Assert.AreEqual(interruptedData.EventType, holdInterruptedData.EventType);
                Assert.AreEqual(interruptedData.SendEventData, holdInterruptedData.SendEventData);
                Assert.AreSame(interruptedData.SenderControllerInfo, holdInterruptedData.SenderControllerInfo);
            }

            Debug.Log($"Success to Add Created Model in Interrupt Callback to BinderInstanceMap!!");
        }
示例#6
0
        public void UsageModelViewBinderMapPasses()
        {
            #region Construct Enviroment
            EventHandlerTypeManager.Instance.EntryEventHandlerExecuter <ITestEventHandler, int>((reciever, sender, eventData) =>
            {
                reciever.Test(sender, eventData);
            });
            var eventDispatcher = new TestEventDispatcher()
            {
                SendData = 111,
            };

            var modelID            = "Model";
            var interruptTargetID  = "Target";
            var interruptModelName = "Interrupt";

            var interruptedTargetQuery = new EventDispatchQuery(modelID, "");
            var viewBinder             = new ModelViewBinder(modelID, null
                                                             , new ModelViewBinder.BindInfo(typeof(EmptyViewObject))
                                                             .AddControllerInfo(new ControllerInfo(TestEventName.Test, new EventHandlerSelector(ModelRelationShip.Self, "", ""))));
            var interruptBinder = new ModelViewBinder(interruptModelName, null
                                                      , new ModelViewBinder.BindInfo(typeof(EmptyViewObject))
                                                      .AddControllerInfo(new ControllerInfo(TestEventName.Test)
                                                                         .SetInterrupt(true))
                                                      );
            var viewCreator = new DefaultViewInstanceCreator(
                (typeof(EmptyViewObject), new EmptyModelViewParamBinder())
                );
            var binderMap = new ModelViewBinderMap(viewCreator
                                                   , viewBinder
                                                   , interruptBinder)
            {
                UseEventDispatcherMap = new EventDispatcherMap(
                    eventDispatcher
                    ),
                UseEventDispatchStateMap = new EventDispatchStateMap()
                                           .AddState(EventDispatchStateName.interrupt, interruptedTargetQuery),
            };
            var binderInstanceMap = binderMap.CreateBinderInstaceMap();
            var root = new TestModel()
            {
                Name = modelID
            };

            binderInstanceMap.RootModel = root;
            #endregion

            var eventInterrupter = new EventInterrupter();
            eventInterrupter.Add(interruptedTargetQuery,
                                 (_binderInstanceMap, interruptedData) =>
            {
                var interruptModel = new Model()
                {
                    Name = interruptModelName
                };
                return(interruptModel, true);
            }
                                 );

            binderMap.UseEventInterrupter = eventInterrupter;

            Assert.IsNotNull(binderInstanceMap.UseEventDispatchStateMap);
            Assert.IsNotNull(binderInstanceMap.UseEventInterrupter);
            Assert.IsTrue(binderInstanceMap.UseEventDispatchStateMap.DoMatch <ITestEventHandler>(EventDispatchStateName.interrupt, root, null), $"イベントの割り込みテストに使用するモデル({root})が割り込み対象になっていません。EventDispatchStateMapの設定を見直してください");

            eventDispatcher.SendTo(binderInstanceMap);

            Assert.AreSame(root, root.SenderModel);
            Assert.AreEqual(eventDispatcher.SendData, root.RecievedData);

            Debug.Log($"Success to Send First Event!!");

            {//割り込み処理が実行されているか確認
                //
                var errorMessage = "イベントが送信される際に処理の割り込みが実行されていません。";
                Assert.IsTrue(binderInstanceMap.BindInstances.Any(_b => _b.Value.Model.Name == interruptModelName), errorMessage);
                var interruptBinderInstance = binderInstanceMap.BindInstances.Values.First(_b => _b.Model.Name == interruptModelName);

                Assert.IsTrue(interruptBinderInstance.HasEventInterruptedData);
                var interruptedData = interruptBinderInstance.HoldedEventInterruptedData;
                Assert.AreSame(root, interruptedData.SenderModel);
                Assert.AreEqual(eventDispatcher.SendData, interruptedData.SendEventData);
            }
            Debug.Log($"Success to Interrupt Event of RootModel!!");

            {     //割り込みが有効化されたControllerInfoが割り込みデータを元に送信できているか確認
                { //ControllerInfo#IsInterruptModeが正しく動作しているか確認するため、rootのBinderInstanceを削除する
                    root.Name = "hoge";
                    Assert.IsFalse(binderInstanceMap.BindInstances.ContainsKey(root));
                }

                root.Reset();
                eventDispatcher.SendTo(binderInstanceMap);

                Assert.AreSame(root, root.SenderModel);
                Assert.AreEqual(eventDispatcher.SendData, root.RecievedData);
            }
            Debug.Log($"Success to Send Interrupted Event!!");
        }
示例#7
0
        public void QueryPathPriorityPasses()
        {
            var root = new ModelClass()
            {
                Name = "root"
            };
            var apple = new ModelClass()
            {
                Name = "apple"
            };
            var grape = new ModelClass()
            {
                Name = "grape"
            };

            root.AddChildren(apple, grape);
            var orange = new ModelClass()
            {
                Name = "orange", LogicalID = new ModelIDList("child")
            };

            grape.AddChildren(orange);

            var allBinder = new ModelViewBinder("*", null,
                                                new ModelViewBinder.BindInfo(typeof(IntViewObjClass)));
            var appleBinder = new ModelViewBinder("apple", null,
                                                  new ModelViewBinder.BindInfo(typeof(IntViewObjClass)));
            var orangeBinder = new ModelViewBinder("orange", null,
                                                   new ModelViewBinder.BindInfo(typeof(FloatViewObjClass)));
            var childOrangeBinder = new ModelViewBinder("orange #child", 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,
                allBinder,
                appleBinder,
                orangeBinder,
                childOrangeBinder);
            var bindInstanceMap = binderMap.CreateBinderInstaceMap();

            bindInstanceMap.Add(false, null, root.GetHierarchyEnumerable());

            var rootBinderInstance = bindInstanceMap.BindInstances[root];

            Assert.AreSame(allBinder, rootBinderInstance.Binder);

            var appleBinderInstance = bindInstanceMap.BindInstances[apple];

            Assert.AreSame(appleBinder, appleBinderInstance.Binder);

            // grape/orangeのものを使用すること
            var orangeBinderInstance = bindInstanceMap.BindInstances[orange];

            Assert.AreSame(childOrangeBinder, orangeBinderInstance.Binder);

            var grapeBinderInstance = bindInstanceMap.BindInstances[grape];

            Assert.AreSame(allBinder, grapeBinderInstance.Binder);
        }
示例#8
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());
            }
        }
示例#9
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);
            }
        }
示例#10
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);
            }
        }
示例#11
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);
            }
        }
示例#12
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);
            }
        }
        public void BasicPasses()
        {
            var viewID = "viewID";

            #region
            var viewCreator = new DefaultViewInstanceCreator(
                (typeof(EmptyViewObject), new EmptyModelViewParamBinder())
                );
            var testBinder = new ModelViewBinder("*", null,
                                                 new ModelViewBinder.BindInfo(typeof(EmptyViewObject))
                                                 .AddControllerInfo(new ControllerInfo(TestEventName.test, new EventHandlerSelector(ModelRelationShip.Self, "", ""))),
                                                 new ModelViewBinder.BindInfo(viewID, typeof(EmptyViewObject))
                                                 .AddControllerInfo(new ControllerInfo(TestEventName.test, new EventHandlerSelector(ModelRelationShip.Self, "", "")))
                                                 );
            var binderMap = new ModelViewBinderMap(viewCreator,
                                                   testBinder
                                                   );
            var binderInstanceMap = binderMap.CreateBinderInstaceMap();
            #endregion

            var root = new Model {
                Name = "root", LogicalID = new ModelIDList("test")
            };
            var child = new Model {
                Name = "root", LogicalID = new ModelIDList("test2")
            };
            child.Parent = root;
            binderInstanceMap.RootModel = root;
            var eventDispatcherStateMap = new EventDispatchStateMap()
                                          .AddState(TestDispatchStateName.test, new EventDispatchQuery("#test", ""))
                                          .AddState(TestDispatchStateName.test, new EventDispatchQuery("#test2", "viewID"))
                                          .AddState(TestDispatchStateName.testSecond, new EventDispatchQuery("#test", "viewID"))
                                          .AddState(TestDispatchStateName.testSecond, new EventDispatchQuery("#test2", ""))
            ;

            {     //DoMatch
                { //root
                    var rootBinderInstance = binderInstanceMap.BindInstances[root];
                    var defaultViewObj     = rootBinderInstance.QueryViews(ModelViewBinder.BindInfo.ToID(typeof(EmptyViewObject))).First();
                    var viewObjWithViewID  = rootBinderInstance.QueryViews(viewID).First();
                    Assert.IsTrue(eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.test, root, null));
                    Assert.IsTrue(rootBinderInstance.ViewObjects
                                  .All(_v => eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.test, root, _v)));

                    Assert.IsFalse(eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.testSecond, root, null));
                    Assert.IsFalse(eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.testSecond, root, defaultViewObj));
                    Assert.IsTrue(eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.testSecond, root, viewObjWithViewID));

                    var errorMessage = "";
                    AssertionUtils.AssertEnumerableByUnordered(
                        new string[] { TestDispatchStateName.test.ToString() },
                        eventDispatcherStateMap.MatchStates <IOnTestReciever>(root, null),
                        errorMessage);

                    AssertionUtils.AssertEnumerableByUnordered(
                        new string[] { TestDispatchStateName.test.ToString() },
                        eventDispatcherStateMap.MatchStates <IOnTestReciever>(root, defaultViewObj),
                        errorMessage);

                    AssertionUtils.AssertEnumerableByUnordered(
                        new string[] { TestDispatchStateName.test.ToString(), TestDispatchStateName.testSecond.ToString() },
                        eventDispatcherStateMap.MatchStates <IOnTestReciever>(root, viewObjWithViewID),
                        errorMessage);
                }

                {//child
                    var childBinderInstace = binderInstanceMap.BindInstances[child];
                    var defaultViewObj     = childBinderInstace.QueryViews(ModelViewBinder.BindInfo.ToID(typeof(EmptyViewObject))).First();
                    var viewObjWithViewID  = childBinderInstace.QueryViews(viewID).First();
                    Assert.IsFalse(eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.test, child, null));
                    Assert.IsFalse(eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.test, child, defaultViewObj));
                    Assert.IsTrue(eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.test, child, viewObjWithViewID));

                    Assert.IsTrue(eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.testSecond, child, null));
                    Assert.IsTrue(eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.testSecond, child, defaultViewObj));
                    Assert.IsTrue(eventDispatcherStateMap.DoMatch <IOnTestReciever>(TestDispatchStateName.testSecond, child, viewObjWithViewID));

                    var errorMessage = "";
                    AssertionUtils.AssertEnumerableByUnordered(
                        new string[] { TestDispatchStateName.testSecond.ToString() },
                        eventDispatcherStateMap.MatchStates <IOnTestReciever>(child, null),
                        errorMessage);

                    AssertionUtils.AssertEnumerableByUnordered(
                        new string[] { TestDispatchStateName.testSecond.ToString() },
                        eventDispatcherStateMap.MatchStates <IOnTestReciever>(child, defaultViewObj),
                        errorMessage);

                    AssertionUtils.AssertEnumerableByUnordered(
                        new string[] { TestDispatchStateName.test.ToString(), TestDispatchStateName.testSecond.ToString() },
                        eventDispatcherStateMap.MatchStates <IOnTestReciever>(child, viewObjWithViewID),
                        errorMessage);
                }
            }
        }
示例#14
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);
            }
        }