public IEnumerator DestroyWhenBindPasses()
        {
            var viewObj = MonoBehaviourViewObject.Create();

            viewObj.UseModel    = new Model();
            viewObj.UseBindInfo = new ModelViewBinder.BindInfo(typeof(MonoBehaviourViewObject));

            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!");
            yield return(null);
        }
        public IEnumerator DestroyPasses()
        {
            var viewObj     = MonoBehaviourViewObject.Create();
            var viewGameObj = viewObj.gameObject;

            viewObj.Destroy();
            yield return(null);

            var scene = SceneManager.GetActiveScene();

            Assert.IsFalse(scene.GetGameObjectEnumerable().Contains(viewGameObj));
        }
        public void BindingPasses()
        {
            {
                var viewObj = MonoBehaviourViewObject.Create();
                viewObj.UseModel    = new Model();
                viewObj.UseBindInfo = new ModelViewBinder.BindInfo(typeof(MonoBehaviourViewObject));
                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 = MonoBehaviourViewObject.Create();
                viewObj.UseModel    = null;
                viewObj.UseBindInfo = new ModelViewBinder.BindInfo(typeof(MonoBehaviourViewObject));
                Assert.IsFalse(viewObj.DoBinding());
            }
            {
                var viewObj = MonoBehaviourViewObject.Create();
                viewObj.UseModel    = new Model();
                viewObj.UseBindInfo = null;
                Assert.IsFalse(viewObj.DoBinding());
            }
            {
                var viewObj = MonoBehaviourViewObject.Create();
                viewObj.UseModel    = null;
                viewObj.UseBindInfo = null;
                Assert.IsFalse(viewObj.DoBinding());
            }
            Debug.Log($"Success all Case (DoBinding() == false)!");
        }
        public void DestroyWhenBindNothingPasses()
        {
            var viewObj = MonoBehaviourViewObject.Create();

            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);
        }
예제 #5
0
        public IEnumerator InsertPasses()
        {
            yield return(null);

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

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

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

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

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

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


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

            child4.transform.SetParent(parent.transform);

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

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