Skip to content
LosManos edited this page Apr 25, 2021 · 4 revisions

CompulsoryCow.ReachIn

Does

Makes it easy to call private (and protected) methods, fields and properties.

The problem solved

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);
}

Code

ReachIn

Clone this wiki locally