-
Notifications
You must be signed in to change notification settings - Fork 0
ReachIn
LosManos edited this page Apr 25, 2021
·
4 revisions
Makes it easy to call private (and protected) methods, fields and properties.
There are certain times the scope (private, public etc.) for a member (field, property, method) or class is a hindrance.
This dynamic class makes it possible to manipulate private fields, properties and methods by just writing normal code. Typically used for unit testing.
[TestMethod]
public void Customer_given_KnownID_should_HaveIDFlagSet()
{
// Arrange.
var sut = new Customer{);
dynamic sutPrivate = new ReachIn(typeof(Customer));
sutPrivate.id = 12; // id is a private variable and not reachable by "normal" code.
// Act.
var res = sut.HasID();
// Assert.
Assert.IsTrue(res);
}