public static ViewContext FromActionContext(HttpTestContext testContext, ActionContext actionContext)
     => FromViewContext(testContext, new ViewContext
     {
         HttpContext = actionContext.HttpContext,
         RouteData = actionContext.RouteData,
         ActionDescriptor = actionContext.ActionDescriptor,
     });
Ejemplo n.º 2
0
 private void PrepareControllerContext(HttpTestContext testContext)
 {
     this.TestContext = testContext;
     this.HttpContext = testContext.HttpContext;
     this.RouteData   = testContext.RouteData ?? new RouteData();
     TestHelper.SetActionContextToAccessor(this);
 }
Ejemplo n.º 3
0
 public static ViewContext FromActionContext(HttpTestContext testContext, ActionContext actionContext)
 => FromViewContext(testContext, new ViewContext
 {
     HttpContext      = actionContext.HttpContext,
     RouteData        = actionContext.RouteData,
     ActionDescriptor = actionContext.ActionDescriptor,
 });
 private void PrepareControllerContext(HttpTestContext testContext)
 {
     this.TestContext = testContext;
     this.HttpContext = testContext.HttpContext;
     this.RouteData = testContext.RouteData ?? new RouteData();
     TestHelper.SetActionContextToAccessor(this);
 }
        private void PrepareViewComponentContext(HttpTestContext testContext, ViewComponentContext viewComponentContext)
        {
            this.TestContext             = testContext;
            this.Arguments               = viewComponentContext.Arguments;
            this.HtmlEncoder             = viewComponentContext.HtmlEncoder;
            this.ViewComponentDescriptor = viewComponentContext.ViewComponentDescriptor;
            this.ViewContext             = viewComponentContext.ViewContext;

            TestHelper.SetActionContextToAccessor(this.ViewContext);
        }
        private void PrepareViewComponentContext(HttpTestContext testContext, ViewComponentContext viewComponentContext)
        {
            this.TestContext = testContext;
            this.Arguments = viewComponentContext.Arguments;
            this.HtmlEncoder = viewComponentContext.HtmlEncoder;
            this.ViewComponentDescriptor = viewComponentContext.ViewComponentDescriptor;
            this.ViewContext = viewComponentContext.ViewContext;

            TestHelper.SetActionContextToAccessor(this.ViewContext);
        }
Ejemplo n.º 7
0
 private static void PrepareDataProviders(HttpTestContext testContext, ViewContext viewContext)
 {
     viewContext.ViewData = viewContext.ViewData ?? ViewDataDictionaryMock.FromViewContext(viewContext);
     viewContext.TempData = viewContext.TempData
                            ?? testContext
                            .HttpContext
                            .RequestServices
                            .GetService <ITempDataDictionaryFactory>()
                            ?.GetTempData(testContext.HttpContext);
 }
 private static void PrepareDataProviders(HttpTestContext testContext, ViewContext viewContext)
 {
     viewContext.ViewData = viewContext.ViewData ?? ViewDataDictionaryMock.FromViewContext(viewContext);
     viewContext.TempData = viewContext.TempData 
         ?? testContext
         .HttpContext
         .RequestServices
         .GetService<ITempDataDictionaryFactory>()
         ?.GetTempData(testContext.HttpContext);
 }
        public static ControllerContext FromActionContext(HttpTestContext testContext, ActionContext actionContext)
        {
            CommonValidator.CheckForNullReference(testContext, nameof(HttpTestContext));
            CommonValidator.CheckForNullReference(actionContext, nameof(ActionContext));

            actionContext.HttpContext = actionContext.HttpContext ?? testContext.HttpContext;
            actionContext.RouteData = actionContext.RouteData ?? testContext.RouteData ?? new RouteData();
            actionContext.ActionDescriptor = actionContext.ActionDescriptor ?? new ControllerActionDescriptor();

            return new MockedControllerContext(testContext, actionContext);
        }
Ejemplo n.º 10
0
        public static ControllerContext FromActionContext(HttpTestContext testContext, ActionContext actionContext)
        {
            CommonValidator.CheckForNullReference(testContext, nameof(HttpTestContext));
            CommonValidator.CheckForNullReference(actionContext, nameof(ActionContext));

            actionContext.HttpContext      = actionContext.HttpContext ?? testContext.HttpContext;
            actionContext.RouteData        = actionContext.RouteData ?? testContext.RouteData ?? new RouteData();
            actionContext.ActionDescriptor = actionContext.ActionDescriptor ?? new ControllerActionDescriptor();

            return(new MockedControllerContext(testContext, actionContext));
        }
        public static ViewComponentContextMock FromViewComponentContext(HttpTestContext testContext, ViewComponentContext viewComponentContext)
        {
            CommonValidator.CheckForNullReference(testContext, nameof(HttpTestContext));
            CommonValidator.CheckForNullReference(viewComponentContext, nameof(ViewComponentContext));

            viewComponentContext.ViewComponentDescriptor = viewComponentContext.ViewComponentDescriptor ?? new ViewComponentDescriptor();
            viewComponentContext.ViewContext = ViewContextMock.FromViewContext(testContext, viewComponentContext.ViewContext ?? new ViewContext());
            viewComponentContext.Arguments = viewComponentContext.Arguments ?? new Dictionary<string, object>();
            viewComponentContext.HtmlEncoder = viewComponentContext.HtmlEncoder ?? HtmlEncoder.Default;

            return new ViewComponentContextMock(testContext, viewComponentContext);
        }
        public static ViewComponentContextMock FromViewComponentContext(HttpTestContext testContext, ViewComponentContext viewComponentContext)
        {
            CommonValidator.CheckForNullReference(testContext, nameof(HttpTestContext));
            CommonValidator.CheckForNullReference(viewComponentContext, nameof(ViewComponentContext));

            viewComponentContext.ViewComponentDescriptor = viewComponentContext.ViewComponentDescriptor ?? new ViewComponentDescriptor();
            viewComponentContext.ViewContext             = ViewContextMock.FromViewContext(testContext, viewComponentContext.ViewContext ?? new ViewContext());
            viewComponentContext.Arguments   = viewComponentContext.Arguments ?? new Dictionary <string, object>();
            viewComponentContext.HtmlEncoder = viewComponentContext.HtmlEncoder ?? HtmlEncoder.Default;

            return(new ViewComponentContextMock(testContext, viewComponentContext));
        }
        private static void ApplyHtmlHelperOptions(HttpTestContext testContext, ViewContext viewContext)
        {
            var htmlHelperOptions = testContext.HttpContext.RequestServices.GetService<MvcViewOptions>()?.HtmlHelperOptions;
            if (htmlHelperOptions != null)
            {
                if (string.IsNullOrEmpty(viewContext.ValidationMessageElement))
                {
                    viewContext.ValidationMessageElement = htmlHelperOptions.ValidationMessageElement;
                }

                if (string.IsNullOrEmpty(viewContext.ValidationSummaryMessageElement))
                {
                    viewContext.ValidationSummaryMessageElement = htmlHelperOptions.ValidationSummaryMessageElement;
                }
            }
        }
Ejemplo n.º 14
0
        private static void ApplyHtmlHelperOptions(HttpTestContext testContext, ViewContext viewContext)
        {
            var htmlHelperOptions = testContext.HttpContext.RequestServices.GetService <MvcViewOptions>()?.HtmlHelperOptions;

            if (htmlHelperOptions != null)
            {
                if (string.IsNullOrEmpty(viewContext.ValidationMessageElement))
                {
                    viewContext.ValidationMessageElement = htmlHelperOptions.ValidationMessageElement;
                }

                if (string.IsNullOrEmpty(viewContext.ValidationSummaryMessageElement))
                {
                    viewContext.ValidationSummaryMessageElement = htmlHelperOptions.ValidationSummaryMessageElement;
                }
            }
        }
Ejemplo n.º 15
0
        public static ViewContext FromViewContext(HttpTestContext testContext, ViewContext viewContext)
        {
            CommonValidator.CheckForNullReference(testContext, nameof(HttpTestContext));
            CommonValidator.CheckForNullReference(viewContext, nameof(ViewContext));

            viewContext.HttpContext      = viewContext.HttpContext ?? testContext.HttpContext;
            viewContext.RouteData        = viewContext.RouteData ?? testContext.RouteData ?? new RouteData();
            viewContext.ActionDescriptor = viewContext.ActionDescriptor ?? ActionDescriptorMock.Default;
            viewContext.FormContext      = viewContext.FormContext ?? new FormContext();
            viewContext.View             = viewContext.View ?? NullView.Instance;
            viewContext.Writer           = viewContext.Writer ?? TextWriter.Null;

            PrepareDataProviders(testContext, viewContext);
            ApplyHtmlHelperOptions(testContext, viewContext);

            return(new ViewContextMock(viewContext));
        }
        public static ViewContext FromViewContext(HttpTestContext testContext, ViewContext viewContext)
        {
            CommonValidator.CheckForNullReference(testContext, nameof(HttpTestContext));
            CommonValidator.CheckForNullReference(viewContext, nameof(ViewContext));

            viewContext.HttpContext = viewContext.HttpContext ?? testContext.HttpContext;
            viewContext.RouteData = viewContext.RouteData ?? testContext.RouteData ?? new RouteData();
            viewContext.ActionDescriptor = viewContext.ActionDescriptor ?? ActionDescriptorMock.Default;
            viewContext.FormContext = viewContext.FormContext ?? new FormContext();
            viewContext.View = viewContext.View ?? NullView.Instance;
            viewContext.Writer = viewContext.Writer ?? TextWriter.Null;

            PrepareDataProviders(testContext, viewContext);
            ApplyHtmlHelperOptions(testContext, viewContext);
           
            return new ViewContextMock(viewContext);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="HttpTestContext"/> containing data about the currently executed assertion chain.</param>
 protected BaseTestBuilder(HttpTestContext testContext)
 {
     TestCounter.IncrementAndValidate();
     this.TestContext = testContext;
 }
 private MockedControllerContext(HttpTestContext testContext, ActionContext actionContext)
     : base(actionContext)
 {
     this.PrepareControllerContext(testContext);
 }
 public MockedControllerContext(HttpTestContext testContext)
 {
     this.PrepareControllerContext(testContext);
 }
 private ViewComponentContextMock(HttpTestContext testContext, ViewComponentContext viewComponentContext)
 {
     this.PrepareViewComponentContext(testContext, viewComponentContext);
 }
 public static ViewComponentContextMock FromViewContext(HttpTestContext testContext, ViewContext viewContext)
     => FromViewComponentContext(testContext, new ViewComponentContext { ViewContext = viewContext });
Ejemplo n.º 22
0
 public static ViewContext Default(HttpTestContext testContext)
 => FromViewContext(testContext, new ViewContext());
 internal static IMockedMemoryCache GetMockedMemoryCache(this HttpTestContext testContext)
 => testContext.GetMemoryCache().AsMockedMemoryCache();
 public static ControllerContext Default(HttpTestContext testContext)
     => FromActionContext(testContext, new ActionContext());
 public static ViewContext Default(HttpTestContext testContext)
     => FromViewContext(testContext, new ViewContext());
 public static ViewComponentContextMock FromViewContext(HttpTestContext testContext, ViewContext viewContext)
 => FromViewComponentContext(testContext, new ViewComponentContext {
     ViewContext = viewContext
 });
Ejemplo n.º 27
0
 private MockedControllerContext(HttpTestContext testContext, ActionContext actionContext)
     : base(actionContext)
 {
     this.PrepareControllerContext(testContext);
 }
 public static ControllerContext Default(HttpTestContext testContext)
 => FromActionContext(testContext, new ActionContext());
Ejemplo n.º 29
0
 public MockedControllerContext(HttpTestContext testContext)
 {
     this.PrepareControllerContext(testContext);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="HttpTestContext"/> containing data about the currently executed assertion chain.</param>
 protected BaseTestBuilder(HttpTestContext testContext)
 {
     TestCounter.IncrementAndValidate();
     this.TestContext = testContext;
 }
 private ViewComponentContextMock(HttpTestContext testContext, ViewComponentContext viewComponentContext)
 {
     this.PrepareViewComponentContext(testContext, viewComponentContext);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ShouldPassForTestBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="HttpTestContext"/> containing data about the currently executed assertion chain.</param>
 public ShouldPassForTestBuilder(HttpTestContext testContext)
 {
     CommonValidator.CheckForNullReference(testContext, nameof(HttpTestContext));
     this.testContext = testContext;
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OptionsBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="HttpTestContext"/> containing data about the currently executed assertion chain.</param>
 public OptionsBuilder(HttpTestContext testContext)
     : base(testContext)
 {
 }
 public static IMemoryCache GetMemoryCache(this HttpTestContext testContext)
 => testContext.HttpContext.RequestServices.GetService <IMemoryCache>();
 /// <summary>
 /// Initializes a new instance of the <see cref="DbContextBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="HttpTestContext"/> containing data about the currently executed assertion chain.</param>
 public DbContextBuilder(HttpTestContext testContext)
     : base(testContext)
 {
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WithoutDbContextBuilder"/> class.
 /// </summary>
 /// <param name="testContext"><see cref="HttpTestContext"/> containing data about the currently executed assertion chain.</param>
 public WithoutDbContextBuilder(HttpTestContext testContext)
     : base(testContext)
 {
 }