I am using TypeMock for the first time, and am trying to mock an instance of the .Net SerialPort class for a listener i am writing. However when i add a handler to the SerialPort.DataReceived event, my tests are still failing when the event is fired (stating there are no handlers attached to the event). Below is my code:
Mock<SerialPort> mock;
IRfidListener listener;
[TestFixtureSetUp]
public void Setup()
{
mock = MockManager.MockObject<SerialPort>();
mock.ExpectGet("IsOpen", true);
listener = new ComPortListener(mock.MockedInstance);
}
[Test]
public void Start_attaches_to_port_DataReceived_event()
{
MockedEvent dataReceived = mock.ExpectAddEvent("DataReceived");
listener.Start();
dataReceived.Fire(this, EventArgs.Empty);
}