Unit testing C# protected methods

You can inherit the class you are testing on your test class.

[TestClass]
public class Test1 : SomeClass
{
    [TestMethod]
    public void MyTest
    {
        Assert.AreEqual(1, ProtectedMethod());
    }

}

Another option is to use internal for these methods and then use InternalsVisibleTo to allow your test assembly to access these methods. This does not stop the methods being consumed by other classes in the same assembly, but it does stop them being accessed by other assembles that are not your test assembly.

This does not give you as much encapsulation and protection but it's pretty straight forward and can be useful.

Add to AssemblyInfo.cs in the assembly containing the internal methods

[assembly: InternalsVisibleTo("TestsAssembly")]

You can expose the protected methods in a new class that inherits the class you want to test.

public class ExposedClassToTest : ClassToTest
{
    public bool ExposedProtectedMethod(int parameter)
    {
        return base.ProtectedMethod(parameter);
    }
}