Пример #1
0
        public View createView(string name, string prefix, AttributeSet attrs)
        {
            //PoC
            try
            {
                string fullname = "AndroidInteropLib." + (prefix != null ? (prefix + name) : name);
                Type   viewType = Type.GetType(fullname);
                if (viewType != null)
                {
                    View view = (View)Activator.CreateInstance(viewType, mContext, attrs);
                    return(view);
                }

                else
                {
                    NullView nv = new NullView(mContext, attrs);
                    nv.setText("View not found: " + name);
                    return(nv);
                }
                //TODO: Check w/ filter if view is allowed
            }
            catch (Exception ex)
            {
                //Maybe in the future return a black box with layout info saying "loading failed?"
                NullView nv = new NullView(mContext, attrs);
                nv.setText("View not found: " + name + $"\n\n{ex.Message}");
                return(nv);
                //throw ex;
            }
        }
Пример #2
0
        public MvcViewTestContext(ActionContext actionContext, IModelMetadataProvider modelMetadataProvider, IHtmlGenerator htmlGenerator)
        {
            ViewData = new ViewDataDictionary <TModel>(modelMetadataProvider, new ModelStateDictionary());
            View     = new NullView();
            Writer   = Substitute.For <TextWriter>();
            TempData = new TempDataDictionary(actionContext.HttpContext, new TempDataProviderMock());
            var htmlHelperOptions = new HtmlHelperOptions();

            htmlHelperOptions.ClientValidationEnabled = true;
            ViewContext = new ViewContext(actionContext, View, ViewData, TempData, Writer, htmlHelperOptions);

            HtmlHelper = new HtmlHelper <TModel>(
                htmlGenerator,
                TestApplication.Services.GetRequiredService <ICompositeViewEngine>(),
                TestApplication.Services.GetRequiredService <IModelMetadataProvider>(),
                TestApplication.Services.GetRequiredService <IViewBufferScope>(),
                HtmlEncoder.Default,
                UrlEncoder.Default,
                new ModelExpressionProvider(TestApplication.Services.GetRequiredService <IModelMetadataProvider>()));
            HtmlHelper.Contextualize(ViewContext);
        }