Skip to content
LosManos edited this page Jul 16, 2019 · 4 revisions

CompulsoryCow.ReachIn

ReachIn

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);
}
Clone this wiki locally