Ejemplo n.º 1
0
        public void DonotMatchQueryPathFailed()
        {
            var model = new ModelClass {
                Name = "apple", Value1 = 111, Value2 = 1.234f
            };
            var empry = new ModelClass {
                Name = "empty"
            };

            //作成のテスト
            var viewInstanceCreator = new DefaultViewInstanceCreator(
                (typeof(IntViewObjClass), new IntViewObjClass.Binder()),
                (typeof(FloatViewObjClass), new FloatViewObjClass.Binder())
                );
            var binder = new ModelViewBinder("apple", viewInstanceCreator,
                                             new ModelViewBinder.BindInfo(typeof(IntViewObjClass)),
                                             new ModelViewBinder.BindInfo(typeof(FloatViewObjClass))
                                             );

            Assert.Throws <UnityEngine.Assertions.AssertionException>(() =>
            {
                var empty = new ModelClass {
                    Name = "empty"
                };
                var bindInstance = binder.CreateBindInstance(empty, null);
            }, "クエリパスが一致しない時は例外を投げて、生成しないようにしてください");
        }
Ejemplo n.º 2
0
        public void QueryViewsPasses()
        {
            var model = new ModelClass {
                Name = "apple", Value1 = 111, Value2 = 1.234f
            };
            var empry = new ModelClass {
                Name = "empty"
            };

            //作成のテスト
            var viewInstanceCreator = new DefaultViewInstanceCreator(
                (typeof(IntViewObjClass), new IntViewObjClass.Binder()),
                (typeof(FloatViewObjClass), new FloatViewObjClass.Binder())
                );
            var binder = new ModelViewBinder("apple", viewInstanceCreator,
                                             new ModelViewBinder.BindInfo(typeof(IntViewObjClass)),
                                             new ModelViewBinder.BindInfo(typeof(FloatViewObjClass)),
                                             new ModelViewBinder.BindInfo("Int", typeof(IntViewObjClass))
                                             );
            var binderInstance = binder.CreateBindInstance(model, null);

            {//query => typeof(IntViewObjClass).FullName
                var ID = ModelViewBinder.BindInfo.ToID(typeof(IntViewObjClass));
                var queryViewResult = binderInstance.QueryViews(ID);
                Assert.AreEqual(1, queryViewResult.Count(), $"Failed to Query Views... ID={ID}");
                var intViewObj = binderInstance.ViewObjects.First(_v => _v.UseBindInfo.ID == ID);
                Assert.IsTrue(intViewObj == queryViewResult.First());
            }

            {//query => typeof(FloatViewObjClass).FullName
                var ID = ModelViewBinder.BindInfo.ToID(typeof(FloatViewObjClass));
                var queryViewResult = binderInstance.QueryViews(ID);
                Assert.AreEqual(1, queryViewResult.Count());
                var floatViewObj = binderInstance.ViewObjects.First(_v => _v.UseBindInfo.ID == ID);
                Assert.IsTrue(floatViewObj == queryViewResult.First());
            }

            {//query => Int
                var queryViewResult = binderInstance.QueryViews("Int");
                Assert.AreEqual(1, queryViewResult.Count());
                var intIdViewObj = binderInstance.ViewObjects.First(_v => _v.UseBindInfo.ID.MainID == "Int");
                Assert.IsTrue(intIdViewObj == queryViewResult.First());
            }
        }
Ejemplo n.º 3
0
        public void BasicUsagePasses()
        {
            var model = new ModelClass {
                Name = "apple", Value1 = 111, Value2 = 1.234f
            };
            var empry = new ModelClass {
                Name = "empty"
            };

            //作成のテスト
            //var bindInfoList = ModelViewBinder.CreateBindInfoDict(
            //    (typeof(IntViewObjClass), new IntViewObjClass.Binder()),
            //    (typeof(FloatViewObjClass), new FloatViewObjClass.Binder()));
            //var binder = new ModelViewBinder("apple", bindInfoList);

            var viewInstanceCreator = new DefaultViewInstanceCreator(
                (typeof(IntViewObjClass), new IntViewObjClass.Binder()),
                (typeof(FloatViewObjClass), new FloatViewObjClass.Binder())
                );
            var binder = new ModelViewBinder("apple", viewInstanceCreator,
                                             new ModelViewBinder.BindInfo(typeof(IntViewObjClass)),
                                             new ModelViewBinder.BindInfo(typeof(FloatViewObjClass))
                                             );

            Assert.AreSame(binder.ViewInstaceCreator, viewInstanceCreator);
            { //QueryPathの検証のテスト
                Assert.IsTrue(binder.DoMatch(model));
                Assert.IsFalse(binder.DoMatch(new Model {
                    Name = "orange"
                }));
            }

            {//ViewObjectの作成のテスト
                var bindInstance = binder.CreateBindInstance(model, null);
                var intViewObj   = bindInstance.ViewObjects.FirstOrDefault(_o => _o is IntViewObjClass) as IntViewObjClass;
                var floatViewObj = bindInstance.ViewObjects.FirstOrDefault(_o => _o is FloatViewObjClass) as FloatViewObjClass;
                Assert.IsNotNull(intViewObj);
                Assert.IsNotNull(floatViewObj);

                bindInstance.UpdateViewObjects();
                Assert.AreEqual(model.Value1, intViewObj.IntValue);
                Assert.AreEqual(model.Value2, floatViewObj.FloatValue);

                //対応するModelViewBinderの取得のテスト
                {//IntViewObjClass
                    model.Value1 = -1234;
                    Assert.IsTrue(binder.BindInfos.Any(_i => _i == intViewObj.UseBindInfo));
                    var paramBinder = binder.GetParamBinder(intViewObj.UseBindInfo);
                    Assert.IsNotNull(paramBinder);
                    Assert.AreEqual(typeof(IntViewObjClass.Binder), paramBinder.GetType());
                    paramBinder.Update(model, intViewObj);
                    Assert.AreEqual(model.Value1, intViewObj.IntValue);
                }

                {//FloatViewObjClass
                    model.Value2 = 0.987f;
                    Assert.IsTrue(binder.BindInfos.Any(_i => _i == floatViewObj.UseBindInfo));
                    var paramBinder = binder.GetParamBinder(floatViewObj.UseBindInfo);
                    Assert.IsNotNull(paramBinder);
                    Assert.AreEqual(typeof(FloatViewObjClass.Binder), paramBinder.GetType());
                    paramBinder.Update(model, floatViewObj);
                    Assert.AreEqual(model.Value2, floatViewObj.FloatValue);
                }
            }
        }
Ejemplo n.º 4
0
        public void ModelOnUpdatedPasses()
        {
            var model = new ModelClass {
                Name = "apple", Value1 = 111, Value2 = 1.234f
            };
            var empry = new ModelClass {
                Name = "empty"
            };

            var viewInstanceCreator = new DefaultViewInstanceCreator(
                (typeof(IntViewObjClass), new IntViewObjClass.Binder()),
                (typeof(FloatViewObjClass), new FloatViewObjClass.Binder())
                );
            var binder = new ModelViewBinder("apple", viewInstanceCreator,
                                             new ModelViewBinder.BindInfo(typeof(IntViewObjClass)),
                                             new ModelViewBinder.BindInfo(typeof(FloatViewObjClass))
                                             );

            {//Model#OnUpdatedと連動しているかテスト
                var obj = new ModelClass()
                {
                    Name = "apple", Value1 = 456, Value2 = 6.7f
                };
                var bindInstance = binder.CreateBindInstance(obj, null);
                var intViewObj   = bindInstance.ViewObjects.FirstOrDefault(_o => _o is IntViewObjClass) as IntViewObjClass;
                var floatViewObj = bindInstance.ViewObjects.FirstOrDefault(_o => _o is FloatViewObjClass) as FloatViewObjClass;

                {//Model#DoneUpdatedとの連動テスト
                    obj.DoneUpdate();

                    var errorMessage = "ModelViewBindInstaceの生成時には指定したModel#OnUpdatedと連動するようにしてください";
                    obj.Value1 = 9847;
                    obj.DoneUpdate();
                    Assert.AreEqual(obj.Value1, intViewObj.IntValue, errorMessage);
                    Assert.AreEqual(obj.Value2, floatViewObj.FloatValue, errorMessage);

                    obj.Value1 = -1234;
                    obj.DoneUpdate();
                    Assert.AreEqual(obj.Value1, intViewObj.IntValue, errorMessage);

                    //
                    errorMessage = $"ModelViewBindInstace#DettachModelOnUpdated()を呼び出した後はModel#OnUpdatedとの連しないようにしてください。";
                    bindInstance.DettachModelCallback();
                    obj.Value1 = -678;
                    obj.DoneUpdate();
                    Assert.AreNotEqual(obj.Value1, intViewObj.IntValue, errorMessage);

                    errorMessage = "ModelViewBindInstace#AttachModelOnUpdated()を呼び出した後は設定されたModelのModel#OnUpdatedと連動するようにしてください";
                    bindInstance.AttachModelCallback();
                    obj.Value1 = 939753;
                    obj.DoneUpdate();
                    Assert.AreEqual(obj.Value1, intViewObj.IntValue, errorMessage);
                    Assert.AreEqual(obj.Value2, floatViewObj.FloatValue, errorMessage);
                }

                {//ModelViewBindInstance#Disposeテスト
                    bindInstance.Dispose();
                    obj.Value1 = -48593;
                    obj.DoneUpdate();
                    Assert.AreNotEqual(obj.Value1, intViewObj.IntValue, $"ModelViewBindInstance#DisposeのあとはModel#OnUpdatedと連動しないようにしてください。");

                    Assert.IsNull(bindInstance.Model);
                    Assert.IsNull(bindInstance.Binder);
                    Assert.IsNull(bindInstance.UseInstanceMap);
                    Assert.IsFalse(bindInstance.ViewObjects.Any());
                    Assert.IsFalse(bindInstance.AutoLayoutViewObjects.Any());
                    Assert.IsFalse(bindInstance.EventDispatcherHelpObjectsForView.Any());
                }
            }
        }