0

so I'm currently creating a unit test for a class that I've implemented a few weeks ago. I'll show you first the particular part of the class where I'm working on.

public void PostEvent(eVtCompId inSenderComponentId, eVtEvtId inEventId, long inEventReference, IF_SerializableData inEventData)
        {
            if(mEventMap.ContainsKey(inEventId))
            {
                mEventMap[inEventId](inSenderComponentId, inEventReference, inEventData);
            }
        }

For this method, I have 4 parameters. 1st, an enum; 2nd, another enum; 3rd, long; 4th, an interface.

Assume that I have declared/coded all the proper enums and interface required for this method to work. This next bit right here is part of the unit test code.

target.PostEvent(eVtCompId.MainWindowsCommDevice, eVtEvtId.OnLanguageChange, 3, );

as you can see, I don't have anything yet for the last argument, because I don't know what value I should set for the interface. Any ideas? Please feel free to ask questions if you think more information is required, I'd be glad to do my best to clear things up.

Anthony
  • 437
  • 2
  • 8
  • 18

1 Answers1

2

Use mocking framework (RhinoMock, Moq,...) and mock the interface. Moq sample below:

var serializable = new Mock<IF_SerializableData>();
target.PostEvent(..., serializable.Object);

Or you can manually implement interface i.e. on local class in the test.

class MySerializable : IF_SerializableData {...}

target.PostEvent(..., new MySerializable());
Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • thank you very much. I just needed a "filler" for it since it's just a test. I've manually implemented the interface, the test runs now with no problems ^^ – Anthony Dec 01 '12 at 02:50