Ejemplo n.º 1
0
        private static ViewContext CreateViewContext(
            RazorPageCreateModelExpressionModel model,
            IModelMetadataProvider provider)
        {
            var viewData = new ViewDataDictionary <RazorPageCreateModelExpressionModel>(provider)
            {
                Model = model,
            };

            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider
            .Setup(real => real.GetService(typeof(IModelMetadataProvider)))
            .Returns(provider);

            var httpContext = new Mock <HttpContext>();

            httpContext
            .SetupGet(real => real.RequestServices)
            .Returns(serviceProvider.Object);

            var actionContext = new ActionContext(httpContext.Object, new RouteData(), new ActionDescriptor());

            return(new ViewContext(
                       actionContext,
                       view: Mock.Of <IView>(),
                       viewData: viewData,
                       tempData: Mock.Of <ITempDataDictionary>(),
                       writer: new StringWriter(),
                       htmlHelperOptions: new HtmlHelperOptions()));
        }
Ejemplo n.º 2
0
 private static ViewContext CreateViewContext(RazorPageCreateModelExpressionModel model)
 {
     return(CreateViewContext(model, new TestModelMetadataProvider()));
 }