PrivateHelper is a library intended for unit test purposes to allow access to private properties. This allows for a clean public interface, while allowing unit tests to get to internal values via private properties.
Initial Version - supports private properties
DOWNLOADS TBD NUGET TBD
Install the package from nuget.org TBD
Install-Package PrivateHelperExample Code Project
public interface ITestClass
{
int GetValue();
void SetValue(int value);
}
public class TestClass : ITestClass
{
private int _value;
public int GetValue()
{
return _value;
}
public void SetValue(int value)
{
_value = value;
}
// For Unit Tests...
private int Value
{
get { return _value; }
set { _value = value; }
}
}
In your unit test project
using UnitTestHelper;
[Fact]
public void SetTest()
{
int testValue = 23;
ITestClass instance = new TestClass();
PrivateHelper.SetProperty(instance, "Value", testValue);
Assert.Equal(testValue, instance.GetValue());
}
[Fact]
public void Test2()
{
int testValue = 56;
ITestClass instance = new TestClass();
instance.SetValue(testValue);
Assert.Equal(testValue, (int)PrivateHelper.GetProperty(instance, "Value"));
}