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

  • Home
  • SEARCH
  • 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 6099657
In Process

The Archive Base Latest Questions

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

I’m trying to write some tests for an MVC application we’re developing. We have

  • 0

I’m trying to write some tests for an MVC application we’re developing. We have a BaseController class that contains the following:

public class BaseController : Controller
{
    protected string UserRole { get; private set; }

We then have a controller that inherits from the BaseController:

public class CustomFieldController : BaseController

I’ve generated private accessors for both classes (just regenerated them a few minutes ago). In one of my unit tests for CustomFieldController I want to set the UserRole, so I’ve got the following code:

CustomFieldController controller = new CustomFieldController();
CustomFieldController_Accessor accessor = new CustomFieldController_Accessor( 
    new PrivateObject( controller, new PrivateType( typeof( BaseController ) ) ) );

accessor.UserRole = "OTHER";

Every time I try to run this test it throws an exception on the last line stating:

The member specified (CustomFieldEdit) could not be found. You might need to regenerate your private accessor, or the member may be private and defined on a base class. If the latter is true, you need to pass the type that defines the member into PrivateObject’s constructor.

As far as I can tell, I’ve done what it says. Not only have I recently regenerated the private accessor, but I am passing the type that defines the member into PrivateObject’s constructor.

Any thoughts as to what I’m missing here? I know I can make it work by taking the “private” off the property setter, but I’d rather not do that if I can avoid it (don’t want subclass implementers thinking they can inject a value into that property).

  • 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-23T13:17:53+00:00Added an answer on May 23, 2026 at 1:17 pm


    CustomFieldController controller = new CustomFieldController();
    var po = new PrivateObject( controller, new PrivateType( typeof( BaseController ) ) );
    CustomFieldController_Accessor accessor = new CustomFieldController_Accessor( po );

    po.SetFieldOrProperty("UserRole","OTHER");
    

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... 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.