views:

167

answers:

2

I am having issues mocking an array with Rhino Mock, any direction would be great.

namespace Checks_Rhino_Mocks
{
    public class Check
    {
        public Header header;
        public Detail[] details;
    }

    public class Header
    {
        public string Number;
        public decimal Amount;
    }

    public class Detail
    {
        public string Id;
    }


    [TestFixture]
    public class CheckUT
    {
        [Test]
        public void CheckShouldHaveMultipleDetails()
        {
            MockRepository mock = new MockRepository();

            Check check = mock.StrictMock<Check>();
            check.header = mock.StrictMock<Header>();
            //issue
            check.details = mock.StrictMock<Detail[]>();
        }
    }
}
A: 

When creating the check details, you will probably have to do it with IEnumerable:

check.details = mock.StrictMock<IEnumerable<Detail>>();

instead of an array...

Chris Missal
A: 

You can't mock Check.details because it's not virtual. RhinoMocks, Moq, etc, can't mock non-virtual methods.

To solve this, make the field virtual:

public class Check
{
    public virtual Header header;
    public virtual Detail[] details;
}

But...and here's the real point: why are you trying to mock a Detail array? What are you trying to do, exactly? Explain what you're trying to do and we'll be able to really help you.

Judah Himango