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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:48:50+00:00 2026-06-03T01:48:50+00:00

Background : We are using MVC4 and using WIF for Claims/Authorization. We are using

  • 0

Background : We are using MVC4 and using WIF for Claims/Authorization. We are using Moq/MvcContrib for Mockup Objects. I have looked here and created the MockIdentity and MockPrincipal Objects – do I need them?

Goal : I have a controller class that has a class level attribute that only allows users with ‘Manager’ claim to access the actions. I want to create mock users and test to see if anyone that doesn’t have ‘Manager’ claim can access the actions or not.

I get the mock concept but I have only dealt with the data objects mocking and having a tough time figuring out what plugins/classes/methods/setups I need in place to do what I need to do.

Thanks in advance.

  • 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-03T01:48:51+00:00Added an answer on June 3, 2026 at 1:48 am

    I want to create mock users and test to see if anyone that doesn’t have ‘Manager’ claim can access the actions or not.

    No, you don’t. You just want to pass users to that attribute you wrote and test that sets the filterContext.Result correctly. That’s it. You don’t need to test that System.Web.Mvc works. Single unit under test!

    Presumably your attribute is an AuthorizeAttribute, correct? So you need to test OnAuthorization(AuthorizationContext).

    Disclaimer: I haven’t used moq in a while, but your code would presumably look generally like this:

    var user = new Mock<IPrincipal>();
    user.Setup(/* whatever you need to look at */);
    
    var authContext = new Mock<AuthorizationContext>();
    authContext.Setup(ac => ac.HttpContext.User).Returns(user);
    
    var myAttribute = new RequireManagerAttribute();
    myAttribute.OnAuthorization(authContext);
    
    authContext.VerifySet(ac => ac.Result = /* whatever you expect */);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have given a table background image using css background-image property. The cells are
Is it possible to have transparent background image using CSS3? background: url(../img/bg_paperlines.jpg) repeat-x; Using
I am from DW/BI background using SAS for many years now I have task
I have a project which downloads images in background using NSOperationQueue . It was
I have created plugin for background service (to run the application in background) in
Is it possible to have the camera running in the background (using multitasking) and
i have 3 navigation controller and i want to change each background using different
How to change image resolution using jQuery.I have applied a image on body background
I have a song playing continuously in background using an Android MediaPlayer , by
I have followed an online tut to get a full-size background using an inline

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.