Example #1
0
        public void DestroyWhenBindPasses()
        {
            var viewObj = new EmptyViewObject()
            {
                UseModel    = new Model(),
                UseBindInfo = new ModelViewBinder.BindInfo(typeof(EmptyViewObject)),
            };

            Assert.IsTrue(viewObj.DoBinding());

            int unbindCounter  = 0;
            int destroyCounter = 0;

            viewObj.OnUnbinded.Add(_v => unbindCounter++);
            viewObj.OnDestroyed.Add(_v => destroyCounter++);

            viewObj.Destroy();

            Assert.IsNull(viewObj.UseModel);
            Assert.IsNull(viewObj.UseBindInfo);
            Assert.IsNull(viewObj.UseBinderInstance);
            Assert.AreEqual(1, unbindCounter);
            Assert.AreEqual(1, destroyCounter);
            Debug.Log($"Success to IViewObject#Destroy!");

            unbindCounter  = 0;
            destroyCounter = 0;
            viewObj.Destroy();
            Assert.AreEqual(0, unbindCounter);
            Assert.AreEqual(0, destroyCounter);
            Debug.Log($"Success to IViewObject#Destroy When already destroy!");
        }
        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()),
                $"想定された並び順になっていません");
        }
Example #3
0
        public void BasicPasses()
        {
            var viewID = "viewID";
            var model  = new Model()
            {
                Name = "model1", LogicalID = new ModelIDList("lg")
            };
            var viewObj = new EmptyViewObject()
            {
                UseModel    = model,
                UseBindInfo = new ModelViewBinder.BindInfo(viewID, typeof(EmptyViewObject))
            };

            {
                var query = new EventDispatchQuery("#lg", "");
                Assert.IsTrue(query.DoEnableEventType <IOnTestReciever>());
                Assert.IsTrue(query.DoEnableEventType <IOnTest2Reciever>());

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTestReciever>(null, null));
                Assert.IsTrue(query.DoMatch <IOnTestReciever>(model, null));
                Assert.IsTrue(query.DoMatch <IOnTestReciever>(model, viewObj));

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTest2Reciever>(null, null));
                Assert.IsTrue(query.DoMatch <IOnTest2Reciever>(model, null));
                Assert.IsTrue(query.DoMatch <IOnTest2Reciever>(model, viewObj));
            }

            {
                var query = new EventDispatchQuery("#lg", viewID);
                Assert.IsTrue(query.DoEnableEventType <IOnTestReciever>());
                Assert.IsTrue(query.DoEnableEventType <IOnTest2Reciever>());

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTestReciever>(null, null));
                Assert.IsFalse(query.DoMatch <IOnTestReciever>(model, null));
                Assert.IsTrue(query.DoMatch <IOnTestReciever>(model, viewObj));

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTest2Reciever>(null, null));
                Assert.IsFalse(query.DoMatch <IOnTest2Reciever>(model, null));
                Assert.IsTrue(query.DoMatch <IOnTest2Reciever>(model, viewObj));
            }

            {
                var query = new EventDispatchQuery("#lg", "")
                            .AddIncludedEventType <IOnTestReciever>();

                Assert.IsTrue(query.DoEnableEventType <IOnTestReciever>());
                Assert.IsFalse(query.DoEnableEventType <IOnTest2Reciever>());

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTestReciever>(null, null));
                Assert.IsTrue(query.DoMatch <IOnTestReciever>(model, null));
                Assert.IsTrue(query.DoMatch <IOnTestReciever>(model, viewObj));

                Assert.Throws <UnityEngine.Assertions.AssertionException>(() => query.DoMatch <IOnTest2Reciever>(null, null));
                Assert.IsFalse(query.DoMatch <IOnTest2Reciever>(model, null));
                Assert.IsFalse(query.DoMatch <IOnTest2Reciever>(model, viewObj));
            }
        }
Example #4
0
        public void BindingPasses()
        {
            {
                var viewObj = new EmptyViewObject()
                {
                    UseModel    = new Model(),
                    UseBindInfo = new ModelViewBinder.BindInfo(typeof(EmptyViewObject)),
                };
                Assert.IsTrue(viewObj.DoBinding());
                Debug.Log($"Success to DoBinding()");

                int counter = 0;
                viewObj.OnUnbinded.Add(_v => counter++);
                viewObj.Unbind();

                Assert.IsNull(viewObj.UseModel);
                Assert.IsNull(viewObj.UseBindInfo);
                Assert.IsFalse(viewObj.DoBinding());
                Assert.AreEqual(1, counter);
                Debug.Log($"Success to Unbind()");

                counter = 0;
                viewObj.Unbind(); // <- when DoBinding() == false
                Assert.AreEqual(0, counter);
                Debug.Log($"Success to not Call OnUnbind() when Bind Nothing!");
            }

            {
                var viewObj = new EmptyViewObject()
                {
                    UseModel    = null,
                    UseBindInfo = new ModelViewBinder.BindInfo(typeof(EmptyViewObject)),
                };
                Assert.IsFalse(viewObj.DoBinding());
            }
            {
                var viewObj = new EmptyViewObject()
                {
                    UseModel    = new Model(),
                    UseBindInfo = null,
                };
                Assert.IsFalse(viewObj.DoBinding());
            }
            {
                var viewObj = new EmptyViewObject()
                {
                    UseModel    = null,
                    UseBindInfo = null,
                };
                Assert.IsFalse(viewObj.DoBinding());
            }
            Debug.Log($"Success all Case (DoBinding() == false)!");
        }
Example #5
0
        public void DestroyWhenBindNothingPasses()
        {
            var viewObj = new EmptyViewObject();

            Assert.IsFalse(viewObj.DoBinding());

            int unbindCounter  = 0;
            int destroyCounter = 0;

            viewObj.OnUnbinded.Add(_v => unbindCounter++);
            viewObj.OnDestroyed.Add(_v => destroyCounter++);

            viewObj.Destroy();

            Assert.IsNull(viewObj.UseModel);
            Assert.IsNull(viewObj.UseBindInfo);
            Assert.IsNull(viewObj.UseBinderInstance);
            Assert.AreEqual(0, unbindCounter);
            Assert.AreEqual(1, destroyCounter);
        }
        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)
                , "");
        }
Example #7
0
        public void DisposePasses()
        {
            var creator = new DefaultViewInstanceCreator(
                (typeof(PoolingViewObj), new EmptyModelViewParamBinder()),
                (typeof(EmptyViewObject), new EmptyModelViewParamBinder())
                );
            var objPool = new ViewInstanceCreatorObjectPool(creator);

            Assert.AreSame(creator, objPool.UseCreator);

            var clearPoolingViewObj = new PoolingViewObj();

            objPool.Push(clearPoolingViewObj);

            var clearEmptyViewObj = new EmptyViewObject();

            objPool.Push(clearEmptyViewObj);


            objPool.Dispose();

            Assert.IsNull(objPool.UseCreator);
        }