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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:41:43+00:00 2026-06-07T11:41:43+00:00

i am trying to test this method: [Test] public void Test_GetReferenceValue() { Person person=

  • 0

i am trying to test this method:

[Test]
public void Test_GetReferenceValue()
{
  Person person= new Person() { Name = "PJ" };
  PersonalProperty<Person> personalProperty = new PersonalProperty<Person>();
  var result = personalProperty.GetReferenceValue(person);
  Assert.AreEqual("PJ", result);
}

the method GetReferenceValue has the following implementation:

public override object GetReferenceValue(TOwner owner)
{
    Person value = this.Accessor(owner);

    if (value == null)
        return null;
    else
        return value.Name;
}

i tried to find the origin of the Accessor property, and i found it in ANOTHER assembly:

public class PersonalProperty<TOwner> : Property<TOwner, Person>
where TOwner : class
{
  public virtual Func<TOwner, TProperty> Accessor { get; internal set; }
}

my test above will run perfectly if only i can put the code in my test:

   personalProperty.Accessor = p =>p;

this is to put a definition/method for the Func delegate.. however, i cant do this because Accessor is internally set. Meaning, i cant set it if i am in an another assembly (which i am right now). i cant friend the Accessor’s assembly because i am not allowed to change any code. i am only allowed to create a test in an another project/assembly.

so how am i going to test GetReferenceValue? can reflection help?

  • 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-07T11:41:45+00:00Added an answer on June 7, 2026 at 11:41 am

    Yes, you can do it using reflection. This function can set property value ignoring setter access modifier:

    public static void SetPropertyValue(object instance, string property, object value)
    {
        instance.GetType().GetProperty(property).SetValue(instance, value, null);
    }
    

    Usage:

    Func<Person, Person> accessor = p => p;
    SetPropertyValue(personalProperty, "Accessor", accessor);
    

    Anyway, it is an indicator that something might be wrong with PersonalProperty<T> class design.

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

Sidebar

Related Questions

This fails with an ObjectDisposedException when trying to assert: [Test] public void Resolve_SingletonAndDisposeChildContainer_ShouldNotDisposeSingleton() {
I'm trying to write a method like this: public static T Test<T>() { if
I'm trying to write a test for this class its called Receiver : public
I'm trying to unit test, using VS unit testing facility following method. void Get(string
I'm trying to figure out the best way to unit test this class: public
I'm trying to write a test for the following method: public class Sort {
I'm trying to test a simple search method in twitter4j. My code is public
I'm trying to use a method group in a lambda expression, like this: public
just trying to test for equality in this piece of code, but getting a
I'm trying to test the first answer to this question: SQL - message schema

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.