I started using the dynamic private access feature, which is part of the nuget Chain package for MSTest , and I am very pleased with it. One loses strong typing, but at least the syntax is still readable. This works with a dynamic function. There are also packages for other testing systems. The verification code is as follows:
var target = CreateMyObjectUnderTest(); dynamic dynamicTarget = target.AsDynamic(); Assert.AreEqual("abc", dynamicTarget.MyPrivateProperty); Assert.AreEqual("xyz", dynamicTarget.PrivateMethod(123));
source share