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 8947093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:39:52+00:00 2026-06-15T12:39:52+00:00

Moq Code: mockControllerContext.SetupGet(x => x.HttpContext.Session[User]).Returns(new User { Name = Moto, IsAdmin = true });

  • 0

Moq Code:

mockControllerContext.SetupGet(x => x.HttpContext.Session["User"]).Returns(new User
{
    Name = "Moto", 
    IsAdmin = true                                                                                        
});
taskController.ControllerContext = mockControllerContext.Object;

How can i use MS Fakes to Mock HttpContext.Session???

  • 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-06-15T12:39:53+00:00Added an answer on June 15, 2026 at 12:39 pm

    You can use shims for that with Microsoft Fakes. However, I find this to be a bad practice. Instead you should isolate yourself from third party libraries by wrapping them in your own class. Then you can put an interface on that class and use your interface throughout your code. This anti-corruption layer allows you to shield yourself from third party assemblies and you are less affected when the third party assembly changes.

    If you want to learn more about using shims, you can checkout this Pluralsight course I authored on Microsoft Fakes. (Full disclosure: I get royalties on this course, but it is a quick way to get up to speed)

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

Sidebar

Related Questions

With the following code (using Moq 4.0.10501.6): HomeController controller = new HomeController(); ActionResult result
i have the following code, which fails during runtime... var mock = new Mock<ControllerContext>();
I have been writing unit tests using NUnit and Moq with my Silverlight code
I am new to Moq, so hopefully I am just missing something here. For
I am new to use moq. I am into creating some unit test case
Can someone please help? I use Google code’s Moq framework for mocking within my
I am using Moq as my mocking framework. As per the code below, I
I've read through some of the discussions on the Moq user group and have
I'm using Entity Frameworc 4.1 Code First and Moq . And I want to
I'm trying to use an IHTMLSelectElement with Moq. My code is something like: //

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.