Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 363943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:23:27+00:00 2026-05-12T13:23:27+00:00

I have the override below to do a few things with cookies using the

  • 0

I have the override below to do a few things with cookies using the FormsIdentity Object. But when I instantiate a controller on my Unit Testing this method is not triggered. Any ideas how to do this?

   protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        base.Initialize(requestContext);

        // Grab the user's login information from FormsAuth
        _userState = new UserState();
        if (this.User.Identity != null && this.User.Identity is FormsIdentity)
            this._userState.FromString(((FormsIdentity)this.User.Identity).Ticket.UserData);

        // have to explicitly add this so Master can see untyped value
        this.UserState = _userState;
        //this.ViewData["ErrorDisplay"] = this.ErrorDisplay;

        // custom views should also add these as properties
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:23:27+00:00Added an answer on May 12, 2026 at 1:23 pm

    Controller.Initialize(RequestContext) is invoked inside ControllerBase.Execute(RequestContext), which in turn can be invoked by the explicit implementation of IController.Execute(RequestContext), so this code will initialize and execute a controller:

    IController controller = new TestController();
    controller.Execute(requestContext);

    I’ve analyzed the dependency tree for Initialize() and I can’t see any other way of invoking this method without resorting to Reflection. You will need to create the RequestContext passed to Execute() as well, which is easier as it looks like you are using Moq:

    var wrapper = new HttpContextWrapper(httpContext);
    var requestContext = new RequestContext(wrapper, new RouteData());
    

    This link has helpful details on mocking an HttpContext using Moq.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a function, a() , that I want to override, but also have
Edit: original question below, but I revise it now that I have some code
UPDATE - No need to answer this now, I have solved below. Hi, I'm
I have a C# WinForms borderless window, for which I override WndProc and handle
I have a base class with a virtual method, and multiple subclasses that override
I have a base recipe class and I am using a datacontext. I overrode
Have just started using Google Chrome , and noticed in parts of our site,
Short Version This query works in the database but fails with Linq To NHibernate.
I have a few questions (so far) with the the LocationManager on Android and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.