Exemple #1
0
        public void DoMatchWithModelTypeAndEmptyQueryPathPasses()
        {
            //作成のテスト
            var viewInstanceCreator = new DefaultViewInstanceCreator(
                (typeof(IntViewObjClass), new IntViewObjClass.Binder()),
                (typeof(FloatViewObjClass), new FloatViewObjClass.Binder())
                );
            var appleBinder = new ModelViewBinder("", viewInstanceCreator,
                                                  new ModelViewBinder.BindInfo(typeof(IntViewObjClass)),
                                                  new ModelViewBinder.BindInfo(typeof(FloatViewObjClass))
                                                  );

            appleBinder.AddEnabledModelType <ModelClass>();

            var matchModel = new ModelClass {
                Name = "apple", Value1 = 111, Value2 = 1.234f
            };
            var notMatchQueryModel = new ModelClass {
                Name = "empty"
            };
            var notMatchTypeModel = new Model {
                Name = "apple"
            };

            Assert.IsTrue(appleBinder.DoMatch(matchModel));
            Assert.IsTrue(appleBinder.DoMatch(notMatchQueryModel));
            Assert.IsFalse(appleBinder.DoMatch(notMatchTypeModel));

            appleBinder.AddEnabledModelType <Model>();
            Assert.IsTrue(appleBinder.DoMatch(matchModel));
            Assert.IsTrue(appleBinder.DoMatch(notMatchQueryModel));
            Assert.IsTrue(appleBinder.DoMatch(notMatchTypeModel));

            appleBinder.RemoveEnabledModelType <ModelClass>();
            Assert.IsFalse(appleBinder.DoMatch(matchModel));
            Assert.IsFalse(appleBinder.DoMatch(notMatchQueryModel));
            Assert.IsTrue(appleBinder.DoMatch(notMatchTypeModel));
        }
Exemple #2
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);
                }
            }
        }