Reply to comment

Your reply

You need to sign up / log in to reply to this comment

Existing comment

Don't do this in unit testing. Sure, you can but you really shouldn't. If Name has a private setter, and you have access to the code for that class, then it should be set inside the class it belongs.

Instead, identify where the property is being set and perform assignment there. If the name is coming from a database or file, for example, then inject that dependency and mock the part of that dependency that returns the name.

Or... mock the object.

Let the class worry about its internals. Setting the name could trigger some other processes to run. Purely as a demonstration for reflection, however, no problem.

:)

Thanks for commenting

Please remember:
Be polite, helpful and keep a positive attitude
Keep it short
Use examples
Review spelling and grammar

Please avoid:
Long texts
Code that is untested
Wall of text