Unit test protected methods using Rhino mocks

If your method is in a different assembly then you need to allow access to your own assembly (e.g MyAssembly) and e.g. Rhino mocks () or whatever you use for mocking

you can do so:

[assembly: InternalsVisibleTo("MyAssembly")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

then your unit test would look something like this:

public void TestMethod1()
    var txt = "testdata";
    var rawRequestProcessor = MockRepository.GenerateStub<RawRequestProcessor>();
    Assert.AreEqual(txt, rawRequestProcessor.RawInput);
    rawRequestProcessor.Expect(m => m.processInput());

example of the code being tested here:

public class RawRequestProcessor
    public void Process(string txt)
        RawInput = txt;

    private string _rawInput;
    public string RawInput {
        get { return _rawInput; }
            _rawInput = value;

    internal virtual void processInput()



What's your thoughts on this?


Protected by WP Anti Spam