Ejemplo n.º 1
0
        public void ConstructorSetsInstanceeAndOptionType()
        {
            // Arrange
            var viewEngine = new TestModelBinder();

            // Act
            var descriptor = new ModelBinderDescriptor(viewEngine);

            // Assert
            Assert.Same(viewEngine, descriptor.Instance);
            Assert.Equal(viewEngine.GetType(), descriptor.OptionType);
        }
Ejemplo n.º 2
0
        public void ConstructorSetsInstanceeAndOptionType()
        {
            // Arrange
            var viewEngine = new TestModelBinder();

            // Act
            var descriptor = new ModelBinderDescriptor(viewEngine);

            // Assert
            Assert.Same(viewEngine, descriptor.Instance);
            Assert.Equal(viewEngine.GetType(), descriptor.OptionType);
        }
Ejemplo n.º 3
0
        private ViewHandler InitializeViewHandler()
        {
            _typeCatalog = new TestTypeCatalog();
            _modelBinder = new TestModelBinder();
            _viewTarget  = new TestViewTarget();

            var viewHandler = new ViewHandler();

            viewHandler.RegisterViewCatalog(_typeCatalog);
            viewHandler.RegisterModelBinder(_modelBinder);
            viewHandler.RegisterViewTarget(_viewTarget);

            return(viewHandler);
        }
Ejemplo n.º 4
0
 public string TestSubmitModelBinder(TestModelBinder e, string ms5, string btnSubmit)
 {
     // ModelBinder會自動比對(URL接收欄位)與(action函數參數欄位), 相同名稱的欄位會自動填入接收的資料內容.
     // (action函數參數欄位)比對範圍為: (函數中的參數名稱)以及(class中的所有property欄位, 包括子class).
     // 也可由Request.Form["欄位名稱"]方式取得接收資料.
     return("ms1=" + e.ms1 +                       // 比對property名稱符合
            "<br />, ms2=" + e.ms2 +               // 比對property名稱符合
            "<br />, ms3=" + e.ms3 +               // 比對property名稱符合
            "<br />, ms4=" + e.ms4 +               // 比對property名稱符合
            "<br />, ms5=" + ms5 +                 // 比對函數參數名稱符合.
            "<br />, ms6=" + Request.Form["ms6"] + // 自行取得
            "<br />, mT0010.ms1=" + e.mT0010.ms1 + // 比對子class欄位.
            "<br />, mT0010.ms2=" + e.mT0010.ms2 + // 比對子class欄位.
            "<br />, mT0010.mi1=" + e.mT0010.mi1 + // 比對子class欄位.
            "<br />, mT0010.mi2=" + e.mT0010.mi2 + // 比對子class欄位.
            "<br />, btnSumit=" + btnSubmit        // 比對函數參數名稱符合.
            + new CMN0010().GetModelStateErrorList(ModelState));
 }
Ejemplo n.º 5
0
        private ViewHandler InitializeViewHandler()
        {
            _typeCatalog = new TestTypeCatalog();
            _modelBinder = new TestModelBinder();
            _viewTarget = new TestViewTarget();

            var viewHandler = new ViewHandler();
            viewHandler.RegisterViewCatalog(_typeCatalog);
            viewHandler.RegisterModelBinder(_modelBinder);
            viewHandler.RegisterViewTarget(_viewTarget);

            return viewHandler;
        }
 public void AsModelBinderForTypesRegistersInstanceModelBinder()
 {
     var builder = new ContainerBuilder();
     var binder = new TestModelBinder(new Dependency());
     builder.RegisterInstance(binder).AsModelBinderForTypes(typeof(TestModel1));
     var container = builder.Build();
     var resolver = new AutofacWebApiDependencyResolver(container);
     var configuration = new HttpConfiguration { DependencyResolver = resolver };
     var provider = new AutofacWebApiModelBinderProvider();
     Assert.Same(binder, provider.GetBinder(configuration, typeof(TestModel1)));
 }